Arduino ethernet udp packet sender1/6/2024 ![]() It's better to check `udp.parsePacket()` without a delay. It might not make a difference because `Serial` goes over USB, but I'm in the habit of using 115200 and not 9600.ģ. (But having it there won't do anything.)Ģ. There's no need to declare your own MAC address. Then, when it's received into `data2` on the other Teensy, not only is the received size from `Udp.read()` not checked, but there's no guarantee that `data2` contains a NUL character, so calling `Serial.println(data2)` might not be well-behaved, depending what's in memory.ġ. One major thing I noticed about the code is that you're printing strings without a guaranteed NUL terminator. It seems that even if I change the delay it still happens (tried various values between 0-500).Įverything is working (tested for 16 hours straight), parsePacket varies from 1 to 0 but the program keeps running. Outcome: after a minute or two parsePacket = 0 and stays 0. Udp.beginPacket(destinationIp, destinationPort) Serial.begin(9600) //enable serial data print if needed IPAddress destinationIp(10, 100, 102, 126) Įthernet.begin(staticIP, subnetMask, gateway) Unsigned int UDPPort = 7772 // local port to listen onĬhar packetBuffer // buffer to hold incoming packet,Ĭhar MessageBuffer // a string to send backĮthernetUDP Udp // An EthernetUDP instance to let us send and receive packets over UDPīyte mac = Works as long as the devices are on the same LAN as the server. IPAddress UDPServer(255, 255, 255, 255) // Use UDP Broadcast address so the IP address of the server doesn't have to be known. ![]() ![]() #define UDP_TX_PACKET_MAX_SIZE 1000 //increase UDP buffer size I've tried running the code in a thread with the same results, I've tried using a long instead of an int, no luck.Īny idea why the incoming UDP comms randomly stop working, while the outgoing UDP continues working fine? I'm using a Teensy 3.5 and a W5500 Ethernet module. It still continues to send successfully when the incoming messages stop. I also have a keep alive, which sends a small UDP message every 2 seconds. I simplified the code and added a bunch of traps to see where the sketch was hanging up, and it always hangs at the same line:Īdding a delay(1) helped, and adding a delay(10) helped even more, but eventually it still stops working. Other times, I can run the sketch for hours without a single hiccup. Sometimes it happens after 1-2 minutes, and sometimes longer. Challenge is, incoming UDP messages simply stop working after a random interval. I've been using the Ethernet.h library for a while, and generally it works great! I can send and receive UDP broadcast messages to/from other devices.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |