optimise wifi events
This commit is contained in:
parent
d69027658b
commit
aa1c548551
@ -63,7 +63,7 @@ namespace Display {
|
|||||||
currentHour = hour();
|
currentHour = hour();
|
||||||
Display::adjustBrightness();
|
Display::adjustBrightness();
|
||||||
hourChanged.signal();
|
hourChanged.signal();
|
||||||
if (currentHour == 8) dayChanged.signal();
|
if (currentHour == 8) Wifi::reconnect();
|
||||||
}
|
}
|
||||||
if (currentMin != minute()) {
|
if (currentMin != minute()) {
|
||||||
currentMin = minute();
|
currentMin = minute();
|
||||||
|
|||||||
@ -51,6 +51,7 @@ namespace Ir {
|
|||||||
{
|
{
|
||||||
case 0x9F:
|
case 0x9F:
|
||||||
avrOn = false;
|
avrOn = false;
|
||||||
|
tCheckWifi.enable();
|
||||||
break;
|
break;
|
||||||
case 0xC4:
|
case 0xC4:
|
||||||
case 0xD0:
|
case 0xD0:
|
||||||
|
|||||||
@ -1,14 +1,18 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
void checkWifiCallback();
|
||||||
|
void onWifiConnected();
|
||||||
|
|
||||||
#define _TASK_STATUS_REQUEST
|
#define _TASK_STATUS_REQUEST
|
||||||
#include <TaskScheduler.h>
|
#include <TaskScheduler.h>
|
||||||
Scheduler ts;
|
Scheduler ts;
|
||||||
StatusRequest hourChanged;
|
StatusRequest hourChanged;
|
||||||
StatusRequest dayChanged;
|
|
||||||
StatusRequest wifiConnected;
|
StatusRequest wifiConnected;
|
||||||
|
Task tCheckWifi(5000, TASK_FOREVER, checkWifiCallback, &ts);
|
||||||
|
Task tWifiConnected(onWifiConnected, &ts);
|
||||||
|
|
||||||
#include "display.h"
|
|
||||||
#include "wifi.h"
|
#include "wifi.h"
|
||||||
|
#include "display.h"
|
||||||
#include "ntp_time.h"
|
#include "ntp_time.h"
|
||||||
#include "mqtt.h"
|
#include "mqtt.h"
|
||||||
#include "ota.h"
|
#include "ota.h"
|
||||||
@ -16,13 +20,6 @@ StatusRequest wifiConnected;
|
|||||||
|
|
||||||
#define STAY_CONNECTED_AFTER_BOOT 5*60
|
#define STAY_CONNECTED_AFTER_BOOT 5*60
|
||||||
|
|
||||||
void wifiConnectedCallback();
|
|
||||||
void checkWifiCallback();
|
|
||||||
|
|
||||||
Task tCheckWifi(5000, TASK_FOREVER, checkWifiCallback, &ts);
|
|
||||||
Task tWifiReconnect(Wifi::reconnect, &ts);
|
|
||||||
Task tWifiConnected(wifiConnectedCallback, &ts);
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
|
||||||
@ -33,9 +30,7 @@ void setup() {
|
|||||||
Mqtt::setup();
|
Mqtt::setup();
|
||||||
|
|
||||||
hourChanged.setWaiting();
|
hourChanged.setWaiting();
|
||||||
dayChanged.setWaiting();
|
|
||||||
wifiConnected.setWaiting();
|
wifiConnected.setWaiting();
|
||||||
tWifiReconnect.waitFor(&dayChanged);
|
|
||||||
tWifiConnected.waitFor(&wifiConnected);
|
tWifiConnected.waitFor(&wifiConnected);
|
||||||
|
|
||||||
Wifi::setup();
|
Wifi::setup();
|
||||||
@ -45,19 +40,19 @@ void loop() {
|
|||||||
ts.execute();
|
ts.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
void wifiConnectedCallback() {
|
void onWifiConnected() {
|
||||||
Wifi::printStatus();
|
Wifi::printStatus();
|
||||||
if (time_t newTime = Ntp::updateTime()) {
|
if (time_t newTime = Ntp::updateTime()) {
|
||||||
Serial.println(asctime(localtime(&newTime)));
|
Serial.println(asctime(localtime(&newTime)));
|
||||||
Ntp::lastConnectedTime = newTime;
|
Ntp::lastConnectedTime = newTime;
|
||||||
}
|
}
|
||||||
Ota::tLoop.enable();
|
Ota::tLoop.enable();
|
||||||
tCheckWifi.enable();
|
if (!Ir::avrOn) tCheckWifi.enable();
|
||||||
Mqtt::client.connect();
|
Mqtt::client.connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkWifiCallback() {
|
void checkWifiCallback() {
|
||||||
if ((difftime(now(), Ntp::lastConnectedTime) > STAY_CONNECTED_AFTER_BOOT) && !Ir::avrOn) {
|
if (difftime(now(), Ntp::lastConnectedTime) > STAY_CONNECTED_AFTER_BOOT) {
|
||||||
Wifi::disconnect();
|
Wifi::disconnect();
|
||||||
Ota::tLoop.disable();
|
Ota::tLoop.disable();
|
||||||
tCheckWifi.disable();
|
tCheckWifi.disable();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user