Particle Electron: 1 year of temperature monitor data

I want to monitor temperature in a rural area for a year (each 60 seconds of publishing data). , But I want a reliable and stable connection with no many drops. I am using a 3rd party SIM and somebody recommend me to put “Particle.keepAlive(120)” in void setup. Is there another reliable method ? Watchdog timer?
P.S I am using millis() counter to send data each 60 seconds to ThingSpeak/Losant platform. Eg. millis() - lastPublish >= PUBLISH_RATE

Not sure what you mean with that?
What troubles are you experiencing?
Particle.keepAlive() is a prerequisite when using 3rd party SIMs but doesn't really change the reliability of the connection.
Watchdogs are usually last resorts to prevent the code from hanging, they don't increase reliability either.

If you have connection problems you may need to buffer your data with timestamps and decouple the reading and publishing from eachother.
Software Timers are one way to go for that, but millis() - lastPublish >= PUBLISH_RATE is another acceptable way.

BTW, your last edit has messed up the original post, can you correct that?

1 Like
#define publish_cycle 30000 
unsigned int lastPublish = 0;

int led = D7;
double reading = 0.0;
double mvolts = 0.0;
double tempC = 0.0;
double tempF = 0.0;
boolean flag = false;

double readingl=0.0;

void setup() {
    pinMode(led,OUTPUT);
    Particle.keepAlive(120);
    Particle.function("led", ledStatus);

}

void loop() {
    unsigned long now = millis();
    reading = analogRead(A0);
    mvolts = (reading * 3300.0)/4095.0;
    mvolts = mvolts -500.0;
    tempC = mvolts/10.0;
    tempF = (tempC*1.8) + 32.0;
    readingl = analogRead(A1);
    
   //to IFTTT
    if ( tempC > 26.0 && flag == false){
    Particle.publish("toohot");
    flag = true;
    }
    if (tempC < 24.0 && flag == true){
    Particle.publish("tempnormal");
    flag = false;
    }

    
    if ((now - lastPublish) > publish_cycle) {
    //to LOSANT
    Particle.publish("temp-reading", String(tempC), PRIVATE) ;
    Particle.publish("light-intensity",String(readingl), PRIVATE) ;
    delay(500);
    //to ThingSpeak
    Particle.publish("temperature", "{ \"1\": \"" + String(tempC) + "\"," + "\"2\": \"" + String(readingl) + "\"}", PRIVATE);
    lastPublish = now;
    }
    

}

int ledStatus(String command){
    if(command.equalsIgnoreCase("on")){
        digitalWrite(led,HIGH);
        return 1;
    }
    else if (command.equalsIgnoreCase("off")){
        digitalWrite(led,LOW);
        return 0;
    }
    else{
        return -1;
    }
    
}

I see you want to continue the discussion in the other thread.
Is this the reason for not answering any of the questions I asked?

I did not understand “you may need to buffer your data with timestamps and decouple the reading and publishing from eachother.”, please explain me with my code.

Maybe you first answer these

I can't see what issues you are having or anticipating.

BTW, since you are not using a 3rd party SIM Particle.keepAlive() is not the way to go with the Particle SIM.

The troubles I am experiencing is so many drops eg. 1 drop per minute.

The other trouble is if I can take a stable connection publishing 3 different events with no delays between them.

and yes I am using 3rd party SIM thats the reason I am using Particle.keepAlive(120)

You are not setting the APN for the 3rd party SIM in your code.
And have you confirmed that 120 is the correct parameter for your provider? It might be less than 120s maybe 30s or even down to 5s.

1 Like

Thanks I will check if 120 is the correct parameter for my provider. =)