optimisation: run task once to disable wifi
This commit is contained in:
parent
84f97d9da4
commit
fd3f32ca70
@ -22,7 +22,7 @@ namespace Bmp {
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
Serial.println(F("BMP280 test"));
|
||||
Serial.println(F("BMP280 setup"));
|
||||
|
||||
if (!bmp.begin(0x76)) {
|
||||
Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
|
||||
|
||||
@ -39,7 +39,7 @@ namespace Ir {
|
||||
|
||||
void command(const char c[]) {
|
||||
avrOn = true;
|
||||
tCheckWifi.disable();
|
||||
tCheckWifi.cancel();
|
||||
Wifi::reconnect();
|
||||
Display::displayText(c);
|
||||
}
|
||||
@ -50,7 +50,7 @@ namespace Ir {
|
||||
{
|
||||
case 0x9F:
|
||||
avrOn = false;
|
||||
tCheckWifi.enableDelayed();
|
||||
tCheckWifi.restartDelayed();
|
||||
Display::displayText("Off");
|
||||
break;
|
||||
case 0x12:
|
||||
|
||||
@ -8,7 +8,6 @@ namespace Ntp {
|
||||
|
||||
WiFiUDP ntpUDP;
|
||||
NTPClient timeClient(ntpUDP, "europe.pool.ntp.org");
|
||||
time_t lastConnectedTime;
|
||||
|
||||
// Central European Time (Frankfurt, Paris)
|
||||
TimeChangeRule CEST = { "CEST", Last, Sun, Mar, 2, 120 }; // Central European Summer Time
|
||||
|
||||
@ -5,10 +5,9 @@ void onWifiConnected();
|
||||
void onButtonPressed();
|
||||
void onButtonCallback();
|
||||
|
||||
// #define _TASK_STATUS_REQUEST
|
||||
#include <TaskScheduler.h>
|
||||
Scheduler ts;
|
||||
Task tCheckWifi(5 * TASK_SECOND, TASK_FOREVER, checkWifiCallback, &ts);
|
||||
Task tCheckWifi(5 * TASK_MINUTE, TASK_ONCE, checkWifiCallback, &ts);
|
||||
Task tWifiConnected(TASK_IMMEDIATE, TASK_ONCE, onWifiConnected, &ts);
|
||||
Task tButton(TASK_IMMEDIATE, TASK_ONCE, onButtonCallback, &ts);
|
||||
|
||||
@ -20,9 +19,9 @@ Task tButton(TASK_IMMEDIATE, TASK_ONCE, onButtonCallback, &ts);
|
||||
#include "ota.h"
|
||||
#include "ir.h"
|
||||
|
||||
#define STAY_CONNECTED_AFTER_BOOT 5*60
|
||||
#define BUTTON D3
|
||||
|
||||
|
||||
void setup() {
|
||||
|
||||
Serial.begin(9600);
|
||||
@ -48,22 +47,18 @@ void onWifiConnected() {
|
||||
Serial.println("Wifi connected event");
|
||||
Wifi::printStatus();
|
||||
Ota::tLoop.enable();
|
||||
if (!Ir::avrOn) tCheckWifi.enableDelayed();
|
||||
if (!Ir::avrOn) tCheckWifi.restartDelayed();
|
||||
Mqtt::client.connect();
|
||||
if (time_t newTime = Ntp::updateTime()) {
|
||||
Serial.println(asctime(localtime(&newTime)));
|
||||
Ntp::lastConnectedTime = newTime;
|
||||
}
|
||||
}
|
||||
|
||||
void checkWifiCallback() {
|
||||
if (difftime(now(), Ntp::lastConnectedTime) > STAY_CONNECTED_AFTER_BOOT) {
|
||||
Serial.println("Wifi connection timed out");
|
||||
Mqtt::client.disconnect();
|
||||
Ota::tLoop.disable();
|
||||
tCheckWifi.disable();
|
||||
Wifi::disconnect();
|
||||
}
|
||||
Serial.println("Wifi connection timed out");
|
||||
Mqtt::client.disconnect();
|
||||
Ota::tLoop.disable();
|
||||
Wifi::disconnect();
|
||||
}
|
||||
|
||||
ICACHE_RAM_ATTR void onButtonPressed() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user