Boron blinks red on 2.0.0-rc.1

Upgraded my Boron LTE to 2.0.0-rc.1.

Now anytime I call the function 'Particle.function("SES", setEmail); or Particle.function("SPS", setPhone);from the code belowthe Boron flashes red and reboots.

Any idea why EEPROM.put causes this ?

#include <PublishQueueAsyncRK.h>

#define DELAY_BEFORE_REBOOT (3 * 1000)


SYSTEM_THREAD(ENABLED);

retained uint8_t publishQueueRetainedBuffer[2048];
PublishQueueAsync publishQueue(publishQueueRetainedBuffer, sizeof(publishQueueRetainedBuffer));

int pin = D4;
int led1 = D7;
int sensorStatus;
int powerStatus =1;

int setPhoneEEPROMLocation = 1;
int setEmailEEPROMLocation = 100;
int setAlertEEPROMLocation = 200;

int setAlertEmailPowerEEPROMLocation = 500;
int setAlertEmailSensorEEPROMLocation = 600;

int setAlertPhonePowerEEPROMLocation = 700;
int setAlertPhoneSensorEEPROMLocation = 800;

char dev_name[40];
char phone_str[40] = "Not Set";
char email_str[40] = "Not Set";
char alertPowerSms[256] = "0";
char alertPowerEmail[256] = "0";
char alertSensorEmail[256] = "0";
char alertSensorSms[256] = "0";



char alert[10];

int A = 0;
int PS = 0;
int ES = 0;
int PP = 0;
int EP= 0;

double voltage;
double power;
double charging;

unsigned int rebootDelayMillis = DELAY_BEFORE_REBOOT;
unsigned long rebootSync = millis();

bool resetFlag = false;

int SG;
double batterySoc = System.batteryCharge();
int powerSource = System.powerSource();


void setup()
{

    Particle.variable("S", sensorStatus);
    Particle.variable("SPS", phone_str);
    Particle.variable("SES", email_str);

    Particle.function("SES", setEmail);
    Particle.function("SPS", setPhone);
    Particle.function("EA", enableAlerts);
    Particle.function("EP", enableEmailPowerAlerts);
    Particle.function("ES", enableEmailSensorAlerts);
    Particle.function("PP", enablePhonePowerAlerts);
    Particle.function("PS", enablePhoneSensorAlerts);
    Particle.variable("A", A);
    Particle.variable("EP", EP);
    Particle.variable("ES", ES);
    Particle.variable("PP", PP);
    Particle.variable("PS", PS);
    Particle.variable("SG", SG);
    Particle.variable("BAT", batterySoc);
    Particle.variable("PWR", powerSource);
    Particle.function("RT", cloudResetFunction);
    
    getStoredInfo();

    pinMode(pin, INPUT_PULLUP);
    pinMode(led1, OUTPUT);

    
    if (digitalRead(pin) == LOW)
    {

        digitalWrite(led1, LOW);
    }
    else {
        
        digitalWrite(led1, HIGH);
    }

    Particle.subscribe("particle/device/name", handler);
    waitFor(Particle.connected, 600000);
    Particle.publish("particle/device/name");
    
}

