ESP8266 Developer Zone The Official ESP8266 Forum 2015-12-22T15:46:39+08:00 https://bbs.espressif.com:443/feed.php?f=7&t=1544 2015-12-22T15:46:39+08:00 2015-12-22T15:46:39+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1544&p=5129#p5129 <![CDATA[Re: Is there anything similar to wifi_set_event_handler_cb() that works for STATION mode?]]>
Thanks a lot for help!

Statistics: Posted by doragasu — Tue Dec 22, 2015 3:46 pm


]]>
2015-12-22T11:36:56+08:00 2015-12-22T11:36:56+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1544&p=5121#p5121 <![CDATA[Re: Is there anything similar to wifi_set_event_handler_cb() that works for STATION mode?]]>
wifi_set_event_handler_cb can work in station mode.
Here is an example:

Code:

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);
}

Statistics: Posted by ESP_Faye — Tue Dec 22, 2015 11:36 am


]]>
2015-12-22T03:46:49+08:00 2015-12-22T03:46:49+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1544&p=5117#p5117 <![CDATA[[Solved] Is there anything similar to wifi_set_event_handler_cb() that works for STATION mode?]]>
Is it possible to receive wifi connection and dhcp events using something similar to wifi_set_event_handler_cb() when in STATION mode?

Statistics: Posted by doragasu — Tue Dec 22, 2015 3:46 am


]]>