It consists of 3 serial ports, one for GPS, second for GSM and third for viewing what is going on. GPS longitude, latitude, north-south, east-west are extracted and send as an SMS to the number saved in the program and displayed on LCD. SMS is also retrieved and deleted

Dependencies:   Bus_Navigation GPS_HelloWorld TextLCD mbed

Fork of GPS_HelloWorld by Simon Ford

Files at this revision

API Documentation at this revision

Comitter:
josmy
Date:
Fri Oct 31 05:27:23 2014 +0000
Parent:
0:6b7345059afe
Commit message:
It consists of 3 serial ports, one for GPS, second for GSM and third for viewing what is going on. GPS latitude, longitude, north-south, east-westis extracted and send as an SMS to the number saved in the program and displayed on LCD.

Changed in this revision

GPS.lib Show annotated file Show diff for this revision Revisions of this file
GPS_HelloWorld.lib Show annotated file Show diff for this revision Revisions of this file
TextLCD.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
--- a/GPS.lib	Tue Jun 08 14:12:30 2010 +0000
+++ b/GPS.lib	Fri Oct 31 05:27:23 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/simon/code/GPS/#15611c7938a3
+http://developer.mbed.org/users/josmy/code/Bus_Navigation/#5c5177f8c0d8
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GPS_HelloWorld.lib	Fri Oct 31 05:27:23 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/GPS_HelloWorld/#6b7345059afe
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Fri Oct 31 05:27:23 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/TextLCD/#308d188a2d3a
--- a/main.cpp	Tue Jun 08 14:12:30 2010 +0000
+++ b/main.cpp	Fri Oct 31 05:27:23 2014 +0000
@@ -1,15 +1,200 @@
 #include "mbed.h"
 #include "GPS.h"
+#include "string.h"
+#include "TextLCD.h"
 
-Serial pc(USBTX, USBRX);
-GPS gps(p9, p10);
+
+TextLCD lcd(PB_3, PB_5, PB_4, PA_8, PC_7, PB_6); // rs, e, d4-d7
+
+//Serial pc(USBTX, USBRX);
+Serial pc(SERIAL_TX, SERIAL_RX);
+GPS gps(PA_9, PA_10);
+DigitalOut myled(LED1);
+Serial GSM(PB_10, PB_11);
+DigitalIn Mybutton(PC_13);
+char Mybuf[100];
+char buff[100];
+
+
+
+//global variables
+char comm[100];
+//char num[15]="+919920355869";
+char num[15]="+919820300951";
+int time1;
+int msg[100];
+int numb[20];
+int log1[20];
+int dm;
+
+
+int read_GSM()
+{
+    int i=0;
+    
+    while(1)
+    { 
+        comm[i]=GSM.getc();
+        if(comm[i]==10 && comm[i-1]==13 && comm[i-2]==75 && comm[i-3]==79)
+        {
+            return i;
+        }
+        pc.putc(comm[i]);
+        i++; 
+    }
+}
+
+void send_sms(char* text)
+{
+
+//    GSM.printf("AT+CMGS=\"+919820300951\"\r\n");
+    GSM.printf("AT+CMGS=\"+919920355869\"\r\n");
+
+//    GSM.printf("AT+CMGS=\"%s\"\r\n",num);
+    wait(1);
+
+    GSM.printf("Latitude:%f,%c,Longitude:%f,%c\r\n", gps.latitude,gps.ns, gps.longitude, gps.ew);
+    
+    wait(1);
+
+    GSM.putc(0x1A);
+    wait(1);
+//    dm=read_GSM();
+    sprintf(buff,"Lat:%f %c",gps.latitude,gps.ns);
+    lcd.locate(0,0);
+    lcd.printf(buff);
+    sprintf(buff,"Log:%f %c",gps.longitude, gps.ew);
+    lcd.locate(0,1);
+    lcd.printf(buff);
+
+    pc.printf("SMS Send");
+}
+
+void GPS_init(){
+    GSM.printf("AT+CGPSPWR=1\r");
+    dm=read_GSM();
+    pc.printf("GPS Power ON\n");
+    GSM.printf("AT+CGPSRST=1\r");
+    dm=read_GSM();
+    pc.printf("GPS Cold Reset\n");
+    GSM.printf("AT+CGPSIPR=9600\r");
+    dm=read_GSM();
+    pc.printf("GPS baud rate set\n");
+}    
 
