Hi,
I triyng to make a communication between Arduino and a Pc via UDP Ethernet.
To test the connection I used this simple script:
#include <Ethernet.h>
#include <EthernetUdp.h> // UDP library from: bjoern@cs.stanford.edu 12/30/2008
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 177);
unsigned int localPort = 8888; // local port to listen on
// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;
void setup() {
// start the Ethernet and UDP:
Ethernet.begin(mac, ip);
Udp.begin(localPort);
Serial.begin(9600);
}
void loop() {
// if there's data available, read a packet
int packetSize = Udp.parsePacket();
Serial.println("1) Received packet of size ");
if (packetSize)
{
Serial.print("Received packet of size ");
Serial.println(packetSize);
}
delay(10);
}
The problem is that the script freeze at the "int packetSize = Udp.parsePacket();" line 'cause the monitor shows:
- Received packet of size
Received packet of size 3 - Received packet of size
Received packet of size 5 - Received packet of size
Received packet of size 12594 - Received packet of size
Received packet of size -24399
When the negative value arrive the sketch crash.
I use an Arduino nano (old bootloader)
An ethernet module 5100
IDE 1.8.19
What could be the problem?
Many thanks in advance.