Core2, W5500 and ESP-IDF example eth2ap
-
Hello,
I like to use a Core2 as Wifi-AP for some small sensors. My starting point was the eth2ap example from ESP-IDF v4.3.2. I added some outputs to the example to see was going on. I changed FLOW_CONTROL_QUEUE_TIMEOUT_MS to 500:
#define FLOW_CONTROL_QUEUE_TIMEOUT_MS (5*100) #define FLOW_CONTROL_QUEUE_LENGTH (40) #define FLOW_CONTROL_WIFI_SEND_TIMEOUT_MS (100) typedef struct { void *packet; uint16_t length; } flow_control_msg_t; // Forward packets from Wi-Fi to Ethernet static esp_err_t pkt_wifi2eth(void *buffer, uint16_t len, void *eb) { if (s_ethernet_is_connected) { if (esp_eth_transmit(s_eth_handle, buffer, len) != ESP_OK) { ESP_LOGE(TAG, "Wifi->ETH: Ethernet send packet failed"); } } esp_wifi_internal_free_rx_buffer(eb); return ESP_OK; } // Forward packets from Ethernet to Wi-Fi // Note that, Ethernet works faster than Wi-Fi on ESP32, // so we need to add an extra queue to balance their speed difference. static esp_err_t pkt_eth2wifi(esp_eth_handle_t eth_handle, uint8_t *buffer, uint32_t len, void *priv) { esp_err_t ret = ESP_OK; flow_control_msg_t msg = { .packet = buffer, .length = len }; if (xQueueSend(flow_control_queue, &msg, pdMS_TO_TICKS(FLOW_CONTROL_QUEUE_TIMEOUT_MS)) != pdTRUE) { ESP_LOGE(TAG, "ETH->Wifi: send flow control message failed or timeout, length=%d", len); free(buffer); ret = ESP_FAIL; } return ret; } // This task will fetch the packet from the queue, and then send out through Wi-Fi. // Wi-Fi handles packets slower than Ethernet, we might add some delay between each transmitting. static void eth2wifi_flow_control_task(void *args) { flow_control_msg_t msg; int res = 0; uint32_t timeout = 0; while (1) { if (xQueueReceive(flow_control_queue, &msg, pdMS_TO_TICKS(FLOW_CONTROL_QUEUE_TIMEOUT_MS)) == pdTRUE) { timeout = 0; if (s_sta_is_connected && msg.length) { do { vTaskDelay(pdMS_TO_TICKS(timeout)); timeout += 2; res = esp_wifi_internal_tx(WIFI_IF_AP, msg.packet, msg.length); } while (res && timeout < FLOW_CONTROL_WIFI_SEND_TIMEOUT_MS); if (res != ESP_OK) { ESP_LOGE(TAG, "ETH->WiFi: send packet failed: %d, timeout=%d, length=%d", res, timeout, msg.length); } else { ESP_LOGI(TAG, "ETH->WiFi: send packet ok: %d, timeout=%d, length=%d", res, timeout, msg.length); } } free(msg.packet); } } vTaskDelete(NULL); }
It worked sometimes: If I send 10 pings, 2-3 reached the server. I cann't used a browser to show some small html-page.
My output is:I (14004) wifi:new:<1,0>, old:<1,1>, ap:<1,1>, sta:<255,255>, prof:1 I (14004) wifi:station: 5e:6c:e2:e0:0f:66 join, AID=1, bgn, 20 I (14034) eth_example: Wi-Fi AP got a station connected I (14074) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=60 I (14104) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=60 I (14174) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=60 I (14204) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=60 E (16534) eth_example: ETH->WiFi: send packet failed: 12309, timeout=100, length=60 I (16534) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=60 I (16534) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=60 I (16544) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=60 I (16554) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=590 I (16554) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=60 I (16564) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=60 I (16574) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=60 I (16584) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=86 I (16584) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=295 I (16594) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=60 I (16604) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=770 I (16614) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=60 I (16614) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=1314 I (16624) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=86 I (16634) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=88 I (16644) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=60 I (16644) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=590 I (16654) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=812 I (16664) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=832 I (16674) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=316 I (16674) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=336 I (16684) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=1168 I (16694) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=1188 I (16704) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=1398 I (16704) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=1418 I (16714) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=86 E (18974) eth_example: ETH->WiFi: send packet failed: 12309, timeout=100, length=60 I (18974) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=60 I (18974) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=60 I (18984) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=60 I (18994) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=60 I (18994) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=60 I (19004) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=60 I (19014) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=60 I (19014) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=60 I (19024) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=88 I (19034) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=74 I (19044) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=60 I (19044) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=590 I (19054) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=60 I (19064) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=60 E (21324) eth_example: ETH->WiFi: send packet failed: 12309, timeout=100, length=60 I (21324) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=60 I (21324) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=60 I (21334) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=60 I (21344) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=316 I (21344) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=336 I (21354) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=590 I (21364) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=812 I (21374) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=832 I (21374) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=1398 I (21384) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=1418 I (21394) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=1168 I (21404) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=1188 I (21404) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=60 I (21414) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=60 I (21424) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=60 I (21434) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=88 I (21434) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=107 I (21444) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=131 I (21454) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=86 I (21464) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=60 I (21464) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=86 I (21474) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=86 I (21484) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=60 I (21494) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=60 I (21494) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=705 I (21504) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=60 I (21514) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=60 E (22494) eth_example: ETH->Wifi: send flow control message failed or timeout, length=832 E (22994) eth_example: ETH->Wifi: send flow control message failed or timeout, length=1398 E (23494) eth_example: ETH->Wifi: send flow control message failed or timeout, length=1418 E (23774) eth_example: ETH->WiFi: send packet failed: 12309, timeout=100, length=60 I (23774) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=60 I (23774) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=60 I (23784) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=60 I (23794) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=60 I (23794) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=86 I (23804) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=60 I (23814) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=191 I (23824) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=191 I (23824) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=86 I (23834) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=60 I (23844) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=86 I (23854) eth_example: ETH->WiFi: send packet ok: 0, timeout=2, length=750 ...
Have anyone used the ESP32 as WiFi-AP and knows the challenges?
-
Hello @sheepDog
the eth2ap sample code runs fine on my M5Core2 w/o any modifications except adapting the GPIOs. Ping are fine and I can surf the Internet just fine from the wireless cleint.
- Have you tried to change the channel the softAP is using? Maybe there is too much interference in your area?
- Have you tried with a different wireless client?
- How are you powering the M5Core2 and LAN module? Maybe there is a power issue?
Thanks
Felix -
Hello Felix,
thank you for your quick answer. I can ping sometimes and I cann't surf the Internet with my phone or with my computer and eth2ap-modul.
-
I have changed the channel the softAP is using. Small changes in quality can be seen, but no significant improvement.
-
I tried a different wireless client, for example my computer and my phone.
-
I used a 12V/3A power adapter on LAN-Module with W5500. The M5Core2 and the LAN module also run stably with other applications and the same power supply.
Bye,
Uwe -