Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <GSM.h>
- #define PINNUMBER ""
- GSM gsmAccess;
- GSM_SMS sms;
- int thresholds;
- int lightThresholds;
- int tempMIN;
- int tempMAX;
- int lightMIN;
- int lightMAX;
- char senderNumber[20];
- char remoteNum[20] = "+48723999962";
- String txtMenu = "1 - Currently temperature| 2 - set MIN, MAX temperature| 3 - ";
- String error = "Something is wrong Senior !";
- void setup() {
- Serial.begin(9600);
- while (!Serial) {
- }
- Serial.println(" Welcome in heating mobile remote");
- Serial.println(" Checking connection of GSM signal...");
- // connection state
- boolean notConnected = true;
- // Start GSM connection
- while (notConnected) {
- if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
- notConnected = false;
- } else {
- Serial.println("Not connected");
- delay(1000);
- }
- }
- Serial.println(" Authorization has been successful");
- sendMenu();
- }
- void loop() {
- char menu[4];
- String msg = "";
- int tempMIN, tempMAX;
- if (sms.available()) {
- Serial.println("Message received from:");
- sms.remoteNumber(senderNumber, 20);
- Serial.println(senderNumber);
- if (sms.peek() == '#') {
- Serial.println("Discarded SMS");
- sms.flush();
- }
- while (char tmp = sms.read()) {
- msg += tmp;
- }
- Serial.println(msg);
- msg.toCharArray(menu, 4);
- switch (menu[0]) {
- case '1':
- Serial.println("Send cur temp");
- break;
- case '2':
- int mintmp ;
- int maxtmp;
- mintmp = msg.substring(2, 4).toInt();
- maxtmp = msg.substring(5, 7).toInt();
- if (mintmp < maxtmp && mintmp > 0 && maxtmp > 0) {
- tempMIN = mintmp;
- tempMAX = maxtmp;
- } else {
- SmsError();
- }
- break;
- case '3':
- thresholds = msg.substring(2, 4).toInt();
- default:
- Serial.println("Wrong Command");
- break;
- }
- // Delete message from modem memory
- sms.flush();
- Serial.println("MESSAGE DELETED");
- }
- delay(1000);
- }
- int settemp(int x, int y) {
- }
- int SendTemp() {
- sms.beginSMS(remoteNum);
- sms.print(txtMenu);
- sms.endSMS();
- Serial.print("end ");
- }
- void sendMenu() {
- sms.beginSMS(remoteNum);
- sms.print(txtMenu);
- sms.endSMS();
- Serial.print("end ");
- }
- void SmsError() {
- sms.beginSMS(remoteNum);
- sms.print(error);
- sms.endSMS();
- Serial.print("end ");
- }
- int readSerial(char result[]) {
- int i = 0;
- while (1) {
- while (Serial.available() > 0) {
- char inChar = Serial.read();
- if (inChar == '\n') {
- result[i] = '\0';
- Serial.flush();
- return 0;
- }
- if (inChar != '\r') {
- result[i] = inChar;
- i++;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement