EMS_Final_5/11/13 (HVM here)

Dependencies:   mbed TextLCD

Fork of 4_LCD_With_Lib by Harish Mekali

Committer:
prathapbmsce
Date:
Mon Nov 04 22:25:41 2013 +0000
Revision:
2:1a5d54f3d818
Parent:
1:71e371ba55cd
EMS_Final_5/11/13

Who changed what in which revision?

UserRevisionLine numberNew contents of line
HarishMekali 0:15a70393058f 1 #include "mbed.h"
HarishMekali 0:15a70393058f 2 #include "TextLCD.h"
prathapbmsce 2:1a5d54f3d818 3
prathapbmsce 2:1a5d54f3d818 4 AnalogIn sm1(p18);
prathapbmsce 2:1a5d54f3d818 5 DigitalOut relay(p30);
prathapbmsce 2:1a5d54f3d818 6
prathapbmsce 2:1a5d54f3d818 7 Serial GPRS(p9,p10);
prathapbmsce 2:1a5d54f3d818 8 Serial pc(USBTX, USBRX); // tx, rx
HarishMekali 0:15a70393058f 9
prathapbmsce 2:1a5d54f3d818 10 TextLCD lcd(p26, p25, p24, p23, p22, p21); // rs, e, d4, d5, d6, d7
prathapbmsce 2:1a5d54f3d818 11
prathapbmsce 2:1a5d54f3d818 12 LocalFileSystem local("local");
prathapbmsce 2:1a5d54f3d818 13
prathapbmsce 2:1a5d54f3d818 14 char z=0x1A,e=0x22,c=0x0d; // ASCII equivalent of 0X22 is "(Double invited coma)
prathapbmsce 2:1a5d54f3d818 15 char num[]="9535811293"; // Mobile phone number to which emergancy information has to be delivered
HarishMekali 0:15a70393058f 16
HarishMekali 0:15a70393058f 17 int main()
HarishMekali 0:15a70393058f 18 {
prathapbmsce 2:1a5d54f3d818 19 float a,m;
prathapbmsce 2:1a5d54f3d818 20 int b=100,time=0;
prathapbmsce 2:1a5d54f3d818 21
HarishMekali 1:71e371ba55cd 22 while(1)
HarishMekali 1:71e371ba55cd 23 {
prathapbmsce 2:1a5d54f3d818 24 GPRS.baud(9600);
prathapbmsce 2:1a5d54f3d818 25 GPRS.printf("AT+CMGF=1\r\n");
prathapbmsce 2:1a5d54f3d818 26 q=m; //Storing the sensor value in a variable
prathapbmsce 2:1a5d54f3d818 27
prathapbmsce 2:1a5d54f3d818 28 //Sensor read and Callibrate
prathapbmsce 2:1a5d54f3d818 29 a=sm1.read();
prathapbmsce 2:1a5d54f3d818 30 m=(0.057*(a*1024))+25.072;
prathapbmsce 2:1a5d54f3d818 31 lcd.cls();
prathapbmsce 2:1a5d54f3d818 32 lcd.printf("Raw SM1=%0.3f",a);
prathapbmsce 2:1a5d54f3d818 33 wait(5);
prathapbmsce 2:1a5d54f3d818 34
prathapbmsce 2:1a5d54f3d818 35 //Local storage (On board flash memory of 2MB)
prathapbmsce 2:1a5d54f3d818 36 FILE *fp=fopen("/local/KAEMS.csv","a");
prathapbmsce 2:1a5d54f3d818 37 fprintf(fp,"%d,%0.3f\n",time,m);
prathapbmsce 2:1a5d54f3d818 38 fclose(fp);
prathapbmsce 2:1a5d54f3d818 39 lcd.cls();
prathapbmsce 2:1a5d54f3d818 40 lcd.printf("File updated");
prathapbmsce 2:1a5d54f3d818 41 wait(5);
prathapbmsce 2:1a5d54f3d818 42
prathapbmsce 2:1a5d54f3d818 43 //Display
prathapbmsce 2:1a5d54f3d818 44 lcd.cls();
prathapbmsce 2:1a5d54f3d818 45 lcd.locate(0,0);
prathapbmsce 2:1a5d54f3d818 46 lcd.printf("SM1=%0.3f",m);
prathapbmsce 2:1a5d54f3d818 47 wait(5);
prathapbmsce 2:1a5d54f3d818 48
prathapbmsce 2:1a5d54f3d818 49 //Realy control
prathapbmsce 2:1a5d54f3d818 50 if(m>50)
prathapbmsce 2:1a5d54f3d818 51 relay=0;
prathapbmsce 2:1a5d54f3d818 52 else
prathapbmsce 2:1a5d54f3d818 53 relay=1;
prathapbmsce 2:1a5d54f3d818 54 wait(2);
prathapbmsce 2:1a5d54f3d818 55 lcd.cls();
prathapbmsce 2:1a5d54f3d818 56 lcd.locate(0,0);
prathapbmsce 2:1a5d54f3d818 57 lcd.printf("Relay Function...");
prathapbmsce 2:1a5d54f3d818 58
prathapbmsce 2:1a5d54f3d818 59 //GPRS commands
prathapbmsce 2:1a5d54f3d818 60 lcd.cls();
prathapbmsce 2:1a5d54f3d818 61 lcd.locate(0,0);
prathapbmsce 2:1a5d54f3d818 62 lcd.printf("Updating BMSEMS...");
prathapbmsce 2:1a5d54f3d818 63 wait(3);
prathapbmsce 2:1a5d54f3d818 64 GPRS.printf("AT+SAPBR=0,1\r\n");
prathapbmsce 2:1a5d54f3d818 65 wait(3);
prathapbmsce 2:1a5d54f3d818 66 GPRS.printf("AT+SAPBR=3,1,%cCONTYPE%c,%cGPRS%c\r\n",e,e,e,e);
prathapbmsce 2:1a5d54f3d818 67 wait(3);
prathapbmsce 2:1a5d54f3d818 68 GPRS.printf("AT+SAPBR=3,1,%cAPN%c,%cwww%c\r\n",e,e,e,e);
prathapbmsce 2:1a5d54f3d818 69 wait(3);
prathapbmsce 2:1a5d54f3d818 70 GPRS.printf("AT+SAPBR=1,1\r\n");
prathapbmsce 2:1a5d54f3d818 71 wait(5);
prathapbmsce 2:1a5d54f3d818 72 GPRS.printf("AT+HTTPINIT\r\n");
prathapbmsce 2:1a5d54f3d818 73 wait(2);
prathapbmsce 2:1a5d54f3d818 74 GPRS.printf("AT+HTTPPARA=%cCID%c,1\r\n",e,e);
prathapbmsce 2:1a5d54f3d818 75 wait(2);
prathapbmsce 2:1a5d54f3d818 76 GPRS.printf("AT+HTTPPARA=%cURL%c,%chttp://bmsems.org/update.php?u=3&t=23&h=34&s1=%f&s2=24&s3=25&s4=26&ph=5&b=%d%c\r\n",e,e,e,m,b--,e);
prathapbmsce 2:1a5d54f3d818 77 wait(2);
prathapbmsce 2:1a5d54f3d818 78 GPRS.printf("AT+HTTPDATA=1000,5000\r\n");
prathapbmsce 2:1a5d54f3d818 79 wait(10);
prathapbmsce 2:1a5d54f3d818 80 GPRS.printf("AT+HTTPACTION=1\r\n");
prathapbmsce 2:1a5d54f3d818 81 wait(5);
prathapbmsce 2:1a5d54f3d818 82 GPRS.printf("AT+HTTPTERM\r\n");
prathapbmsce 2:1a5d54f3d818 83 wait(5);
prathapbmsce 2:1a5d54f3d818 84
prathapbmsce 2:1a5d54f3d818 85 time=time+1;
prathapbmsce 2:1a5d54f3d818 86 lcd.cls();
prathapbmsce 2:1a5d54f3d818 87 lcd.locate(0,0);
prathapbmsce 2:1a5d54f3d818 88 lcd.printf("BMSEMS Updated");
prathapbmsce 2:1a5d54f3d818 89 wait(10);
prathapbmsce 2:1a5d54f3d818 90 }
HarishMekali 0:15a70393058f 91 }