There is only scant mention of UDP::receivePacket() in the docs. It should have its own sub-section such as parsePacket() does.
I noticed this because of @rickkas7's very useful code snippet that allows UDP reception to continue when Particle Cloud connection is lost or non-existent.
// receivePacket() is preferable to parsePacket()/read() because it saves a buffering step but more importantly
// it returns an error code if an error occurs!
// This is important to reinitialize the listener on error.
@rickkas7, do you know what a return code of -26 means with udp.receivePacket()?
// Thanks to rickkas7
// receivePacket() is preferable to parsePacket()/read() because it saves a buffering step but more importantly
// it returns an error code if an error occurs!
// This is important to reinitialize the listener on error.
count = udp.receivePacket(szBuf, MAX_RX_PACKET_SIZE - 1);
if (count > 0)
{
szBuf[count] = '\0'; // it's an sz string!
}
else
if (count == -1 || count == 0)
{
// No packet
return(EDGE_RELAY_NO_ACTION);
}
else
{
if (debugLevel > 0)
Serial.printlnf("** receivePacket error %d", count);
udp.begin(nPort);
return(EDGE_RELAY_NO_ACTION);
}
Haven't seen this error code before. Am running v0.6.2 firmware.
Your ticket has opened up some clues. Am NOT connecting to the cloud, so perhaps something here… it was working a few hours ago, a bit of code change since then… I will respond back, if and when fixed, for the curious.
Error -26, INVALID_SOCKET, looks to have been caused by configuring the Photon for an external antenna, but not attaching one, giving possibly flakey comms.