change battery and cpttem format to xx.xx

This commit is contained in:
Harald Pichler 2014-04-16 09:31:48 +02:00
parent a656cf1dcd
commit 678891a1a9

View file

@ -804,14 +804,15 @@ temperature_handler(void* request, void* response, uint8_t *buffer, uint16_t pre
if ((num==0) || (num && accept[0]==REST.type.TEXT_PLAIN))
{
REST.set_header_content_type(response, REST.type.TEXT_PLAIN);
snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "%d", temperature);
snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "%d.%02d", temperature/100, temperature % 100);
REST.set_response_payload(response, (uint8_t *)buffer, strlen((char *)buffer));
}
else if (num && (accept[0]==REST.type.APPLICATION_JSON))
{
REST.set_header_content_type(response, REST.type.APPLICATION_JSON);
snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "{'temperature':%d}", temperature);
snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "{'temperature':%d.%02d}", temperature/100, temperature % 100);
REST.set_response_payload(response, buffer, strlen((char *)buffer));
}
@ -839,14 +840,14 @@ battery_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
if ((num==0) || (num && accept[0]==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));
}
else if (num && (accept[0]==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));
}