feature/InfluxDB-Connection-Update #1

Merged
klaute merged 39 commits from feature/InfluxDB-Connection-Update into master 2022-05-23 17:36:59 +02:00
5 changed files with 70 additions and 55 deletions
Showing only changes of commit 79b61baf71 - Show all commits

1
.gitignore vendored
View file

@ -3,3 +3,4 @@ firmware/.DS_Store
.DS_Store .DS_Store
schematics/#auto_saved_files# schematics/#auto_saved_files#
schematics/_autosave-oko-weatherstation.sch schematics/_autosave-oko-weatherstation.sch
firmware.ino.bin

View file

@ -1,20 +1,7 @@
#ifndef __CONFIG_H__ #ifndef __CONFIG_H__
#define __CONFIG_H__ #define __CONFIG_H__
#define SENSOR_TEMPERATURE 0 // config general setting and behavior of the weatherstation
#define SENSOR_HUMIDITY 1
#define SENSOR_LIGHT 2
#define SENSOR_WINDSPEED 3
#define SENSOR_PRESSURE 4
#define SENSOR_BAT_VOLTAGE 5
#define SENSOR_ESAVEMODE 6
#define SENSOR_BATCHARGESTATE 7
#define BAT_CHARGE_STATE_CHARGED 2.0
#define BAT_CHARGE_STATE_CHARGING 1.0
#define BAT_CHARGE_STATE_NOTCHARGING 0.0
#define ENERGY_SAVE_MODE_ENABLED 1.0
#define ENERGY_SAVE_MODE_DISABLED 0.0
#define WIFI_AUTOCONNECT_TIMEOUT_S 120 #define WIFI_AUTOCONNECT_TIMEOUT_S 120
#define WIFI_CONFIG_PORTAL_TIMEOUT_S 120 #define WIFI_CONFIG_PORTAL_TIMEOUT_S 120
@ -25,30 +12,11 @@
#define EMERGENCY_SLEEP_S 172800 // Sleep for 2 days to recover #define EMERGENCY_SLEEP_S 172800 // Sleep for 2 days to recover
#define RESET_ESP_TIME_INTERVAL_MS 3600000 #define RESET_ESP_TIME_INTERVAL_MS 3600000
#define WIND_SENSOR_MEAS_TIME_S 15.0 #define WIND_SENSOR_MEAS_TIME_S 15.0
#define INITIAL_WEBSERVER_TIME 20
#define ENERGY_SAVING_ITERATIONS 30 #define ENERGY_SAVING_ITERATIONS 30
#define WIFI_MINIMUM_SIGNAL_QUALITY 10 // percent #define WIFI_MINIMUM_SIGNAL_QUALITY 10 // percent
// 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) // 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) // 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.178.100:3001/button-windspeedexceed?event=click"
#define BAT_LOW_VOLTAGE 3.6 #define BAT_LOW_VOLTAGE 3.6
#define BAT_EMERGENCY_DEEPSLEEP_VOLTAGE 3.5 #define BAT_EMERGENCY_DEEPSLEEP_VOLTAGE 3.5
@ -71,7 +39,6 @@
#define BME_CS 10 #define BME_CS 10
#define BME_ADDRESS 0x76 #define BME_ADDRESS 0x76
#define INITIAL_WEBSERVER_TIME 20
#define WEB_UPDATER_HTTP_PORT 8080 #define WEB_UPDATER_HTTP_PORT 8080
#endif #endif

View file

@ -7,6 +7,11 @@
// Debug output on the serial console // Debug output on the serial console
#define DEBUG #define DEBUG
// Device name
// WARNING: Keep the name short! If your access point did not show up, you
// maybe have a TOO LONG SSID!
String DEVICE_NAME = "weatherstation";
// Enable/Disable features // Enable/Disable features
//#define WEBUPDATER_FEATURE //#define WEBUPDATER_FEATURE
#define INFLUXDB_FEATURE #define INFLUXDB_FEATURE
@ -19,13 +24,13 @@
#define SENSOR_BME280 #define SENSOR_BME280
#define SENSOR_BATTERY #define SENSOR_BATTERY
//#define BAT_PINS_D34 //#define BAT_PINS_D34
// only possible if webupdater is also enabled // Homebridge Webstat is only possible if webupdater is also enabled
//#define HOMEBRIDGE_WEBSTAT //#define HOMEBRIDGE_WEBSTAT
// retries to connect after 5 seconds or starts the wifimanager // retries to connect after 5 seconds or starts the wifimanager
#define SLEEP_IF_NO_WLAN_CONNECTION #define SLEEP_IF_NO_WLAN_CONNECTION
// Restarts the firmware every n seconds // Restarts the firmware every n seconds
//#define RESET_ESP_TIMEINTERVAL //#define RESET_ESP_TIMEINTERVAL // BETA STATUS
//#define HTTP_CALL_ON_WINDSPEED_EXCEED //#define HTTP_CALL_ON_WINDSPEED_EXCEED // BETA STATUS
const float HUMIDITY_FACTOR = 1.0; const float HUMIDITY_FACTOR = 1.0;
const float LIGHT_FACTOR = 1.0; const float LIGHT_FACTOR = 1.0;
@ -39,15 +44,33 @@ const char *INFLUXDB_USER = "user";
const char *INFLUXDB_PASS = "password"; const char *INFLUXDB_PASS = "password";
// InfluxDB2 credentials // InfluxDB2 credentials
/*
const char *INFLUXDB_URL = "http://192.168.0.123:3124"; const char *INFLUXDB_URL = "http://192.168.0.123:3124";
const char *INFLUXDB_ORG = "home_org"; const char *INFLUXDB_ORG = "home_org";
const char *INFLUXDB_BUCKET = "mybucket"; const char *INFLUXDB_BUCKET = "mybucket";
const char *INFLUXDB_TOKEN = "your api token"; const char *INFLUXDB_TOKEN = "your api token";
*/
// Device name // enable HTTP_CALL_ON_WINDSPEED_EXCEED to enable this feature
// WARNING: Keep the name short! If your access point did not show up, you #define HTTP_CALL_ON_WINDSPEED_EXCEED_MPS 5.0 // 5.0 m/s == 18 km/h
// maybe have a TOO LONG SSID! #define HTTP_CALL_ON_WINDSPEED_INTERVAL_S 60 // it's required to be bigger than WIND_SENSOR_MEAS_TIME_S
String DEVICE_NAME = "devicename"; #define HTTP_CALL_ON_WINDSPEED_URL "http://192.168.178.100:3001/button-windspeedexceed?event=click"
// anemometer settings, to use enable SENSOR_WIND
// thingiverse anemometer 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) // 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) // 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
#endif #endif

