Missing event using WiFiMulti.h
Posted: Sun Oct 14, 2018 1:55 pm
Why dont we get any event for "STA Disconnect" or "STA Lost IP" when using WiFiMulti ?
As you can see below, the esp connect to the best wifi, then when I power down the best wifi, it connect to the next one,
but without sending the above events.
Thx in advance for your support.
System information:
-------------------
OS: Windows 10
Arduino ide: 1.8.7
SDK: SDK Version: v3.2-dev-39-gaaf12390
Board: ESP32-PICO-KIT_v4
Serial Monitor output:
----------------------
Setup started . . .
Connecting Wifi...
(Ticks: 197) (Id: 2) (Free Heap: 234264 bytes) STA Start
(Ticks: 196) (Id: 0) (Free Heap: 234692 bytes) WiFi Ready
(Ticks: 3386) (Id: 1) (Free Heap: 233076 bytes) Scan Done
(Ticks: 5710) (Id: 4) (Free Heap: 232632 bytes) STA Connected
(Ticks: 11703) (Id: 1) (Free Heap: 231900 bytes) Scan Done
(Ticks: 11717) (Id: 5) (Free Heap: 233384 bytes) STA Disconnected
(Ticks: 14027) (Id: 4) (Free Heap: 232632 bytes) STA Connected
(Ticks: 14045) (Id: 7) (Free Heap: 232820 bytes) STA Got IP
IP address: 192.168.8.101 CH: 1 RSSI: 18 MAC: 54:B1:21:07:D1:9D
(Ticks: 189428) (Id: 0) (Free Heap: 233876 bytes) WiFi Ready
(Ticks: 189429) (Id: 2) (Free Heap: 233612 bytes) STA Start
(Ticks: 189429) (Id: 2) (Free Heap: 233612 bytes) STA Start
(Ticks: 189435) (Id: 2) (Free Heap: 233796 bytes) STA Start
(Ticks: 193437) (Id: 1) (Free Heap: 232500 bytes) Scan Done
(Ticks: 195531) (Id: 0) (Free Heap: 233868 bytes) WiFi Ready
(Ticks: 195532) (Id: 2) (Free Heap: 233604 bytes) STA Start
(Ticks: 195533) (Id: 2) (Free Heap: 233604 bytes) STA Start
(Ticks: 195538) (Id: 2) (Free Heap: 232080 bytes) STA Start
(Ticks: 196843) (Id: 0) (Free Heap: 233868 bytes) WiFi Ready
(Ticks: 196844) (Id: 2) (Free Heap: 233604 bytes) STA Start
(Ticks: 196845) (Id: 2) (Free Heap: 233604 bytes) STA Start
(Ticks: 196849) (Id: 2) (Free Heap: 232080 bytes) STA Start
(Ticks: 197193) (Id: 4) (Free Heap: 232588 bytes) STA Connected
(Ticks: 197222) (Id: 7) (Free Heap: 232908 bytes) STA Got IP
IP address: 192.168.1.205 CH: 8 RSSI: 49 MAC: 14:91:82:B1:17:7D
As you can see below, the esp connect to the best wifi, then when I power down the best wifi, it connect to the next one,
but without sending the above events.
Thx in advance for your support.
System information:
-------------------
OS: Windows 10
Arduino ide: 1.8.7
SDK: SDK Version: v3.2-dev-39-gaaf12390
Board: ESP32-PICO-KIT_v4
Serial Monitor output:
----------------------
Setup started . . .
Connecting Wifi...
(Ticks: 197) (Id: 2) (Free Heap: 234264 bytes) STA Start
(Ticks: 196) (Id: 0) (Free Heap: 234692 bytes) WiFi Ready
(Ticks: 3386) (Id: 1) (Free Heap: 233076 bytes) Scan Done
(Ticks: 5710) (Id: 4) (Free Heap: 232632 bytes) STA Connected
(Ticks: 11703) (Id: 1) (Free Heap: 231900 bytes) Scan Done
(Ticks: 11717) (Id: 5) (Free Heap: 233384 bytes) STA Disconnected
(Ticks: 14027) (Id: 4) (Free Heap: 232632 bytes) STA Connected
(Ticks: 14045) (Id: 7) (Free Heap: 232820 bytes) STA Got IP
IP address: 192.168.8.101 CH: 1 RSSI: 18 MAC: 54:B1:21:07:D1:9D
(Ticks: 189428) (Id: 0) (Free Heap: 233876 bytes) WiFi Ready
(Ticks: 189429) (Id: 2) (Free Heap: 233612 bytes) STA Start
(Ticks: 189429) (Id: 2) (Free Heap: 233612 bytes) STA Start
(Ticks: 189435) (Id: 2) (Free Heap: 233796 bytes) STA Start
(Ticks: 193437) (Id: 1) (Free Heap: 232500 bytes) Scan Done
(Ticks: 195531) (Id: 0) (Free Heap: 233868 bytes) WiFi Ready
(Ticks: 195532) (Id: 2) (Free Heap: 233604 bytes) STA Start
(Ticks: 195533) (Id: 2) (Free Heap: 233604 bytes) STA Start
(Ticks: 195538) (Id: 2) (Free Heap: 232080 bytes) STA Start
(Ticks: 196843) (Id: 0) (Free Heap: 233868 bytes) WiFi Ready
(Ticks: 196844) (Id: 2) (Free Heap: 233604 bytes) STA Start
(Ticks: 196845) (Id: 2) (Free Heap: 233604 bytes) STA Start
(Ticks: 196849) (Id: 2) (Free Heap: 232080 bytes) STA Start
(Ticks: 197193) (Id: 4) (Free Heap: 232588 bytes) STA Connected
(Ticks: 197222) (Id: 7) (Free Heap: 232908 bytes) STA Got IP
IP address: 192.168.1.205 CH: 8 RSSI: 49 MAC: 14:91:82:B1:17:7D
Code: Select all
#include <WiFi.h>
#include <WiFiMulti.h>
static void wifi_event(WiFiEvent_t event);
static void print_wifi_info();
bool wifi_debug_on = true;
WiFiMulti wifiMulti;
void setup()
{
Serial.begin(115200);
while (!Serial);
Serial.println("Setup started . . .");
WiFi.onEvent(wifi_event);
delay(100);
WiFi.disconnect(true);
wifiMulti.addAP("iMobile", "password1");
wifiMulti.addAP("iCable", "password2");
Serial.println("Connecting Wifi...");
if (wifiMulti.run() == WL_CONNECTED)
{
Serial.println("");
Serial.println("WiFi connected");
}
}
void loop()
{
if (wifiMulti.run() != WL_CONNECTED)
{
Serial.println("WiFi not connected!");
delay(1000);
}
delay(2000);
}
void print_wifi_info()
{
Serial.print("IP address: ");
Serial.print(WiFi.localIP());
Serial.print(" CH: ");
Serial.print(WiFi.channel());
Serial.print(" RSSI: ");
Serial.print(WiFi.RSSI() * -1);
Serial.print(" MAC: ");
Serial.println(WiFi.BSSIDstr());
}
void wifi_event(WiFiEvent_t event)
{
switch (event)
{
case SYSTEM_EVENT_WIFI_READY:
if (wifi_debug_on) printf(" (Ticks: % d) (Id: % 02d) (Free Heap: % d bytes) WiFi Ready \n", millis(), event, ESP.getFreeHeap());
break;
case SYSTEM_EVENT_SCAN_DONE:
if (wifi_debug_on) printf(" (Ticks: % d) (Id: % 02d) (Free Heap: % d bytes) Scan Done \n", millis(), event, ESP.getFreeHeap());
break;
case SYSTEM_EVENT_STA_START:
if (wifi_debug_on) printf(" (Ticks: % d) (Id: % 02d) (Free Heap: % d bytes) STA Start \n", millis(), event, ESP.getFreeHeap());
break;
case SYSTEM_EVENT_STA_STOP:
if (wifi_debug_on) printf(" (Ticks: % d) (Id: % 02d) (Free Heap: % d bytes) STA Stop \n", millis(), event, ESP.getFreeHeap());
break;
case SYSTEM_EVENT_STA_CONNECTED:
if (wifi_debug_on) printf(" (Ticks: % d) (Id: % 02d) (Free Heap: % d bytes) STA Connected \n", millis(), event, ESP.getFreeHeap());
break;
case SYSTEM_EVENT_STA_DISCONNECTED:
if (wifi_debug_on) printf(" (Ticks: % d) (Id: % 02d) (Free Heap: % d bytes) STA Disconnected \n", millis(), event, ESP.getFreeHeap());
break;
case SYSTEM_EVENT_STA_AUTHMODE_CHANGE:
if (wifi_debug_on) printf(" (Ticks: % d) (Id: % 02d) (Free Heap: % d bytes) STA Auth Mode Change \n", millis(), event, ESP.getFreeHeap());
break;
case SYSTEM_EVENT_STA_GOT_IP:
if (wifi_debug_on)
{
printf(" (Ticks: % d) (Id: % 02d) (Free Heap: % d bytes) STA Got IP \n", millis(), event, ESP.getFreeHeap());
print_wifi_info();
}
break;
case SYSTEM_EVENT_STA_LOST_IP:
if (wifi_debug_on) printf(" (Ticks: % d) (Id: % 02d) (Free Heap: % d bytes) STA Lost IP \n", millis(), event, ESP.getFreeHeap());
break;
case SYSTEM_EVENT_STA_WPS_ER_SUCCESS:
if (wifi_debug_on) printf(" (Ticks: % d) (Id: % 02d) (Free Heap: % d bytes) STA WPS ER Success \n", millis(), event, ESP.getFreeHeap());
break;
case SYSTEM_EVENT_STA_WPS_ER_FAILED:
if (wifi_debug_on) printf(" (Ticks: % d) (Id: % 02d) (Free Heap: % d bytes) STA WPS ER Failed \n", millis(), event, ESP.getFreeHeap());
break;
case SYSTEM_EVENT_STA_WPS_ER_TIMEOUT:
if (wifi_debug_on) printf(" (Ticks: % d) (Id: % 02d) (Free Heap: % d bytes) STA WPS ER Timeout \n", millis(), event, ESP.getFreeHeap());
break;
case SYSTEM_EVENT_STA_WPS_ER_PIN:
if (wifi_debug_on) printf(" (Ticks: % d) (Id: % 02d) (Free Heap: % d bytes) STA WPS ER PIN \n", millis(), event, ESP.getFreeHeap());
break;
case SYSTEM_EVENT_AP_START:
if (wifi_debug_on) printf(" (Ticks: % d) (Id: % 02d) (Free Heap: % d bytes) AP Start \n", millis(), event, ESP.getFreeHeap());
break;
case SYSTEM_EVENT_AP_STOP:
if (wifi_debug_on) printf(" (Ticks: % d) (Id: % 02d) (Free Heap: % d bytes) AP Stop \n", millis(), event, ESP.getFreeHeap());
break;
case SYSTEM_EVENT_AP_STACONNECTED:
if (wifi_debug_on) printf(" (Ticks: % d) (Id: % 02d) (Free Heap: % d bytes) AP STA Connected \n", millis(), event, ESP.getFreeHeap());
break;
case SYSTEM_EVENT_AP_STADISCONNECTED:
if (wifi_debug_on) printf(" (Ticks: % d) (Id: % 02d) (Free Heap: % d bytes) AP STA Disconnected \n", millis(), event, ESP.getFreeHeap());
break;
case SYSTEM_EVENT_AP_PROBEREQRECVED:
if (wifi_debug_on) printf(" (Ticks: % d) (Id: % 02d) (Free Heap: % d bytes) AP Probe Req Received \n", millis(), event, ESP.getFreeHeap());
break;
case SYSTEM_EVENT_ETH_START:
if (wifi_debug_on) printf(" (Ticks: % d) (Id: % 02d) (Free Heap: % d bytes) ETH Start \n", millis(), event, ESP.getFreeHeap());
break;
case SYSTEM_EVENT_ETH_STOP:
if (wifi_debug_on) printf(" (Ticks: % d) (Id: % 02d) (Free Heap: % d bytes) ETH Stop \n", millis(), event, ESP.getFreeHeap());
break;
case SYSTEM_EVENT_ETH_CONNECTED:
if (wifi_debug_on) printf(" (Ticks: % d) (Id: % 02d) (Free Heap: % d bytes) ETH Connected \n", millis(), event, ESP.getFreeHeap());
break;
case SYSTEM_EVENT_ETH_DISCONNECTED:
if (wifi_debug_on) printf(" (Ticks: % d) (Id: % 02d) (Free Heap: % d bytes) ETH Disconnected \n", millis(), event, ESP.getFreeHeap());
break;
case SYSTEM_EVENT_ETH_GOT_IP:
if (wifi_debug_on) printf(" (Ticks: % d) (Id: % 02d) (Free Heap: % d bytes) ETH Got IP \n", millis(), event, ESP.getFreeHeap());
break;
case SYSTEM_EVENT_MAX:
if (wifi_debug_on) printf(" (Ticks: % d) (Id: % 02d) (Free Heap: % d bytes) MAX Event \n", millis(), event, ESP.getFreeHeap());
break;
default:
if (wifi_debug_on) printf(" (Ticks: % d) (Id: % 02d) (Free Heap: % d bytes) UNKNOWN EVENT \n", millis(), event, ESP.getFreeHeap());
break;
}
}