Page 1 of 1

If statement with WiFiEvent_t event

Posted: Fri Aug 19, 2022 6:36 pm
by martinius96
Hello there, I have problem with ESP32 and PHY Ethernet LAN8720 that is connected to ESP via RMII interface.
I am running 2 tasks. One will do measurement and add value into Queue (FIFO buffer) and other will do data transfer over HTTP or HTTPS (based on sketch) when data are available in Queue.

But there is problem.. There is ETH initialied in setup(). But sometimes it didnt initialize before there are data sent (there is also attached 5000 ms delay in setup, sometimes help, sometimes not). So datas are successfully sent on second interation (after 5 minutes as planned in program).

I want to add if statement to task that is doing data transfer to webpage.
But I dont know how I can use WiFiEvent_t event in if statement...
It is used in WiFi.onEvent(WiFiEvent) function.

So how I can use it in if statement? I want to know if event is ARDUINO_EVENT_ETH_GOT_IP, so Ethernet will have IP and I can do successful request on first try.
So i want something like...

Code: Select all

if (WiFiEvent_t event != ARDUINO_EVENT_ETH_GOT_IP){
return;
}
Code of WiFiEvent used from ETH example

Code: Select all

void WiFiEvent(WiFiEvent_t event);

void setup() {
  WiFi.onEvent(WiFiEvent);
}

void WiFiEvent(WiFiEvent_t event)
{
  switch (event) {
    case ARDUINO_EVENT_ETH_START:
      Serial.println("ETH Started");
      //set eth hostname here
      ETH.setHostname("esp32-ethernet");
      break;
    case ARDUINO_EVENT_ETH_CONNECTED:
      Serial.println("ETH Connected");
      break;
    case ARDUINO_EVENT_ETH_GOT_IP:
      Serial.print("ETH MAC: ");
      Serial.print(ETH.macAddress());
      Serial.print(", IPv4: ");
      Serial.print(ETH.localIP());
      if (ETH.fullDuplex()) {
        Serial.print(", FULL_DUPLEX");
      }
      Serial.print(", ");
      Serial.print(ETH.linkSpeed());
      Serial.println("Mbps");
      break;
    case ARDUINO_EVENT_ETH_DISCONNECTED:
      Serial.println("ETH Disconnected");
      break;
    case ARDUINO_EVENT_ETH_STOP:
      Serial.println("ETH Stopped");
      break;
    default:
      break;
  }
}