Particle Photon Stops Working randomly


#1

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: https://community.particle.io/t/stack-size-heap-size-and-system-freememory/29361
        lightlevel = analogRead(photoResistor);
        temperature = dht.getTempCelcius();
        humidity = dht.getHumidity();
        magnetsensor = digitalRead(DOOR_SENSOR);
        if (counter > 1 && free_memory < 15000) {
            System.reset();
        }
        if (counter > 600) {
            //start a system reset every ~10 minutes see here: https://docs.particle.io/reference/firmware/photon/#reset--2
            System.reset();
        }
        if (client.isConnected()) {
            client.loop();
            client.publish("photon1topicout", "{\"counter\":\"" + String(counter)+ "\", \"memory\":\"" + String(free_memory) + + "\", \"light\":\"" + String(lightlevel) + "\", \"temp\":\"" + String(temperature) + "\", \"humi\":\"" + String(humidity) + "\", \"door\":\"" + String(magnetsensor)  +  "\"}");
        }
        else {
            client.connect("client");
            client.subscribe("topic");
        }
        delay(1000);
        counter = counter +1;
    }

#2

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…
Nathan