I have a working event handler that displays many events but also the number if one is not recognised:
Code: Select all
esp_err_t wifi_event_handler(void *ctx, system_event_t *event)
{
static char tag[] = "app_main";
static int nextStatus = 0;
switch(event->event_id)
{
case SYSTEM_EVENT_WIFI_READY:
{
ESP_LOGI(tag, "SYSTEM_EVENT_WIFI_READY");
break;
}
case SYSTEM_EVENT_SCAN_DONE:
{
ESP_LOGI(tag, "SYSTEM_EVENT_SCAN_DONE");
break;
}
case SYSTEM_EVENT_STA_START:
{
ESP_LOGI(tag, "SYSTEM_EVENT_STA_START");
ESP_ERROR_CHECK( esp_wifi_connect() );
break;
}
case SYSTEM_EVENT_STA_STOP:
{
ESP_LOGI(tag, "SYSTEM_EVENT_STA_STOP");
break;
}
case SYSTEM_EVENT_STA_CONNECTED:
{
ESP_LOGI(tag, "SYSTEM_EVENT_STA_CONNECTED");
break;
}
case SYSTEM_EVENT_AP_STACONNECTED:
{
ESP_LOGI(tag, "SYSTEM_EVENT_AP_STACONNECTED");
nextStatus = SYSTEM_EVENT_AP_STAIPASSIGNED;
break;
}
case SYSTEM_EVENT_AP_STADISCONNECTED:
{
ESP_LOGI(tag, "SYSTEM_EVENT_AP_STADISCONNECTED");
if (nextStatus == SYSTEM_EVENT_AP_STAIPASSIGNED){
printf("Disconnect without IP assigned - wrong password? Starting magnet scan...\n");
nextStatus = 0;
xTaskCreate(task_magnet, "magnet", 2048, NULL, 5, NULL);
}
break;
}
case SYSTEM_EVENT_AP_STAIPASSIGNED:
{
ESP_LOGI(tag, "SYSTEM_EVENT_AP_STAIPASSIGNED");
nextStatus = 0;
break;
}
case SYSTEM_EVENT_STA_DISCONNECTED:
{
ESP_LOGI(tag, "SYSTEM_EVENT_STA_DISCONNECTED");
break;
}
case SYSTEM_EVENT_STA_AUTHMODE_CHANGE:
{
ESP_LOGI(tag, "SYSTEM_EVENT_STA_AUTHMODE_CHANGE");
break;
}
case SYSTEM_EVENT_STA_GOT_IP:
{
ESP_LOGI(tag, "SYSTEM_EVENT_STA_GOT_IP");
break;
}
case SYSTEM_EVENT_STA_LOST_IP:
{
ESP_LOGI(tag, "SYSTEM_EVENT_STA_LOST_IP");
break;
}
default:
{
ESP_LOGI(tag, "EventHandler received %i", event->event_id);
break;
}
}
return ESP_OK;
}
Code: Select all
I (48164) wifi: new:<1,1>, old:<1,0>, ap:<1,1>, sta:<255,255>, prof:1
I (48165) wifi: station: 70:c9:4e:d3:b6:17 join, AID=1, bgn, 40U
I (52167) wifi: station: 70:c9:4e:d3:b6:17 leave, AID = 1, bss_flags is 134242
I (52168) wifi: new:<1,0>, old:<1,1>, ap:<1,1>, sta:<255,255>, prof:1
I (52209) wifi: new:<1,1>, old:<1,0>, ap:<1,1>, sta:<255,255>, prof:1
I (52210) wifi: station: 70:c9:4e:d3:b6:17 join, AID=1, bgn, 40U
I (56211) wifi: station: 70:c9:4e:d3:b6:17 leave, AID = 1, bss_flags is 134242
I (56212) wifi: new:<1,0>, old:<1,1>, ap:<1,1>, sta:<255,255>, prof:1
I (56253) wifi: new:<1,1>, old:<1,0>, ap:<1,1>, sta:<255,255>, prof:1
I (56253) wifi: station: 70:c9:4e:d3:b6:17 join, AID=1, bgn, 40U
I (60255) wifi: station: 70:c9:4e:d3:b6:17 leave, AID = 1, bss_flags is 134242
I (60255) wifi: new:<1,0>, old:<1,1>, ap:<1,1>, sta:<255,255>, prof:1
I (60299) wifi: new:<1,1>, old:<1,0>, ap:<1,1>, sta:<255,255>, prof:1
I (60299) wifi: station: 70:c9:4e:d3:b6:17 join, AID=1, bgn, 40U
I (64301) wifi: station: 70:c9:4e:d3:b6:17 leave, AID = 1, bss_flags is 134242
I (64301) wifi: new:<1,0>, old:<1,1>, ap:<1,1>, sta:<255,255>, prof:1
I (64344) wifi: new:<1,1>, old:<1,0>, ap:<1,1>, sta:<255,255>, prof:1
I (64345) wifi: station: 70:c9:4e:d3:b6:17 join, AID=1, bgn, 40U
I (68346) wifi: station: 70:c9:4e:d3:b6:17 leave, AID = 1, bss_flags is 134242
I (68347) wifi: new:<1,0>, old:<1,1>, ap:<1,1>, sta:<255,255>, prof:1
I (68982) wifi: new:<1,0>, old:<1,0>, ap:<1,1>, sta:<255,255>, prof:1
I (68982) wifi: station: 70:c9:4e:d3:b6:17 join, AID=1, bg, 20
I (72984) wifi: station: 70:c9:4e:d3:b6:17 leave, AID = 1, bss_flags is 131106
I (72984) wifi: new:<1,0>, old:<1,0>, ap:<1,1>, sta:<255,255>, prof:1
I (73024) wifi: new:<1,0>, old:<1,0>, ap:<1,1>, sta:<255,255>, prof:1
I (73024) wifi: station: 70:c9:4e:d3:b6:17 join, AID=1, bg, 20
I (77026) wifi: station: 70:c9:4e:d3:b6:17 leave, AID = 1, bss_flags is 131106
I (77026) wifi: new:<1,0>, old:<1,0>, ap:<1,1>, sta:<255,255>, prof:1
I (77071) wifi: new:<1,0>, old:<1,0>, ap:<1,1>, sta:<255,255>, prof:1
I (77071) wifi: station: 70:c9:4e:d3:b6:17 join, AID=1, bg, 20
I (81073) wifi: station: 70:c9:4e:d3:b6:17 leave, AID = 1, bss_flags is 131106
I (81073) wifi: new:<1,0>, old:<1,0>, ap:<1,1>, sta:<255,255>, prof:1
I (81117) wifi: new:<1,0>, old:<1,0>, ap:<1,1>, sta:<255,255>, prof:1
I (81117) wifi: station: 70:c9:4e:d3:b6:17 join, AID=1, bg, 20
I (85119) wifi: station: 70:c9:4e:d3:b6:17 leave, AID = 1, bss_flags is 131106
I (85119) wifi: new:<1,0>, old:<1,0>, ap:<1,1>, sta:<255,255>, prof:1
I (85161) wifi: new:<1,0>, old:<1,0>, ap:<1,1>, sta:<255,255>, prof:1
I (85161) wifi: station: 70:c9:4e:d3:b6:17 join, AID=1, bg, 20
I (89163) wifi: station: 70:c9:4e:d3:b6:17 leave, AID = 1, bss_flags is 131106
I (89163) wifi: new:<1,0>, old:<1,0>, ap:<1,1>, sta:<255,255>, prof:1