add battery

This commit is contained in:
Harald Pichler 2014-11-27 15:01:07 +01:00
parent 1dacefce01
commit 730d9e2d11
2 changed files with 5 additions and 4 deletions

View file

@ -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 {

View file

@ -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)