Hello to the whole forum.
I currently have a problem that has cost me many hours and where I can't really get any further.
I have an ESP32 with a W5500 Ethernet Shield. The standard Ehernet.h from the Arduino was used as the library. The development environment is VSCode and PlatformIO.
The shield is also initialised and you can "ping" the IP. However, the function "Ethernet.hardwareStatus()" does not return a result. The shield is not recognised correctly.
I want to use the whole thing to read an electricity meter that sends a datagram via UDP. (600Byte via port 9583)
Because of the datagram length I have changed the maximum packet length in the Ethernet.h file. (UDP_TX_PACKET_MAX_SIZE 650)
Otherwise nothing was changed.
But I can't receive anything with the W5500. I have connected a W5100 from the Arduino UNO as a test.
With the source code unchanged, the reception works perfectly. The function "Ethernet.hardwareStatus()" also works.
Can anyone give me a tip on what I'm doing wrong?
Many greetings
Andreas
#include <Arduino.h>
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
// Network Settings
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 178, 99);
IPAddress udp_ip(239, 12, 255, 253);
unsigned int localPort = 9522; // local port to listen on
EthernetUDP Udp; // An EthernetUDP instance to send and receive packets over UDP
byte packetBuffer[600]; //buffer to hold incoming packet,
uint32_t Einspeisung;
uint32_t Bezug;
uint32_t Voltage;
void setup()
{
Serial.begin(115200);
Ethernet.init(33); // (33) default for ESP32 ; -->(10) for most Arduino
Ethernet.begin(mac,ip);
// Udp.begin(localPort);
Udp.beginMulticast(udp_ip, localPort);
// Check for Ethernet hardware present
if (Ethernet.hardwareStatus() == EthernetNoHardware)
{
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
while (true)
{
delay(1); // do nothing, no point running without Ethernet hardware
}
}
else if (Ethernet.hardwareStatus() == EthernetW5100)
{
Serial.println("W5100 Ethernet controller detected.");
delay(5000);
}
else if (Ethernet.hardwareStatus() == EthernetW5200)
{
Serial.println("W5200 Ethernet controller detected.");
}
else if (Ethernet.hardwareStatus() == EthernetW5500)
{
Serial.println("W5500 Ethernet controller detected.");
delay(5000);
}
}
void loop ()
{
uint16_t packetSize = Udp.parsePacket();
Udp.read(packetBuffer,packetSize);
uint16_t port = Udp.remotePort();
// check of packet to be received
if(packetSize=600)
// execution if packet has been received
{
if(port=45865)
{
// IPAddress remote = Udp.remoteIP(); // determination of port information; only a packet from Port 45865 is needed
Serial.print("\033[2J");
Serial.print("Received packet of size: "); // packet size information
Serial.println(packetSize);
Serial.print("From Remote Port: ");
Serial.println(port);
// read the packet into packetBuffer
Serial.println("Wert vom SMA-EM ");
Serial.print("Bezug: ");
Bezug = 0;
Bezug |= packetBuffer[0x20] <<24; //high byte first
Bezug |= packetBuffer[0x21] <<16;
Bezug |=packetBuffer[0x22] <<8;
Bezug |= packetBuffer[0x23] ;
Serial.print(Bezug);
Serial.println(" W");
Einspeisung=0;
Einspeisung |= packetBuffer[0x34] <<24; //high byte first
Einspeisung |= packetBuffer[0x35] <<16;
Einspeisung |= packetBuffer[0x36] <<8;
Einspeisung |= packetBuffer[0x37] ;
Serial.print("Einspeisung: ");
Serial.print(Einspeisung);
Serial.println(" W");
Voltage=0;
Voltage |= packetBuffer[0x120] <<24 ;
Voltage |= packetBuffer[0x121] <<16 ; //high byte first
Voltage |= packetBuffer[0x122] <<8;
Voltage |= packetBuffer[0x123] ;
Serial.print("Spannung ");
Serial.print(Voltage);
Serial.println(" V");
}
}
else
{
Serial.println("------------------");
Serial.println("no Packet received");
}
delay(1000);
}
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:NodeMCU-ESP-32S-Kit]
platform = espressif32
board = esp32doit-devkit-v1
framework = arduino
monitor_speed = 115200
lib_deps = arduino-libraries/Ethernet@^2.0.2
system
Closed
December 30, 2023, 9:07pm
4
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.