void loop()
{   
     batterySoc = System.batteryCharge();
     powerSource = System.powerSource();
    

    if (powerSource == 5)
    {

        if (powerStatus != 0)
        {

            if ((A == 1) && (PP == 1))
            {
               snprintf(alertPowerSms, sizeof(alertPowerSms)  , "{\"N\": \"%s\", \"T\": \"%s\"}"   , dev_name , phone_str  );
               publishQueue.publish("test1", alertPowerSms, 60, PRIVATE);
            }

            if ((A == 1) && (EP == 1))
            {

                snprintf(alertPowerEmail, sizeof(alertPowerEmail)  , "{\"N\": \"%s\", \"T\": \"%s\"}"   , dev_name , email_str  );
                publishQueue.publish("test2", alertPowerEmail, 60, PRIVATE);
            }

            powerStatus = 0;
        }
    }
    else if (powerSource < 5)
    {

        if (powerStatus != 1)
        {

         if ((A == 1) && (PP ==1)){
		snprintf(alertPowerSms, sizeof(alertPowerSms)  , "{\"N\": \"%s\", \"T\": \"%s\"}"   , dev_name , phone_str  );
        publishQueue.publish("test3", alertPowerSms, 60, PRIVATE);
     
      }
      
      if ((A == 1) && (EP ==1)) {
		snprintf(alertPowerEmail, sizeof(alertPowerEmail)  , "{\"N\": \"%s\", \"T\": \"%s\"}"   , dev_name , email_str  );
        publishQueue.publish("test4", alertPowerEmail, 60, PRIVATE);
      }
            powerStatus = 1;
        }
    }

    if (digitalRead(pin) == HIGH)
    {

        if (sensorStatus != 0)
        {

            digitalWrite(led1, HIGH);


            if ((A == 1) && (PS == 1))
            {
                 snprintf(alertSensorSms, sizeof(alertSensorSms)  , "{\"N\": \"%s\", \"T\": \"%s\"}"   , dev_name , phone_str  );
                publishQueue.publish("test5", alertSensorSms, 60, PRIVATE);
            }

            if ((A == 1) && (ES == 1))
            {
                snprintf(alertSensorEmail, sizeof(alertSensorEmail)  , "{\"N\": \"%s\", \"T\": \"%s\"}"   , dev_name , email_str  );
                publishQueue.publish("test6", alertSensorEmail, 60, PRIVATE);
            }

            sensorStatus = 0;
        }
    }
    else if (digitalRead(pin) == LOW)
    {

        if (sensorStatus != 1)
        {
            digitalWrite(led1, LOW);
            sensorStatus = 1;
        }
    }

    if ((resetFlag) && (millis() - rebootSync >= rebootDelayMillis))
    {

        delay(1000);
        System.reset();
    }

    if ((PP == 0) && (EP == 0) && (PS == 0) && (ES == 0))

    {
        enableAlerts("0");
    }
    
       if ((PP == 1) | (EP == 1) | (PS== 1) | (ES == 1))
    
    {
        enableAlerts("1");
    }
}

int enableAlerts(String command)
{

    if (command.equalsIgnoreCase("1"))
    {
        A = 1;
        EEPROM.put(setAlertEEPROMLocation, A);
        return 1;
    }
    else
    {

        A = 0;
        EEPROM.put(setAlertEEPROMLocation, A);
        return 0;
    }
}

int enableEmailPowerAlerts(String command)
{

    if (command.equalsIgnoreCase("1"))
    {
        EP = 1;
        EEPROM.put(setAlertEmailPowerEEPROMLocation, EP);
        return 1;
    }
    else
    {

        EP = 0;
        EEPROM.put(setAlertEmailPowerEEPROMLocation, EP);
        return 0;
    }
}

int enableEmailSensorAlerts(String command)
{

    if (command.equalsIgnoreCase("1"))
    {
        ES = 1;
        EEPROM.put(setAlertEmailSensorEEPROMLocation, ES);
        return 1;
    }
    else
    {
        ES = 0;
        EEPROM.put(setAlertEmailSensorEEPROMLocation, ES);
        return 0;
    }
}

int enablePhonePowerAlerts(String command)
{

    if (command.equalsIgnoreCase("1"))
    {
        PP = 1;
        EEPROM.put(setAlertPhonePowerEEPROMLocation, PP);
        return 1;
    }
    else
    {

        PP = 0;
        EEPROM.put(setAlertPhonePowerEEPROMLocation, PP);
        return 0;
    }
}

int enablePhoneSensorAlerts(String command)
{

    if (command.equalsIgnoreCase("1"))
    {
        PS = 1;
        EEPROM.put(setAlertPhoneSensorEEPROMLocation, PS);
        return 1;
    }
    else
    {

        PS = 0;
        EEPROM.put(setAlertPhoneSensorEEPROMLocation, PS);
        return 0;
    }
}

