Example code to do an action based on a received SMS. WARNING: this code has been written in a hurry during an hackathon. It's total crap.

Dependencies:   GPS_CanSat_gen mbed

Example code to do an action based on a received SMS. WARNING: this code has been written in a hurry during an hackathon. It's total crap.

Files at this revision

API Documentation at this revision

Comitter:
gipmad
Date:
Sat Sep 19 14:44:20 2015 +0000
Commit message:
-;

Changed in this revision

GPS_CanSat.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GPS_CanSat.lib	Sat Sep 19 14:44:20 2015 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/gipmad/code/GPS_CanSat_gen/#a944bfff56da
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Sep 19 14:44:20 2015 +0000
@@ -0,0 +1,156 @@
+#include "mbed.h"
+#include "GPS.h"
+//#include "gsm.h"
+  
+ Serial pc(SERIAL_TX, SERIAL_RX);
+ //v0.2
+ Serial GSM(PC_10, PC_11);
+ GPS g1(PB_6, PB_7);
+ 
+DigitalOut myled(PB_2);
+DigitalOut GSMsw(PA_15);
+
+DigitalOut DET(PB_13);
+ 
+ 
+float LAT;
+float LON;
+
+
+int flag_gsm_get = 0;
+int flag_gsm_getend = 0;
+int count = 0;
+char msg[128];
+
+void getline() {
+    char temp;
+    temp = GSM.getc();
+    
+    pc.putc(temp);
+    
+    if((temp == '+') || (temp == 'D')){
+        flag_gsm_get = 1;
+        count = 0;
+    }
+    if(flag_gsm_get)
+    {
+    //    pc.printf(".%d%c.",count,temp);
+        
+        msg[count] = temp;
+        if(temp == '\r'){
+            msg[count] = '\0';
+            flag_gsm_getend = 1;
+            //pc.printf(".%s.",msg);
+            flag_gsm_get = 0;
+        }
+        count ++;
+    }
+}
+
+int SMSid = -1;
+int Bum = 0;
+void GSMin() {    
+    getline();
+    if(flag_gsm_getend == 1)
+    {
+        if(sscanf(msg, "+CMTI: \"SM\",%d", &SMSid) >= 1) {
+                pc.printf("Got SMS! ID: %d\n", SMSid);
+        }
+        else if(strstr(msg, "DETONATE") != NULL) {
+                pc.printf("Scoppia!\n");
+                Bum = 55;
+        }
+        flag_gsm_getend = 0;
+    }
+}
+
+int main() {
+  
+  DET = 0;
+  
+ /*while(1)
+  {
+            DET = 1;
+            wait(5);
+            DET = 0;
+            wait(1);
+}
+  */
+  
+  
+  pc.baud(115200);
+  //GPS.baud(9600);
+  GSM.baud(115200);
+  GSM.attach(&GSMin);
+      
+  int i = 1;
+  pc.printf("Hello World !\n");
+  
+  ///INIT
+  myled = 1;
+  GSMsw = 1;
+  wait(15);
+  myled = 0; 
+  
+  pc.printf("ON\n");
+  
+  //init
+  GSM.printf("AT+CMGF=1\n");
+    wait(1);
+
+ while(1) { 
+
+      //if(GSM.readable())
+       // pc.putc(GSM.getc());
+      if(pc.readable())
+        GSM.putc(pc.getc());
+       
+       if(SMSid != -1)
+       {
+            GSM.printf("AT+CMGR=%d\n",SMSid);
+            wait(1);
+            GSM.printf("AT+CMGD=%d\n",SMSid);
+            wait(1);
+            SMSid = -1;
+        }
+        
+        if(Bum == 55)
+        {
+            pc.printf("DETON ON\n");
+            myled = 1;
+            DET = 1;
+            wait(10);
+            DET = 0;
+            myled = 0;
+            Bum = 0;
+        }
+      /*if(GPS.readable())
+        pc.putc(GPS.getc());
+      if(pc.readable())
+        GPS.putc(pc.getc());*/
+       
+
+      /*wait(1);
+      
+      pc.printf("ns: %d\r\n", g1.ns());
+      pc.printf("ew: %d\r\n", g1.ew());
+      pc.printf("lock: %d\r\n", g1.lock());
+      pc.printf("t: %f\r\n", g1.time());
+      
+      if(g1.lock() == 0)
+      {
+          pc.printf("No fix; faking it...\r\n");
+          LAT = 45.564411;
+          LON = 12.428018;
+      }
+      else
+      {
+          LAT = g1.latitude();
+          LON = g1.longitude();
+      }
+      
+      pc.printf("lat: %f\r\n", LAT);
+      pc.printf("lon: %f\r\n", LON);*/
+  }
+}
+ 
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Sep 19 14:44:20 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/da0ca467f8b5
\ No newline at end of file