Testing the module's internet connection (spoiler: it doesn't work) WARNING: this code has been written in a hurry during an hackathon. It's total crap.

Dependencies:   GPS_CanSat mbed

Testing the module's internet connection (spoiler: it doesn't work) WARNING: this code has been written in a hurry during an hackathon. It's total crap.

Revision:
0:8f9b472ff818
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Jul 11 20:48:40 2015 +0000
@@ -0,0 +1,115 @@
+#include "mbed.h"
+#include "GPS.h"
+//#include "gsm.h"
+//#include "modem.h"
+  
+ Serial pc(SERIAL_TX, SERIAL_RX);
+ //v0.2
+ Serial GSM(PC_10, PC_11);
+// Serial GPS(PB_6, PB_7);
+ GPS g1(PB_6, PB_7);
+ //Modem gsm1(PC_10, PC_11, 115200);
+ 
+ //v0.1
+ //Serial GPS(PC_10, PC_11);
+ //Serial GSM(PA_14, PA_15);
+ 
+//breadboard
+//Serial GSM(PB_6, PB_7);
+//Serial GPS(PC_4, PC_5);
+
+//GPS g1(PC_10, PC_11);
+
+//DigitalIn mybutton(USER_BUTTON);
+DigitalOut myled(PB_2);
+DigitalOut GSMsw(PA_15);
+
+DigitalOut DET(PB_13);
+ /*
+int main() {
+  while(1) {
+    if (mybutton == 0) { // Button is pressed
+      myled = !myled; // Toggle the LED state
+      wait(0.2); // 200 ms
+    }
+  }
+}
+ */
+ 
+
+int main() {
+  
+  DET = 0;
+  
+  pc.baud(115200);
+  //GPS.baud(9600);
+  GSM.baud(115200);
+  
+  int i = 1;
+  pc.printf("Hello World !\n");
+  
+  
+  ///INIT
+  myled = 1;
+  GSMsw = 1;
+  wait(1);
+  myled = 0; 
+  
+  pc.printf("ON\n");
+  
+float LAT;
+float LON;
+
+    /*if(gsm1.sendCmdAndWaitForResp("AT+CMGF=1\r\n","OK",DEFAULT_TIMEOUT,CMD) == 0)  pc.printf("bea!\r\n"); else pc.printf("Err\r\n");
+    if(gsm1.sendCmdAndWaitForResp("AT+SAPBR=3,1,\"APN\",\"mobile.vodafone.it\"\r\n","OK",DEFAULT_TIMEOUT,CMD) == 0)  pc.printf("bea!\r\n"); else pc.printf("Err\r\n");
+    if(gsm1.sendCmdAndWaitForResp("AT+SAPBR=3,1,\"USER\",\"\"\r\n","OK",DEFAULT_TIMEOUT,CMD) == 0)  pc.printf("bea!\r\n"); else pc.printf("Err\r\n");
+    if(gsm1.sendCmdAndWaitForResp("AT+SAPBR=3,1,\"PWD\",\"\"\r\n","OK",DEFAULT_TIMEOUT,CMD) == 0)  pc.printf("bea!\r\n"); else pc.printf("Err\r\n");
+    if(gsm1.sendCmdAndWaitForResp("AT+SAPBR=3,1,\"PHONENUM\",\"*99#\"\r\n","OK",DEFAULT_TIMEOUT,CMD) == 0)  pc.printf("bea!\r\n"); else pc.printf("Err\r\n");
+    if(gsm1.sendCmdAndWaitForResp("AT+SAPBR=1,1\r\n","OK",DEFAULT_TIMEOUT,CMD) == 0)  pc.printf("bea!\r\n"); else pc.printf("Err\r\n");
+   if(gsm1.sendCmdAndWaitForResp("AT+HTTPINIT\r\n","OK",DEFAULT_TIMEOUT,CMD) == 0)  pc.printf("bea!\r\n"); else pc.printf("Err\r\n");
+   if(gsm1.sendCmdAndWaitForResp("AT+HTTPPARA=\"CID\",1\r\n","OK",DEFAULT_TIMEOUT,CMD) == 0)  pc.printf("bea!\r\n"); else pc.printf("Err\r\n");       
+       */ 
+ while(1) { 
+
+    /*if(gsm1.sendCmdAndWaitForResp("AT+HTTPPARA=\"URL\",\"http://www.mastrogippo.it/b/conta.php\"\r\n","OK",DEFAULT_TIMEOUT,CMD) == 0)  pc.printf("bea!\r\n"); else pc.printf("Err\r\n");
+    if(gsm1.sendCmdAndWaitForResp("AT+HTTPACTION=0\r\n","OK",DEFAULT_TIMEOUT,CMD) == 0)  pc.printf("bea!\r\n"); else pc.printf("Err\r\n");
+
+    //if(gsm1.sendCmdAndWaitForResp("AT\r\n","OK",DEFAULT_TIMEOUT,CMD) == 0) pc.printf("bea!\r\n"); else pc.printf("Err\r\n");
+    wait(1);*/
+    
+  
+      if(GSM.readable())
+        pc.putc(GSM.getc());
+      if(pc.readable())
+        GSM.putc(pc.getc());
+       
+      /*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