Add DHT temp/humidity getters.
+float mgos_prometheus_sensors_dht_get_temp(uint8_t idx); +float mgos_prometheus_sensors_dht_get_humidity(uint8_t idx); They return NAN if the index is invalid, or the sensor couldn't be found. Otherwise, they return the last measured temperature or humidity values as floats.
This commit is contained in:
@ -4,4 +4,7 @@
|
|||||||
#include "mgos.h"
|
#include "mgos.h"
|
||||||
#include "mgos_gpio.h"
|
#include "mgos_gpio.h"
|
||||||
|
|
||||||
|
float mgos_prometheus_sensors_dht_get_temp(uint8_t idx);
|
||||||
|
float mgos_prometheus_sensors_dht_get_humidity(uint8_t idx);
|
||||||
|
|
||||||
#endif // __MGOS_PROMETHEUS_SENSORS_H
|
#endif // __MGOS_PROMETHEUS_SENSORS_H
|
||||||
|
16
src/dht.c
16
src/dht.c
@ -91,6 +91,22 @@ static bool dht_sensor_create(int pin, enum dht_type type) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float mgos_prometheus_sensors_dht_get_temp(uint8_t idx) {
|
||||||
|
if (idx>=s_num_dht)
|
||||||
|
return NAN;
|
||||||
|
if (!s_dht_sensor[idx])
|
||||||
|
return NAN;
|
||||||
|
return s_dht_sensor[idx]->temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
float mgos_prometheus_sensors_dht_get_humidity(uint8_t idx) {
|
||||||
|
if (idx>=s_num_dht)
|
||||||
|
return NAN;
|
||||||
|
if (!s_dht_sensor[idx])
|
||||||
|
return NAN;
|
||||||
|
return s_dht_sensor[idx]->humidity;
|
||||||
|
}
|
||||||
|
|
||||||
void dht_init() {
|
void dht_init() {
|
||||||
char *tok;
|
char *tok;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user