Hi
I'm using Arduino to measure temperatures in two kettles and control heating in those two kettles through heating elements connected to SSRs, just so you get the brackground of my question.
I'm using the EthernetShield of Arduino to send status messages about measured temperatures and SSR status to the global broadcast address on UDP port 8000:
//Broadcast status message
void bcStatus()
{
char statusmsg[UDP_TX_PACKET_MAX_SIZE];
memset(statusmsg, 0, UDP_TX_PACKET_MAX_SIZE);
//If the temperatures show silly values, set them to 0
//That could be because something is wrong, or usually
//when the temperature sensor was not connected!
if(temp1 > 102 || temp1 < 0)
temp1 = 0.0;
if(temp2 > 102 || temp2 < 0)
temp2 = 0.0;
//Arduino platform does not allow "%f" in sprintf function
//so we need to get the values after comma in a different way :-)
int ctemp1 = (temp1 - (int)temp1) * 100;
int ctemp2 = (temp2 - (int)temp2) * 100;
sprintf(statusmsg, "%d,%d,%d,%d,%d,%d,%d.%d,%d.%d,%d.%d", statBrew, (digitalRead(P1) == HIGH) ? 1 : 0,
(digitalRead(P2) == HIGH) ? 1 : 0, (digitalRead(H1) == HIGH) ? 1 : 0,
(digitalRead(H2) == HIGH) ? 1 : 0, (digitalRead(H3) == HIGH) ? 1 : 0,
(int)temp1, ctemp1, (int)temp2, ctemp2, 1, 2);
//If there are any rests configured, attach information about them to the status message
//Information will be: <TotalRestTime>,<RestTemperature>,<TimeAlreadySpentOnRest>
for(int i = 0; i < numRests; i++)
{
sprintf(statusmsg+strlen(statusmsg), ",%d,%d,%d", restTimes[i], restTemps[i], currentRestTime[i]);
}
sprintf(statusmsg+strlen(statusmsg), "\n");
Udp.beginPacket(bcast, bcPort);
Udp.write(statusmsg);
Udp.endPacket();
}
Where bcast and bcPort are defined like:
//Broadcast address and port for status messages
IPAddress bcast(255,255,255,255);
unsigned int bcPort = 8000;
I used Wireshark to capture the behaviour of EthernetShield. I get normal messages for about 20 minutes, sometimes even longer, they look like this:
Summary in Wireshark:
2712 505.318299000 10.0.1.2 255.255.255.255 UDP 84 Source port: vcom-tunnel Destination port: irdmi
As you can see there are 84 bytes in the packet.
Printable bytes in the packet (the actual string I send from Arduino is 1,1,1,1,1,0,27.16,24.12,1.2,5,30,0,5,40,0):
EF@A@2Q1,1,1,1,1,0,27.16,24.12,1.2,5,30,0,5,40,0
At some point however, Arduino begins to "merge" several packets into 1 packet,...! After sending about 40 of these merged packets, Arduino crashes and doesn't answer no more over the Ethernet module, nor over serial port.
Summary in Wireshark:
2736 507.621248000 10.0.1.2 255.255.255.255 UDP 1514 Source port: vcom-tunnel Destination port: irdmi
As you can see there are 1514 bytes in the damn packet!
Printable bytes in the packet look now:
E@a
A@c,0,26.82,23.93,1.2,5,30,0,5,40,0
1,1,1,1,1,0,26.13,23.70,1.2,5,30,0,5,40,0
1,1,1,1,1,0,26.99,23.95,1.2,5,30,0,5,40,0
1,1,1,1,1,0,26.65,23.60,1.2,5,30,0,5,40,0
1,1,1,1,1,0,26.99,23.79,1.2,5,30,0,5,40,0
1,1,1,1,1,0,27.16,23.96,1.2,5,30,0,5,40,0
1,1,1,1,1,0,26.65,23.76,1.2,5,30,0,5,40,0
1,1,1,1,1,0,26.82,23.93,1.2,5,30,0,5,40,0
1,1,1,1,1,0,26.82,23.62,1.2,5,30,0,5,40,0
1,1,1,1,1,0,26.99,24.10,1.2,5,30,0,5,40,0
1,1,1,1,1,0,26.99,23.95,1.2,5,30,0,5,40,0
1,1,1,1,1,0,26.99,23.95,1.2,5,30,0,5,40,0
1,1,1,1,1,0,26.47,23.74,1.2,5,30,0,5,40,0
1,1,1,1,1,0,26.82,24.8,1.2,5,30,0,5,40,0
1,1,1,1,1,0,27.16,24.12,1.2,5,30,0,5,40,0
1,1,1,1,1,0,26.82,23.93,1.2,5,30,0,5,40,0
1,1,1,1,1,0,27.16,24.12,1.2,5,30,0,5,40,0
1,1,1,1,1,0,26.99,23.79,1.2,5,30,0,5,40,0
,1,0,25.96,23.38,1.2,5,30,0,5,40,0
1,1,1,1,1,0,26.47,23.89,1.2,5,30,0,5,40,0
1,1,1,1,1,0,25.96,23.22,1.2,5,30,0,5,40,0
1,1,1,1,1,0,26.30,23.72,1.2,5,30,0,5,40,0
1,1,1,1,1,0,25.61,23.19,1.2,5,30,0,5,40,0
1,1,1,1,1,0,26.30,23.72,1.2,5,30,0,5,40,0
1,1,1,1,1,0,26.13,23.55,1.2,5,30,0,5,40,0
1,1,1,1,1,0,26.99,23.95,1.2,5,30,0,5,40,0
1,1,1,1,1,0,26.30,23.41,1.2,5,30,0,5,40,0
1,1,1,1,1,0,26.13,23.86,1.2,5,30,0,5,40,0
1,1,1,1,1,0,26.13,24.2,1.2,5,30,0,5,40,0
1,1,1,1,1,0,25.78,23.51,1.2,5,30,0,5,40,0
1,1,1,1,1,0,26.13,23.55,1.2,5,30,0,5,40,0
1,1,1,1,1,0,26.30,23.57,1.2,5,30,0,5,40,0
1,1,1,1,1,0,26.13,23.70,1.2,5,30,0,5,40,0
1,1,1,1,1,0,27.16,23.65,1.2,5,30,0,5,40,0
1,1,1,1,1,0,26.30,23.57,1.2,5,30,0,5,40,0
1,1,1,1,1,0,26.65,23
As you can see,...several messages in one packet, but not even correct sometimes. I don't really get the problem here, but I somehow suspect that something with the EthernetShield is very wrong, or with the UDP implementation of it.
Anybody got an idea? I really would appreciate help :-/