Hello, all. I am working on a program that sends two packets via UDP (one packet of size 14 bytes and another of size 5 bytes). Right now, I am only using two devices for the two-way communication, and I am having a lot of problems. Given below is the code that I am having trouble with (this code is from the "base unit" which is an ESP32-PoE-ISO).
This code works great the first time. However, after the first call of this WiFi_UDPHandler(void) function, my Serial monitor starts spitting out garbage -- even when I comment out ALL Serial.print statements in my code. What's up with that? Also, there seems to be a significant lag between the transmit time and receive time (aka when I unplug the transmitting device, it takes the ESP32-PoE-ISO about 20 seconds to stop receiving the messages).
Any ideas?
void WiFi_UDPHandler(void)
{
udpPacketSize = UDP.parsePacket(); // get incoming packet size
if (udpPacketSize > 4) // if there is data to be read
{
remoteIP = UDP.remoteIP(); // get IP address from transmitting device
UDP.read(udpBufferReceive, BUFFER_LEN); // save incoming data packet into udpBufferReceive
emergencyButtonIndex = 0; // clear first
emergencyButtonIndex = udpBufferReceive[0]; // get (deviceID)
//Serial.print("emergencyButtonIndex = "); Serial.println(emergencyButtonIndex);
// Separate Data
memcpy(&emergencyButtonData[emergencyButtonIndex], udpBufferReceive, BUFFER_LEN); // copy incoming data (in udpBufferReceive) to the emergencyMessage struct
Serial.print("Device ID: 0x"); Serial.println(emergencyButtonData[emergencyButtonIndex].deviceID, HEX);
Serial.print("Transmission ID: 0x"); Serial.println(emergencyButtonData[emergencyButtonIndex].transmissionID, HEX);
Serial.print("Transmission Type: 0x"); Serial.println(emergencyButtonData[emergencyButtonIndex].transmissionType, HEX);
Serial.print("Emergency Flag: 0x"); Serial.println(emergencyButtonData[emergencyButtonIndex].emergency, HEX);
Serial.print("Emergency Message ID: 0x"); Serial.println(emergencyButtonData[emergencyButtonIndex].emergencyMessageID, HEX);
Serial.print("Connectivity Check Message ID: 0x"); Serial.println(emergencyButtonData[emergencyButtonIndex].connectivityCheckMessageID, HEX);
Serial.print("Transmission Location ID: 0x"); Serial.println(emergencyButtonData[emergencyButtonIndex].transmissionLocationID, HEX);
}
Here is what my serial monitor (running at 230400 baud) looks like when I comment out ALL Serial.print statements (and it never stops -- even when the transmitting device is powered off):
5 posts - 2 participants