[SOLVED] Particle publish oddities

I’m trying to pin down the root cause of an issue I seem to have with the Electron when there is no signal (flashing green)
With a good signal present my code runs fine (on photons and electrons), I’m using
SYSTEM_THREAD(ENABLED);
SYSTEM_MODE(AUTOMATIC);
Firmware 0.7 and I always check Particle.connected before a publish.

However with the electron unlike the highly detailed post here from @rickkas7 the Particle.connected check seems not to work, sending values to my publish routine causes loop to stop running for an extended period until I get this [system] WARN: Resetting WLAN due to WLAN_WD_TO()

If I add a cellular ready check as well like this:

void SendyMcSenderson(){  
Log.info("Before Connectivity check");
        char Status[255];

        snprintf(Status,sizeof(Status), dooberywhatsitsgoinhere);

        if (Cellular.ready() && Particle.connected)
        {
          Log.info("Send Values - Particle.connected");
                Particle.publish("PAT",Status,PRIVATE);
              
        }
        else Log.info("We were not connected");
}

That works.
if I add a little check in the the else bit

  snprintf(response,sizeof(response),"Connected : %s, Not Sent",Particle.connected() ? "True":"False");
                Log.info(response);

That returns connected as false as expected, given how basic a problem this is I can’t help but feel its something truly dumb, however if there was some blocking code in my app then when a signal is present or I set Cellular.off it would also manifest itself… and it doesn’t.

I believe that should be Particle.connected(). You want to know if the function connected() returns true. Since you're missing the () its testing whether the function pointer is not null, which is always true.

1 Like

Dammit, it had to be simple how did that slip past me? I’ve certainly used it correctly elsewhere!
Thanks!

Out of curiosity is there any purpose to the function pointer being readable by user code?

1 Like

That's a standard C behaviour.
For example if you have a function pointer (e.g. a callback routine as parameter for a function) you'd be checking the pointer whether it's actually set before you call the function.

So yes, there is a purpose for being able to "read" the function pointer. If you wouldn't you couldn't call the function either.