track your object
Dependencies: EthernetInterface mbed-rtos mbed
Fork of SimpleThing by
main.cpp@16:5d72a1f1c81f, 2015-06-08 (annotated)
- Committer:
- zeeshan0123
- Date:
- Mon Jun 08 15:45:10 2015 +0000
- Revision:
- 16:5d72a1f1c81f
- Parent:
- 15:a15d0b575131
track your object
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
donatien | 0:bb128f0e952f | 1 | #include "mbed.h" |
donatien | 0:bb128f0e952f | 2 | #include "EthernetInterface.h" |
donatien | 0:bb128f0e952f | 3 | |
zeeshan0123 | 16:5d72a1f1c81f | 4 | char* thingSpeakUrl = "api.thingspeak.com"; |
zeeshan0123 | 16:5d72a1f1c81f | 5 | char* thingSpeakKey = "KXD7399710CF3CIN"; |
zeeshan0123 | 16:5d72a1f1c81f | 6 | float latitude = 26.9; |
zeeshan0123 | 16:5d72a1f1c81f | 7 | |
emilmont | 7:65188f4a8c25 | 8 | int main() { |
donatien | 0:bb128f0e952f | 9 | EthernetInterface eth; |
donatien | 0:bb128f0e952f | 10 | eth.init(); //Use DHCP |
donatien | 0:bb128f0e952f | 11 | eth.connect(); |
emilmont | 2:e087e9b789e9 | 12 | printf("IP Address is %s\n", eth.getIPAddress()); |
donatien | 0:bb128f0e952f | 13 | |
zeeshan0123 | 16:5d72a1f1c81f | 14 | for (float longitude = 70.90; longitude < 76.0; longitude = longitude + 0.50) |
zeeshan0123 | 16:5d72a1f1c81f | 15 | { |
emilmont | 7:65188f4a8c25 | 16 | TCPSocketConnection sock; |
zeeshan0123 | 16:5d72a1f1c81f | 17 | sock.connect(thingSpeakUrl , 80); |
zeeshan0123 | 16:5d72a1f1c81f | 18 | char http_cmd[256]; |
zeeshan0123 | 16:5d72a1f1c81f | 19 | sprintf(http_cmd,"GET /update?key=%s&field1=%f&field2=%f HTTP/1.0\n\n",thingSpeakKey,latitude,longitude); |
emilmont | 11:59dcefdda506 | 20 | sock.send_all(http_cmd, sizeof(http_cmd)-1); |
zeeshan0123 | 16:5d72a1f1c81f | 21 | printf("sent url"); |
emilmont | 7:65188f4a8c25 | 22 | |
emilmont | 9:4757a976148d | 23 | char buffer[300]; |
donatien | 0:bb128f0e952f | 24 | int ret; |
zeeshan0123 | 16:5d72a1f1c81f | 25 | |
zeeshan0123 | 16:5d72a1f1c81f | 26 | ret = sock.receive(buffer, sizeof(buffer)-1); |
zeeshan0123 | 16:5d72a1f1c81f | 27 | buffer[ret] = '\0'; |
zeeshan0123 | 16:5d72a1f1c81f | 28 | printf("Received %d chars from server:\n%s\n", ret, buffer); |
zeeshan0123 | 16:5d72a1f1c81f | 29 | |
zeeshan0123 | 16:5d72a1f1c81f | 30 | wait(16); // limited by ThingSpeak's API |
zeeshan0123 | 16:5d72a1f1c81f | 31 | |
donatien | 0:bb128f0e952f | 32 | |
emilmont | 7:65188f4a8c25 | 33 | sock.close(); |
zeeshan0123 | 16:5d72a1f1c81f | 34 | } |
donatien | 0:bb128f0e952f | 35 | |
emilmont | 7:65188f4a8c25 | 36 | eth.disconnect(); |
donatien | 5:01f6c3e112af | 37 | |
emilmont | 9:4757a976148d | 38 | while(1) {} |
donatien | 0:bb128f0e952f | 39 | } |