EasyManua.ls Logo

Espressif Systems ESP8266EX - Events Triggered When Wi-Fi Connection State Changes

Espressif Systems ESP8266EX
41 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
!
3. Sample Codes
6. Compile the application program, generate firmware and download it into the ESP8266
module.
7. Power off the module, and change it to operation mode; then power on the module and
run the program. Connect a PC or other Stations to the ESP8266 SoftAP.
!
Result:
ESP8266 works as SoftAP, and the following information will be printed when a Station is
connected to it:
station:󰲧c8:3a:35:cc:14:94󰲧join,󰲧AID󰲧=󰲧1
3.2.5. Events Triggered When Wi-Fi Connection State Changes
1. The event monitor Wi-Fi_set_event_handler_cb monitors ESP8266’s Wi-Fi connection
state, either when it is working as Station or SoftAP, and executes a user callback when
the connection state changes.
2. Sample code:
void󰲧Wi-Fi_handle_event_cb(System_Event_t󰲧*evt)
{
󰲧󰲧󰲧󰲧printf("event󰲧%x\n",󰲧evt->event_id);
󰲧󰲧󰲧󰲧switch󰲧(evt->event_id)󰲧{
󰲧󰲧󰲧󰲧case󰲧EVENT_STAMODE_CONNECTED:
󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧printf("connect󰲧to󰲧ssid󰲧%s,󰲧channel󰲧%d\n",󰲧
󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧evt->event_info.connected.ssid,󰲧
󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧evt->event_info.connected.channel);
󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧break;
󰲧󰲧󰲧󰲧case󰲧EVENT_STAMODE_DISCONNECTED:
󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧printf("disconnect󰲧from󰲧ssid󰲧%s,󰲧reason󰲧%d\n",󰲧
󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧evt->event_info.disconnected.ssid,󰲧
󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧evt->event_info.disconnected.reason);
󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧break;
󰲧󰲧󰲧󰲧case󰲧EVENT_STAMODE_AUTHMODE_CHANGE:
󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧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:
󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧printf("ip:"󰲧IPSTR󰲧",mask:"󰲧IPSTR󰲧",gw:"󰲧IPSTR,
󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧IP2STR(&evt->event_info.got_ip.ip),
Espressif
! /!9 37
2017.05

Other manuals for Espressif Systems ESP8266EX

Related product manuals