+void GSM_init()
+{  
+    // check if GSM is fine
+    GSM.printf("AT\r");                     
+    dm=read_GSM();
+    //pc.printf("%s",comm);
+    //if(strcmp("OK",comm)==0)
+    pc.printf("GSM Working fine\n");
+    wait(1);
+    
+    //no echo
+    GSM.printf("ATE0\r");
+    dm=read_GSM();
+    pc.printf("Echo Switched off\n");
+    wait(1);
+    
+    //network reg
+    GSM.printf("AT+CREG?\r");
+    dm=read_GSM();
+    pc.printf("Network Registered\n"); 
+    wait(1);
+    //Service provider
+    pc.printf("\n Network Provider\n"); 
+    GSM.printf("AT+CGMI\r");
+    dm=read_GSM();
+    wait(1);
+ }
+ 
+void sms_init()
+{
+    GSM.printf("AT+CMGF=1\r");
+    dm=read_GSM();
+    pc.printf("GSM SMS set to Text Mode\n");
+    wait(0.5);
+    //delete all previous messages  
+    GSM.printf("AT+CMGDA=\"DEL ALL\"\r");
+    //pc.printf("AT+CMGDA=\"DEL ALL\"\r");
+
+    read_GSM();
+    pc.printf("All previous messages cleared");
+}
+ 
+void retrieve_sms()
+{ 
+    GSM.printf("AT+CMGR=1\r");
+    int i=0;
+    while(1)
+    {
+        comm[i]=GSM.getc();
+        if(comm[i]==10 && comm[i-1]==13 && comm[i-2]==75 && comm[i-3]==79)
+        break;
+        i++;
+    }
+    int len=i; 
+    int j=0;
+    // Get message
+    for(i=len-8;i>0;i--)
+    if(comm[i]==13 && comm[i+1]==10)
+    break;
+    pc.printf("Message retrieved is: ");
+    lcd.locate(0,0);
+    int k=0;
+    for(j=i+2;j<=len-8;j++)
+    { 
+        msg[k]=comm[j];
+        pc.putc(msg[k]);
+        lcd.putc(msg[k]);
+        k++; 
+    }
+    //sprintf(buff,"%d",msg);
+    //lcd.printf(buff);
+       
+    
+    //get Sender number
+    pc.printf("\n Message received from: ");
+    k=0;
+    for(i=24;i<=36;i++)
+    { 
+        num[k]=comm[i];  
+        pc.putc(num[k]);
+        k++;
+    }
+    GSM.printf("AT+CMGDA=\"DEL ALL\"\r");
+/*
+   
+    // Get Time
+    pc.printf("\n Message received at: ");
+    for(j=47;j<=54;j++) 
+    {
+        log1[k]=comm[j];
+        pc.putc(log1[k]);
+        k++;
+    }   
+*/
+}
 int main() {
+    GPS_init();
+    GSM_init();
+    sms_init();
+    
     while(1) {
-        if(gps.sample()) {
-            pc.printf("I'm at %f, %f\n", gps.longitude, gps.latitude);
+        retrieve_sms();
+        
+        myled=!myled;
+        if(gps.sample()){
+            pc.printf("\nLatitude: %f, %c, Longitude: %f, %c\n",  gps.latitude,gps.ns, gps.longitude, gps.ew);
+            if(Mybutton == 0){
+                sprintf(Mybuf,"Latitude:%f, %c, Longitude:%f, %c\r\n", gps.latitude,gps.ns, gps.longitude, gps.ew);
+                send_sms(Mybuf);    
+            }
+            
         } else {
-            pc.printf("Oh Dear! No lock :(\n");
+            pc.printf("No lock!\n");
         }
     }
 }
--- a/mbed.bld	Tue Jun 08 14:12:30 2010 +0000
+++ b/mbed.bld	Fri Oct 31 05:27:23 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/029aa53d7323
+http://mbed.org/users/mbed_official/code/mbed/builds/552587b429a1
\ No newline at end of file