Some finishing touches.
- Print *_timer_cb consistently (add units "C" and "%" at .2f precision) - Guard HTU21DF and SI7021 from co-existing (both devices are on the same I2C address) - Differentiate between BME280 and BMP280 in metrics - Update README with timing information - Link in all drivers
This commit is contained in:
10
README.md
10
README.md
@ -30,7 +30,7 @@ humidity{sensor="1",type="DHT"} 35.599998
|
|||||||
This is using `veml6075-i2c` library; one sensor is allowed based on I2C
|
This is using `veml6075-i2c` library; one sensor is allowed based on I2C
|
||||||
address on the bus, normally `0x10`, but configurable with `sensors.veml6075_i2caddr`
|
address on the bus, normally `0x10`, but configurable with `sensors.veml6075_i2caddr`
|
||||||
in `mos.yml`. The chip is polled with a period of `sensors.veml6075_period`
|
in `mos.yml`. The chip is polled with a period of `sensors.veml6075_period`
|
||||||
which defaults to 3 seconds, each sensor reading takes approximately 11ms.
|
which defaults to 3 seconds, each sensor reading takes approximately 15ms.
|
||||||
|
|
||||||
Please see the upstream [source](https://github.com/mongoose-os-libs/veml6075-i2c)
|
Please see the upstream [source](https://github.com/mongoose-os-libs/veml6075-i2c)
|
||||||
for more information on the driver.
|
for more information on the driver.
|
||||||
@ -67,7 +67,7 @@ pressure{sensor="0",type="BME280"} 96720.4
|
|||||||
This is using `mcp9808-i2c` library; one sensor is allowed based on I2C
|
This is using `mcp9808-i2c` library; one sensor is allowed based on I2C
|
||||||
address on the bus, normally `0x18`, but configurable with `sensors.mcp9808_i2caddr`
|
address on the bus, normally `0x18`, but configurable with `sensors.mcp9808_i2caddr`
|
||||||
in `mos.yml`. The chip is polled with a period of `sensors.mcp9808_period`
|
in `mos.yml`. The chip is polled with a period of `sensors.mcp9808_period`
|
||||||
which defaults to 3 seconds, each sensor reading takes approximately 4ms.
|
which defaults to 3 seconds, each sensor reading takes approximately 3ms.
|
||||||
|
|
||||||
Please see the upstream [source](https://github.com/mongoose-os-libs/mcp9808-i2c)
|
Please see the upstream [source](https://github.com/mongoose-os-libs/mcp9808-i2c)
|
||||||
for more information on the driver.
|
for more information on the driver.
|
||||||
@ -82,7 +82,7 @@ temperature{sensor="0",type="MCP9808"} 18.6
|
|||||||
This is using `si7021-i2c` library; one sensor is allowed based on I2C
|
This is using `si7021-i2c` library; one sensor is allowed based on I2C
|
||||||
address on the bus, normally `0x40`, but configurable with `sensors.si7021_i2caddr`
|
address on the bus, normally `0x40`, but configurable with `sensors.si7021_i2caddr`
|
||||||
in `mos.yml`. The chip is polled with a period of `sensors.si7021_period`
|
in `mos.yml`. The chip is polled with a period of `sensors.si7021_period`
|
||||||
which defaults to 3 seconds, each sensor reading takes approximately 4ms.
|
which defaults to 3 seconds, each sensor reading takes approximately 54ms.
|
||||||
|
|
||||||
Please see the upstream [source](https://github.com/mongoose-os-libs/si7021-i2c)
|
Please see the upstream [source](https://github.com/mongoose-os-libs/si7021-i2c)
|
||||||
for more information on the driver.
|
for more information on the driver.
|
||||||
@ -98,7 +98,7 @@ humidity{sensor="0",type="SI7021"} 56.4
|
|||||||
This is using `sht31-i2c` library; one sensor is allowed based on I2C
|
This is using `sht31-i2c` library; one sensor is allowed based on I2C
|
||||||
address on the bus, normally `0x44`, but configurable with `sensors.sht31_i2caddr`
|
address on the bus, normally `0x44`, but configurable with `sensors.sht31_i2caddr`
|
||||||
in `mos.yml`. The chip is polled with a period of `sensors.sht31_period`
|
in `mos.yml`. The chip is polled with a period of `sensors.sht31_period`
|
||||||
which defaults to 3 seconds, each sensor reading takes approximately 4ms.
|
which defaults to 3 seconds, each sensor reading takes approximately 18ms.
|
||||||
|
|
||||||
Please see the upstream [source](https://github.com/mongoose-os-libs/si7021-i2c)
|
Please see the upstream [source](https://github.com/mongoose-os-libs/si7021-i2c)
|
||||||
for more information on the driver.
|
for more information on the driver.
|
||||||
@ -114,7 +114,7 @@ humidity{sensor="0",type="SHT31"} 56.4
|
|||||||
This is using `htu21df-i2c` library; one sensor is allowed based on I2C
|
This is using `htu21df-i2c` library; one sensor is allowed based on I2C
|
||||||
address on the bus, normally `0x40`, but configurable with `sensors.htu21df_i2caddr`
|
address on the bus, normally `0x40`, but configurable with `sensors.htu21df_i2caddr`
|
||||||
in `mos.yml`. The chip is polled with a period of `sensors.htu21df_period`
|
in `mos.yml`. The chip is polled with a period of `sensors.htu21df_period`
|
||||||
which defaults to 3 seconds, each sensor reading takes approximately 4ms.
|
which defaults to 3 seconds, each sensor reading takes approximately 105ms.
|
||||||
|
|
||||||
Please see the upstream [source](https://github.com/mongoose-os-libs/si7021-i2c)
|
Please see the upstream [source](https://github.com/mongoose-os-libs/si7021-i2c)
|
||||||
for more information on the driver.
|
for more information on the driver.
|
||||||
|
@ -11,20 +11,23 @@ static struct mgos_bme280_data s_bme280_data;
|
|||||||
|
|
||||||
static void bme280_prometheus_metrics(struct mg_connection *nc, void *user_data) {
|
static void bme280_prometheus_metrics(struct mg_connection *nc, void *user_data) {
|
||||||
|
|
||||||
|
bool bme280;
|
||||||
|
|
||||||
if (!s_bme280) return;
|
if (!s_bme280) return;
|
||||||
|
bme280=mgos_bme280_is_bme280(s_bme280);
|
||||||
|
|
||||||
mgos_prometheus_metrics_printf(nc, GAUGE,
|
mgos_prometheus_metrics_printf(nc, GAUGE,
|
||||||
"pressure", "Barometer pressure in HPa",
|
"pressure", "Barometer pressure in HPa",
|
||||||
"{sensor=\"0\", type=\"BME280\"} %f", s_bme280_data.press);
|
"{sensor=\"0\", type=\"BM%s280\"} %f", bme280?"E":"P", s_bme280_data.press);
|
||||||
|
|
||||||
mgos_prometheus_metrics_printf(nc, GAUGE,
|
mgos_prometheus_metrics_printf(nc, GAUGE,
|
||||||
"temperature", "Temperature in Celcius",
|
"temperature", "Temperature in Celcius",
|
||||||
"{sensor=\"0\",type=\"BME280\"} %f", s_bme280_data.temp);
|
"{sensor=\"0\",type=\"BM%s280\"} %f", bme280?"E":"P", s_bme280_data.temp);
|
||||||
|
|
||||||
if (mgos_bme280_is_bme280(s_bme280)) {
|
if (mgos_bme280_is_bme280(s_bme280)) {
|
||||||
mgos_prometheus_metrics_printf(nc, GAUGE,
|
mgos_prometheus_metrics_printf(nc, GAUGE,
|
||||||
"humidity", "Relative humidity in percent",
|
"humidity", "Relative humidity in percent",
|
||||||
"{sensor=\"0\",type=\"BME280\"} %f", s_bme280_data.humid);
|
"{sensor=\"0\",type=\"BM%s280\"} %f", bme280?"E":"P", s_bme280_data.humid);
|
||||||
}
|
}
|
||||||
|
|
||||||
(void) user_data;
|
(void) user_data;
|
||||||
@ -39,9 +42,9 @@ static void bme280_timer_cb(void *user_data) {
|
|||||||
usecs=1000000*(mgos_uptime()-start);
|
usecs=1000000*(mgos_uptime()-start);
|
||||||
|
|
||||||
if (mgos_bme280_is_bme280(s_bme280)) {
|
if (mgos_bme280_is_bme280(s_bme280)) {
|
||||||
LOG(LL_INFO, ("sensor=0 humidity=%.1f%% temperature=%.1fC pressure=%.1fHPa usecs=%u", s_bme280_data.humid, s_bme280_data.temp, s_bme280_data.press, usecs));
|
LOG(LL_INFO, ("BME280 sensor=0 humidity=%.2f%% temperature=%.2fC pressure=%.1fHPa usecs=%u", s_bme280_data.humid, s_bme280_data.temp, s_bme280_data.press, usecs));
|
||||||
} else {
|
} else {
|
||||||
LOG(LL_INFO, ("sensor=0 temperature=%.1fC pressure=%.1fHPa usecs=%u", s_bme280_data.temp, s_bme280_data.press, usecs));
|
LOG(LL_INFO, ("BMP280 sensor=0 temperature=%.2fC pressure=%.1fHPa usecs=%u", s_bme280_data.temp, s_bme280_data.press, usecs));
|
||||||
}
|
}
|
||||||
|
|
||||||
(void) user_data;
|
(void) user_data;
|
||||||
|
@ -46,7 +46,7 @@ static void dht_timer_cb(void *user_data) {
|
|||||||
dht_sensor->temp = mgos_dht_get_temp(dht_sensor->dht);
|
dht_sensor->temp = mgos_dht_get_temp(dht_sensor->dht);
|
||||||
dht_sensor->humidity = mgos_dht_get_humidity(dht_sensor->dht);
|
dht_sensor->humidity = mgos_dht_get_humidity(dht_sensor->dht);
|
||||||
usecs=1000000*(mgos_uptime()-start);
|
usecs=1000000*(mgos_uptime()-start);
|
||||||
LOG(LL_DEBUG, ("DHT sensor=%u gpio=%u temp=%.2fC humidity=%.0f%% usecs=%u", dht_sensor->idx, dht_sensor->gpio, dht_sensor->temp, dht_sensor->humidity, usecs));
|
LOG(LL_INFO, ("DHT sensor=%u gpio=%u temperature=%.2fC humidity=%.0f%% usecs=%u", dht_sensor->idx, dht_sensor->gpio, dht_sensor->temp, dht_sensor->humidity, usecs));
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool dht_sensor_create(int pin, enum dht_type type) {
|
static bool dht_sensor_create(int pin, enum dht_type type) {
|
||||||
|
@ -28,12 +28,15 @@ static void htu21df_timer_cb(void *user_data) {
|
|||||||
temperature=mgos_htu21df_getTemperature(s_htu21df);
|
temperature=mgos_htu21df_getTemperature(s_htu21df);
|
||||||
humidity=mgos_htu21df_getHumidity(s_htu21df);
|
humidity=mgos_htu21df_getHumidity(s_htu21df);
|
||||||
usecs=1000000*(mgos_uptime()-start);
|
usecs=1000000*(mgos_uptime()-start);
|
||||||
LOG(LL_INFO, ("HTU21DF sensor=0 temperature=%.2f humidity=%.1f usecs=%u", temperature, humidity, usecs));
|
LOG(LL_INFO, ("HTU21DF sensor=0 temperature=%.2fC humidity=%.1f%% usecs=%u", temperature, humidity, usecs));
|
||||||
|
|
||||||
(void) user_data;
|
(void) user_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void htu21df_drv_init() {
|
void htu21df_drv_init() {
|
||||||
|
#ifdef MGOS_HAVE_SI7021_I2C
|
||||||
|
LOG(LL_WARN, ("HTU21DF and SI7021 are both on I2C address 0x40 -- do not enable both!"));
|
||||||
|
#endif
|
||||||
s_htu21df = mgos_htu21df_create(mgos_i2c_get_global(), mgos_sys_config_get_sensors_htu21df_i2caddr());
|
s_htu21df = mgos_htu21df_create(mgos_i2c_get_global(), mgos_sys_config_get_sensors_htu21df_i2caddr());
|
||||||
if (s_htu21df) {
|
if (s_htu21df) {
|
||||||
mgos_set_timer(mgos_sys_config_get_sensors_htu21df_period()*1000, true, htu21df_timer_cb, NULL);
|
mgos_set_timer(mgos_sys_config_get_sensors_htu21df_period()*1000, true, htu21df_timer_cb, NULL);
|
||||||
|
@ -23,7 +23,7 @@ static void mcp9808_timer_cb(void *user_data) {
|
|||||||
start=mgos_uptime();
|
start=mgos_uptime();
|
||||||
temperature=mgos_mcp9808_getTemperature(s_mcp9808);
|
temperature=mgos_mcp9808_getTemperature(s_mcp9808);
|
||||||
usecs=1000000*(mgos_uptime()-start);
|
usecs=1000000*(mgos_uptime()-start);
|
||||||
LOG(LL_INFO, ("MCP9808 sensor=0 temperature=%.2f usecs=%u", temperature, usecs));
|
LOG(LL_INFO, ("MCP9808 sensor=0 temperature=%.2fC usecs=%u", temperature, usecs));
|
||||||
|
|
||||||
(void) user_data;
|
(void) user_data;
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,10 @@
|
|||||||
void dht_drv_init();
|
void dht_drv_init();
|
||||||
void veml6075_drv_init();
|
void veml6075_drv_init();
|
||||||
void bme280_drv_init();
|
void bme280_drv_init();
|
||||||
|
void sht31_drv_init();
|
||||||
|
void si7021_drv_init();
|
||||||
|
void htu21df_drv_init();
|
||||||
|
void mcp9808_drv_init();
|
||||||
|
|
||||||
static void pushgateway_timer(void *user_data) {
|
static void pushgateway_timer(void *user_data) {
|
||||||
mgos_prometheus_metrics_push(MGOS_APP, mgos_sys_config_get_device_id());
|
mgos_prometheus_metrics_push(MGOS_APP, mgos_sys_config_get_device_id());
|
||||||
@ -15,6 +19,11 @@ bool mgos_prometheus_sensors_init(void) {
|
|||||||
dht_drv_init();
|
dht_drv_init();
|
||||||
veml6075_drv_init();
|
veml6075_drv_init();
|
||||||
bme280_drv_init();
|
bme280_drv_init();
|
||||||
|
si7021_drv_init();
|
||||||
|
sht31_drv_init();
|
||||||
|
htu21df_drv_init();
|
||||||
|
mcp9808_drv_init();
|
||||||
|
|
||||||
if (mgos_sys_config_get_sensors_pushgateway_period()>0)
|
if (mgos_sys_config_get_sensors_pushgateway_period()>0)
|
||||||
mgos_set_timer(mgos_sys_config_get_sensors_pushgateway_period()*1000, true, pushgateway_timer, NULL);
|
mgos_set_timer(mgos_sys_config_get_sensors_pushgateway_period()*1000, true, pushgateway_timer, NULL);
|
||||||
return true;
|
return true;
|
||||||
|
@ -28,12 +28,14 @@ static void sht31_timer_cb(void *user_data) {
|
|||||||
temperature=mgos_sht31_getTemperature(s_sht31);
|
temperature=mgos_sht31_getTemperature(s_sht31);
|
||||||
humidity=mgos_sht31_getHumidity(s_sht31);
|
humidity=mgos_sht31_getHumidity(s_sht31);
|
||||||
usecs=1000000*(mgos_uptime()-start);
|
usecs=1000000*(mgos_uptime()-start);
|
||||||
LOG(LL_INFO, ("SHT31 sensor=0 temperature=%.2f humidity=%.1f usecs=%u", temperature, humidity, usecs));
|
LOG(LL_INFO, ("SHT31 sensor=0 temperature=%.2fC humidity=%.1f%% usecs=%u", temperature, humidity, usecs));
|
||||||
|
|
||||||
(void) user_data;
|
(void) user_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sht31_drv_init() {
|
void sht31_drv_init() {
|
||||||
|
#ifdef MGOS_HAVE_SI7021_I2C
|
||||||
|
#endif
|
||||||
s_sht31 = mgos_sht31_create(mgos_i2c_get_global(), mgos_sys_config_get_sensors_sht31_i2caddr());
|
s_sht31 = mgos_sht31_create(mgos_i2c_get_global(), mgos_sys_config_get_sensors_sht31_i2caddr());
|
||||||
if (s_sht31) {
|
if (s_sht31) {
|
||||||
mgos_set_timer(mgos_sys_config_get_sensors_sht31_period()*1000, true, sht31_timer_cb, NULL);
|
mgos_set_timer(mgos_sys_config_get_sensors_sht31_period()*1000, true, sht31_timer_cb, NULL);
|
||||||
|
@ -28,12 +28,15 @@ static void si7021_timer_cb(void *user_data) {
|
|||||||
temperature=mgos_si7021_getTemperature(s_si7021);
|
temperature=mgos_si7021_getTemperature(s_si7021);
|
||||||
humidity=mgos_si7021_getHumidity(s_si7021);
|
humidity=mgos_si7021_getHumidity(s_si7021);
|
||||||
usecs=1000000*(mgos_uptime()-start);
|
usecs=1000000*(mgos_uptime()-start);
|
||||||
LOG(LL_INFO, ("SI7021 sensor=0 temperature=%.2f humidity=%.1f usecs=%u", temperature, humidity, usecs));
|
LOG(LL_INFO, ("SI7021 sensor=0 temperature=%.2fC humidity=%.1f%% usecs=%u", temperature, humidity, usecs));
|
||||||
|
|
||||||
(void) user_data;
|
(void) user_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void si7021_drv_init() {
|
void si7021_drv_init() {
|
||||||
|
#ifdef MGOS_HAVE_HTU21DF_I2C
|
||||||
|
LOG(LL_WARN, ("HTU21DF and SI7021 are both on I2C address 0x40 -- do not enable both!"));
|
||||||
|
#endif
|
||||||
s_si7021 = mgos_si7021_create(mgos_i2c_get_global(), mgos_sys_config_get_sensors_si7021_i2caddr());
|
s_si7021 = mgos_si7021_create(mgos_i2c_get_global(), mgos_sys_config_get_sensors_si7021_i2caddr());
|
||||||
if (s_si7021) {
|
if (s_si7021) {
|
||||||
mgos_set_timer(mgos_sys_config_get_sensors_si7021_period()*1000, true, si7021_timer_cb, NULL);
|
mgos_set_timer(mgos_sys_config_get_sensors_si7021_period()*1000, true, si7021_timer_cb, NULL);
|
||||||
|
Reference in New Issue
Block a user