20
firmware/constants.h Normal file
View file

@ -0,0 +1,20 @@
#ifndef __CONSTANTS_H__
#define __CONSTANTS_H__
#define SENSOR_TEMPERATURE 0
#define SENSOR_HUMIDITY 1
#define SENSOR_LIGHT 2
#define SENSOR_WINDSPEED 3
#define SENSOR_PRESSURE 4
#define SENSOR_BAT_VOLTAGE 5
#define SENSOR_ESAVEMODE 6
#define SENSOR_BATCHARGESTATE 7
#define BAT_CHARGE_STATE_CHARGED 2.0
#define BAT_CHARGE_STATE_CHARGING 1.0
#define BAT_CHARGE_STATE_NOTCHARGING 0.0
#define ENERGY_SAVE_MODE_ENABLED 1.0
#define ENERGY_SAVE_MODE_DISABLED 0.0
#endif

View file

@ -10,17 +10,21 @@
#include <WiFiManager.h> // WiFiManager from bib manager #include <WiFiManager.h> // WiFiManager from bib manager
// Project includes // Project includes
#include "constants.h"
#include "config.h" #include "config.h"
#include "config_user.h"
//*************************************************************************//
// check if some settings are correct
#ifdef HTTP_CALL_ON_WINDSPEED_EXCEED #ifdef HTTP_CALL_ON_WINDSPEED_EXCEED
#if (HTTP_CALL_ON_WINDSPEED_INTERVAL_S < HTTP_CALL_ON_WINDSPEED_EXCEED_MPS) #if (HTTP_CALL_ON_WINDSPEED_INTERVAL_S < WIND_SENSOR_MEAS_TIME_S)
#error "HTTP_CALL_ON_WINDSPEED_INTERVAL_S < WIND_SENSOR_MEAS_TIME_S" #error "HTTP_CALL_ON_WINDSPEED_INTERVAL_S < WIND_SENSOR_MEAS_TIME_S"
#endif #endif
#endif #endif
#include "config_user.h"
//*************************************************************************// //*************************************************************************//
// constant variables
const uint8_t VALUES = 8; const uint8_t VALUES = 8;
float currentSensorData[VALUES] = {nanf("no value"), nanf("no value"), nanf("no value"), nanf("no value"), nanf("no value"), nanf("no value"), nanf("no value"), nanf("no value")}; float currentSensorData[VALUES] = {nanf("no value"), nanf("no value"), nanf("no value"), nanf("no value"), nanf("no value"), nanf("no value"), nanf("no value"), nanf("no value")};
@ -66,6 +70,7 @@ void setup()
#ifdef BATTERY_POWERED #ifdef BATTERY_POWERED
criticalBatCheck(); criticalBatCheck();
#endif #endif
// Establish WiFi connection // Establish WiFi connection
String wifiName = "oko-weather-" + DEVICE_NAME; String wifiName = "oko-weather-" + DEVICE_NAME;
@ -181,7 +186,6 @@ void criticalBatCheck()
} }
#endif #endif
void loop() void loop()
{ {
#ifdef BATTERY_POWERED #ifdef BATTERY_POWERED
@ -189,14 +193,7 @@ void loop()
return; return;
#endif #endif
#ifdef WEBUPDATER_FEATURE // call sub loop function
if (UPDATE_WEBSERVER_INTVERVAL_S * 1000 / DELAY_LOOP_MS <= update_webserver_cnt)
{
update_webserver_cnt = 0;
doWebUpdater();
}
#endif
_loop(); _loop();
//Needed to give WIFI time to function properly //Needed to give WIFI time to function properly
@ -215,6 +212,14 @@ void loop()
void _loop() { void _loop() {
#ifdef WEBUPDATER_FEATURE
if (UPDATE_WEBSERVER_INTVERVAL_S * 1000 / DELAY_LOOP_MS <= update_webserver_cnt)
{
update_webserver_cnt = 0;
doWebUpdater();
}
#endif
#ifdef HTTP_CALL_ON_WINDSPEED_EXCEED #ifdef HTTP_CALL_ON_WINDSPEED_EXCEED
if (HTTP_CALL_ON_WINDSPEED_INTERVAL_S * 1000 / DELAY_LOOP_MS > update_windspeed_exceed_cnt) if (HTTP_CALL_ON_WINDSPEED_INTERVAL_S * 1000 / DELAY_LOOP_MS > update_windspeed_exceed_cnt)
{ {
@ -256,7 +261,6 @@ void _loop() {
#endif #endif
update_sensor_cnt = 0; update_sensor_cnt = 0;
for (uint8_t i = 0; i < VALUES; i++) { for (uint8_t i = 0; i < VALUES; i++) {
if (sensors[i]) { if (sensors[i]) {
currentSensorData[i] = sensors[i](); currentSensorData[i] = sensors[i]();