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
schematics/#auto_saved_files#
schematics/_autosave-oko-weatherstation.sch
firmware.ino.bin

View file

@ -1,20 +1,7 @@
#ifndef __CONFIG_H__
#define __CONFIG_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
// config general setting and behavior of the weatherstation
#define WIFI_AUTOCONNECT_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 RESET_ESP_TIME_INTERVAL_MS 3600000
#define WIND_SENSOR_MEAS_TIME_S 15.0
#define INITIAL_WEBSERVER_TIME 20
#define ENERGY_SAVING_ITERATIONS 30
#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_EMERGENCY_DEEPSLEEP_VOLTAGE 3.5
@ -71,7 +39,6 @@
#define BME_CS 10
#define BME_ADDRESS 0x76
#define INITIAL_WEBSERVER_TIME 20
#define WEB_UPDATER_HTTP_PORT 8080
klaute marked this conversation as resolved Outdated
Outdated
Review

Ist das die Callback-URL, wenn der Wind zu stark weht?
Es wäre gut, wenn man das Feature an/ausschalten könnte, da es schon sehr spezifisch auf deinen Anwendungsfall gestrickt ist.

Ist das die Callback-URL, wenn der Wind zu stark weht? Es wäre gut, wenn man das Feature an/ausschalten könnte, da es schon sehr spezifisch auf deinen Anwendungsfall gestrickt ist.
#endif

View file

@ -7,6 +7,11 @@
// Debug output on the serial console
#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
//#define WEBUPDATER_FEATURE
#define INFLUXDB_FEATURE
@ -19,13 +24,13 @@
#define SENSOR_BME280
#define SENSOR_BATTERY
//#define BAT_PINS_D34
// only possible if webupdater is also enabled
// Homebridge Webstat is only possible if webupdater is also enabled
//#define HOMEBRIDGE_WEBSTAT
// retries to connect after 5 seconds or starts the wifimanager
#define SLEEP_IF_NO_WLAN_CONNECTION
// Restarts the firmware every n seconds
//#define RESET_ESP_TIMEINTERVAL
//#define HTTP_CALL_ON_WINDSPEED_EXCEED
//#define RESET_ESP_TIMEINTERVAL // BETA STATUS
//#define HTTP_CALL_ON_WINDSPEED_EXCEED // BETA STATUS
const float HUMIDITY_FACTOR = 1.0;
const float LIGHT_FACTOR = 1.0;
@ -39,15 +44,33 @@ const char *INFLUXDB_USER = "user";
const char *INFLUXDB_PASS = "password";
klaute marked this conversation as resolved Outdated
Outdated
Review

" fehlt.

" fehlt.

Erledigt

Erledigt
klaute marked this conversation as resolved Outdated
Outdated
Review

token

token
// 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 token";
*/
// 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 = "devicename";
// enable HTTP_CALL_ON_WINDSPEED_EXCEED 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"
// 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

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