Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.76 KB | None | 0 0
  1. #include <GSM.h>
  2.  
  3. #define PINNUMBER ""
  4.  
  5. GSM gsmAccess;
  6. GSM_SMS sms;
  7.  
  8. int thresholds;
  9. int lightThresholds;
  10. int tempMIN;
  11. int tempMAX;
  12. int lightMIN;
  13. int lightMAX;
  14. char senderNumber[20];
  15. char remoteNum[20] = "+48723999962";
  16. String txtMenu = "1 - Currently temperature| 2 - set MIN, MAX temperature| 3 -   ";
  17. String error = "Something is wrong Senior !";
  18.  
  19.  
  20. void setup() {
  21.   Serial.begin(9600);
  22.   while (!Serial) {
  23.   }
  24.  
  25.   Serial.println(" Welcome in heating mobile remote");
  26.   Serial.println(" Checking connection of GSM signal...");
  27.  
  28.   // connection state
  29.   boolean notConnected = true;
  30.  
  31.   // Start GSM connection
  32.   while (notConnected) {
  33.     if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
  34.       notConnected = false;
  35.     } else {
  36.       Serial.println("Not connected");
  37.       delay(1000);
  38.     }
  39.   }
  40.   Serial.println(" Authorization has been successful");
  41.   sendMenu();
  42. }
  43.  
  44. void loop() {
  45.   char menu[4];
  46.   String msg = "";
  47.   int tempMIN, tempMAX;
  48.   if (sms.available()) {
  49.     Serial.println("Message received from:");
  50.  
  51.     sms.remoteNumber(senderNumber, 20);
  52.     Serial.println(senderNumber);
  53.  
  54.     if (sms.peek() == '#') {
  55.       Serial.println("Discarded SMS");
  56.       sms.flush();
  57.     }
  58.  
  59.     while (char tmp = sms.read()) {
  60.       msg += tmp;
  61.     }
  62.     Serial.println(msg);
  63.  
  64.     msg.toCharArray(menu, 4);
  65.     switch (menu[0]) {
  66.       case '1':
  67.         Serial.println("Send cur temp");
  68.         break;
  69.       case '2':
  70.         int mintmp ;
  71.         int maxtmp;
  72.         mintmp = msg.substring(2, 4).toInt();
  73.         maxtmp = msg.substring(5, 7).toInt();
  74.  
  75.         if (mintmp < maxtmp && mintmp > 0 && maxtmp > 0) {
  76.           tempMIN = mintmp;
  77.           tempMAX = maxtmp;
  78.         } else {
  79.           SmsError();
  80.         }
  81.  
  82.  
  83.         break;
  84.       case '3':
  85.         thresholds = msg.substring(2, 4).toInt();
  86.       default:
  87.         Serial.println("Wrong Command");
  88.         break;
  89.     }
  90.  
  91.     // Delete message from modem memory
  92.     sms.flush();
  93.     Serial.println("MESSAGE DELETED");
  94.   }
  95.  
  96.   delay(1000);
  97.  
  98. }
  99.  
  100. int settemp(int x, int y) {
  101.  
  102.  
  103. }
  104.  
  105. int SendTemp() {
  106.   sms.beginSMS(remoteNum);
  107.   sms.print(txtMenu);
  108.   sms.endSMS();
  109.   Serial.print("end ");
  110. }
  111.  
  112.  
  113. void sendMenu() {
  114.  
  115.   sms.beginSMS(remoteNum);
  116.   sms.print(txtMenu);
  117.   sms.endSMS();
  118.   Serial.print("end ");
  119.  
  120.  
  121. }
  122.  
  123. void SmsError() {
  124.  
  125.   sms.beginSMS(remoteNum);
  126.   sms.print(error);
  127.   sms.endSMS();
  128.   Serial.print("end ");
  129.  
  130.  
  131. }
  132.  
  133.  
  134. int readSerial(char result[]) {
  135.   int i = 0;
  136.   while (1) {
  137.     while (Serial.available() > 0) {
  138.       char inChar = Serial.read();
  139.       if (inChar == '\n') {
  140.         result[i] = '\0';
  141.         Serial.flush();
  142.         return 0;
  143.       }
  144.       if (inChar != '\r') {
  145.         result[i] = inChar;
  146.         i++;
  147.       }
  148.     }
  149.   }
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement