Add support for WiZMote with WiFi disabled

This commit is contained in:
Theo Arends 2025-02-14 12:55:58 +01:00
parent f383c877c6
commit a2af12c969
3 changed files with 40 additions and 22 deletions

View File

@ -52,11 +52,18 @@ bool QuickEspNow::begin (uint8_t channel, uint32_t wifi_interface, bool synchron
void QuickEspNow::stop () {
DEBUG_INFO (QESPNOW_TAG, "-------------> ESP-NOW STOP");
vTaskDelete (espnowTxTask);
vTaskDelete (espnowRxTask);
if (espnowTxTask) {
vTaskDelete (espnowTxTask);
espnowTxTask = nullptr;
}
if (espnowRxTask) {
vTaskDelete (espnowRxTask);
espnowRxTask = nullptr;
}
esp_now_unregister_recv_cb ();
esp_now_unregister_send_cb ();
esp_now_deinit ();
followWiFiChannel = false;
}
bool QuickEspNow::readyToSendData () {

View File

@ -85,6 +85,7 @@ void QuickEspNow::stop () {
esp_now_unregister_recv_cb ();
esp_now_unregister_send_cb ();
esp_now_deinit ();
followWiFiChannel = false;
}
bool QuickEspNow::readyToSendData () {

View File

@ -30,7 +30,7 @@ struct WizMote {
int rssi;
uint8_t index;
uint8_t battery_level;
bool active;
uint8_t active;
} WizMote;
/*********************************************************************************************\
@ -146,19 +146,36 @@ void EspNowDataReceived(uint8_t* mac, uint8_t* data, uint8_t len, signed int rss
}
}
/*********************************************************************************************\
*
\*********************************************************************************************/
void EspNowInit(void) {
if (!WizMote.active) {
quickEspNow.onDataRcvd(EspNowDataReceived);
#ifdef ESP32
// quickEspNow.setWiFiBandwidth (WIFI_IF_STA, WIFI_BW_HT20); // Only needed for ESP32 in case you need coexistence with ESP8266 in the same network
if (0 == Settings->flag4.network_wifi) { // WiFi Off
if (WizMote.active != 2) {
uint32_t channel = 1;
quickEspNow.stop();
delay(500); // Allow time to finish stopped WiFi by WifiDisable()
WiFi.mode(WIFI_STA);
#if defined ESP32
WiFi.disconnect(false, true);
#elif defined ESP8266
WiFi.disconnect(false);
#endif //ESP32
if (quickEspNow.begin()) {
AddLog(LOG_LEVEL_INFO, PSTR("NOW: ESP-NOW started"));
WizMote.active = true;
quickEspNow.onDataRcvd(EspNowDataReceived);
if (quickEspNow.begin(channel)) { // Specify channel if no connected WiFi
AddLog(LOG_LEVEL_INFO, PSTR("NOW: ESP-NOW started on channel %d"), channel);
WizMote.active = 2;
}
}
} else { // WiFi On
if (TasmotaGlobal.global_state.wifi_down) {
WizMote.active = 0;
}
else if (WizMote.active != 1) {
quickEspNow.stop();
quickEspNow.onDataRcvd(EspNowDataReceived);
if (quickEspNow.begin()) {
AddLog(LOG_LEVEL_INFO, PSTR("NOW: ESP-NOW started"));
WizMote.active = 1;
}
}
}
}
@ -172,16 +189,9 @@ bool Xdrv77(uint32_t function) {
bool result = false;
/*
if (FUNC_INIT == function) {
if (FUNC_EVERY_SECOND == function) {
EspNowInit();
}
*/
if (FUNC_NETWORK_UP == function) {
if (!TasmotaGlobal.global_state.wifi_down) {
EspNowInit();
}
}
else if (WizMote.active) {
switch (function) {
case FUNC_LOOP: