Added ping host config and code, also added ISR independent windspeed measurement.

This commit is contained in:
Kai Lauterbach 2023-04-02 13:24:32 +02:00
parent 58ea2c1822
commit 6ad9dddb99
4 changed files with 57 additions and 6 deletions

View File

@ -7,11 +7,12 @@
#define WIFI_CONFIG_PORTAL_TIMEOUT_S 120
#define UPDATE_SENSOR_INTERVAL_S 300
#define UPDATE_WEBSERVER_INTVERVAL_MS 500 // Values greater than 1000 will negative affect availability of the webinterface
#define DELAY_LOOP_MS 100
#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 (60*60*12*1000) // reset every 12 hours
#define WIND_SENSOR_MEAS_TIME_S 15
#define WIND_SPEED_MEAS_NO_ISR_TIME_MS 50
#define WATCHDOG_TIMEOUT_MS WDTO_8S // Look at Esp.h for further possible time declarations
#define WIFI_CHECK_INTERVAL_MS 120000
#define INFLUXDB_TIMEOUT_MS 1000

View File

@ -26,6 +26,8 @@ String DEVICE_NAME = "weatherstation";
//#define SERIAL_FEATURE
#define SENSOR_WIND
//#define SENSOR_WIND_NO_ISR // enable in case that the ISR shoud not be used to measure wind speed
#define SENSOR_APDS9960
//#define SENSOR_APDS9930
#define SENSOR_BME280
@ -55,6 +57,7 @@ String DEVICE_NAME = "weatherstation";
//#define SHOW_SENSOR_DATA_ON_WEBUPDATER_MAIN_PAGE
//#define DEBUG_RESET_REASON
#define WEB_RESET
//#define ENABLE_PING_HOST_TEST
/********************************************************************************/
@ -108,6 +111,8 @@ const char *INFLUXDB_TOKEN = "your api token";
/********************************************************************************/
#define PING_HOST_IP "192.168.178.1"
#ifdef DISABLE_WIFIMANAGER
// Set your Static IP address
IPAddress local_IP(192, 168, 178, 123);

View File

@ -807,11 +807,10 @@ void http_call_send_json_data()
WDT_FEED();
#endif
if (httpResponseCode > 0) {
String response = http.getString();
debug("http response code: " + String(httpResponseCode) + " = " + response);
// TODO handle response
}
String response = http.getString();
debug("http response code: " + String(httpResponseCode) + " = " + response);
http.end();
digitalWrite(STATUS_LED_PIN, HIGH);

View File

@ -6,6 +6,7 @@ volatile unsigned int anemometerRotations = 0;
uint32_t start_meas_wind_time = 0;
int interruptNumber;
#ifndef SENSOR_WIND_NO_ISR
void ICACHE_RAM_ATTR _anemometerInterrupt()
{
anemometerRotations++;
@ -14,6 +15,7 @@ void ICACHE_RAM_ATTR _anemometerInterrupt()
debug("*");
#endif
}
#endif
float wind_speed()
{
@ -28,16 +30,60 @@ void start_measure_wind()
{
start_meas_wind_time = millis();
anemometerRotations = 0;
#ifndef SENSOR_WIND_NO_ISR
interruptNumber = digitalPinToInterrupt(ANEMOMETER_PIN);
attachInterrupt(interruptNumber, _anemometerInterrupt, FALLING);
#endif
}
boolean check_measure_wind_done()
{
static uint8_t previous_pin_state = 255;
static uint8_t tmp_pin_state = 255;
if ((start_meas_wind_time + (WIND_SENSOR_MEAS_TIME_S * 1000)) <= millis())
{
#ifndef SENSOR_WIND_NO_ISR
detachInterrupt(interruptNumber);
#endif
return true;
#ifdef SENSOR_WIND_NO_ISR
} else {
// measure wind without ISR
uint32_t start = millis();
/*#ifdef DEBUG
Serial.print(".");
debug(".");
#endif*/
do {
// read pin state
previous_pin_state = tmp_pin_state;
tmp_pin_state = digitalRead(ANEMOMETER_PIN);
/*#ifdef DEBUG
Serial.print("+");
debug("+");
#endif*/
if (previous_pin_state != tmp_pin_state && previous_pin_state != 255)
{
anemometerRotations++;
#ifdef DEBUG
Serial.print("*");
debug("*");
#endif
}
// wait 5 ms
delay(5);
#ifdef ENABLE_WATCHDOG
// feed the watchdog to prevent reset
WDT_FEED();
#endif
} while ((start + WIND_SPEED_MEAS_NO_ISR_TIME_MS) >= millis());
#endif // SENSOR_WIND_NO_ISR
}
return false;
}