event: post got ip event when use static ip

TW6926
pull/21/head
Wu Jian Gang 2016-09-05 11:05:07 +08:00
rodzic c3af6e51d7
commit 1588d1aa6e
3 zmienionych plików z 31 dodań i 8 usunięć

Wyświetl plik

@ -13,6 +13,7 @@
// limitations under the License.
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include "esp_err.h"
#include "esp_wifi.h"
@ -77,6 +78,12 @@ static esp_err_t system_event_sta_gotip_default(system_event_t *event)
{
extern esp_err_t esp_wifi_set_sta_ip(void);
WIFI_API_CALL_CHECK("esp_wifi_set_sta_ip", esp_wifi_set_sta_ip(), ESP_OK);
printf("ip: " IPSTR ", mask: " IPSTR ", gw: " IPSTR "\n",
IP2STR(&event->event_info.got_ip.ip),
IP2STR(&event->event_info.got_ip.netmask),
IP2STR(&event->event_info.got_ip.gw));
return ESP_OK;
}
@ -134,6 +141,19 @@ esp_err_t system_event_sta_connected_handle_default(system_event_t *event)
if (status == TCPIP_ADAPTER_DHCP_INIT) {
tcpip_adapter_dhcpc_start(TCPIP_ADAPTER_IF_STA);
} else if (status == TCPIP_ADAPTER_DHCP_STOPPED) {
struct ip_info ip_info;
system_event_t evt;
tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &ip_info);
//notify event
evt.event_id = SYSTEM_EVENT_STA_GOTIP;
memcpy(&evt.event_info.got_ip.ip, &ip_info.ip, sizeof(evt.event_info.got_ip.ip));
memcpy(&evt.event_info.got_ip.netmask, &ip_info.netmask, sizeof(evt.event_info.got_ip.netmask));
memcpy(&evt.event_info.got_ip.gw, &ip_info.gw, sizeof(evt.event_info.got_ip.gw));
esp_event_send(&evt);
}
return ESP_OK;

Wyświetl plik

@ -17,6 +17,8 @@
#include <stdint.h>
#include "rom/queue.h"
#include "esp_wifi.h"
#define CONFIG_TCPIP_LWIP 1
@ -24,7 +26,13 @@
#if CONFIG_TCPIP_LWIP
#include "lwip/ip_addr.h"
#include "rom/queue.h"
#define IP2STR(ipaddr) ip4_addr1_16(ipaddr), \
ip4_addr2_16(ipaddr), \
ip4_addr3_16(ipaddr), \
ip4_addr4_16(ipaddr)
#define IPSTR "%d.%d.%d.%d"
struct ip_info {
ip4_addr_t ip;

Wyświetl plik

@ -74,9 +74,8 @@ esp_err_t tcpip_adapter_start(tcpip_adapter_if_t tcpip_if, uint8_t *mac, struct
if (dhcps_status == TCPIP_ADAPTER_DHCP_INIT) {
dhcps_start(esp_netif[tcpip_if], info);
printf("dhcp server start:(ip: %s, ", inet_ntoa(info->ip));
printf("mask: %s, ", inet_ntoa(info->netmask));
printf("gw: %s)\n", inet_ntoa(info->gw));
printf("dhcp server start:(ip: " IPSTR ", mask: " IPSTR ", gw: " IPSTR ")\n",
IP2STR(&info->ip), IP2STR(&info->netmask), IP2STR(&info->gw));
dhcps_status = TCPIP_ADAPTER_DHCP_STARTED;
}
@ -456,10 +455,6 @@ static void tcpip_adapter_dhcpc_cb(void)
memcpy(&evt.event_info.got_ip.gw, &ip_info->gw, sizeof(evt.event_info.got_ip.gw));
esp_event_send(&evt);
printf("ip: %s, ", inet_ntoa(ip_info->ip));
printf("mask: %s, ", inet_ntoa(ip_info->netmask));
printf("gw: %s\n", inet_ntoa(ip_info->gw));
} else {
TCPIP_ADAPTER_DEBUG("ip unchanged\n");
}