{前略}
void app_main()
{
//Initialize
NVS
esp_err_t ret =
nvs_flash_init();
if (ret ==
ESP_ERR_NVS_NO_FREE_PAGES || ret ==
ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK(ret);
ESP_LOGI(TAG,
"ESP_WIFI_MODE_STA");
if
(wifi_init_sta() == ESP_OK) {
ESP_LOGI(TAG, "Connection success");
} else {
ESP_LOGE(TAG, "Connection failed");
while(1) { vTaskDelay(1); }
}
esp_netif_ip_info_t ip_info;
esp_netif_get_ip_info(esp_netif_get_handle_from_ifkey("WIFI_STA_DEF"),
&ip_info);
ESP_LOGI(TAG,
"ip_info.ip=%s", ip4addr_ntoa((const ip4_addr_t
*)&ip_info.ip));
ESP_LOGI(TAG,
"ip_info.ip=" IPSTR, IP2STR(&ip_info.ip));
ESP_LOGI(TAG,
"esp_ip4_addr_get_byte(0)=%d",
esp_ip4_addr_get_byte(&ip_info.ip, 0));
ESP_LOGI(TAG,
"esp_ip4_addr_get_byte(1)=%d",
esp_ip4_addr_get_byte(&ip_info.ip, 1));
ESP_LOGI(TAG,
"esp_ip4_addr_get_byte(2)=%d",
esp_ip4_addr_get_byte(&ip_info.ip, 2));
ESP_LOGI(TAG,
"esp_ip4_addr_get_byte(3)=%d",
esp_ip4_addr_get_byte(&ip_info.ip, 3));
esp_ip4_addr_t
esp_ip4_addr; // 4 byte
ESP_LOGD(TAG,
"sizeof(esp_ip4_addr_t)=%d", sizeof(esp_ip4_addr_t));
esp_ip4_addr =
ip_info.ip;
ESP_LOGI(TAG,
"esp_ip4_addr=" IPSTR, IP2STR(&esp_ip4_addr));
esp_ip_addr_t
esp_ip_addr; // 24 byte
ESP_LOGD(TAG,
"sizeof(esp_ip_addr_t)=%d", sizeof(esp_ip_addr_t));
esp_ip_addr.u_addr.ip4 = esp_ip4_addr;
ESP_LOGI(TAG,
"esp_ip_addr.u_addr.ip4=" IPSTR,
IP2STR(&esp_ip_addr.u_addr.ip4));
const
ip4_addr_t ip4_addr; // 4 byte
ESP_LOGD(TAG,
"sizeof(ip4_addr_t)=%d", sizeof(ip4_addr_t));
memcpy((char
*)&ip4_addr, (char *)&ip_info.ip,
sizeof(ip4_addr));
ESP_LOGI(TAG,
"ip4_addr=%s", ip4addr_ntoa(&ip4_addr));
ip_addr_t
ip_addr; // 24 byte
ESP_LOGD(TAG,
"sizeof(ip_addr_t)=%d", sizeof(ip_addr_t));
ip_addr.u_addr.ip4 = ip4_addr;
ip_addr.type =
IPADDR_TYPE_V4;
ESP_LOGI(TAG,
"ip_addr.u_addr.ip4=%s",
ip4addr_ntoa(&ip_addr.u_addr.ip4));
}
|