完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
本帖最后由 城东 于 2016-12-11 12:54 编辑
当WiFi的状态发生改变或者wifi底层产生了一些要应用程序处理的事件的时候底层协议栈将调用回调函数et_wifi_event_cb,这个函数内容如下: void et_wifi_event_cb(System_Event_t *event) { switch(event->event_id) { case EVENT_STAMODE_SCAN_DONE://ESP8266 station finish scanning AP break; case EVENT_STAMODE_CONNECTED://ESP8266 station connected to AP os_printf("et connect to ssid %s, channel %dn", event->event_info.connected.ssid, event->event_info.connected.channel); break; case EVENT_STAMODE_DISCONNECTED://ESP8266 station disconnected to AP disARM_wifi_spark_timer(); wifi_led_off(); if(true != wifi_station_get_reconnect_policy()) { os_printf("et wifi set to reconnectn"); wifi_station_set_reconnect_policy(true); } //os_printf("et disconnect from ssid %s, reason %dn", event->event_info.disconnected.ssid, event->event_info.disconnected.reason); if(wifi_reconnect_start_flag != 1) { os_printf("airkiss start or start first don't restart %dn",wifi_reconnect_start_flag); } else { os_printf("et wifi station connect status %d, restart systemn",wifi_station_get_connect_status()); system_restart(); } break; case EVENT_STAMODE_AUTHMODE_CHANGE://the auth mode of AP connected by ESP8266 station changed os_printf("mode: %d -> %dn", event->event_info.auth_change.old_mode, event->event_info.auth_change.new_mode); break; case EVENT_STAMODE_GOT_IP://ESP8266 station got IP from connected AP set_wifi_spark_timer(1000); //os_printf("ip:" IPSTR ",mask:" IPSTR ",gw:" IPSTR, IP2STR(&event->event_info.got_ip.ip), IP2STR(&event->event_info.got_ip.mask), // IP2STR(&event->event_info.got_ip.gw)); break; // case EVENT_STAMODE_DHCP_TIMEOUT://ESP8266 station dhcp client got IP timeout // break; case EVENT_SOFTAPMODE_STACONNECTED://a station connected to ESP8266 soft-AP os_printf("et station: " MACSTR "join, AID = %dn", MAC2STR(event->event_info.sta_connected.mac), event->event_info.sta_connected.aid); break; case EVENT_SOFTAPMODE_STADISCONNECTED://a station disconnected to ESP8266 soft-AP os_printf("et station: " MACSTR "leave, AID = %dn", MAC2STR(event->event_info.sta_disconnected.mac), event->event_info.sta_disconnected.aid); break; // case EVENT_SOFTAPMODE_PROBEREQRECVED: // break; // case EVENT_MAX: // break; default: break; } } 这个函数根据WiFi底层的状态做出相应的响应,所有的状态如下: typedef enum { EVENT_STAMODE_SCAN_DONE = 0, /**< ESP8266 station finish scanning AP */ EVENT_STAMODE_CONNECTED, /**< ESP8266 station connected to AP */ EVENT_STAMODE_DISCONNECTED, /**< ESP8266 station disconnected to AP */ EVENT_STAMODE_AUTHMODE_CHANGE, /**< the auth mode of AP connected by ESP8266 station changed */ EVENT_STAMODE_GOT_IP, /**< ESP8266 station got IP from connected AP */ EVENT_STAMODE_DHCP_TIMEOUT, /**< ESP8266 station dhcp client got IP timeout */ EVENT_SOFTAPMODE_STACONNECTED, /**< a station connected to ESP8266 soft-AP */ EVENT_SOFTAPMODE_STADISCONNECTED, /**< a station disconnected to ESP8266 soft-AP */ EVENT_SOFTAPMODE_PROBEREQRECVED, /**< Receive probe request packet in soft-AP interface */ EVENT_MAX } SYSTEM_EVENT; 这里我们看看连接上AP的情况: case EVENT_STAMODE_CONNECTED://ESP8266 station connected to AP os_printf("et connect to ssid %s, channel %dn", event->event_info.connected.ssid, event->event_info.connected.channel); break; 将打印出et connect to。。。。。。语句代表已经连接上了AP,开发板作为station模式,然后在看看断开连接的情况: case EVENT_STAMODE_DISCONNECTED://ESP8266 station disconnected to AP disarm_wifi_spark_timer(); wifi_led_off(); if(true != wifi_station_get_reconnect_policy()) { os_printf("et wifi set to reconnectn"); wifi_station_set_reconnect_policy(true); } //os_printf("et disconnect from ssid %s, reason %dn", event->event_info.disconnected.ssid, event->event_info.disconnected.reason); if(wifi_reconnect_start_flag != 1) { os_printf("airkiss start or start first don't restart %dn",wifi_reconnect_start_flag); } else { os_printf("et wifi station connect status %d, restart systemn",wifi_station_get_connect_status()); system_restart(); } break; 这里会关掉绿灯,然后将检查是否重连,如果要重连的话这里将设置重连,然后这里判断 wifi_reconnect_start_flag标志位,如果这个标志位为1就会复位系统并重新连接,否则将不会采取任何操作,这个函数只有一个地方需要会设置这个重新连接标志位,就是已经获得到IP的情况下需要重新连接,在user_esp_platform_check_ip函数中如下 if (wifi_station_get_connect_status() == STATION_GOT_IP && ipconfig.ip.addr != 0) { wifi_reconnect_start_flag = 1; } 下来看看 et_wifi_event_cb获得IP连接之后的函数: case EVENT_STAMODE_GOT_IP://ESP8266 station got IP from connected AP set_wifi_spark_timer(1000); //os_printf("ip:" IPSTR ",mask:" IPSTR ",gw:" IPSTR, IP2STR(&event->event_info.got_ip.ip), IP2STR(&event->event_info.got_ip.mask), // IP2STR(&event->event_info.got_ip.gw)); break; 这里将再次启动spark定时器让绿色LED灯闪烁。 et_wifi_event_cb函数剩下的内容和本例程无关,不再分析。 |
|
相关推荐
1 个讨论
|
|
你好,请问一下wifi_set_event_handler_cb(et_wifi_event_cb);这个函数是怎么把et_wifi_event_cb(System_Event_t *event)中的event参数传递进来的?
|
|
|
|
|
|
只有小组成员才能发言,加入小组>>
[小e体验板] 【小体积大智慧】关于体验板的技术问题,看这一篇就够了
2855 浏览 4 评论
【小e1开发板试用体验】分析程序架构四~/Share/SDK/makefile分析
3613 浏览 1 评论
6705 浏览 19 评论
29077 浏览 59 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-28 00:15 , Processed in 0.710602 second(s), Total 73, Slave 56 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号