kaems
Dependencies: TextLCD WakeUp mbed
Fork of Final by
main.cpp
00001 #include"mbed.h" 00002 #include"TextLCD.h" 00003 #include"WakeUp.h" 00004 #include"mBuinoSleep.h" 00005 //AnalogIn sm1(p16); 00006 //AnalogIn sm2(p17); 00007 //AnalogIn sm3(p18); 00008 //AnalogIn sm4(p19); 00009 00010 DigitalOut myled(LED1); 00011 DigitalOut ac(p20); 00012 Serial GPRS(p9,p10); 00013 Serial pc(USBTX,USBRX); 00014 TextLCD lcd(p26, p25, p24, p23, p22, p21); //rs,e,d0-d3 00015 LocalFileSystem local("local"); 00016 00017 char a=0x1A,c=0x0D; 00018 char num[]="7411755981"; 00019 float s[5],m[5]; 00020 float ma; 00021 00022 int b=100,count,fb; 00023 char col1[]="ITERATION",col2[]="SM1",col3[]="SM2",col4[]="SM3",col5[]="SM4",col6[]="Mean",col7[]="Configuring for data services",col8[]="Uploading Sensor values to the Internet ",col9[]="Feedback from Internet",col10[]="Required action",col11[]="Sending SMS",col12[]="Excel Shet File Updated"; 00024 char *char1; 00025 float d; 00026 ///////////////////////////////////////////////////////////////////////////////////////////////////////////// 00027 void sleepwait(int q) 00028 { int x; 00029 x=q*1000; 00030 myled=1; 00031 WakeUp::calibrate(); 00032 WakeUp::set_ms(x); 00033 mBuinoSleep(Sleep); 00034 } 00035 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// 00036 void SensorRead() 00037 { lcd.cls(); 00038 lcd.locate(0,0); 00039 lcd.printf("Sensor Readings\r"); 00040 s[1]=0.31; 00041 m[1]=(0.057*(s[1]*1024))+25.072; 00042 lcd.cls(); 00043 lcd.printf("Raw SM1=%0.3f",s[1]); 00044 sleepwait(1); 00045 s[2]=0.25; 00046 m[2]=(0.057*(s[2]*1024))+25.072; 00047 lcd.cls(); 00048 lcd.printf("Raw SM2=%0.3f",s[2]); 00049 sleepwait(1); 00050 s[3]=0.33; 00051 m[3]=(0.057*(s[3]*1024))+25.072; 00052 lcd.cls(); 00053 lcd.printf("Raw SM3=%0.3f",s[3]); 00054 sleepwait(1); 00055 s[4]=0.25; 00056 m[4]=(0.057*(s[4]*1024))+25.072; 00057 lcd.cls(); 00058 lcd.printf("Raw SM4=%0.3f",s[4]); 00059 sleepwait(1); 00060 ma=(m[1]+m[2]+m[3]+m[4])/4; 00061 lcd.cls(); 00062 lcd.locate(0,0); 00063 lcd.printf("Mean =%0.3f",ma); 00064 sleepwait(2); 00065 } 00066 00067 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 00068 void ac_control() 00069 { 00070 if(char1[0]=='0' ||char1[0]=='2'||char1[0]=='4'||char1[0]=='6'||char1[0]=='8') 00071 { lcd.cls(); 00072 lcd.printf("Bulb ON"); 00073 ac=1; 00074 } 00075 else 00076 { lcd.cls(); 00077 lcd.printf("Bulb OFF"); 00078 ac=0; 00079 } 00080 } 00081 00082 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 00083 void xlfile() 00084 { 00085 //Local storage (On board flash memory of 2MB) 00086 count++; 00087 FILE *fp=fopen("/local/KAEMS.csv","a"); 00088 fprintf(fp,"%d,%0.3f,%0.3f,%0.3f,%0.3f,%0.3f,%s,%s,%c,%s,%s,%s\n",count,m[1],m[2],m[3],m[4],ma,col7,col8,char1[0],col10,col11,col12); 00089 fclose(fp); 00090 lcd.cls(); 00091 lcd.printf("File updated"); 00092 sleepwait(1); 00093 } 00094 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 00095 00096 void flushSerialBuffer(void) 00097 { char char2=0; 00098 while (GPRS.readable()) 00099 { char2=GPRS.getc(); 00100 } return; 00101 } 00102 00103 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 00104 void data_tx_rx() 00105 { 00106 //GPRS commands 00107 WakeUp::calibrate(); 00108 lcd.cls(); 00109 lcd.locate(0,0); 00110 lcd.printf(" Updating\n www.kaems.org"); 00111 sleepwait(3); 00112 00113 GPRS.printf("AT+SAPBR=0,1\r\n"); 00114 sleepwait(3); 00115 00116 GPRS.printf("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"\r\n"); 00117 sleepwait(3); 00118 00119 GPRS.printf("AT+SAPBR=3,1,\"APN\",\"AIRCELGPRS.COM\"\r\n"); 00120 sleepwait(3); 00121 00122 GPRS.printf("AT+SAPBR=1,1\r\n"); 00123 sleepwait(3); 00124 00125 GPRS.printf("AT+HTTPINIT\r\n"); 00126 sleepwait(2); 00127 00128 GPRS.printf("AT+HTTPPARA=\"CID\",1\r\n"); 00129 sleepwait(2); 00130 00131 GPRS.printf("AT+HTTPPARA=\"URL\",\"http://kaems.org/update.php?u=3&t=23&h=34&s1=%f&s2=%f&s3=%f&s4=%f&ph=5&b=%d\"\r\n",m[1],m[2],m[3],m[4],b--); 00132 sleepwait(2); 00133 00134 GPRS.printf("AT+HTTPDATA=1000,5000\r\n"); 00135 sleepwait(8); 00136 00137 GPRS.printf("AT+HTTPACTION=1\r\n"); 00138 sleepwait(5); 00139 00140 GPRS.printf("AT+HTTPPARA=\"CID\",1\r\n"); 00141 sleepwait(2); 00142 00143 GPRS.printf("AT+HTTPPARA=\"URL\",\"http://kaems.org/feedback.php\"\r\n"); 00144 sleepwait(2); 00145 00146 GPRS.printf("AT+HTTPACTION=0\r\n"); 00147 sleepwait(5); 00148 00149 flushSerialBuffer(); 00150 GPRS.printf("AT+HTTPREAD\r\n"); 00151 while(!GPRS.readable()) 00152 { } 00153 GPRS.scanf("%s",char1); 00154 GPRS.scanf("%s",char1); 00155 GPRS.scanf("%s",char1); 00156 00157 pc.printf("Str=%c\r\n",char1[0]); 00158 GPRS.printf("AT+HTTPTERM\r\n"); 00159 00160 00161 lcd.cls(); 00162 lcd.printf("KAEMS UPDATED"); 00163 00164 lcd.cls(); 00165 lcd.printf("Fbk=%c",char1[0]); 00166 sleepwait(2); 00167 } 00168 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 00169 00170 /*void feedback() 00171 { lcd.cls(); 00172 lcd.locate(0,0); 00173 lcd.printf("Waiting for feedback"); 00174 wait(3); 00175 GPRS.printf("AT+SAPBR=0,1\r\n"); 00176 wait(3); 00177 GPRS.printf("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"\r\n"); 00178 wait(3); 00179 GPRS.printf("AT+SAPBR=3,1,\"APN\",\"AIRCELGPRS.COM\"\r\n"); 00180 wait(3); 00181 GPRS.printf("AT+SAPBR=1,1\r\n"); 00182 wait(3); 00183 GPRS.printf("AT+HTTPINIT\r\n"); 00184 wait(2); 00185 GPRS.printf("AT+HTTPPARA=\"CID\",1\r\n"); 00186 wait(2); 00187 00188 // switch(str2[0]){ 00189 // case '1': break; 00190 // 00191 // } 00192 wait(5); 00193 GPRS.printf("AT+HTTPTERM\r\n"); 00194 } */ 00195 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 00196 void sms() 00197 { 00198 GPRS.printf("AT\r\n"); 00199 sleepwait(2); 00200 00201 GPRS.printf("AT+CMGF=1\r\n"); 00202 sleepwait(2); 00203 00204 GPRS.printf("AT+CMGS=\"%s\"\r\n",num); 00205 sleepwait(3); 00206 00207 if(ma<40) 00208 { 00209 GPRS.printf(" Water level is low \nMoisture level = %f \r\n",ma); 00210 sleepwait(1); 00211 00212 GPRS.printf("%c",a); 00213 sleepwait(2); 00214 } 00215 00216 if(ma>40) 00217 { 00218 GPRS.printf(" Land has sufficient amount of water \n Moisture level = %f \r\n",ma); 00219 sleepwait(1); 00220 00221 GPRS.printf("%c",a); 00222 sleepwait(2); 00223 } 00224 lcd.cls(); 00225 lcd.printf("SMS Sent"); 00226 sleepwait(2); 00227 } 00228 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 00229 int main() 00230 { 00231 lcd.cls(); 00232 lcd.printf(" PRECISION\n AGRICULTURE"); 00233 GPRS.baud(9600); 00234 GPRS.printf("AT\n"); 00235 sleepwait(3); 00236 FILE *fp=fopen("/local/KAEMS.csv","a"); 00237 fprintf(fp,"%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s\n",col1,col2,col3,col4,col5,col6,col7,col8,col9,col10,col11,col12); 00238 fclose(fp); 00239 00240 while(1) 00241 { 00242 SensorRead(); 00243 //sms(); 00244 data_tx_rx(); 00245 ac_control(); 00246 xlfile(); 00247 lcd.cls(); 00248 lcd.printf(" PRECISION\n AGRICULTURE"); 00249 sleepwait(2); 00250 } 00251 }
Generated on Tue Jul 19 2022 20:23:10 by 1.7.2