track your object

Dependencies:   EthernetInterface mbed-rtos mbed

Fork of SimpleThing by Ganesh Gore

Files at this revision

API Documentation at this revision

Comitter:
zeeshan0123
Date:
Mon Jun 08 15:45:10 2015 +0000
Parent:
15:a15d0b575131
Commit message:
track your object

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Mon Jun 08 06:42:13 2015 +0000
+++ b/main.cpp	Mon Jun 08 15:45:10 2015 +0000
@@ -1,29 +1,37 @@
 #include "mbed.h"
 #include "EthernetInterface.h"
 
+char* thingSpeakUrl = "api.thingspeak.com";
+char* thingSpeakKey = "KXD7399710CF3CIN";
+float latitude = 26.9;
+
 int main() {
     EthernetInterface eth;
     eth.init(); //Use DHCP
     eth.connect();
     printf("IP Address is %s\n", eth.getIPAddress());
     
+    for (float longitude = 70.90; longitude < 76.0; longitude = longitude + 0.50)
+    {
     TCPSocketConnection sock;
-    sock.connect("data.sparkfun.com", 80);
-    
-    char http_cmd[] = "GET /input/pw19y5K1J9ILGj3o8ObA?private_key=64e8m7gey8UNXgl69GZJ&variable1=10&variable2=12 HTTP/1.0\n\n";
+    sock.connect(thingSpeakUrl , 80);
+    char http_cmd[256];
+    sprintf(http_cmd,"GET /update?key=%s&field1=%f&field2=%f HTTP/1.0\n\n",thingSpeakKey,latitude,longitude);
     sock.send_all(http_cmd, sizeof(http_cmd)-1);
+    printf("sent url");
     
     char buffer[300];
     int ret;
-    while (true) {
-        ret = sock.receive(buffer, sizeof(buffer)-1);
-        if (ret <= 0)
-            break;
-        buffer[ret] = '\0';
-        printf("Received %d chars from server:\n%s\n", ret, buffer);
-    }
+    
+    ret = sock.receive(buffer, sizeof(buffer)-1);
+    buffer[ret] = '\0';
+    printf("Received %d chars from server:\n%s\n", ret, buffer);
+    
+    wait(16);  // limited by ThingSpeak's API
+    
       
     sock.close();
+    }
     
     eth.disconnect();