@@ -165,6 +165,21 @@ void espnowStop()
165165#ifdef COMPILE_ESPNOW
166166 if (espnowState == ESPNOW_OFF) return ;
167167
168+ // Turn off promiscuous WiFi mode
169+ esp_wifi_set_promiscuous (false );
170+ esp_wifi_set_promiscuous_rx_cb (NULL );
171+
172+ // Deregister callbacks
173+ // esp_now_unregister_send_cb();
174+ esp_now_unregister_recv_cb ();
175+
176+ // Deinit ESP-NOW
177+ if (esp_now_deinit () != ESP_OK) {
178+ Serial.println (" Error deinitializing ESP-NOW" );
179+ return ;
180+ }
181+ #endif
182+
168183 if (wifiState == WIFI_OFF)
169184 {
170185 // ESP Now is the only thing using the radio, turn it off entirely
@@ -175,7 +190,9 @@ void espnowStop()
175190 // If WiFi is on, then disable LR protocol
176191 else if (wifiState > WIFI_OFF)
177192 {
178- wifiSetState (WIFI_NOT_CONNECTED);
193+ #ifdef COMPILE_WIFI
194+ wifiSetState (WIFI_NOTCONNECTED);
195+ #endif
179196
180197 // Return protocol to default settings (no WIFI_PROTOCOL_LR for ESP NOW)
181198 esp_wifi_set_protocol (WIFI_IF_STA, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N); // Stops WiFi Station.
@@ -184,21 +201,7 @@ void espnowStop()
184201
185202 log_d (" WiFi protocols on, LR protocol off" );
186203 }
187-
188- // Turn off promiscuous WiFi mode
189- esp_wifi_set_promiscuous (false );
190- esp_wifi_set_promiscuous_rx_cb (NULL );
191-
192- // Deregister callbacks
193- // esp_now_unregister_send_cb();
194- esp_now_unregister_recv_cb ();
195-
196- // Deinit ESP-NOW
197- if (esp_now_deinit () != ESP_OK) {
198- Serial.println (" Error deinitializing ESP-NOW" );
199- return ;
200- }
201- #endif
204+
202205 espnowSetState (ESPNOW_OFF);
203206}
204207
0 commit comments