UDP::receivePacket() not documented well

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.

2 Likes

It seems to be used internally in the UDP class since it’s implementation 2 years ago. I don’t see the equivalent in ArduinoLand though…

Definitely useful to have it documented!

3 Likes

@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.

All help appreciated!

Cheers - @umd.

2 Likes

@timx, excellent response.

Now understand that -26 is INVALID_SOCKET.

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.

@timx,

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.

Case closed!

1 Like