static int eth_cmd_control(int argc, char **argv) { int nerrors = arg_parse(argc, argv, (void **)ð_control_args); if (nerrors != 0) { arg_print_errors(stderr, eth_control_args.end, argv[0]); return 1; } if (!strncmp(eth_control_args.control->sval[0], "start", 5) && !started) { ESP_ERROR_CHECK(esp_eth_enable()); started = true; } if (!strncmp(eth_control_args.control->sval[0], "stop", 4) && started) { ESP_ERROR_CHECK(esp_eth_disable()); started = false; } if (!strncmp(eth_control_args.control->sval[0], "info", 4)) { uint8_t mac_addr[6]; esp_eth_get_mac(mac_addr); printf("HW ADDR: " MACSTR "\r\n", MAC2STR(mac_addr)); tcpip_adapter_get_ip_info(ESP_IF_ETH, &ip); printf("ETHIP: " IPSTR "\r\n", IP2STR(&ip.ip)); printf("ETHMASK: " IPSTR "\r\n", IP2STR(&ip.netmask)); printf("ETHGW: " IPSTR "\r\n", IP2STR(&ip.gw)); } return 0; }
void ICACHE_FLASH_ATTR wifi_get_ip_info(tcpip_adapter_if_t type, tcpip_adapter_ip_info_t* ipinfo) { tcpip_adapter_get_ip_info(type, ipinfo); // printf("wifi_get_ip_info:(ip: " IPSTR ", mask: " IPSTR ", gw: " IPSTR ")\n", // IP2STR(&ipinfo->ip), IP2STR(&ipinfo->netmask), IP2STR(&ipinfo->gw)); }
/** * An ESP32 WiFi event handler. * The types of events that can be received here are: * * SYSTEM_EVENT_AP_PROBEREQRECVED * SYSTEM_EVENT_AP_STACONNECTED * SYSTEM_EVENT_AP_STADISCONNECTED * SYSTEM_EVENT_AP_START * SYSTEM_EVENT_AP_STOP * SYSTEM_EVENT_SCAN_DONE * SYSTEM_EVENT_STA_AUTHMODE_CHANGE * SYSTEM_EVENT_STA_CONNECTED * SYSTEM_EVENT_STA_DISCONNECTED * SYSTEM_EVENT_STA_GOT_IP * SYSTEM_EVENT_STA_START * SYSTEM_EVENT_STA_STOP * SYSTEM_EVENT_WIFI_READY */ static esp_err_t esp32_wifi_eventHandler(void *ctx, system_event_t *event) { // Your event handling code here... switch(event->event_id) { // When we have started being an access point, then start being a web server. case SYSTEM_EVENT_AP_START: { // Handle the AP start event tcpip_adapter_ip_info_t ip_info; tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_AP, &ip_info); ESP_LOGD(tag, "**********************************************"); ESP_LOGD(tag, "* We are now an access point and you can point") ESP_LOGD(tag, "* your browser to http://" IPSTR, IP2STR(&ip_info.ip)); ESP_LOGD(tag, "**********************************************"); // Start Mongoose ... if (!g_mongooseStarted) { g_mongooseStarted = 1; xTaskCreatePinnedToCore(&mongooseTask, "bootwifi_mongoose_task", 8000, NULL, 5, NULL, 0); } break; } // SYSTEM_EVENT_AP_START // If we fail to connect to an access point as a station, become an access point. case SYSTEM_EVENT_STA_DISCONNECTED: { ESP_LOGD(tag, "Station disconnected started"); // We think we tried to connect as a station and failed! ... become // an access point. becomeAccessPoint(); break; } // SYSTEM_EVENT_AP_START // If we connected as a station then we are done and we can stop being a // web server. case SYSTEM_EVENT_STA_GOT_IP: { ESP_LOGD(tag, "********************************************"); ESP_LOGD(tag, "* We are now connected and ready to do work!") ESP_LOGD(tag, "* - Our IP address is: " IPSTR, IP2STR(&event->event_info.got_ip.ip_info.ip)); ESP_LOGD(tag, "********************************************"); g_mongooseStopRequest = 1; // Stop mongoose (if it is running). // Invoke the callback if Mongoose has NOT been started ... otherwise // we will invoke the callback when mongoose has ended. if (!g_mongooseStarted) { if (g_callback) { g_callback(1); } } // Mongoose was NOT started break; } // SYSTEM_EVENT_STA_GOTIP default: // Ignore the other event types break; } // Switch event return ESP_OK; } // esp32_wifi_eventHandler
static esp_err_t eth_event_handler(void *ctx, system_event_t *event) { switch (event->event_id) { case SYSTEM_EVENT_ETH_START: started = true; break; case SYSTEM_EVENT_ETH_GOT_IP: memset(&ip, 0, sizeof(tcpip_adapter_ip_info_t)); ESP_ERROR_CHECK(tcpip_adapter_get_ip_info(ESP_IF_ETH, &ip)); xEventGroupSetBits(eth_event_group, GOTIP_BIT); break; case SYSTEM_EVENT_ETH_STOP: xEventGroupClearBits(eth_event_group, GOTIP_BIT); started = false; default: break; } return ESP_OK; }
void eth_task(void *pvParameter) { tcpip_adapter_ip_info_t ip; memset(&ip, 0, sizeof(tcpip_adapter_ip_info_t)); vTaskDelay(2000 / portTICK_PERIOD_MS); while (1) { vTaskDelay(2000 / portTICK_PERIOD_MS); if (tcpip_adapter_get_ip_info(ESP_IF_ETH, &ip) == 0) { ESP_LOGI(TAG, "~~~~~~~~~~~"); ESP_LOGI(TAG, "ETHIP:"IPSTR, IP2STR(&ip.ip)); ESP_LOGI(TAG, "ETHPMASK:"IPSTR, IP2STR(&ip.netmask)); ESP_LOGI(TAG, "ETHPGW:"IPSTR, IP2STR(&ip.gw)); ESP_LOGI(TAG, "~~~~~~~~~~~"); } } }
/** * Get the interface subnet mask address. * @return IPAddress subnetMask */ IPAddress WiFiSTAClass::subnetMask() { tcpip_adapter_ip_info_t ip; tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &ip); return IPAddress(ip.netmask.addr); }
/** * Get the softAP interface IP address. * @return IPAddress softAP IP */ IPAddress WiFiAPClass::softAPIP() { tcpip_adapter_ip_info_t ip; tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_AP, &ip); return IPAddress(ip.ip.addr); }
/** * Get the gateway ip address. * @return IPAddress gatewayIP */ IPAddress WiFiSTAClass::gatewayIP() { tcpip_adapter_ip_info_t ip; tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &ip); return IPAddress(ip.gw.addr); }