From 85bb539ae68ff08de3be1e641ea47f08180f3d22 Mon Sep 17 00:00:00 2001 From: jeansami Date: Sun, 28 Jan 2018 16:26:04 +0100 Subject: [PATCH] Update res-light.c The light was always at 0 because of the uint type. I correct it by using a type float instead. --- examples/iotlab/04-er-rest-example/resources/res-light.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/iotlab/04-er-rest-example/resources/res-light.c b/examples/iotlab/04-er-rest-example/resources/res-light.c index 78e42db393a..e29e1a3e15f 100644 --- a/examples/iotlab/04-er-rest-example/resources/res-light.c +++ b/examples/iotlab/04-er-rest-example/resources/res-light.c @@ -58,24 +58,24 @@ RESOURCE(res_light, static void res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) { - uint16_t light = light_sensor.value(0) / LIGHT_SENSOR_VALUE_SCALE; + float light = ((float)light_sensor.value(0)) / LIGHT_SENSOR_VALUE_SCALE; unsigned int accept = -1; REST.get_header_accept(request, &accept); 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, "%u", light); + snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "%f", light); REST.set_response_payload(response, (uint8_t *)buffer, strlen((char *)buffer)); } else if(accept == REST.type.APPLICATION_XML) { REST.set_header_content_type(response, REST.type.APPLICATION_XML); - snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "", light); + snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "", light); 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, "{'light':%u}", light); + snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "{'light':%f}", light); REST.set_response_payload(response, buffer, strlen((char *)buffer)); } else {