Mysterious events published by Photon

Hi all,

after updating two of my Photons to 0.4.6 one of them publishes mysterious events …

event: 0
data: {"data":"undefined","ttl":"60","published_at":"2015-10-05T18:37:33.598Z","coreid":"25002c000447343339373536"}
event: 1
data: {"data":"undefined","ttl":"60","published_at":"2015-10-05T18:37:33.759Z","coreid":"25002c000447343339373536"}
event: 1
data: {"data":"undefined","ttl":"60","published_at":"2015-10-05T18:37:33.919Z","coreid":"25002c000447343339373536"}

The event number chances sometimes to 2,6 or 14, 174 (looks random) but most of the time it is 0 or 1.

My application has not changed, only the firmware was updated. The app publishes one event every 60 seconds, which works fine. The mysterious events are published ~3 seconds after my app event shows up in the stream, but not every time.

Any idea what is going on here?

Thx.
Markus

1 Like

Well that sounds weird. Looking into it now.

Hmm, not able to immediately reproduce this issue, can you provide any other details? Does it happen while your photon is running tinker? Are you publishing using a mutable string pointer anywhere in your app / can you share the code?

Thanks,
David

@Dave I believe they are related to an SOS crash of my application.

See my post here: TCPClient unstable in 0.4.6

The code can be found here: https://github.com/mhaack/Particle-Photon-Apps/tree/master/plant-monitor

If I comment out line 122 in plant-monitor.ino the application does not crash any more the the mysterious events are gone as well.

Markus

1 Like

Hi @mhdevx

I had a look at your code here:

        int postToParticle() {
          char publishString[128];
          sprintf(publishString,"{\"status\": %d, \"temp\": %0.2f, \"pressure\": %0.2f, \"humidity\": %0.2f, \"soil1\": %u, \"soil2\": %u, \"soil3\": %u}",
            currentSensorStatus, temperature, pressure, humidity, soil1, soil2, soil3);
          Particle.publish("sensor",publishString);
          return 1;
        }

So you are using a stack allocated char array for the publish data. I think if you move the char publishString[128]; declaration to global context, that is above setup(), it will work better.

There can be a time lag between when a publish is queue for sending and when it is sent and if the char array is deallocated and that memory reused, you could easily get the confusing results you are seeing. With the char array in global memory (not stack) there is no danger of the string getting overwritten.

Can you try moving that declaration?

2 Likes

This might also be a case where this open issue might bring a solution
https://github.com/spark/firmware/issues/659

When this gets implemented as proposed a call to Particle.process(); would ensure that the event is completely published before the variable gets “invalidated”.

Hi @bko

I belive the mysterious events are more related to the SOS crash (see TCPClient unstable in 0.4.6). After taking SparkFun Phant library and whit that the TCPClient out the application does not crash any more and the mysterious events are gone.
The Particle.publish("sensor",publishString); event was correctly fired all the time.

Nevertheless I changed the code and moved char publishString[128]; declaration to global scope. Think that is more memory efficient anyway since it does not allocate new memory with every method call. Right?

Markus

1 Like