temp and hum sensors values xxxx -> xx.xx

This commit is contained in:
harald 2014-03-03 14:24:58 +01:00
parent f8c298a495
commit 87028c1f60
2 changed files with 13 additions and 11 deletions

View file

@ -45,9 +45,9 @@
/* Define which resources to include to meet memory constraints. */
#define REST_RES_INFO 1
#define REST_RES_DS1820 0
#define REST_RES_DS1820 1
#define REST_RES_DHT11 1
#define REST_RES_DHT11TEMP 1
#define REST_RES_DHT11TEMP 0
#define REST_RES_LEDS 1
#define REST_RES_TOGGLE 0
#define REST_RES_BATTERY 1
@ -163,7 +163,8 @@ ds1820_handler(void* request, void* response, uint8_t *buffer, uint16_t preferre
if ((num==0) || (num && accept[0]==REST.type.TEXT_PLAIN))
{
REST.set_header_content_type(response, REST.type.TEXT_PLAIN);
snprintf(message, REST_MAX_CHUNK_SIZE, "%2d.%d C",grad,kgrad);
// snprintf(message, REST_MAX_CHUNK_SIZE, "%2d.%d C",grad,kgrad);
snprintf(message, REST_MAX_CHUNK_SIZE, "%4d",grad*100+kgrad*10);
length = strlen(message);
memcpy(buffer, message,length );
@ -173,7 +174,8 @@ ds1820_handler(void* request, void* response, uint8_t *buffer, uint16_t preferre
else if (num && (accept[0]==REST.type.APPLICATION_JSON))
{
REST.set_header_content_type(response, REST.type.APPLICATION_JSON);
snprintf(message, REST_MAX_CHUNK_SIZE, "{\"temp\":\"%d.%d\"}",grad,kgrad);
// snprintf(message, REST_MAX_CHUNK_SIZE, "{\"temp\":\"%d.%d\"}",grad,kgrad);
snprintf(message, REST_MAX_CHUNK_SIZE, "{\"temp\":\"%4d\"}",grad*100+kgrad*10);
length = strlen(message);
memcpy(buffer, message,length );
@ -203,7 +205,7 @@ dht11temp_handler(void* request, void* response, uint8_t *buffer, uint16_t prefe
if ((num==0) || (num && accept[0]==REST.type.TEXT_PLAIN))
{
REST.set_header_content_type(response, REST.type.TEXT_PLAIN);
snprintf(message, REST_MAX_CHUNK_SIZE, "%2d",dht11_temp);
snprintf(message, REST_MAX_CHUNK_SIZE, "%4d",dht11_temp);
length = strlen(message);
memcpy(buffer, message,length );
@ -213,7 +215,7 @@ dht11temp_handler(void* request, void* response, uint8_t *buffer, uint16_t prefe
else if (num && (accept[0]==REST.type.APPLICATION_JSON))
{
REST.set_header_content_type(response, REST.type.APPLICATION_JSON);
snprintf(message, REST_MAX_CHUNK_SIZE, "{\"temp\":\"%d\"}",dht11_temp);
snprintf(message, REST_MAX_CHUNK_SIZE, "{\"temp\":\"%4d\"}",dht11_temp);
length = strlen(message);
memcpy(buffer, message,length );

View file

@ -107,11 +107,11 @@ uint8_t DHT_Read_Data(uint16_t *temperature, uint16_t *humidity){
//Check if data received are correct by checking the CheckSum
if ((uint8_t)(data[0] + data[1] + data[2] + data[3]) == data[4]) {
#ifdef DHT11
*humidity = data[0];
*temperature = data[2];
*humidity = data[0]*100;
*temperature = data[2]*100;
#else
*humidity = (uint16_t)data[0]<<8 | data[1];
*temperature = (uint16_t)data[2]<<8 | data[3];
*humidity = ((uint16_t)data[0]<<8 | data[1])*10;
*temperature = ((uint16_t)data[2]<<8 | data[3])*10;
#endif
return 0;
}else{