TA1 / Mbed 2 deprecated Sim800_tiap20s_http

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
faisa_suksesta
Date:
Fri Dec 11 10:45:22 2020 +0000
Parent:
0:50d54df4a4c2
Commit message:
Sim800l buat HTTP

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Aug 05 08:49:59 2016 +0000
+++ b/main.cpp	Fri Dec 11 10:45:22 2020 +0000
@@ -5,18 +5,17 @@
 #include "mbed.h"
 #include <string> 
 
-Serial sim800(PTE0,PTE1);                                   //Serial communication of the sim800 and pc.
+Serial sim800(D8,D2);                                   //Serial communication of the sim800 and pc.
 Serial pc(USBTX,USBRX);
 
-AnalogIn pot(PTB0);
-AnalogIn ldr(PTB1);
+Ticker t_SendData;
 
-char x[300],y[30],z[30],l[30],m[30];
-            
+char x[300],y[30],z[30],l[30],m[30];;
+float nilai = 44 ;
+
+void SendData();
 int main()
 {
-    float potval = 0;
-    float ldrval = 0;
 
     pc.baud(9600);
     sim800.baud(9600);
@@ -34,12 +33,12 @@
         sim800.printf("AT+CIPSHUT\r\n");                    //To reset the IP session if any.
             sim800.scanf("%s%s",x,y);
             pc.printf("%s   %s\r\n",x,y);
-  
+    
         sim800.printf("AT+SAPBR=3,1,Contype,GPRS\r\n");     //To Set the connection type to GPRS.
             sim800.scanf("%s",x);
             pc.printf("%s\r\n",x);
         
-        sim800.printf("AT+SAPBR=3,1,APN,www\r\n");          //To Set the APN to to "www" , It might be different for you, and depends on the network.
+        sim800.printf("AT+SAPBR=3,1,APN,internet\r\n");          //To Set the APN to to "www" , It might be different for you, and depends on the network.
             sim800.scanf("%s",x);
             pc.printf("%s\r\n",x);
         
@@ -60,35 +59,45 @@
             sim800.scanf("%s",x);
             pc.printf("%s\r\n",x);
             
-        
-        float lng,lat = 0;
-        while(lat == 0)
-        {                            
-            sim800.printf("AT+CIPGSMLOC=1,1\r\n");          //To check the Location of GSM in Co-Ordinates(Longitude,Latitude).
-            sim800.scanf("%s%s%s",x,y,z);
-            sscanf(y,"0,%f,%f",&lng,&lat);                  //To sperate out the value of longitude and latitude from the string 'y'.       
+        t_SendData.attach(&SendData, 20);
+        while(true)
+        {
+            //nilai = nilai + 1;
+//            pc.printf("loop nilai : %f\r\n",nilai);
+//        
+//            sim800.printf("AT+HTTPPARA=URL,api.thingspeak.com/update?api_key=9R927S4HY3F10GRQ&field2=%0.2f\r\n",nilai);
+//                                                            //The above command is for "To Set the url to the address of the webpage you want to access".
+//                sim800.scanf("%s",x);
+//                pc.printf("%s\r\n",x);
+//            
+//            sim800.printf("AT+HTTPACTION=0\r\n");           //To Start the HTTP GET session, by giving this command.
+//                sim800.scanf("%s%s%s",x,y,z);
+//                pc.printf("%s   %s  %s\r\n",x,y,z);
+//        
+//            //sim800.printf("AT+HTTPREAD\r\n");               //To read the received data.
+////                sim800.scanf("%s%s%s%s%s",x,y,z,l,m);
+////                pc.printf("%s   %s  %s  %s  %s\r\n",x,y,z,l,m);
+////            
+//            wait(10000);
         }
-        pc.printf("%0.6f   %0.6f",lng,lat);
-        
-        
-        while(1)
-        {
-            potval = pot.read();
-            ldrval = ldr.read();
+}
+
+void SendData() {
+    
+    nilai = nilai + 1;
+    pc.printf("loop nilai : %f\r\n",nilai);
         
-            sim800.printf("AT+HTTPPARA=URL,data.sparkfun.com/input/roYVdJgWrXUpxVpDYJpA?private_key=jkgpNMYr81cgMGgbypgr&co_lat=%0.6f&co_long=%0.6f&ldr=%0.2f&pot=%0.2f\r\n",lat,lng,potval,ldrval);
+    sim800.printf("AT+HTTPPARA=URL,api.thingspeak.com/update?api_key=9R927S4HY3F10GRQ&field3=%0.2f\r\n",nilai);
                                                             //The above command is for "To Set the url to the address of the webpage you want to access".
-                sim800.scanf("%s",x);
-                pc.printf("%s\r\n",x);
+    sim800.scanf("%s",x);
+    pc.printf("%s\r\n",x);
             
-            sim800.printf("AT+HTTPACTION=0\r\n");           //To Start the HTTP GET session, by giving this command.
-                sim800.scanf("%s%s%s",x,y,z);
-                pc.printf("%s   %s  %s\r\n",x,y,z);
+    sim800.printf("AT+HTTPACTION=0\r\n");           //To Start the HTTP GET session, by giving this command.
+    sim800.scanf("%s%s%s",x,y,z);
+    pc.printf("%s   %s  %s\r\n",x,y,z);
         
-            sim800.printf("AT+HTTPREAD\r\n");               //To read the received data.
-                sim800.scanf("%s%s%s%s%s",x,y,z,l,m);
-                pc.printf("%s   %s  %s  %s  %s\r\n",x,y,z,l,m);
-            
-            wait(5);
-        }
+            //sim800.printf("AT+HTTPREAD\r\n");               //To read the received data.
+//                sim800.scanf("%s%s%s%s%s",x,y,z,l,m);
+//                pc.printf("%s   %s  %s  %s  %s\r\n",x,y,z,l,m);
+    
 }
\ No newline at end of file