Fixed review findings

This commit is contained in:
Kai Lauterbach 2022-05-22 16:35:10 +02:00
parent 23bf57648c
commit bf413c9897
4 changed files with 29 additions and 23 deletions

20
firmware/config.h Executable file → Normal file
View file

@ -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)
// china aliexpress anemometer settings (calculation unknown) <add link here>
//#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.0.250:3001/button-windspeedexceed?event=click"
#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

View file

@ -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

View file

@ -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)

View file

@ -1,9 +1,9 @@
#include <InfluxDbClient.h> // from bib manager
#include "config_user.h"
#if INFLUXDB_VERSION == 1
#include <ESP8266Influxdb.h> // 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 <InfluxDbClient.h> // from bib manager
// Data point
Point sensor(DEVICE_NAME);