yet another 18B20 Temperature sensor. variable number of sensors working in parasite mode, serial 16x2 display with diagnostic output and post to a rest web service
Dependencies: EthernetInterface HTTPClient NTPClient mbed-rtos mbed
collector_proxy.cpp@1:9e88b2508768, 2013-01-03 (annotated)
- Committer:
- wkinkeldei
- Date:
- Thu Jan 03 18:50:43 2013 +0000
- Revision:
- 1:9e88b2508768
- Parent:
- 0:53f05303850a
added switch sensor
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wkinkeldei | 0:53f05303850a | 1 | #include "collector_proxy.h" |
wkinkeldei | 0:53f05303850a | 2 | #include "HTTPClient.h" |
wkinkeldei | 0:53f05303850a | 3 | |
wkinkeldei | 0:53f05303850a | 4 | #include <cstring> |
wkinkeldei | 0:53f05303850a | 5 | |
wkinkeldei | 1:9e88b2508768 | 6 | CollectorProxy::CollectorProxy(const char *url) :base_url(url) {} |
wkinkeldei | 0:53f05303850a | 7 | |
wkinkeldei | 0:53f05303850a | 8 | int CollectorProxy::send_measure(char *path_part, int value) { |
wkinkeldei | 0:53f05303850a | 9 | HTTPClient http; |
wkinkeldei | 0:53f05303850a | 10 | HTTPMap data; |
wkinkeldei | 0:53f05303850a | 11 | char str[512]; |
wkinkeldei | 0:53f05303850a | 12 | HTTPText in_text(str, 512); |
wkinkeldei | 0:53f05303850a | 13 | |
wkinkeldei | 0:53f05303850a | 14 | char url[200]; |
wkinkeldei | 0:53f05303850a | 15 | strcpy(url, base_url); |
wkinkeldei | 0:53f05303850a | 16 | strcat(url, "/"); |
wkinkeldei | 0:53f05303850a | 17 | strcat(url, path_part); |
wkinkeldei | 0:53f05303850a | 18 | |
wkinkeldei | 0:53f05303850a | 19 | char value_buffer[10]; |
wkinkeldei | 0:53f05303850a | 20 | sprintf(value_buffer, "%d", value); |
wkinkeldei | 0:53f05303850a | 21 | data.put("value", value_buffer); |
wkinkeldei | 0:53f05303850a | 22 | |
wkinkeldei | 0:53f05303850a | 23 | int ret = http.post(url, data, &in_text); |
wkinkeldei | 0:53f05303850a | 24 | |
wkinkeldei | 0:53f05303850a | 25 | if (!ret) { |
wkinkeldei | 0:53f05303850a | 26 | // printf("Executed POST successfully - read %d characters\n", strlen(str)); |
wkinkeldei | 0:53f05303850a | 27 | // printf("Result: %s\n", str); |
wkinkeldei | 0:53f05303850a | 28 | return 1; |
wkinkeldei | 0:53f05303850a | 29 | } else { |
wkinkeldei | 0:53f05303850a | 30 | // printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); |
wkinkeldei | 0:53f05303850a | 31 | return 0; |
wkinkeldei | 0:53f05303850a | 32 | } |
wkinkeldei | 0:53f05303850a | 33 | } |