int setPhone(const char *data)
{

    strncpy(phone_str, data, sizeof(phone_str) - 1);
    phone_str[sizeof(phone_str) - 1] = '\0';
    EEPROM.put(setPhoneEEPROMLocation, phone_str);
}

int setEmail(const char *data)
{
    strncpy(email_str, data, sizeof(email_str) - 1);
    email_str[sizeof(email_str) - 1] = '\0';
    EEPROM.put(setEmailEEPROMLocation, email_str);
}

void getStoredInfo()
{
    EEPROM.get(setPhoneEEPROMLocation, phone_str);
    EEPROM.get(setEmailEEPROMLocation,   email_str );
    EEPROM.get(setAlertEEPROMLocation, A);
    EEPROM.get(setAlertEmailSensorEEPROMLocation, ES);
    EEPROM.get(setAlertEmailPowerEEPROMLocation, EP);
    EEPROM.get(setAlertPhoneSensorEEPROMLocation, PS);
    EEPROM.get(setAlertPhonePowerEEPROMLocation, PP);

}

void handler(const char *topic, const char *data)
{
    strncpy(dev_name, data, sizeof(dev_name) - 1);
   
}

int cloudResetFunction(String command)
{
    resetFlag = true;
    rebootSync = millis();
    return 0;
}

void system_display_rssi()
{

    int rssi = 0;

#if Wiring_WiFi == 1
    rssi = WiFi.RSSI();
#elif Wiring_Cellular == 1
    CellularSignal sig = Cellular.RSSI();
    rssi = sig.getStrength();
#endif
    if (rssi < 0)
    {
        if (rssi >= -57)
        {
            SG = 5;
        }
        else if (rssi > -68)
        {
            SG = 4;
        }
        else if (rssi > -80)
        {
            SG = 3;
        }
        else if (rssi > -92)
        {
            SG = 2;
        }
        else if (rssi > -104)
        {
            SG = 1;
        }
    }

    if (rssi >= 0)
    {
        if (rssi >= 60)
        {
            SG = 5;
        }
        else if (rssi > 40)
        {
            SG = 4;
        }
        else if (rssi > 20)
        {
            SG = 3;
        }
        else if (rssi > 1)
        {
            SG = 2;
        }
        else if (rssi >= 0)
        {
            SG = 1;
        }
    }
}

Any reason why this code doesn’t work on 2.0.0-rc.1.

If you encounter unexpected behaviour it’s always advisable to first search for possible causes and remove any distracting factors before having others look at a load of code that most likely hasn’t got anything to do with the problem at hand.

Try to reproduce the problem with the simplest possible test code that makes it easy for community members to test without the need for all sorts of extra setup (libraries, hardware, …).
Also when seeing red flashes always describe what kind of flashes that are (e.g. SOS + x slow blinks) or provide a video with enough time before and after the incident.

Just for the sake of testing (as it normally shouldn’t matter) try to keep your Particle.function() names distinct from Particle.variable() names to see whether this contributes to a possible bug.

To hone in on the possible cause you may also want to remove the EEPROM.put() call from the function to see whether this causes the reset.

Finally what may actually cause the crash is the fact that your functions are not doing what they are expected to do.
They are supposed to return an int but your code does not feature a return statement that does that.

Try this

int setPhone(const char *data)
{
    strncpy(phone_str, data, sizeof(phone_str) - 1);
    phone_str[sizeof(phone_str) - 1] = '\0';
    EEPROM.put(setPhoneEEPROMLocation, phone_str);

    return strlen(phone_str);
}
1 Like

Sorry I didn’t have a chance to confirm this until now but you are correct I was missing the return statement. It worked on the older firmware so I assumed it make have been something with the update.
As always thanks for your help @ScruffR

1 Like