Hi,
I'm working on sending UDP Datagrams to a server over the Ethernet on the Teensy 4.1 and i get crashes as soon as i send a Package without receiving one first
here is the example code:
this is a mostly unchanged example UDPSendReceiveString.ino with the send part removed from after the reception and put into an extra segment that sends a UDP Datagram every 2.5s.
it just stops doing anything after the first send, while conforming to the Arduino convention. The same code works fine on ESP32 Wifi.
I have a UDP Echo Server running in 192.168.178.100:5100 and it received the Datagram. the response is also received on the Teensy but the freezes.
here is the Serial printout that shows that the message is received and then the code freezes
I tested this in the Arduino IDE as well as on PlatformIO (both up to date versions)
I'm working on sending UDP Datagrams to a server over the Ethernet on the Teensy 4.1 and i get crashes as soon as i send a Package without receiving one first
here is the example code:
Code:
#include <NativeEthernet.h>
#include <NativeEthernetUdp.h>
#define EXECUTE_EVERY(ms) { \
static ulong _last_time = 0; \
if (millis() - _last_time > (ms)) \
{ \
_last_time = millis();\
#define EXECUTE_EVERY_END }}
// 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, 178, 150);
unsigned int localPort = 8888; // local port to listen on
// buffers for receiving and sending data
#define UDP_RX_BUFF_SIZE 1024
char packetBuffer[UDP_RX_BUFF_SIZE]; // buffer to hold incoming packet,
char ReplyBuffer[] = "acknowledged abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz "; // a string to send back
// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// start the Ethernet
Ethernet.begin(mac, ip);
// 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
}
}
if (Ethernet.linkStatus() == LinkOFF) {
Serial.println("Ethernet cable is not connected.");
}
// start UDP
Udp.begin(localPort);
}
void loop() {
EXECUTE_EVERY(1000)
static int loop_count = 0;
Serial.printf("loop: count=%d\n", loop_count++);
EXECUTE_EVERY_END
#if 1
EXECUTE_EVERY(10)
// if there's data available, read a packet
int packetSize = Udp.parsePacket();
if (packetSize)
{
Serial.print("Received packet of size ");
Serial.println(packetSize);
Serial.print("From ");
IPAddress remote = Udp.remoteIP();
for (int i=0; i < 4; i++) {
Serial.print(remote[i], DEC);
if (i < 3) {
Serial.print(".");
}
}
Serial.print(", port ");
Serial.println(Udp.remotePort());
// read the packet into packetBufffer
Udp.read(packetBuffer, UDP_RX_BUFF_SIZE);
Serial.println("Contents:");
Serial.println(packetBuffer);
// send a reply to the IP address and port that sent us the packet we received
//Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
//Udp.write(ReplyBuffer);
//Udp.endPacket();
}
EXECUTE_EVERY_END
#endif
#if 1
EXECUTE_EVERY(2500)
// send a reply to the IP address and port that sent us the packet we received
Udp.beginPacket("192.168.178.100", 5100);
Udp.write(ReplyBuffer);
Udp.endPacket();
EXECUTE_EVERY_END
#endif
}
this is a mostly unchanged example UDPSendReceiveString.ino with the send part removed from after the reception and put into an extra segment that sends a UDP Datagram every 2.5s.
it just stops doing anything after the first send, while conforming to the Arduino convention. The same code works fine on ESP32 Wifi.
I have a UDP Echo Server running in 192.168.178.100:5100 and it received the Datagram. the response is also received on the Teensy but the freezes.
here is the Serial printout that shows that the message is received and then the code freezes
Code:
loop: count=0
Received packet of size 96
From 192.168.178.100, port 5100
Contents:
acknowledged abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz
I tested this in the Arduino IDE as well as on PlatformIO (both up to date versions)