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.
main.cpp
00001 #include "mbed.h" 00002 #include "GPS.h" 00003 //#include "gsm.h" 00004 //#include "modem.h" 00005 00006 Serial pc(SERIAL_TX, SERIAL_RX); 00007 //v0.2 00008 Serial GSM(PC_10, PC_11); 00009 // Serial GPS(PB_6, PB_7); 00010 GPS g1(PB_6, PB_7); 00011 //Modem gsm1(PC_10, PC_11, 115200); 00012 00013 //v0.1 00014 //Serial GPS(PC_10, PC_11); 00015 //Serial GSM(PA_14, PA_15); 00016 00017 //breadboard 00018 //Serial GSM(PB_6, PB_7); 00019 //Serial GPS(PC_4, PC_5); 00020 00021 //GPS g1(PC_10, PC_11); 00022 00023 //DigitalIn mybutton(USER_BUTTON); 00024 DigitalOut myled(PB_2); 00025 DigitalOut GSMsw(PA_15); 00026 00027 DigitalOut DET(PB_13); 00028 /* 00029 int main() { 00030 while(1) { 00031 if (mybutton == 0) { // Button is pressed 00032 myled = !myled; // Toggle the LED state 00033 wait(0.2); // 200 ms 00034 } 00035 } 00036 } 00037 */ 00038 00039 00040 int main() { 00041 00042 DET = 0; 00043 00044 pc.baud(115200); 00045 //GPS.baud(9600); 00046 GSM.baud(115200); 00047 00048 int i = 1; 00049 pc.printf("Hello World !\n"); 00050 00051 00052 ///INIT 00053 myled = 1; 00054 GSMsw = 1; 00055 wait(1); 00056 myled = 0; 00057 00058 pc.printf("ON\n"); 00059 00060 float LAT; 00061 float LON; 00062 00063 /*if(gsm1.sendCmdAndWaitForResp("AT+CMGF=1\r\n","OK",DEFAULT_TIMEOUT,CMD) == 0) pc.printf("bea!\r\n"); else pc.printf("Err\r\n"); 00064 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"); 00065 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"); 00066 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"); 00067 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"); 00068 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"); 00069 if(gsm1.sendCmdAndWaitForResp("AT+HTTPINIT\r\n","OK",DEFAULT_TIMEOUT,CMD) == 0) pc.printf("bea!\r\n"); else pc.printf("Err\r\n"); 00070 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"); 00071 */ 00072 while(1) { 00073 00074 /*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"); 00075 if(gsm1.sendCmdAndWaitForResp("AT+HTTPACTION=0\r\n","OK",DEFAULT_TIMEOUT,CMD) == 0) pc.printf("bea!\r\n"); else pc.printf("Err\r\n"); 00076 00077 //if(gsm1.sendCmdAndWaitForResp("AT\r\n","OK",DEFAULT_TIMEOUT,CMD) == 0) pc.printf("bea!\r\n"); else pc.printf("Err\r\n"); 00078 wait(1);*/ 00079 00080 00081 if(GSM.readable()) 00082 pc.putc(GSM.getc()); 00083 if(pc.readable()) 00084 GSM.putc(pc.getc()); 00085 00086 /*if(GPS.readable()) 00087 pc.putc(GPS.getc()); 00088 if(pc.readable()) 00089 GPS.putc(pc.getc());*/ 00090 00091 00092 /*wait(1); 00093 00094 pc.printf("ns: %d\r\n", g1.ns()); 00095 pc.printf("ew: %d\r\n", g1.ew()); 00096 pc.printf("lock: %d\r\n", g1.lock()); 00097 pc.printf("t: %f\r\n", g1.time()); 00098 00099 if(g1.lock() == 0) 00100 { 00101 pc.printf("No fix; faking it...\r\n"); 00102 LAT = 45.564411; 00103 LON = 12.428018; 00104 } 00105 else 00106 { 00107 LAT = g1.latitude(); 00108 LON = g1.longitude(); 00109 } 00110 00111 pc.printf("lat: %f\r\n", LAT); 00112 pc.printf("lon: %f\r\n", LON);*/ 00113 } 00114 } 00115
Generated on Sun Jul 17 2022 23:06:21 by 1.7.2