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@0:53f05303850a, 2012-12-31 (annotated)
- Committer:
- wkinkeldei
- Date:
- Mon Dec 31 12:08:24 2012 +0000
- Revision:
- 0:53f05303850a
- Child:
- 1:9e88b2508768
first working version with all needed features implemented: measure, display, post
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 | 0:53f05303850a | 6 | CollectorProxy::CollectorProxy(char *url) :base_url(url) { |
wkinkeldei | 0:53f05303850a | 7 | } |
wkinkeldei | 0:53f05303850a | 8 | |
wkinkeldei | 0:53f05303850a | 9 | int CollectorProxy::send_measure(char *path_part, int value) { |
wkinkeldei | 0:53f05303850a | 10 | HTTPClient http; |
wkinkeldei | 0:53f05303850a | 11 | HTTPMap data; |
wkinkeldei | 0:53f05303850a | 12 | char str[512]; |
wkinkeldei | 0:53f05303850a | 13 | HTTPText in_text(str, 512); |
wkinkeldei | 0:53f05303850a | 14 | |
wkinkeldei | 0:53f05303850a | 15 | char url[200]; |
wkinkeldei | 0:53f05303850a | 16 | strcpy(url, base_url); |
wkinkeldei | 0:53f05303850a | 17 | strcat(url, "/"); |
wkinkeldei | 0:53f05303850a | 18 | strcat(url, path_part); |
wkinkeldei | 0:53f05303850a | 19 | |
wkinkeldei | 0:53f05303850a | 20 | char value_buffer[10]; |
wkinkeldei | 0:53f05303850a | 21 | sprintf(value_buffer, "%d", value); |
wkinkeldei | 0:53f05303850a | 22 | data.put("value", value_buffer); |
wkinkeldei | 0:53f05303850a | 23 | |
wkinkeldei | 0:53f05303850a | 24 | int ret = http.post(url, data, &in_text); |
wkinkeldei | 0:53f05303850a | 25 | |
wkinkeldei | 0:53f05303850a | 26 | if (!ret) { |
wkinkeldei | 0:53f05303850a | 27 | // printf("Executed POST successfully - read %d characters\n", strlen(str)); |
wkinkeldei | 0:53f05303850a | 28 | // printf("Result: %s\n", str); |
wkinkeldei | 0:53f05303850a | 29 | return 1; |
wkinkeldei | 0:53f05303850a | 30 | } else { |
wkinkeldei | 0:53f05303850a | 31 | // printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); |
wkinkeldei | 0:53f05303850a | 32 | return 0; |
wkinkeldei | 0:53f05303850a | 33 | } |
wkinkeldei | 0:53f05303850a | 34 | } |