Format code (BCPP)
This commit is contained in:
@ -6,5 +6,4 @@
|
||||
|
||||
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
|
||||
|
@ -49,10 +49,10 @@ static void bme280_prometheus_metrics(struct mg_connection *nc, void *user_data)
|
||||
"{sensor=\"0\",type=\"BM%s280\"} %f", bme280?"E":"P", stats.read_success_usecs);
|
||||
}
|
||||
|
||||
|
||||
(void) user_data;
|
||||
}
|
||||
|
||||
|
||||
static void bme280_timer_cb(void *user_data) {
|
||||
struct mgos_bme280_stats stats_before, stats_after;
|
||||
uint32_t usecs=0;
|
||||
@ -65,23 +65,27 @@ static void bme280_timer_cb(void *user_data) {
|
||||
|
||||
if (mgos_bme280_is_bme280(s_bme280)) {
|
||||
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, ("BMP280 sensor=0 temperature=%.2fC pressure=%.1fHPa usecs=%u", s_bme280_data.temp, s_bme280_data.press, usecs));
|
||||
}
|
||||
|
||||
(void) user_data;
|
||||
}
|
||||
|
||||
|
||||
void bme280_drv_init() {
|
||||
s_bme280 = mgos_bme280_i2c_create(mgos_sys_config_get_sensors_bme280_i2caddr());
|
||||
if (s_bme280) {
|
||||
mgos_set_timer(mgos_sys_config_get_sensors_bme280_period()*1000, true, bme280_timer_cb, NULL);
|
||||
mgos_prometheus_metrics_add_handler(bme280_prometheus_metrics, NULL);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
LOG(LL_ERROR, ("Could not create BME280 sensor on I2C address 0x%02x", mgos_sys_config_get_sensors_bme280_i2caddr()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
void bme280_drv_init() {
|
||||
LOG(LL_ERROR, ("BME280 disabled, include library in mos.yml to enable"));
|
||||
|
@ -8,7 +8,8 @@
|
||||
|
||||
#define MAX_DHT 8
|
||||
|
||||
struct dht_sensor {
|
||||
struct dht_sensor
|
||||
{
|
||||
struct mgos_dht *dht;
|
||||
float temp;
|
||||
float humidity;
|
||||
@ -54,6 +55,7 @@ static void dht_prometheus_metrics(struct mg_connection *nc, void *user_data) {
|
||||
(void) user_data;
|
||||
}
|
||||
|
||||
|
||||
static void dht_timer_cb(void *user_data) {
|
||||
struct dht_sensor *dht_sensor = (struct dht_sensor *)user_data;
|
||||
struct mgos_dht_stats stats_before, stats_after;
|
||||
@ -70,6 +72,7 @@ static void dht_timer_cb(void *user_data) {
|
||||
LOG(LL_INFO, ("DHT sensor=%u gpio=%u temperature=%.2fC humidity=%.1f%% 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) {
|
||||
struct dht_sensor *dht_sensor = calloc(1, sizeof(struct dht_sensor));
|
||||
if (s_num_dht == MAX_DHT) {
|
||||
@ -92,6 +95,7 @@ static bool dht_sensor_create(int pin, enum dht_type type) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
float mgos_prometheus_sensors_dht_get_temp(uint8_t idx) {
|
||||
if (idx>=s_num_dht)
|
||||
return NAN;
|
||||
@ -100,6 +104,7 @@ float mgos_prometheus_sensors_dht_get_temp(uint8_t idx) {
|
||||
return s_dht_sensor[idx]->temp;
|
||||
}
|
||||
|
||||
|
||||
float mgos_prometheus_sensors_dht_get_humidity(uint8_t idx) {
|
||||
if (idx>=s_num_dht)
|
||||
return NAN;
|
||||
@ -108,6 +113,7 @@ float mgos_prometheus_sensors_dht_get_humidity(uint8_t idx) {
|
||||
return s_dht_sensor[idx]->humidity;
|
||||
}
|
||||
|
||||
|
||||
void dht_drv_init() {
|
||||
char *tok;
|
||||
|
||||
@ -125,6 +131,7 @@ void dht_drv_init() {
|
||||
mgos_prometheus_metrics_add_handler(dht_prometheus_metrics, NULL);
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
void dht_drv_init() {
|
||||
LOG(LL_ERROR, ("DHT disabled, include library in mos.yml to enable"));
|
||||
|
@ -40,6 +40,7 @@ static void htu21df_prometheus_metrics(struct mg_connection *nc, void *user_data
|
||||
(void) user_data;
|
||||
}
|
||||
|
||||
|
||||
static void htu21df_timer_cb(void *user_data) {
|
||||
float temperature, humidity;
|
||||
struct mgos_htu21df_stats stats_before, stats_after;
|
||||
@ -56,10 +57,11 @@ static void htu21df_timer_cb(void *user_data) {
|
||||
(void) user_data;
|
||||
}
|
||||
|
||||
|
||||
void htu21df_drv_init() {
|
||||
#ifdef MGOS_HAVE_SI7021_I2C
|
||||
#ifdef MGOS_HAVE_SI7021_I2C
|
||||
LOG(LL_WARN, ("HTU21DF and SI7021 are both on I2C address 0x40 -- do not enable both!"));
|
||||
#endif
|
||||
#endif
|
||||
s_htu21df = mgos_htu21df_create(mgos_i2c_get_global(), mgos_sys_config_get_sensors_htu21df_i2caddr());
|
||||
if (s_htu21df) {
|
||||
mgos_set_timer(mgos_sys_config_get_sensors_htu21df_period()*1000, true, htu21df_timer_cb, NULL);
|
||||
@ -67,6 +69,7 @@ void htu21df_drv_init() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
void htu21df_drv_init() {
|
||||
LOG(LL_ERROR, ("HTU21DF disabled, include library in mos.yml to enable"));
|
||||
|
@ -37,6 +37,7 @@ static void mcp9808_prometheus_metrics(struct mg_connection *nc, void *user_data
|
||||
(void) user_data;
|
||||
}
|
||||
|
||||
|
||||
static void mcp9808_timer_cb(void *user_data) {
|
||||
float temperature;
|
||||
struct mgos_mcp9808_stats stats_before, stats_after;
|
||||
@ -52,6 +53,7 @@ static void mcp9808_timer_cb(void *user_data) {
|
||||
(void) user_data;
|
||||
}
|
||||
|
||||
|
||||
void mcp9808_drv_init() {
|
||||
s_mcp9808 = mgos_mcp9808_create(mgos_i2c_get_global(), mgos_sys_config_get_sensors_mcp9808_i2caddr());
|
||||
if (s_mcp9808) {
|
||||
@ -60,6 +62,7 @@ void mcp9808_drv_init() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
void mcp9808_drv_init() {
|
||||
LOG(LL_ERROR, ("MCP9808 disabled, include library in mos.yml to enable"));
|
||||
|
@ -15,6 +15,7 @@ static void pushgateway_timer(void *user_data) {
|
||||
(void) user_data;
|
||||
}
|
||||
|
||||
|
||||
bool mgos_prometheus_sensors_init(void) {
|
||||
dht_drv_init();
|
||||
veml6075_drv_init();
|
||||
|
@ -40,6 +40,7 @@ static void sht31_prometheus_metrics(struct mg_connection *nc, void *user_data)
|
||||
(void) user_data;
|
||||
}
|
||||
|
||||
|
||||
static void sht31_timer_cb(void *user_data) {
|
||||
float temperature, humidity;
|
||||
struct mgos_sht31_stats stats_before, stats_after;
|
||||
@ -56,9 +57,10 @@ static void sht31_timer_cb(void *user_data) {
|
||||
(void) user_data;
|
||||
}
|
||||
|
||||
|
||||
void sht31_drv_init() {
|
||||
#ifdef MGOS_HAVE_SI7021_I2C
|
||||
#endif
|
||||
#ifdef MGOS_HAVE_SI7021_I2C
|
||||
#endif
|
||||
s_sht31 = mgos_sht31_create(mgos_i2c_get_global(), mgos_sys_config_get_sensors_sht31_i2caddr());
|
||||
if (s_sht31) {
|
||||
mgos_set_timer(mgos_sys_config_get_sensors_sht31_period()*1000, true, sht31_timer_cb, NULL);
|
||||
@ -66,6 +68,7 @@ void sht31_drv_init() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
void sht31_drv_init() {
|
||||
LOG(LL_ERROR, ("SHT31 disabled, include library in mos.yml to enable"));
|
||||
|
@ -40,6 +40,7 @@ static void si7021_prometheus_metrics(struct mg_connection *nc, void *user_data)
|
||||
(void) user_data;
|
||||
}
|
||||
|
||||
|
||||
static void si7021_timer_cb(void *user_data) {
|
||||
float temperature, humidity;
|
||||
struct mgos_si7021_stats stats_before, stats_after;
|
||||
@ -56,10 +57,11 @@ static void si7021_timer_cb(void *user_data) {
|
||||
(void) user_data;
|
||||
}
|
||||
|
||||
|
||||
void si7021_drv_init() {
|
||||
#ifdef MGOS_HAVE_HTU21DF_I2C
|
||||
#ifdef MGOS_HAVE_HTU21DF_I2C
|
||||
LOG(LL_WARN, ("HTU21DF and SI7021 are both on I2C address 0x40 -- do not enable both!"));
|
||||
#endif
|
||||
#endif
|
||||
s_si7021 = mgos_si7021_create(mgos_i2c_get_global(), mgos_sys_config_get_sensors_si7021_i2caddr());
|
||||
if (s_si7021) {
|
||||
mgos_set_timer(mgos_sys_config_get_sensors_si7021_period()*1000, true, si7021_timer_cb, NULL);
|
||||
@ -67,6 +69,7 @@ void si7021_drv_init() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
void si7021_drv_init() {
|
||||
LOG(LL_ERROR, ("SI7021 disabled, include library in mos.yml to enable"));
|
||||
|
@ -43,6 +43,7 @@ static void veml6075_prometheus_metrics(struct mg_connection *nc, void *user_dat
|
||||
(void) user_data;
|
||||
}
|
||||
|
||||
|
||||
static void veml6075_timer_cb(void *user_data) {
|
||||
double start;
|
||||
uint32_t usecs=0;
|
||||
@ -58,6 +59,7 @@ static void veml6075_timer_cb(void *user_data) {
|
||||
(void) user_data;
|
||||
}
|
||||
|
||||
|
||||
void veml6075_drv_init() {
|
||||
s_veml6075 = mgos_veml6075_create(mgos_i2c_get_global(), mgos_sys_config_get_sensors_veml6075_i2caddr());
|
||||
if (s_veml6075) {
|
||||
@ -66,6 +68,7 @@ void veml6075_drv_init() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
void veml6075_drv_init() {
|
||||
LOG(LL_ERROR, ("VEML6075 disabled, include library in mos.yml to enable"));
|
||||
|
Reference in New Issue
Block a user