[Solved] Is there anything similar to wifi_set_event_handler_cb() that works for STATION mode?

doragasu
Posts: 2
Joined: Tue Dec 22, 2015 3:20 am

[Solved] Is there anything similar to wifi_set_event_handler_cb() that works for STATION mode?

Postby doragasu » Tue Dec 22, 2015 3:46 am

When I use wifi_set_event_handler_cb() while in SOFTAP mode, it works like a charm, but if I try using it on STATION mode, it does not work, I receive no events.

Is it possible to receive wifi connection and dhcp events using something similar to wifi_set_event_handler_cb() when in STATION mode?

ESP_Faye
Posts: 1646
Joined: Mon Oct 27, 2014 11:08 am

Re: Is there anything similar to wifi_set_event_handler_cb() that works for STATION mode?

Postby ESP_Faye » Tue Dec 22, 2015 11:36 am

Hi,

wifi_set_event_handler_cb can work in station mode.
Here is an example:

Code: Select all

void wifi_handle_event_cb(System_Event_t *evt)
{
   os_printf("event %x\n", evt->event);
   switch (evt->event) {
       case EVENT_STAMODE_CONNECTED:
          os_printf("connect to ssid %s, channel %d\n",
               evt->event_info.connected.ssid,
               evt->event_info.connected.channel);
          break;
       case EVENT_STAMODE_DISCONNECTED:
          os_printf("disconnect from ssid %s, reason %d\n",
               evt->event_info.disconnected.ssid,
               evt->event_info.disconnected.reason);
          break;
       case EVENT_STAMODE_AUTHMODE_CHANGE:
           os_printf("mode: %d -> %d\n",
               evt->event_info.auth_change.old_mode,
               evt->event_info.auth_change.new_mode);
           break;
       case EVENT_STAMODE_GOT_IP:
          os_printf("ip:" IPSTR ",mask:" IPSTR ",gw:" IPSTR,
                     IP2STR(&evt->event_info.got_ip.ip),
                     IP2STR(&evt->event_info.got_ip.mask),
                     IP2STR(&evt->event_info.got_ip.gw));
          os_printf("\n");
          break;
       case EVENT_SOFTAPMODE_STACONNECTED:
           os_printf("station: " MACSTR "join, AID = %d\n",
            MAC2STR(evt->event_info.sta_connected.mac),
            evt->event_info.sta_connected.aid);
           break;
       case EVENT_SOFTAPMODE_STADISCONNECTED:
           os_printf("station: " MACSTR "leave, AID = %d\n",
            MAC2STR(evt->event_info.sta_disconnected.mac),
            evt->event_info.sta_disconnected.aid);
           break;
       default:
          break;
   }
}
void user_init(void)
{
    wifi_set_opmode(STATION_MODE);
   
    // TODO: add your own code here....
   
    wifi_set_event_handler_cb(wifi_handle_event_cb);
}


doragasu
Posts: 2
Joined: Tue Dec 22, 2015 3:20 am

Re: Is there anything similar to wifi_set_event_handler_cb() that works for STATION mode?

Postby doragasu » Tue Dec 22, 2015 3:46 pm

You are right, it works also in station mode! I don't know why but I got the impression it only worked on softap mode.

Thanks a lot for help!

Who is online

Users browsing this forum: No registered users and 136 guests