mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
event: post got ip event when use static ip
TW6926
This commit is contained in:
parent
c3af6e51d7
commit
1588d1aa6e
@ -13,6 +13,7 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "esp_err.h"
|
#include "esp_err.h"
|
||||||
#include "esp_wifi.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);
|
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);
|
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;
|
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) {
|
if (status == TCPIP_ADAPTER_DHCP_INIT) {
|
||||||
tcpip_adapter_dhcpc_start(TCPIP_ADAPTER_IF_STA);
|
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;
|
return ESP_OK;
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "rom/queue.h"
|
||||||
|
|
||||||
#include "esp_wifi.h"
|
#include "esp_wifi.h"
|
||||||
|
|
||||||
#define CONFIG_TCPIP_LWIP 1
|
#define CONFIG_TCPIP_LWIP 1
|
||||||
@ -24,7 +26,13 @@
|
|||||||
|
|
||||||
#if CONFIG_TCPIP_LWIP
|
#if CONFIG_TCPIP_LWIP
|
||||||
#include "lwip/ip_addr.h"
|
#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 {
|
struct ip_info {
|
||||||
ip4_addr_t ip;
|
ip4_addr_t ip;
|
||||||
|
@ -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) {
|
if (dhcps_status == TCPIP_ADAPTER_DHCP_INIT) {
|
||||||
dhcps_start(esp_netif[tcpip_if], info);
|
dhcps_start(esp_netif[tcpip_if], info);
|
||||||
|
|
||||||
printf("dhcp server start:(ip: %s, ", inet_ntoa(info->ip));
|
printf("dhcp server start:(ip: " IPSTR ", mask: " IPSTR ", gw: " IPSTR ")\n",
|
||||||
printf("mask: %s, ", inet_ntoa(info->netmask));
|
IP2STR(&info->ip), IP2STR(&info->netmask), IP2STR(&info->gw));
|
||||||
printf("gw: %s)\n", inet_ntoa(info->gw));
|
|
||||||
|
|
||||||
dhcps_status = TCPIP_ADAPTER_DHCP_STARTED;
|
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));
|
memcpy(&evt.event_info.got_ip.gw, &ip_info->gw, sizeof(evt.event_info.got_ip.gw));
|
||||||
|
|
||||||
esp_event_send(&evt);
|
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 {
|
} else {
|
||||||
TCPIP_ADAPTER_DEBUG("ip unchanged\n");
|
TCPIP_ADAPTER_DEBUG("ip unchanged\n");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user