wang tang / Mbed 2 deprecated Thingspeak_WiFi_use_IDW01M1

Dependencies:   DHT11 NetworkSocketAPI X_NUCLEO_IDW01M1v2 mbed

Fork of AirQuality_DHT11_Thingspeak_WiFi by Imran Sheikh

Files at this revision

API Documentation at this revision

Comitter:
e58136782000
Date:
Tue Oct 31 03:21:35 2017 +0000
Parent:
13:9a2016106dae
Commit message:
thingspeak IDW01M1

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 9a2016106dae -r a9beb6052a99 main.cpp
--- a/main.cpp	Sat May 06 17:39:25 2017 +0000
+++ b/main.cpp	Tue Oct 31 03:21:35 2017 +0000
@@ -31,7 +31,7 @@
 //char* ntpServerUrl = "0.ca.pool.ntp.org";
 #define IP "184.106.153.149" 
 char* thingSpeakUrl = "http://api.thingspeak.com/update";
-char* thingSpeakKey = "SBYDOEXE50MNOBSI";
+char* thingSpeakKey = "H1KAGWGPJBSHYFH0";
 //------------------------------------
 // Hyperterminal configuration
 // 9600 bauds, 8-bit data, no parity
@@ -53,11 +53,11 @@
 double Rs;                                   // Rs (Ohm) - Sensor resistance
 double ppm;                                  // ppm
 double ratio;
-int temp;
+int testvalue;
 int humid;   
 
 //Calculation of PPM
-void calculatePPM() 
+/*void calculatePPM() 
 {
   double lgPPM;
   Vrl = (double)ain*Vadc_5;             // For 5V Vcc use Vadc_5
@@ -69,7 +69,7 @@
   pc.printf("The raw Rs is %2.3lf\n",ratio);
   pc.printf("The raw voltage is %2.3lf \n",Vrl);
 }
-
+*/
 int http_demo(void)
 {
     TCPSocket socket(&spwf);
@@ -87,9 +87,9 @@
       return -1;
     } else pc.printf("\r\nconnected to host server\r\n"); 
     // Send a simple http request
-    //buffer[0] = 0;
+    buffer[0] = 0;
     //sprintf(buffer, "GET https://api.thingspeak.com/update?api_key=SBYDOEXE50MNOBSI&field1=%f&field2=%d&field3=%d",(float)ppm,temp,humid);//thingSpeakUrl,thingSpeakKey,
-    sprintf(message,"field1=%f&field2=%d&field3=%d",ppm,temp,humid);
+    sprintf(message,"field1=%d",testvalue);
     printf("Message Length=%d\r\n",(int)strlen(message));
     sprintf(buffer,"POST /update HTTP/1.1\r\nHost: api.thingspeak.com\r\nConnection: close\r\nX-THINGSPEAKAPIKEY: %s\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: %d\r\n\r\n%s",thingSpeakKey,(int)strlen(message),message);
     pc.printf("Request to %s\r\n", buffer);
@@ -110,9 +110,9 @@
 int main() 
 {
     int err;    
-    char * ssid = "VM957191-2G";
-    char * seckey = "krzvzkcw";  
-    //char buffer[255];
+    char * ssid = "18-2F";
+    char * seckey = "062432779";
+    //char buffer[255;
     //time_t ctTime;
     //Host server(IpAddr(), 123, ntpServerUrl);
     //ntp.setTime(server);
@@ -131,40 +131,42 @@
     
     pc.printf("\r\nIP Address is: %s\r\n", (ip) ? ip : "No IP");
     pc.printf("\r\nMAC Address is: %s\r\n", (mac) ? mac : "No MAC");     
-    
+    pc.printf("\r\nInternet is already\r\n");    
     while(1) 
     { 
       wait(20);
-      myled = !myled;
-      calculatePPM();
-      err = sensor.readData();
-        if (err ==DHT11::OK)
-        {
-         temp=sensor.readTemperature();
-         humid=sensor.readHumidity();
-         pc.printf("\r\nT: %d oC, H: %d\r\n",temp,humid);   
-        }
-         else
-         printf("\r\nErr %i \n",err);
-         int err=http_demo();
-         if(err ==0)
-         pc.printf("Thingspeak update completed successfully\r\n");
-         else
-         pc.printf("Error occurred %d\r\n",err);
-       /* buffer[0] = 0;
-        sprintf(buffer, "%s?key=%s&field1=%s&field2=%d&field3=%d", thingSpeakUrl, thingSpeakKey, , (float)ppm,temp,humid);
-        printf("Request to %s\r\n", buffer);
+      testvalue++;
+      /*myled = !myled;
+      //calculatePPM();
+     // err = sensor.readData();
+      //  if (err ==DHT11::OK)
+     //   {
+      //   temp=sensor.readTemperature();
+     //    humid=sensor.readHumidity();
+     //    pc.printf("\r\nT: %d oC, H: %d\r\n",temp,humid);   
+     //   }
+      //   else
+      //   printf("\r\nErr %i \n",err);
+      //   int err=http_demo();
+      //   if(err ==0)
+      //   pc.printf("Thingspeak update completed successfully\r\n");
+      //   else
+         pc.printf("Error occurred %d\r\n",err);*/
+         http_demo();
+ //       buffer[0] = 0;
+        printf("%s?key=%s&field1=%d\r\n", thingSpeakUrl, thingSpeakKey, testvalue);
+        printf("Request to %s\r\n", thingSpeakUrl);
         
-        HTTPText resp;
-        HTTPResult res = http.get(buffer, &resp);
-        if (res == HTTP_OK)
-        {
-            printf("Result :\"%s\"\r\n", resp.gets());
-        }
-        else
-        {
-            printf("Error %d\r\n", res);
-        } */        
+ //       HTTPText resp;
+ //       HTTPResult res = http.get(buffer, &resp);
+ //       if (res == HTTP_OK)
+ //       {
+ //           printf("Result :\"%s\"\r\n", resp.gets());
+ //       }
+ //       else
+ //       {
+ //           printf("Error %d\r\n", res);
+ //       }