add got ip event handler

This commit is contained in:
xiaxiaotian 2016-08-19 12:08:45 +08:00 committed by Wu Jian Gang
parent 6f122928f0
commit 1325a761e9
3 changed files with 27 additions and 0 deletions

View file

@ -79,6 +79,7 @@ static system_event_handle_t g_system_event_handle_table[] = {
{SYSTEM_EVENT_STA_CONNECTED, system_event_sta_connected_handle_default}, {SYSTEM_EVENT_STA_CONNECTED, system_event_sta_connected_handle_default},
{SYSTEM_EVENT_STA_DISCONNECTED, system_event_sta_disconnected_handle_default}, {SYSTEM_EVENT_STA_DISCONNECTED, system_event_sta_disconnected_handle_default},
{SYSTEM_EVENT_STA_AUTHMODE_CHANGE, NULL}, {SYSTEM_EVENT_STA_AUTHMODE_CHANGE, NULL},
{SYSTEM_EVENT_STA_GOTIP, NULL},
{SYSTEM_EVENT_AP_START, system_event_ap_start_handle_default}, {SYSTEM_EVENT_AP_START, system_event_ap_start_handle_default},
{SYSTEM_EVENT_AP_STOP, system_event_ap_stop_handle_default}, {SYSTEM_EVENT_AP_STOP, system_event_ap_stop_handle_default},
{SYSTEM_EVENT_AP_STACONNECTED, NULL}, {SYSTEM_EVENT_AP_STACONNECTED, NULL},
@ -161,6 +162,7 @@ static esp_err_t esp_system_event_debug(system_event_t *event)
system_event_sta_connected_t *connected; system_event_sta_connected_t *connected;
system_event_sta_disconnected_t *disconnected; system_event_sta_disconnected_t *disconnected;
system_event_sta_authmode_change_t *auth_change; system_event_sta_authmode_change_t *auth_change;
system_event_sta_gotip_t *got_ip;
system_event_ap_staconnected_t *staconnected; system_event_ap_staconnected_t *staconnected;
system_event_ap_stadisconnected_t *stadisconnected; system_event_ap_stadisconnected_t *stadisconnected;
system_event_ap_probe_req_rx_t *ap_probereqrecved; system_event_ap_probe_req_rx_t *ap_probereqrecved;
@ -202,6 +204,10 @@ static esp_err_t esp_system_event_debug(system_event_t *event)
auth_change = &event->event_info.auth_change; auth_change = &event->event_info.auth_change;
os_printf("SYSTEM_EVENT_STA_AUTHMODE_CHNAGE\nold_mode:%d, new_mode:%d\n", auth_change->old_mode, auth_change->new_mode); os_printf("SYSTEM_EVENT_STA_AUTHMODE_CHNAGE\nold_mode:%d, new_mode:%d\n", auth_change->old_mode, auth_change->new_mode);
break; break;
case SYSTEM_EVENT_STA_GOTIP:
got_ip = &event->event_info.got_ip;
os_printf("SYSTEM_EVENT_STA_GOTIP\n");
break;
case SYSTEM_EVENT_AP_START: case SYSTEM_EVENT_AP_START:
os_printf("SYSTEM_EVENT_AP_START\n"); os_printf("SYSTEM_EVENT_AP_START\n");
break; break;

View file

@ -32,6 +32,7 @@ typedef enum {
SYSTEM_EVENT_STA_CONNECTED, /**< ESP32 station connected to AP */ SYSTEM_EVENT_STA_CONNECTED, /**< ESP32 station connected to AP */
SYSTEM_EVENT_STA_DISCONNECTED, /**< ESP32 station disconnected to AP */ SYSTEM_EVENT_STA_DISCONNECTED, /**< ESP32 station disconnected to AP */
SYSTEM_EVENT_STA_AUTHMODE_CHANGE, /**< the auth mode of AP connected by ESP32 station changed */ SYSTEM_EVENT_STA_AUTHMODE_CHANGE, /**< the auth mode of AP connected by ESP32 station changed */
SYSTEM_EVENT_STA_GOTIP,
SYSTEM_EVENT_AP_START, /**< ESP32 softap start */ SYSTEM_EVENT_AP_START, /**< ESP32 softap start */
SYSTEM_EVENT_AP_STOP, /**< ESP32 softap start */ SYSTEM_EVENT_AP_STOP, /**< ESP32 softap start */
SYSTEM_EVENT_AP_STACONNECTED, /**< a station connected to ESP32 soft-AP */ SYSTEM_EVENT_AP_STACONNECTED, /**< a station connected to ESP32 soft-AP */
@ -40,6 +41,10 @@ typedef enum {
SYSTEM_EVENT_MAX SYSTEM_EVENT_MAX
} system_event_id_t; } system_event_id_t;
typedef struct {
uint32_t addr;
} esp_ip_addr_t;
typedef struct { typedef struct {
uint32_t status; /**< status of scanning APs*/ uint32_t status; /**< status of scanning APs*/
uint8_t number; uint8_t number;
@ -64,6 +69,12 @@ typedef struct {
uint8_t new_mode; /**< the new auth mode of AP */ uint8_t new_mode; /**< the new auth mode of AP */
} system_event_sta_authmode_change_t; } system_event_sta_authmode_change_t;
typedef struct {
esp_ip_addr_t ip;
esp_ip_addr_t netmask;
esp_ip_addr_t gw;
} system_event_sta_gotip_t;
typedef struct { typedef struct {
uint8_t mac[6]; /**< MAC address of the station connected to ESP32 soft-AP */ uint8_t mac[6]; /**< MAC address of the station connected to ESP32 soft-AP */
uint8_t aid; /**< the aid that ESP32 soft-AP gives to the station connected to */ uint8_t aid; /**< the aid that ESP32 soft-AP gives to the station connected to */
@ -84,6 +95,7 @@ typedef union {
system_event_sta_disconnected_t disconnected; /**< ESP32 station disconnected to AP */ system_event_sta_disconnected_t disconnected; /**< ESP32 station disconnected to AP */
system_event_sta_scan_done_t scan_done; /**< ESP32 station scan (APs) done */ system_event_sta_scan_done_t scan_done; /**< ESP32 station scan (APs) done */
system_event_sta_authmode_change_t auth_change; /**< the auth mode of AP ESP32 station connected to changed */ system_event_sta_authmode_change_t auth_change; /**< the auth mode of AP ESP32 station connected to changed */
system_event_sta_gotip_t got_ip;
system_event_ap_staconnected_t sta_connected; /**< a station connected to ESP32 soft-AP */ system_event_ap_staconnected_t sta_connected; /**< a station connected to ESP32 soft-AP */
system_event_ap_stadisconnected_t sta_disconnected; /**< a station disconnected to ESP32 soft-AP */ system_event_ap_stadisconnected_t sta_disconnected; /**< a station disconnected to ESP32 soft-AP */
system_event_ap_probe_req_rx_t ap_probereqrecved; /**< ESP32 softAP receive probe request packet */ system_event_ap_probe_req_rx_t ap_probereqrecved; /**< ESP32 softAP receive probe request packet */

View file

@ -27,6 +27,8 @@
#include "apps/dhcpserver.h" #include "apps/dhcpserver.h"
#include "esp_event.h"
static struct netif *esp_netif[TCPIP_ADAPTER_IF_MAX]; static struct netif *esp_netif[TCPIP_ADAPTER_IF_MAX];
static struct ip_info esp_ip[TCPIP_ADAPTER_IF_MAX]; static struct ip_info esp_ip[TCPIP_ADAPTER_IF_MAX];
@ -183,6 +185,7 @@ esp_err_t tcpip_adapter_get_ip_info(tcpip_adapter_if_t tcpip_if, struct ip_info
esp_err_t tcpip_adapter_addr_change_cb(struct netif *netif) esp_err_t tcpip_adapter_addr_change_cb(struct netif *netif)
{ {
tcpip_adapter_if_t tcpip_if; tcpip_adapter_if_t tcpip_if;
system_event_t evt;
if (!netif) { if (!netif) {
TCPIP_ADAPTER_DEBUG("null netif=%p\n", netif); TCPIP_ADAPTER_DEBUG("null netif=%p\n", netif);
@ -208,6 +211,12 @@ esp_err_t tcpip_adapter_addr_change_cb(struct netif *netif)
ip4_addr_set(&esp_ip[tcpip_if].gw, ip_2_ip4(&netif->gw)); ip4_addr_set(&esp_ip[tcpip_if].gw, ip_2_ip4(&netif->gw));
//notify event //notify event
evt.event_id = SYSTEM_EVENT_STA_GOTIP;
memcpy(&evt.event_info.got_ip.ip, &esp_ip[tcpip_if].ip, sizeof(evt.event_info.got_ip.ip));
memcpy(&evt.event_info.got_ip.netmask, &esp_ip[tcpip_if].netmask, sizeof(evt.event_info.got_ip.netmask));
memcpy(&evt.event_info.got_ip.gw, &esp_ip[tcpip_if].gw, sizeof(evt.event_info.got_ip.gw));
esp_event_send(&evt);
printf("ip: %s, ", inet_ntoa(esp_ip[tcpip_if].ip)); printf("ip: %s, ", inet_ntoa(esp_ip[tcpip_if].ip));
printf("mask: %s, ", inet_ntoa(esp_ip[tcpip_if].netmask)); printf("mask: %s, ", inet_ntoa(esp_ip[tcpip_if].netmask));
printf("gw: %s\n", inet_ntoa(esp_ip[tcpip_if].gw)); printf("gw: %s\n", inet_ntoa(esp_ip[tcpip_if].gw));