Red status LED 'SOS' hard fault

I’ll keep it short. I bought a Xenon, Argon and a temperature Sensor.

Coding the Xenon:

I accessed the temperaturevalue via Particle.function and Particle.variable with an empty loop and everything worked perfectly.
I did some changes to the code so the Argon could subscribe to the value.
Now the Xenon is dead.
I don’t want to kill another Xenon, it would help me alot if some smart talented guy could tell me where the small mistake is.

SYSTEM_THREAD(ENABLED);
/*SYSTEM_MODE(MANUAL)*/ //buggy

#include "math.h"
#include "stdio.h"

#define LM75_ADDRESS 0x48 
#define LM75_TEMPERATURE 0x00
#define LM75_CONFIGURATION 0x01
#define LM75_Tos_SET_POINT 0x02
#define LM75_Thyst_SET_POINT 0x03

int led1 = D7;

uint16_t test = 0b1000000000000001;
double TemperatureValue = test;
char buffer[100];

void setup() {
pinMode(led1, OUTPUT);
//Particle.function("ReadTemperature", ReadTemperature);
//Particle.variable("Temperatur", TemperatureValue);
Wire.begin();
}

void loop() {
    float temp = ReadTemperature();
    snprintf(buffer, sizeof(buffer), "Temp is %f", temp);
    Particle.publish("temp", buffer);
    delay(5000);
}

float ReadTemperature(){
    Wire.beginTransmission(LM75_ADDRESS);
    Wire.write(LM75_TEMPERATURE);
    Wire.endTransmission();
    
    uint16_t val = 0;
    uint16_t val2 = 0;
        
    Wire.requestFrom(LM75_ADDRESS, 2);
    val = Wire.read();
    val <<= 1;
    val2 = Wire.read();
    val2 >>= 7;
    val = val|val2;

    TemperatureValue = val/2;
    return TemperatureValue;
}

How did your Xenon connect to the cloud without a gateway?
How would any changes on the Argon contribute to the “death” of your Xenon?

But one thing smells here :wink:
You have a Particle.publish() (which you should actually limit the scope to PRIVATE) which may be executed before you have a valid cloud connection (due to SYSTEM_THREAD(ENABLED)).
When you wrap that publish with an if (Particle.connected()) check then at least this problem should go away.

BTW, why would you consider SYSTEM_MODE(MANUAL) buggy?

Okay, I limited the scope of Particle.publish to private. I did not know “SYSTEM_THREAD(ENABLED)” does this.
Your solution is very helpful, thanks for your comment.
I will remember you helped me on this ScruffR.

1 Like

Did this solve your problem?

With this your code will start running immediately independent of the connection status.
https://docs.particle.io/reference/device-os/firmware/xenon/#system-threading-behavior

I am too scared to test the changed code on another device, I don’t want to break 2 of them.
I will test it when I know the “exact” reason with the changes you suggested. Then I will inform you about it ScruffR.

Thanks ScruffR, I will read the page you sent me.

How do you know this? What temperature sensor did you use?

I cannot access another mode except dfu.
I tried flashing a user Firmware onto the Xenon like it is explained in this infopage:
https://docs.particle.io/tutorials/device-os/led/argon/#firmware-reset

I used the temperature sensor lm75 with I2C interface

So put the device into DFU - Flashing Yellow.

Then from the CLI enter
particle update

This should restore the OS, then back to DFU mode and enter
particle flash --usb tinker

let it restart and you should have flashing green - or if it is part of a mesh and the gateway is active and connected, it will shortly then transition to breathing cyan.

Let us know what happens

This also the link for restoring an ARGON not the XENON you speak about ?

I did execute the steps you suggested and it worked, the Xenon is now functionally again.
After execution the Xenon was in listening mode.
I let him join the mesh network and it worked.

This should be posted on the infopage as general solution.