From 730d9e2d111a2593109dd8d12090da862af9304a Mon Sep 17 00:00:00 2001 From: Harald Pichler Date: Thu, 27 Nov 2014 15:01:07 +0100 Subject: [PATCH] add battery --- examples/osd/arduino-plantobserving/resources/res-battery.c | 6 +++--- examples/osd/arduino-plantobserving/sketch.pde | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/osd/arduino-plantobserving/resources/res-battery.c b/examples/osd/arduino-plantobserving/resources/res-battery.c index b82523594..c7a025d38 100644 --- a/examples/osd/arduino-plantobserving/resources/res-battery.c +++ b/examples/osd/arduino-plantobserving/resources/res-battery.c @@ -64,12 +64,12 @@ res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferr if(accept == -1 || accept == REST.type.TEXT_PLAIN) { REST.set_header_content_type(response, REST.type.TEXT_PLAIN); - snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "%d", battery); + snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "%d.%02d", battery/1000, battery % 1000); - REST.set_response_payload(response, (uint8_t *)buffer, strlen((char *)buffer)); + REST.set_response_payload(response, buffer, strlen((char *)buffer)); } else if(accept == REST.type.APPLICATION_JSON) { REST.set_header_content_type(response, REST.type.APPLICATION_JSON); - snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "{'battery':%d}", battery); + snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "{'battery':%d.%02d}", battery/1000, battery % 1000); REST.set_response_payload(response, buffer, strlen((char *)buffer)); } else { diff --git a/examples/osd/arduino-plantobserving/sketch.pde b/examples/osd/arduino-plantobserving/sketch.pde index 559596888..be1c339a4 100644 --- a/examples/osd/arduino-plantobserving/sketch.pde +++ b/examples/osd/arduino-plantobserving/sketch.pde @@ -13,7 +13,7 @@ extern "C" { #include "rest-engine.h" -extern resource_t res_moisture; +extern resource_t res_moisture, res_battery; uint8_t moisture_pin = A5; uint16_t moisture_voltage = 0; @@ -28,6 +28,7 @@ void setup (void) // init coap resourcen rest_init_engine (); rest_activate_resource (&res_moisture, "s/moisture"); + rest_activate_resource (&res_battery, "s/battery"); } void loop (void)