Skip to content

Commit

Permalink
Add support for WiZMote with WiFi disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
arendst committed Feb 14, 2025
1 parent f383c87 commit a2af12c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 22 deletions.
11 changes: 9 additions & 2 deletions lib/lib_div/QuickESPNow/src/QuickEspNow_esp32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
1 change: 1 addition & 0 deletions lib/lib_div/QuickESPNow/src/QuickEspNow_esp8266.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
50 changes: 30 additions & 20 deletions tasmota/tasmota_xdrv_driver/xdrv_77_wizmote.ino
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct WizMote {
int rssi;
uint8_t index;
uint8_t battery_level;
bool active;
uint8_t active;
} WizMote;

/*********************************************************************************************\
Expand Down Expand Up @@ -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;
}
}
}
}
Expand All @@ -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:
Expand Down

0 comments on commit a2af12c

Please sign in to comment.