bugfix printf and float
This commit is contained in:
parent
617d42663c
commit
e3ffbe36c8
|
@ -14,6 +14,7 @@ CONTIKI=../../..
|
|||
CONTIKI_WITH_IPV6 = 1
|
||||
|
||||
CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\"
|
||||
LFLAGS += -lm
|
||||
|
||||
PROJECT_SOURCEFILES += ${SKETCH}.cpp Adafruit_HTU21DF.cpp Wire.cpp twi.c new.cpp WString.cpp Stream.cpp
|
||||
|
||||
|
|
|
@ -41,11 +41,11 @@
|
|||
#define LOOP_INTERVAL (10 * CLOCK_SECOND)
|
||||
|
||||
/* Save energy */
|
||||
#define RDC_CONF_PT_YIELD_OFF
|
||||
//#define RDC_CONF_PT_YIELD_OFF
|
||||
|
||||
/* For Debug: Dont allow MCU sleeping between channel checks */
|
||||
//#undef RDC_CONF_MCU_SLEEP
|
||||
//#define RDC_CONF_MCU_SLEEP 0
|
||||
#undef RDC_CONF_MCU_SLEEP
|
||||
#define RDC_CONF_MCU_SLEEP 0
|
||||
|
||||
/* Disabling RDC for demo purposes. Core updates often require more memory. */
|
||||
/* For projects, optimize memory and enable RDC again. */
|
||||
|
|
|
@ -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, "%f", htu21d_hum);
|
||||
snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "%f", (double) htu21d_hum);
|
||||
|
||||
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, "{'moisture':%f}", htu21d_hum);
|
||||
snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "{'moisture':%f}", (double) htu21d_hum);
|
||||
|
||||
REST.set_response_payload(response, buffer, strlen((char *)buffer));
|
||||
} else {
|
||||
|
|
|
@ -63,12 +63,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, "%f", htu21d_temp);
|
||||
snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "%f", (double) htu21d_temp);
|
||||
|
||||
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, "{'moisture':%f}", htu21d_temp);
|
||||
snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "{'moisture':%f}", (double) htu21d_temp);
|
||||
|
||||
REST.set_response_payload(response, buffer, strlen((char *)buffer));
|
||||
} else {
|
||||
|
|
|
@ -24,6 +24,8 @@ extern resource_t res_htu21dtemp, res_htu21dhum, res_battery;
|
|||
|
||||
float htu21d_hum;
|
||||
float htu21d_temp;
|
||||
char htu21d_hum_s[8];
|
||||
char htu21d_temp_s[8];
|
||||
|
||||
#define LED_PIN 4
|
||||
}
|
||||
|
@ -50,6 +52,8 @@ void loop (void)
|
|||
{
|
||||
htu21d_temp = htu.readTemperature();
|
||||
htu21d_hum = htu.readHumidity();
|
||||
printf("Temp: %f",htu21d_temp);
|
||||
printf("\t\tHum: %f",htu21d_hum);
|
||||
dtostrf(htu21d_temp , 6, 2, htu21d_temp_s );
|
||||
dtostrf(htu21d_hum , 6, 2, htu21d_hum_s );
|
||||
printf("Temp: %s",htu21d_temp_s);
|
||||
printf("\t\tHum: %s\n",htu21d_hum_s);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue