[Solved] Electron isn't Accessible After Fully Working for about 5min


#1

Hello Particle Community,

I’m facing an issue right now I can’t find the solution of, which is the Electron not being accessible after about 5min from the point of turning it on. Before this time after being turned on, the Electron is fully working and sending the data to the Android App, but it stops after some time for no obvious reason. Even the status LED is constantly breathing cyan, which should indicate that everything is working properly.

Maybe someone of you can find the issue in my code, which is sending two temperature and humidity readings and a time of a motion detector not being triggered.

Thank you very much!

CODE:

    #include "adafruit-sht31/adafruit-sht31.h"
    #include "math.h"
    
    Adafruit_SHT31 sht31IN = Adafruit_SHT31();
    Adafruit_SHT31 sht31OUT = Adafruit_SHT31();
    
        String sTEMPIN = "";
        String sTEMPOUT = "";
        
        String sHUMIDIN = "";
        String sHUMIDOUT = "";
        
        String sMoveTimeDif = "-";
        
        double dMoveTime = 0;
        double dMoveTimeDif = 0;
        
        double dTEMPIN = 0;
        double dTEMPOUT = 0;
        
        double dHUMIDIN = 0;
        double dHUMIDOUT =0;
        
        int iMove = D3;
        int iMStat = LOW;
    
    
    void setup() {
    
        Particle.variable("TEMPIN", sTEMPIN);
        Particle.variable("TEMPOUT", sTEMPOUT);
        Particle.variable("HUMIDIN", sHUMIDIN);
        Particle.variable("HUMIDOUT", sHUMIDOUT);
        Particle.variable("MOVE", sMoveTimeDif);
        
        pinMode(iMove, INPUT);
        
        sht31IN.begin(0x44);
        sht31OUT.begin(0x45);
      }
    
    void loop() {
       
       
           dTEMPIN = sht31IN.readTemperature();
           dTEMPOUT = sht31OUT.readTemperature();
           
           dHUMIDIN = sht31IN.readHumidity();
           dHUMIDOUT = sht31OUT.readHumidity();
           
           sTEMPIN = String(dTEMPIN).substring(0,4);
           sHUMIDIN = String(dHUMIDIN).substring(0,4);
           sTEMPOUT = String(dTEMPOUT).substring(0,4);
           sHUMIDOUT = String(dHUMIDOUT).substring(0,4);
           
           iMStat = digitalRead(iMove);
           
           if(iMStat == HIGH)
           {
               dMoveTime = Time.now();
               
               iMStat = LOW;
               
            }
            
            dMoveTimeDif = Time.now() - dMoveTime;

           sMoveTimeDif = String(dMoveTimeDif);

           delay(1000);
    }

#2

Are you using a 3rd party sim or the one which came with the Electron?

If it is a 3rd party sim the likely problem is that the connection has been closed by the cell tower. You can use keepAlive() as described here (https://community.particle.io/t/electron-3rd-party-sim-tips/26490) or a simple timed function which makes a publish command after x seconds. This will keep the connection active and your variables will update on your app.

Even if the connection has been lost the Electron still breathes cyan as it doesn’t know the connection has been lost.


#3

Yes I am using a 3rd party sim and I didn’t think that this would be an issue.

Thanks a lot!


#5

In addition to the excellent advice you got above about keepAlive() for third-party SIMs, you also need to have the magic setup lines like these for ATT (they will be different for each carrier):

#include "cellular_hal.h"
STARTUP(cellular_credentials_set("broadband", "", "", NULL));

#6

The 5min accessibility (or what I understood with the above) suggests that’s there already, although I can’t see it in the code either.