Uploading sensor data (voltage divider, MAX4172, INA219) over Ethernet to Thing Speak service. Uses old mbed revision that is compatible with NetServices library. I2C communication is made with I2CR library.
Dependencies: C12832 I2CR INA219 NetServices mbed
Fork of NetServices_HelloWorld by
main.cpp@1:57f922fe8fb5, 2010-11-16 (annotated)
- Committer:
- segundo
- Date:
- Tue Nov 16 20:04:25 2010 +0000
- Revision:
- 1:57f922fe8fb5
- Parent:
- 0:2419d81ee03d
- Child:
- 2:16857d9ab50d
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
segundo | 0:2419d81ee03d | 1 | #include "mbed.h" |
segundo | 0:2419d81ee03d | 2 | #include "EthernetNetIf.h" |
segundo | 0:2419d81ee03d | 3 | #include "HTTPClient.h" |
segundo | 1:57f922fe8fb5 | 4 | #include "NTPClient.h" |
segundo | 0:2419d81ee03d | 5 | |
segundo | 0:2419d81ee03d | 6 | EthernetNetIf eth("mbedSE"); |
segundo | 0:2419d81ee03d | 7 | HTTPClient http; |
segundo | 1:57f922fe8fb5 | 8 | NTPClient ntp; |
segundo | 0:2419d81ee03d | 9 | |
segundo | 0:2419d81ee03d | 10 | int main() { |
segundo | 0:2419d81ee03d | 11 | |
segundo | 0:2419d81ee03d | 12 | printf("Setting up...\n"); |
segundo | 0:2419d81ee03d | 13 | EthernetErr ethErr = eth.setup(); |
segundo | 0:2419d81ee03d | 14 | if (ethErr) { |
segundo | 0:2419d81ee03d | 15 | printf("Error %d in setup\n", ethErr); |
segundo | 0:2419d81ee03d | 16 | return -1; |
segundo | 0:2419d81ee03d | 17 | } |
segundo | 0:2419d81ee03d | 18 | |
segundo | 1:57f922fe8fb5 | 19 | IpAddr ethIp = eth.getIp(); |
segundo | 1:57f922fe8fb5 | 20 | printf("Connected ok, IP : %d.%d.%d.%d\n", ethIp[0], ethIp[1], ethIp[2], ethIp[3]); |
segundo | 0:2419d81ee03d | 21 | |
segundo | 1:57f922fe8fb5 | 22 | printf("\nHTTPClient get...\n"); |
segundo | 0:2419d81ee03d | 23 | HTTPText txt; |
segundo | 0:2419d81ee03d | 24 | HTTPResult r = http.get("http://mbed.org/media/uploads/donatien/hello.txt", &txt); |
segundo | 0:2419d81ee03d | 25 | if (r==HTTP_OK) { |
segundo | 0:2419d81ee03d | 26 | printf("Result ok : %s\n", txt.gets()); |
segundo | 0:2419d81ee03d | 27 | } else { |
segundo | 0:2419d81ee03d | 28 | printf("Error %d\n", r); |
segundo | 0:2419d81ee03d | 29 | } |
segundo | 0:2419d81ee03d | 30 | |
segundo | 1:57f922fe8fb5 | 31 | time_t ctTime; |
segundo | 1:57f922fe8fb5 | 32 | ctTime = time(NULL); |
segundo | 1:57f922fe8fb5 | 33 | printf("\nCurrent time is (UTC): %d %s\n", ctTime, ctime(&ctTime)); |
segundo | 1:57f922fe8fb5 | 34 | printf("NTP setTime...\n"); |
segundo | 1:57f922fe8fb5 | 35 | Host server(IpAddr(), 123, "pool.ntp.org"); |
segundo | 1:57f922fe8fb5 | 36 | printf("Result : %d\n", ntp.setTime(server)); |
segundo | 1:57f922fe8fb5 | 37 | |
segundo | 1:57f922fe8fb5 | 38 | ctTime = time(NULL); |
segundo | 1:57f922fe8fb5 | 39 | printf("\nTime is now (UTC): %d %s\n", ctTime, ctime(&ctTime)); |
segundo | 1:57f922fe8fb5 | 40 | |
segundo | 1:57f922fe8fb5 | 41 | printf("Done!\n"); |
segundo | 0:2419d81ee03d | 42 | return 0; |
segundo | 0:2419d81ee03d | 43 | } |