[Solved/Workaround] Spark Core can't send UDP broadcast packets without cloud connection

OK here’s an even better work-around.

if (once == true) {
    WiFi.ping(WiFi.gatewayIP());
    //Start UDP
    udp.begin(listenPort);
    once = false;

This also allows me to broadcast to 255.255.255.255.

3 Likes

Yes, that's neat. Is there anyway we can get that ping included automatically in WiFi.connect()? Then the issue goes away, for everyone, except possibly those doing SSDP over UDP. @benwis ?

2 Likes

Adding WiFi.ping(WiFi.gatewayIP()); before UDP.begin(); causes everything to work as expected.
Now I’ve just got to pull the Location IP from UDP receive, and send a POST packet with the necessary JSON information.

Thanks @bko @ psb777 @laml. I guess I’ll mark this as solved, with the note that it’s a workaround and definitely not fixed.

2 Likes

Hi,

@bko
I’ve been struggling to get this solution to work for me, until I realised that the ping replies were not getting back to the Core (i.e. it was sending to the network, but signal was not good enough for the core to get replies).

Net result is that something like the following may be more reliable:

if (once == true) {
    if(!WiFi.ping(WiFi.gatewayIP()))
        return; //assuming in loop()
    //Start UDP
    udp.begin(listenPort);
    once = false;
}

Thanks for all the hard work to resolve it!

Hi @wmcelderry

If you can’t ping the default gateway, things are not going to go well with any network activity.

Hi @bko

Yep, it’s not a good sign, but it depends on failure modes that can be tolerated.

In my case, putting in the while loop makes it broadcast reliably after the initial set up. Also my application is all about the local network instead of the Internet, so communicating with the gateway can be flaky and it doesn’t matter to me.

To be clear my issue is not a flaky gateway - it is a Core at the limit of it’s reception from the router, but the router can receive packets from the core more easily it seems - and that’s the way round I happen to want it to work, the core broadcasting to the network. This is also the Dev environment, for others it may not be the deployment environment (for me it is).

I’ve been going nuts trying to understand where my code has been ‘going wrong’ as I’ve had this intermittent fault that has happened to co-occur with certain tests that made no sense. I ended up removing all #defines and the code would appear to run flawlessly with the ping work around, but with the #defs it would not work at all - even though a diff of the bins showed them identical!

Now I know this is pure chance as I can get both to work reliably. I’d love to know the chances of the evidence I collected happening by accident…
Experience tells me the probability of this type of issue occurring is higher than logic tells me it should be, and I reckon that will be a familiar story to many other coders.

All in all, the while loop helped me a lot. I thought I’d mention it in case it helps others…

Thanks again!

W.

1 Like

@benwis At the end - did you manage to discover ActionCam using SSDP and find out it’s IP address to access camera API? Would you mind sharing your code how did finally achieved that? It would be very helpful. Thank you.