Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of Ethernet and WiFi AP & STA simulateneously #10850

Open
1 task done
enriquedbelec opened this issue Jan 13, 2025 · 7 comments
Open
1 task done

Use of Ethernet and WiFi AP & STA simulateneously #10850

enriquedbelec opened this issue Jan 13, 2025 · 7 comments
Labels
Area: WiFi Issue related to WiFi Type: Question Only question

Comments

@enriquedbelec
Copy link

Board

Custom board

Device Description

Custom board with ESP32 Wroom 16 MB of flash with LAN8710A

Hardware Configuration

ETH_CLK_MODE -> ETH_CLOCK_GPIO17_OUT
ETH_POWER_PIN -> 5
ETH_TYPE -> ETH_PHY_LAN8720
ETH_ADDR -> 0
ETH_MDC_PIN -> 23
ETH_MDIO_PIN -> 18
ETH_CLOCK_PIN -> 17

Version

v2.0.17

IDE Name

VSCode

Operating System

Windows 10

Flash frequency

40 Mhz

PSRAM enabled

no

Upload speed

921600

Description

Hi,
I've checked on Arduino 2.0.17 and 3.1.1 that if you begin Ethernet only it can perform an HTTP connection ok. But if you enable the AP, then the ETH connection drops (can't establish connection).

Is there any way to keep working the ethernet connections while the AP is up? Ídem question with ETH + AP/STA ?

Thanks.

Sketch

// Init Ethernet driver
ETH.begin(ETH_ADDR, ETH_POWER_PIN, ETH_MDC_PIN, ETH_MDIO_PIN, ETH_TYPE, ETH_CLK_MODE);

Debug Message

No

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@enriquedbelec enriquedbelec added the Status: Awaiting triage Issue is waiting for triage label Jan 13, 2025
@me-no-dev
Copy link
Member

In 2.0.17 you can not. For 3.x you can decide which is the default outgoing interface by doing

Network.setDefaultInterface(ETH); //outgoing connections go through ETH by default
Network.setDefaultInterface(WiFi.STA); //outgoing connections go through STA by default

@me-no-dev
Copy link
Member

If you switch to ETH as default, make sure that that is done AFTER STA is connected

@SuGlider SuGlider added Type: Question Only question Area: WiFi Issue related to WiFi and removed Status: Awaiting triage Issue is waiting for triage labels Jan 13, 2025
@enriquedbelec
Copy link
Author

enriquedbelec commented Jan 14, 2025

Thank you @me-no-dev.

If ETH is connected and sending data to HTTP(s) and WiFi is put in AP mode it also stops connecting to internet on ETH. Will it work in this situation the Network.setDefaultInterface(ETH); ?

Edit: I have tested this situation, and when the AP is started, or when an user is connected (after IP assignaned) to AP, I have try to call Network.setDefaultInterface(ETH);, and the HTTPS transmission still can't be stablished. Do you know a solution?

@me-no-dev
Copy link
Member

AP should not interfere, unless they are both set in the same subnet.

@enriquedbelec
Copy link
Author

The AP give to my PC the IP 192.168.4.1, and ethernet obtains the IP 192.168.0.58 from the LAN, so they are not in the same subnet. But when the AP is started and/or when I connect with my PC to the AP and an IP is assigned, the HTTPS connections with WiFiClientSecure stop working. Any ideas?

@me-no-dev
Copy link
Member

@enriquedbelec please provide a test sketch to reproduce the issue

@enriquedbelec
Copy link
Author

Hi,

Here is a test sketch to reproduce the issue. The sketch starts ETH and waits for link up and get IP. After that it starts performing GET requests to URL. 30 seconds after start sketch, ir starts AP.

Here you can note, that the GET request is performed with 200 OK status code, until the AP is started. After the AP is started and also if you connect to AP, the requests can't be performed (log verbose shows a timeout).

