Electron stopped connecting to the Internet

HI,

We have two electrons we have been using to create a prototype. The code and the devices worked 3 days ago, I changed one line and they would nt connect last night. I reverted the line and it still did not work.

Any ideas?
One is running 0.7.0 and the other is running 0.6.0

Could you show us the code?
Could you ave blown through your data limit?

The normal sequence on the status LED is: white, blinking green, blinking cyan (light blue), fast blinking cyan, and finally breathing cyan.

How far along the process do you get? And if you get to fast blinking cyan, are there any red or orange blinks before going back to blinking green or blinking cyan?

2 Likes
// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_GPS.h>

// This #include statement was automatically added by the Particle IDE.
#include <AssetTracker.h>


#include <math.h>


AssetTracker t = AssetTracker();

// default interval time
int delayMinutes = 1;
// Used to keep track of the last time we published data
long lastPublish = 0;

float gpsPrevLat;
float gpsPrevLon;

int decimal = 100000;

bool isMoving = false;

int count=0;

//Device number
const char did[9] = "58965412";

void setup() {
    // Sets up all the necessary AssetTracker bits
    t.begin();

    // Enable the GPS module. Defaults to off to save power.
    // Takes 1.5s or so because of delays.
    t.gpsOn();
    
    gpsPrevLon = 0.0f;
    gpsPrevLat = 0.0f;
    
    // Opens up a Serial port so you can listen over USB
    Serial.begin(9600);

    Particle.function("gps", gpsPublish);
}

void loop() {
    // You'll need to run this every loop to capture the GPS output
    t.updateGPS();
    
    // if the current time - the last time we published is greater than your set delay...
    if (millis()-lastPublish > delayMinutes*60*1000) {
        // Remember when we published
        lastPublish = millis();
        
         if (t.gpsFix()) {
            float gpsCurrLat = roundf(t.readLatDeg() * decimal)/decimal;
            float gpsCurrLon = roundf(t.readLonDeg() * decimal)/decimal;
            
            //calculate if gps coordinates have changed
            bool moved = hasMoved(gpsPrevLat, gpsPrevLon, gpsCurrLat, gpsCurrLon);
            
            if (isMoving) {
                //is in the moving state
                if (moved) {
                    //reset count for checking (at least 3 times)
                    count = 0;
                    sendData (1,gpsCurrLat, gpsCurrLon);
                } else {
                    //stopped moving for 3 periods
                    count++;
                    if (count == 3){
                        sendData (0,gpsCurrLat, gpsCurrLon);
                        isMoving = false;
                        delayMinutes = 20;
                    }
                }
            } else {
                //in the non moving state
                if(moved) {
                    isMoving = true;
                    delayMinutes = 5;
                    count = 0;
                }
                
            }
            
         }     
    }         

}

bool hasMoved(float gpsPrevLat, float gpsPrevLon, float gpsCurrLat, float gpsCurrLon){
    
    float latDiff = fabsf(gpsPrevLat - gpsCurrLat);
    float lonDiff = fabsf(gpsPrevLon - gpsCurrLon);
    
    Particle.publish("LaD", String(latDiff), 60, PRIVATE);
    Particle.publish("LoD", String(lonDiff), 60, PRIVATE);
    
    if(latDiff > .001f || lonDiff > .001f){
        return true;
    }else{
        return false;
    }
    
}

// Actively ask for a GPS reading if you're impatient. Only publishes if there's
// a GPS fix, otherwise returns '0'
int gpsPublish(String command) {
    if (t.gpsFix()) {
        Particle.publish("GPS", t.readLatLon(), 60, PRIVATE);

        return 1;
    } else {
      return 0;
    }
}


void sendData(int moveTag, float gpsCurrLat, float gpsCurrLon){
    //variable to hold JSON data
    char data[200];
    
    sprintf(data, "{\"did\": %s, \"gpsLat\": %e, \"gpsLon\": %e, \"isMoving\" : %d}",did,gpsCurrLat,gpsCurrLon,moveTag);
    //cloud integration
    
    //Particle.publish("update_device_info", data, PRIVATE);
    
    // Short publish names save data!
    Particle.publish("Data", data, 60, PRIVATE);
    //try webhook and check if it worked
    //Particle.publish("update_gps",data, 60, PRIVATE);
                
    gpsPrevLat = gpsCurrLat;
    gpsPrevLon = gpsCurrLon;
    memset(data, 0, sizeof data);
    
}

I only get to the blinking green. Both have been updated to 0.7.0 although the console keeps telling me one is 0.6.0 (i updated localling through CLI and then double checked using the firmware manager)

See above

“This can be caused by the currently running application firmware which may interfere with the cloud maintenance tasks which are usually executed between iterations of loop() or via an explicit call of Particle.process(). That commonly happens when the code blocks for more than 10 seconds. In addition to regularly allowing for cloud maintenance (via dropping out of loop() and/or calling Particle.process()) you can take manual control of the connection, choose a better suited SYSTEM_MODE and/or opt for SYSTEM_THREAD(ENABLED). To correct the “offending” firmware you may need to flash new firmware either via USB or Safe Mode.”

I just saw this in the guide which seems like it may apply as I am doing intervals of more than 10 sec. However I do not understand how to implement it

If you’re not getting past blinking green it’s almost certainly not your code. The modem can’t connect to the cellular network.

Are you using a 3rd-party SIM card? If so, make sure the APN is still set correctly.

If you are using the Particle SIM card, make sure it’s still activated in the console and wasn’t paused.

If it looks OK there, create a support ticket and include the ICCID and device ID of your Electron.

No 3rd party, it is a particle sim card. Just checked and both are still active in the console. Will create the support ticket now. I thought it may have been something in my code that was stopping it from connecting.

Thanks,
Britney