bugfix hum temp
This commit is contained in:
parent
730d9e2d11
commit
9c90608d3c
|
@ -67,11 +67,13 @@ extern resource_t res_info;
|
||||||
#if PLATFORM_HAS_DHT11HUM
|
#if PLATFORM_HAS_DHT11HUM
|
||||||
#include "dev/dht11.h"
|
#include "dev/dht11.h"
|
||||||
extern resource_t res_dht11hum;
|
extern resource_t res_dht11hum;
|
||||||
|
extern uint16_t dht11_hum;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if PLATFORM_HAS_DHT11TEMP
|
#if PLATFORM_HAS_DHT11TEMP
|
||||||
#include "dev/dht11.h"
|
#include "dev/dht11.h"
|
||||||
extern resource_t res_dht11temp;
|
extern resource_t res_dht11temp;
|
||||||
|
extern uint16_t dht11_temp;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined (PLATFORM_HAS_DS1820)
|
#if defined (PLATFORM_HAS_DS1820)
|
||||||
|
@ -103,8 +105,7 @@ hw_init()
|
||||||
#if PLATFORM_HAS_DS1820
|
#if PLATFORM_HAS_DS1820
|
||||||
ds1820_temp();
|
ds1820_temp();
|
||||||
#endif
|
#endif
|
||||||
#if PLATFORM_HAS_DHT11
|
#if PLATFORM_HAS_DHT11HUM
|
||||||
//DHT_INIT();
|
|
||||||
DHT_Read_Data(&dht11_temp, &dht11_hum);
|
DHT_Read_Data(&dht11_temp, &dht11_hum);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -153,7 +154,7 @@ PROCESS_THREAD(rest_server_example, ev, data)
|
||||||
#if PLATFORM_HAS_DS1820
|
#if PLATFORM_HAS_DS1820
|
||||||
rest_activate_resource(&res_ds1820,"s/temp");
|
rest_activate_resource(&res_ds1820,"s/temp");
|
||||||
#endif
|
#endif
|
||||||
#if PLATFORM_HAS_DHT11
|
#if PLATFORM_HAS_DHT11HUM
|
||||||
rest_activate_resource(&res_dht11hum,"s/hum");
|
rest_activate_resource(&res_dht11hum,"s/hum");
|
||||||
#endif
|
#endif
|
||||||
#if PLATFORM_HAS_DHT11TEMP
|
#if PLATFORM_HAS_DHT11TEMP
|
||||||
|
@ -186,8 +187,7 @@ PROCESS_THREAD(rest_server_example, ev, data)
|
||||||
if(etimer_expired(&ds_periodic_timer)) {
|
if(etimer_expired(&ds_periodic_timer)) {
|
||||||
PRINTF("Periodic\n");
|
PRINTF("Periodic\n");
|
||||||
etimer_reset(&ds_periodic_timer);
|
etimer_reset(&ds_periodic_timer);
|
||||||
#if PLATFORM_HAS_DHT11
|
#if PLATFORM_HAS_DHT11HUM
|
||||||
// DHT_Read_Data(&dht11_temp, &dht11_hum);
|
|
||||||
DHT_Read_Data(&dht11_temp, &dht11_hum);
|
DHT_Read_Data(&dht11_temp, &dht11_hum);
|
||||||
#endif
|
#endif
|
||||||
#if PLATFORM_HAS_DS1820
|
#if PLATFORM_HAS_DS1820
|
||||||
|
|
|
@ -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) {
|
if(accept == -1 || accept == REST.type.TEXT_PLAIN) {
|
||||||
REST.set_header_content_type(response, 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) {
|
} else if(accept == REST.type.APPLICATION_JSON) {
|
||||||
REST.set_header_content_type(response, 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));
|
REST.set_response_payload(response, buffer, strlen((char *)buffer));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -98,4 +98,4 @@ res_get_dht11hum_handler(void* request, void* response, uint8_t *buffer, uint16_
|
||||||
REST.set_response_payload(response, (uint8_t *)"Supporting content-types text/plain and application/json", 56);
|
REST.set_response_payload(response, (uint8_t *)"Supporting content-types text/plain and application/json", 56);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* PLATFORM_HAS_DS1820 */
|
#endif /* PLATFORM_HAS_DHT11HUM */
|
||||||
|
|
|
@ -71,12 +71,11 @@ res_get_dht11temp_handler(void* request, void* response, uint8_t *buffer, uint16
|
||||||
{
|
{
|
||||||
char message[100];
|
char message[100];
|
||||||
int length = 0; /* |<-------->| */
|
int length = 0; /* |<-------->| */
|
||||||
|
|
||||||
|
unsigned int accept = -1;
|
||||||
|
REST.get_header_accept(request, &accept);
|
||||||
|
|
||||||
const uint16_t *accept = NULL;
|
if(accept == -1 || accept == REST.type.TEXT_PLAIN){
|
||||||
int num = REST.get_header_accept(request, &accept);
|
|
||||||
|
|
||||||
if ((num==0) || (num && accept[0]==REST.type.TEXT_PLAIN))
|
|
||||||
{
|
|
||||||
REST.set_header_content_type(response, REST.type.TEXT_PLAIN);
|
REST.set_header_content_type(response, REST.type.TEXT_PLAIN);
|
||||||
snprintf(message, REST_MAX_CHUNK_SIZE, "%d.%02d",dht11_temp/100, dht11_temp % 100);
|
snprintf(message, REST_MAX_CHUNK_SIZE, "%d.%02d",dht11_temp/100, dht11_temp % 100);
|
||||||
|
|
||||||
|
@ -85,7 +84,7 @@ res_get_dht11temp_handler(void* request, void* response, uint8_t *buffer, uint16
|
||||||
|
|
||||||
REST.set_response_payload(response, buffer, length);
|
REST.set_response_payload(response, buffer, length);
|
||||||
}
|
}
|
||||||
else if (num && (accept[0]==REST.type.APPLICATION_JSON))
|
else if (accept == REST.type.APPLICATION_JSON)
|
||||||
{
|
{
|
||||||
REST.set_header_content_type(response, REST.type.APPLICATION_JSON);
|
REST.set_header_content_type(response, REST.type.APPLICATION_JSON);
|
||||||
snprintf(message, REST_MAX_CHUNK_SIZE, "{\"temp\":\"%d.%02d\"}",dht11_temp/100, dht11_temp % 100);
|
snprintf(message, REST_MAX_CHUNK_SIZE, "{\"temp\":\"%d.%02d\"}",dht11_temp/100, dht11_temp % 100);
|
||||||
|
|
|
@ -72,8 +72,8 @@ res_get_info_handler(void* request, void* response, uint8_t *buffer, uint16_t pr
|
||||||
|
|
||||||
/* Some data that has the length up to REST_MAX_CHUNK_SIZE. For more, see the chunk resource. */
|
/* Some data that has the length up to REST_MAX_CHUNK_SIZE. For more, see the chunk resource. */
|
||||||
// jSON Format
|
// jSON Format
|
||||||
index += sprintf(message + index,"{\n \"version\" : \"V0.4.3\",\n");
|
index += sprintf(message + index,"{\n \"version\" : \"V0.5.0\",\n");
|
||||||
index += sprintf(message + index," \"name\" : \"6lowpan-climate\"\n");
|
index += sprintf(message + index," \"name\" : \"6lowpan-climate2\"\n");
|
||||||
index += sprintf(message + index,"}\n");
|
index += sprintf(message + index,"}\n");
|
||||||
|
|
||||||
length = strlen(message);
|
length = strlen(message);
|
||||||
|
|
Loading…
Reference in a new issue