#include <ETH.h>
#include <WiFi.h>
#include <HTTPClient.h>

#define ETH_CLK_MODE    ETH_CLOCK_GPIO17_OUT

// Pin# of the enable signal for the external crystal oscillator (-1 to disable for internal APLL source)
#define ETH_POWER_PIN   5

// Type of the Ethernet PHY (LAN8720 or TLK110)
#define ETH_TYPE        ETH_PHY_LAN8720

// I²C-address of Ethernet PHY (0 or 1 for LAN8720, 31 for TLK110)
#define ETH_ADDR        0

// Pin# of the I²C clock signal for the Ethernet PHY
#define ETH_MDC_PIN     23

// Pin# of the I²C IO signal for the Ethernet PHY
#define ETH_MDIO_PIN    18

// ETH clock pin
#define ETH_CLOCK_PIN   17

// NRST pin
#define ETH_NRST_PIN    12

// AP config
const char *apSSID = "ESP32_AP";
const char *apPassword = "12345678";

// Time until AP is started
const unsigned long apStartDelay = 30000; // 30 segundos

// Start ap flag
bool startAP = false;

// Already started AP flag
bool apAlreadyStarted = false;

// Task to get data from URL
void httpTask(void *parameter) {
  while (true) {
    if (ETH.linkUp()) {
      HTTPClient http;
      http.begin("http://jsonplaceholder.typicode.com/posts"); // URL de prueba
      int httpResponseCode = http.GET();
      if (httpResponseCode > 0) {
        Serial.printf("HTTP Response code: %d\n", httpResponseCode);
      } else {
        Serial.printf("HTTP POST failed, error: %s\n", http.errorToString(httpResponseCode).c_str());
      }
      http.end();
    }
    vTaskDelay(10000 / portTICK_PERIOD_MS); // Espera 10 segundos
  }
}

void setup() {
    Serial.begin(115200);
    delay(1000);
    // Init ETH
    // Power off/on PHY
    pinMode(ETH_POWER_PIN, INPUT);
    digitalWrite(ETH_POWER_PIN, 0);
    pinMode(ETH_POWER_PIN, OUTPUT);
    delay(99);
    // Reset LAN8710A
    pinMode(ETH_NRST_PIN, OUTPUT);
    digitalWrite(ETH_NRST_PIN, 0);
    delay(200);
    digitalWrite(ETH_NRST_PIN, 1);
    delay(500);
    // Init Ethernet driver
    ETH.begin(ETH_TYPE, ETH_ADDR, ETH_MDC_PIN, ETH_MDIO_PIN, ETH_POWER_PIN, ETH_CLK_MODE);

    // Set hostname
    ETH.setHostname("ESP32_TEST");

    // Wait for linkUp Ethernet connection
    Serial.println("Waiting for ETH linkUp...");
    while (!ETH.linkUp()) {
        delay(500);
        Serial.print(".");
    }
    Serial.println("\nETH link UP!");

    // Wait for having an IP on Ethernet connection
    Serial.println("Waiting for IP on ETH...");
    while (!ETH.hasIP()) {
        delay(500);
        Serial.print(".");
    }
    Serial.println("\nETH now has IP!");

    // Create task to send http posts
    xTaskCreate(httpTask, "HTTP Task", 4096, NULL, 1, NULL);
}

void loop() {
    if(!apAlreadyStarted){
        if(millis() > apStartDelay){
            startAP = true;
        }
        if (startAP) {
            Serial.println("Starting AP...");
            WiFi.mode(WIFI_AP);
            WiFi.softAP(apSSID, apPassword, 1, 0, 1);

            IPAddress IP = WiFi.softAPIP();
            Serial.printf("AP started. IP: %s\n", IP.toString().c_str());

            startAP = false;
            apAlreadyStarted = true;
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: WiFi Issue related to WiFi Type: Question Only question
Projects
None yet
Development

No branches or pull requests

3 participants