Added windspeed exceed functionality, it calls an url if max windspeed is exceeded

This commit is contained in:
Kai Lauterbach 2022-05-22 08:51:24 +02:00
parent b61564d206
commit 7a689034b4
2 changed files with 40 additions and 2 deletions

View file

@ -37,6 +37,10 @@
#define COUNT_TO_MPS (TWO_PI * ROTOR_LENGTH_M / WIND_SENSOR_MEAS_TIME_S) #define COUNT_TO_MPS (TWO_PI * ROTOR_LENGTH_M / WIND_SENSOR_MEAS_TIME_S)
#define WINDSPEED_FACTOR (COUNT_TO_MPS * MPS_CORRECT_FACT) #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"
#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

View file

@ -4,6 +4,7 @@
#include <ESP8266WiFi.h> #include <ESP8266WiFi.h>
#include <DNSServer.h> #include <DNSServer.h>
#include <ESP8266WebServer.h> #include <ESP8266WebServer.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h> // WiFiClient #include <WiFiClient.h> // WiFiClient
#include <WiFiManager.h> // WiFiManager from bib manager #include <WiFiManager.h> // WiFiManager from bib manager
@ -11,6 +12,12 @@
// Project includes // Project includes
#include "config.h" #include "config.h"
#ifdef HTTP_CALL_ON_WINDSPEED_EXCEED
#if (HTTP_CALL_ON_WINDSPEED_INTERVAL_S < HTTP_CALL_ON_WINDSPEED_EXCEED_MPS)
#error "HTTP_CALL_ON_WINDSPEED_INTERVAL_S < WIND_SENSOR_MEAS_TIME_S"
#endif
#endif
#include "config_user.h" #include "config_user.h"
//*************************************************************************// //*************************************************************************//
@ -21,6 +28,7 @@ float (*sensors[VALUES])() = {};
uint16_t update_sensor_cnt = 0; uint16_t update_sensor_cnt = 0;
uint16_t update_webserver_cnt = 0; uint16_t update_webserver_cnt = 0;
uint16_t update_windspeed_exceed_cnt = 0;
WiFiManager wifiManager; WiFiManager wifiManager;
@ -206,10 +214,36 @@ void loop()
#ifdef WEBUPDATER_FEATURE #ifdef WEBUPDATER_FEATURE
update_webserver_cnt++; update_webserver_cnt++;
#endif #endif
#ifdef HTTP_CALL_ON_WINDSPEED_EXCEED
update_windspeed_exceed_cnt++;
#endif
} }
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]) {
currentSensorData[SENSOR_WINDSPEED] = sensors[SENSOR_WINDSPEED]();
if (currentSensorData[SENSOR_WINDSPEED] >= HTTP_CALL_ON_WINDSPEED_EXCEED_MPS)
{
// call the url HTTP_CALL_ON_WINDSPEED_URL
WiFiClient client;
HTTPClient http;
http.begin(client, String(HTTP_CALL_ON_WINDSPEED_URL).c_str());
http.end();
// Send HTTP GET request
int httpResponseCode = http.GET();
}
} else {
currentSensorData[SENSOR_WINDSPEED] = nan("no value");
}
update_windspeed_exceed_cnt = 0;
}
#endif
#ifndef BATTERY_POWERED #ifndef BATTERY_POWERED
if (UPDATE_SENSOR_INTERVAL_S * 1000 / DELAY_LOOP_MS > update_sensor_cnt) { if (UPDATE_SENSOR_INTERVAL_S * 1000 / DELAY_LOOP_MS > update_sensor_cnt) {
return; return;