Particle Photon Stops Working randomly

Hi All,

i have a problem with my photon, it stops working suddenly and I can’t figure out why.

So I have an AWS IoT Server set up and I am reading data from a magnet sensor, a DHT and a light sensor to the IoT Gateway over TLS. This all works fine but sometimes the photon just stops. It’s still on, I can press the reset button then it boots up again and restarts sending. But I don’t want it to end suddenly because I won’t notice and loose data.

At the moment I am checking the free memory and forcing a restart if it is under 15.000, also I have a counter running so after 10min it will restart automatically. I found out, that it stopped working when the memory was under 15.000 for 3 times in a row so I thought this was the problem, but there seems to be another issue.

But it still runs into a breakdown and I can’t figure out why.
Anyone has an idea? Can I add some diagnostics variables that would show me why it is failing? And is there another way how I can implement an automatic restart that is not bypassed?

here’s my code:

    void loop() {
        free_memory = System.freeMemory(); //get the free memory of the system, see here:
        lightlevel = analogRead(photoResistor);
        temperature = dht.getTempCelcius();
        humidity = dht.getHumidity();
        magnetsensor = digitalRead(DOOR_SENSOR);
        if (counter > 1 && free_memory < 15000) {
        if (counter > 600) {
            //start a system reset every ~10 minutes see here:
        if (client.isConnected()) {
            client.publish("photon1topicout", "{\"counter\":\"" + String(counter)+ "\", \"memory\":\"" + String(free_memory) + + "\", \"light\":\"" + String(lightlevel) + "\", \"temp\":\"" + String(temperature) + "\", \"humi\":\"" + String(humidity) + "\", \"door\":\"" + String(magnetsensor)  +  "\"}");
        else {
        counter = counter +1;

I too am having issues with a photon locking up at seemingly random times, though it looks as though you have gotten a bit further than myself with attempting to diagnose the issue…

I am going to go and add some of those variables to my code now to see if memory might be a factor in my issue, but I’m not very optomistic of that being the issue since the last lockup for me was at 1:45am and nothing in particular should have been happening, at least nothing that hadn’t already been happening every 3-5 seconds for the previous day…

Could it be that you are publishing too much data too fast to the Particle console ?
According to the documents “Currently, a device can publish at rate of about 1 event/sec, with bursts of up to 4 allowed in 1 second. Back to back burst of 4 messages will take 4 seconds to recover.”.