Main loop timing optimized.
This commit is contained in:
parent
0e33d52af4
commit
c47116af89
2 changed files with 31 additions and 17 deletions
|
@ -7,7 +7,9 @@
|
||||||
#define SENSOR_WINDSPEED 3
|
#define SENSOR_WINDSPEED 3
|
||||||
#define SENSOR_PRESSURE 4
|
#define SENSOR_PRESSURE 4
|
||||||
|
|
||||||
#define UPDATE_INTERVAL 4
|
#define UPDATE_SENSOR_INTERVAL_S 10
|
||||||
|
#define UPDATE_WEBSERVER_INTVERVAL_S 1
|
||||||
|
#define DELAY_LOOP_MS 50
|
||||||
|
|
||||||
#define STATUS_LED_PIN BUILTIN_LED
|
#define STATUS_LED_PIN BUILTIN_LED
|
||||||
#define ANEMOMETER_PIN D7
|
#define ANEMOMETER_PIN D7
|
||||||
|
|
|
@ -35,6 +35,9 @@
|
||||||
|
|
||||||
float currentSensorData[5] = {0.0, 0.0, 0.0, 0.0, 0.0};
|
float currentSensorData[5] = {0.0, 0.0, 0.0, 0.0, 0.0};
|
||||||
|
|
||||||
|
uint16_t update_sensor_cnt = 0;
|
||||||
|
uint16_t update_webserver_cnt = 0;
|
||||||
|
|
||||||
WiFiManager wifiManager;
|
WiFiManager wifiManager;
|
||||||
Influxdb influxdb(INFLUXDB_HOST, INFLUXDB_PORT);
|
Influxdb influxdb(INFLUXDB_HOST, INFLUXDB_PORT);
|
||||||
Adafruit_APDS9960 apds;
|
Adafruit_APDS9960 apds;
|
||||||
|
@ -93,11 +96,17 @@ void setup() {
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|
||||||
|
if (UPDATE_WEBSERVER_INTVERVAL_S * 1000 / DELAY_LOOP_MS <= update_webserver_cnt) {
|
||||||
|
update_webserver_cnt = 0;
|
||||||
doWebUpdater();
|
doWebUpdater();
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
digitalWrite(STATUS_LED_PIN, HIGH);
|
digitalWrite(STATUS_LED_PIN, HIGH);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (UPDATE_SENSOR_INTERVAL_S * 1000 / DELAY_LOOP_MS <= update_sensor_cnt) {
|
||||||
|
update_sensor_cnt = 0;
|
||||||
currentSensorData[SENSOR_TEMPERATURE] = fetchTemperature();
|
currentSensorData[SENSOR_TEMPERATURE] = fetchTemperature();
|
||||||
currentSensorData[SENSOR_HUMIDITY] = fetchHumidity();
|
currentSensorData[SENSOR_HUMIDITY] = fetchHumidity();
|
||||||
currentSensorData[SENSOR_LIGHT] = fetchLight();
|
currentSensorData[SENSOR_LIGHT] = fetchLight();
|
||||||
|
@ -115,11 +124,14 @@ void loop() {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
pushToInfluxDB(DEVICE_NAME, currentSensorData);
|
pushToInfluxDB(DEVICE_NAME, currentSensorData);
|
||||||
|
}
|
||||||
|
|
||||||
//ESP.deepSleep(UPDATE_INTERVAL * 1000000);
|
//ESP.deepSleep(UPDATE_INTERVAL * 1000000);
|
||||||
//delay(100);
|
//delay(100);
|
||||||
delay(UPDATE_INTERVAL * 1000);
|
delay(DELAY_LOOP_MS);
|
||||||
/**/
|
|
||||||
|
update_sensor_cnt++;
|
||||||
|
update_webserver_cnt++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//*************************************************************************//
|
//*************************************************************************//
|
||||||
|
|
Loading…
Reference in a new issue