platformio / platform-espressif32

Espressif 32: development platform for PlatformIO
https://registry.platformio.org/platforms/platformio/espressif32
Apache License 2.0
855 stars 570 forks source link

Code works with no issues in Arduino IDE, but throws error on PlatformIO #1376

Closed pinarruiz closed 1 month ago

pinarruiz commented 1 month ago

I recently got a WT32-ETH01 and was testing the eth port on an Arduino IDE example, and it went all good, the example is https://github.com/espressif/arduino-esp32/blob/master/libraries/Ethernet/examples/ETH_LAN8720/ETH_LAN8720.ino with some values tweaked for the WT32-ETH01 (as can be seen below on the code provided).

The thing is that it compiles with no issues and upon connecting an ethernet cable it can also make an http get request to google. But when the code is used in PlatformIO now it does not compile, i attach some references, if more is needed please let me know. As you can see the program provided has some modifications, this modifications where also compiled on Arduino IDE and it all worked.

platformio.ini:

[env]
monitor_speed = 115200
build_flags =
    '-DBOARD="$BOARD"'
    -DMONITOR_SPEED=115200

[env:wt32-eth01]
platform = espressif32
board = wt32-eth01
framework = arduino

src/main.cpp:

#ifndef ETH_PHY_TYPE
#define ETH_PHY_TYPE ETH_PHY_LAN8720
#define ETH_PHY_ADDR 1
#define ETH_PHY_MDC 23
#define ETH_PHY_MDIO 18
#define ETH_PHY_POWER 16
#define ETH_CLK_MODE ETH_CLOCK_GPIO0_IN
#endif

#ifndef CONTROLLER_HOSTNAME
#define CONTROLLER_HOSTNAME "test-controller"
#endif

static bool eth_connected = false;

#ifndef DEBUG_CONTROLLER
#define DEBUG_CONTROLLER false
#endif

#ifndef MONITOR_SPEED
#ifndef CONFIG_MONITOR_BAUD
#define MONITOR_SPEED 115200
#else
#define MONITOR_SPEED CONFIG_MONITOR_BAUD
#endif
#endif

#define SW_VERSION "0.0.1"

#include <Arduino.h>
#include <ETH.h>

void debug_println(const char *message) {
  if (DEBUG_CONTROLLER) {
    Serial.println(message);
  }
}

// WARNING: onEvent is called from a separate FreeRTOS task (thread)!
void onEvent(arduino_event_id_t event) {
  switch (event) {
  case ARDUINO_EVENT_ETH_START:
    debug_println("ETH Started");
    // The hostname must be set after the interface is started, but needs
    // to be set before DHCP, so set it from the event handler thread.
    ETH.setHostname(CONTROLLER_HOSTNAME);
    break;
  case ARDUINO_EVENT_ETH_CONNECTED:
    debug_println("ETH Connected");
    break;
  case ARDUINO_EVENT_ETH_GOT_IP:
    debug_println("ETH Got IP");
    Serial.println(ETH);
    eth_connected = true;
    break;
  case ARDUINO_EVENT_ETH_LOST_IP:
    debug_println("ETH Lost IP");
    eth_connected = false;
    break;
  case ARDUINO_EVENT_ETH_DISCONNECTED:
    debug_println("ETH Disconnected");
    eth_connected = false;
    break;
  case ARDUINO_EVENT_ETH_STOP:
    debug_println("ETH Stopped");
    eth_connected = false;
    break;
  default:
    break;
  }
}

void setup() {
  Serial.begin(MONITOR_SPEED);
  debug_println("Starting Program ...");

  // Starting network related stuff
  Network.onEvent(onEvent);
  ETH.begin();
}

void loop() { delay(1000); }

Compilation logs:

src/main.cpp:51:8: error: 'ARDUINO_EVENT_ETH_LOST_IP' was not declared in this scope
   case ARDUINO_EVENT_ETH_LOST_IP:
        ^~~~~~~~~~~~~~~~~~~~~~~~~
src/main.cpp:51:8: note: suggested alternative: 'ARDUINO_EVENT_ETH_GOT_IP'
   case ARDUINO_EVENT_ETH_LOST_IP:
        ^~~~~~~~~~~~~~~~~~~~~~~~~
        ARDUINO_EVENT_ETH_GOT_IP
src/main.cpp: In function 'void setup()':
src/main.cpp:73:3: error: 'Network' was not declared in this scope
   Network.onEvent(onEvent);
   ^~~~~~~
*** [.pio/build/wt32-eth01/src/main.cpp.o] Error 1
pinarruiz commented 1 month ago

Digging a bit deeper, i found that the ~/.platformio/packages/framework-arduinoespressif32/libraries has this directories:

ArduinoOTA
AsyncUDP
BLE
BluetoothSerial
DNSServer
EEPROM
ESP32
ESPmDNS
Ethernet
FFat
FS
HTTPClient
HTTPUpdate
HTTPUpdateServer
I2S
Insights
LittleFS
NetBIOS
Preferences
RainMaker
SD
SD_MMC
SimpleBLE
SPI
SPIFFS
Ticker
Update
USB
WebServer
WiFi
WiFiClientSecure
WiFiProv
Wire

While https://github.com/espressif/arduino-esp32/tree/master/libraries has some others:

ArduinoOTA
AsyncUDP
BLE
BluetoothSerial
DNSServer
EEPROM
ESP32
ESP_I2S
ESP_NOW
ESP_SR
ESPmDNS
Ethernet
FFat
FS
HTTPClient
HTTPUpdate
HTTPUpdateServer
Insights
LittleFS
NetBIOS
Network
NetworkClientSecure
PPP
Preferences
RainMaker
SD
SD_MMC
SPI
SPIFFS
SimpleBLE
TFLiteMicro
Ticker
USB
Update
WebServer
WiFi
WiFiProv
Wire

It seems that the Network library is where the files that I am missing are.

pinarruiz commented 1 month ago

So i just figured it out, the Arduino IDE told me i had an update, me, not noticing the new version I updated blindly, to an rc version, so i guess thats on me.