From bf413c9897f310bedf7f7d6fd99145c7cb8105ce Mon Sep 17 00:00:00 2001 From: Kai Lauterbach Date: Sun, 22 May 2022 16:35:10 +0200 Subject: [PATCH] Fixed review findings --- firmware/config.h | 24 ++++++++++++++++-------- firmware/config_user.h.example | 4 ++-- firmware/firmware.ino | 20 ++++++++------------ firmware/influxdb.ino | 4 +++- 4 files changed, 29 insertions(+), 23 deletions(-) mode change 100755 => 100644 firmware/config.h diff --git a/firmware/config.h b/firmware/config.h old mode 100755 new mode 100644 index 352a019..aeb536e --- a/firmware/config.h +++ b/firmware/config.h @@ -23,23 +23,31 @@ #define DELAY_LOOP_MS 50 #define POWERSAVING_SLEEP_S 600 #define EMERGENCY_SLEEP_S 172800 // Sleep for 2 days to recover +#define RESET_ESP_TIME_INTERVAL_MS 3600000 +#define WIND_SENSOR_MEAS_TIME_S 15.0 + #define ENERGY_SAVING_ITERATIONS 30 #define WIFI_MINIMUM_SIGNAL_QUALITY 10 // percent -#define RESET_ESP_TIME_INTERVAL_MS 3600000 -#define WIND_SENSOR_MEAS_TIME_S 15.0 +// thingiverse anomometer settings: https://www.thingiverse.com/thing:2559929/files #define ROTOR_LENGTH_CM 8.25 #define ROTOR_LENGTH_M (ROTOR_LENGTH_CM / 100.0) -#define ROTOR_LENGTH_KM (ROTOR_LENGTH_M / 1000.0) -#define SEC_TO_HOUR_FACTOR (60.0 * 60.0) +//#define ROTOR_LENGTH_KM (ROTOR_LENGTH_M / 1000.0) // configuration example for generalization +//#define SEC_TO_HOUR_FACTOR (60.0 * 60.0) // configuration example for generalization #define MPS_CORRECT_FACT 9.28 -#define COUNT_TO_KMH ((TWO_PI * ROTOR_LENGTH_KM / WIND_SENSOR_MEAS_TIME_S) * SEC_TO_HOUR_FACTOR) +//#define COUNT_TO_KMH ((TWO_PI * ROTOR_LENGTH_KM / WIND_SENSOR_MEAS_TIME_S) * SEC_TO_HOUR_FACTOR) // configuration exampe for generalization #define COUNT_TO_MPS (TWO_PI * ROTOR_LENGTH_M / WIND_SENSOR_MEAS_TIME_S) +// only this define is used for calculation, all other before are only used to describe the math v_wind = correction_factor * rotations * 2 * pi * radius / time_of_measurement_in_sec +// and if required the result has t be multiplied by another factor to convert it from m/s #define WINDSPEED_FACTOR (COUNT_TO_MPS * MPS_CORRECT_FACT) -#define HTTP_CALL_ON_WINDSPEED_EXCEED_MPS 5.0 // 5.0 m/s == 18 km/h -#define HTTP_CALL_ON_WINDSPEED_INTERVAL_S 60 // it's required to be bigger than WIND_SENSOR_MEAS_TIME_S -#define HTTP_CALL_ON_WINDSPEED_URL "http://192.168.0.250:3001/button-windspeedexceed?event=click" +// china aliexpress anemometer settings (calculation unknown) +//#define WINDSPEED_FACTOR 2.4 + +// enable HTTP_CALL_ON_WINDSPEED_EXCEED in config_user.h to enable this feature +#define HTTP_CALL_ON_WINDSPEED_EXCEED_MPS 5.0 // 5.0 m/s == 18 km/h +#define HTTP_CALL_ON_WINDSPEED_INTERVAL_S 60 // it's required to be bigger than WIND_SENSOR_MEAS_TIME_S +#define HTTP_CALL_ON_WINDSPEED_URL "http://192.168.178.100:3001/button-windspeedexceed?event=click" #define BAT_LOW_VOLTAGE 3.6 #define BAT_EMERGENCY_DEEPSLEEP_VOLTAGE 3.5 diff --git a/firmware/config_user.h.example b/firmware/config_user.h.example index d98217e..b8d4f83 100755 --- a/firmware/config_user.h.example +++ b/firmware/config_user.h.example @@ -41,8 +41,8 @@ const char *INFLUXDB_PASS = "password"; // InfluxDB2 credentials const char *INFLUXDB_URL = "http://192.168.0.123:3124"; const char *INFLUXDB_ORG = "home_org"; -const char *INFLUXDB_BUCKET = "mybucket; -const char *INFLUXDB_TOKEN = "your api tiken"; +const char *INFLUXDB_BUCKET = "mybucket"; +const char *INFLUXDB_TOKEN = "your api token"; // Device name // WARNING: Keep the name short! If your access point did not show up, you diff --git a/firmware/firmware.ino b/firmware/firmware.ino index 24ce7dd..aac9672 100644 --- a/firmware/firmware.ino +++ b/firmware/firmware.ino @@ -75,15 +75,7 @@ void setup() // the time in seconds to wait for the user to configure the device wifiManager.setTimeout(WIFI_CONFIG_PORTAL_TIMEOUT_S); -#ifndef SLEEP_IF_NO_WLAN_CONNECTION - // do not sleep, repeat connecting - while -#endif -#ifdef def SLEEP_IF_NO_WLAN_CONNECTION - // stop connecting after fail to connect to wifi - if -#endif - (!wifiManager.autoConnect(wifiName.c_str(), "DEADBEEF")) + while (!wifiManager.autoConnect(wifiName.c_str(), "DEADBEEF")) { debug("WiFi connection failed, try again in 5 seconds..."); // If autoconnect to WLAN failed and no client connected, go to deep sleep @@ -198,7 +190,8 @@ void loop() #endif #ifdef WEBUPDATER_FEATURE - if (UPDATE_WEBSERVER_INTVERVAL_S * 1000 / DELAY_LOOP_MS <= update_webserver_cnt) { + if (UPDATE_WEBSERVER_INTVERVAL_S * 1000 / DELAY_LOOP_MS <= update_webserver_cnt) + { update_webserver_cnt = 0; doWebUpdater(); } @@ -223,8 +216,11 @@ void loop() void _loop() { #ifdef HTTP_CALL_ON_WINDSPEED_EXCEED - if (HTTP_CALL_ON_WINDSPEED_INTERVAL_S * 1000 / DELAY_LOOP_MS > update_windspeed_exceed_cnt) { - if (sensors[SENSOR_WINDSPEED]) { + if (HTTP_CALL_ON_WINDSPEED_INTERVAL_S * 1000 / DELAY_LOOP_MS > update_windspeed_exceed_cnt) + { + if (sensors[SENSOR_WINDSPEED]) + { + // read from windspeed sensor currentSensorData[SENSOR_WINDSPEED] = sensors[SENSOR_WINDSPEED](); if (currentSensorData[SENSOR_WINDSPEED] >= HTTP_CALL_ON_WINDSPEED_EXCEED_MPS) diff --git a/firmware/influxdb.ino b/firmware/influxdb.ino index 90cd178..8356d43 100644 --- a/firmware/influxdb.ino +++ b/firmware/influxdb.ino @@ -1,9 +1,9 @@ -#include // from bib manager #include "config_user.h" #if INFLUXDB_VERSION == 1 +#include // https://github.com/hwwong/ESP8266Influxdb Influxdb _influxdb(INFLUXDB_HOST, INFLUXDB_PORT); @@ -82,6 +82,8 @@ void pushToInfluxDB(String device, float sensorValues[]) { #elif INFLUXDB_VERSION == 2 +#include // from bib manager + // Data point Point sensor(DEVICE_NAME);