Xinyuan-LilyGO / LilyGO-T-ETH-Series

156 stars 59 forks source link

T-ETH-LITE - S3 Running tcpclient example for rosserial over ethernet with the esp32-s3 #73

Open programmeddeath1 opened 1 week ago

programmeddeath1 commented 1 week ago

In the tcpclient example, where does the variable ETH_PHY_W5500 get defined? i run the example by itself, it gives

'ETH_PHY_W5500' was not declared in this scope 

I am trying to run rosserial over ethernet using tcp. the example implementation for arduino/esp is as shown here

#include <SPI.h>
#include <Ethernet.h>

// To use the TCP version of rosserial_arduino
#define ROSSERIAL_ARDUINO_TCP

#include <ros.h>
#include <std_msgs/String.h>

// Set the shield settings
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 0, 177);

// Set the rosserial socket server IP address
IPAddress server(192,168,0,11);
// Set the rosserial socket server port
const uint16_t serverPort = 11411;

// .. other code functions and initializations

void setup()
{
  // Use serial to monitor the process
  Serial.begin(115200);

  // Connect the Ethernet
  Ethernet.begin(mac, ip);

  // Let some time for the Ethernet Shield to be initialized
  delay(1000);

  Serial.println("");
  Serial.println("Ethernet connected");
  Serial.println("IP address: ");
  Serial.println(Ethernet.localIP());

  // Set the connection to rosserial socket server
  nh.getHardware()->setConnection(server, serverPort);
  nh.initNode();
//... remaining calls before setup 
}
void loop()
{
  if(millis() - last_time >= period)
  {
    last_time = millis();
    if (nh.connected())
    {
      Serial.println("Connected");
      // Say hello
      str_msg.data = hello;
      chatter.publish( &str_msg );
    } else {
      Serial.println("Not Connected");
    }
  }
  nh.spinOnce();
  delay(1);
}

It basically is initialize the ethernet library, add the ip and port for the tcp server. Then during begin start ethernet and call the setConnection with the server IP and port. The setConnection is as can be seen here

It basically uses the Ethernet llibrary initialized for the device to make the tcp read write etc.

So i am currently trying this implementation

  #include <Arduino.h>
  #if ESP_ARDUINO_VERSION < ESP_ARDUINO_VERSION_VAL(3,0,0)
    #include <ETHClass2.h>       //Is to use the modified ETHClass
    #define ETH  ETH2
  #else
    #include <ETH.h>
  #endif
  #include <WiFi.h>
  // To use the TCP version of rosserial_arduino
  #define ROSSERIAL_ARDUINO_TCP
  #define ESP32_ETH
  #include <ros.h>
  #include <trajectory_msgs/JointTrajectoryPoint.h>
  #include <esp_now.h>
  #include "utilities.h"          //Board PinMap   

  // Define the server IP address
  IPAddress serverIP(192, 168, 0, 106);

  // Set the rosserial socket server port
  const uint16_t serverPort = 11411;

  void setup() {
      Serial.begin(115200);

  #ifdef ETH_POWER_PIN
      pinMode(ETH_POWER_PIN, OUTPUT);
      digitalWrite(ETH_POWER_PIN, HIGH);  // Ensure PHY is powered up before initializing
  #endif

      // Initialize Ethernet interface
      #if CONFIG_IDF_TARGET_ESP32
          if (!ETH.begin(ETH_TYPE, ETH_ADDR, ETH_MDC_PIN,
                         ETH_MDIO_PIN, ETH_RESET_PIN, ETH_CLK_MODE)) {
              Serial.println("ETH start Failed!");
          }
      #else
          if (!ETH.begin(ETH_PHY_W5500, 1, ETH_CS_PIN, ETH_INT_PIN, ETH_RST_PIN,
                         SPI3_HOST,
                         ETH_SCLK_PIN, ETH_MISO_PIN, ETH_MOSI_PIN)) {
              Serial.println("ETH start Failed!");
          }
      #endif
      Serial.print("ETH Connected, IP: ");
      Serial.println(ETH.localIP());

      // Initialize ROS
      nh.getHardware()->setConnection(serverIP, serverPort);
      nh.initNode();
  ...

Is this implementation proper? can you guide me with this setup.

for the esp32-s3 both ETH_TYPE and ETH_PHY_W5500 show as not declared in scope

Thanks in advance!

lewisxhe commented 5 days ago

I haven't used what you said, I will try it when I have time. ETH_PHY_W5500 is defined here https://github.com/Xinyuan-LilyGO/LilyGO-T-ETH-Series/blob/41cddd15c1c8aa321b2ede4de7180e36efc084cf/lib/ETHClass2/src/ETHClass2.h#L98