Particle stops working more frequently. Rebooting fixes problem

I’ve been running a particle to take readings from my water meter (using a magnetometer) and a Google sheet to collect the readings every 5 minutes. The process has been running for about 8 months but lately, the particle has been shutting down until I go pull the plug for 10 seconds and reconnect. It works fine until the next time. That interval has been getting shorter and shorter. Currently it stops about every three days. Didn’t see any articles covering this topic. Any suggestions?

First, what device are you using; Photon, Electron, or Core? What do you mean by, “it stops”? What colors and flash pattern is the LED giving you? It would help to see your code.


It is a Photon and it is currently working (it is slowly blinking cyan). I didn’t note the result after it stopped working. It should stop soon so I can check it then. The magnetometer uses I2C to communicate with the Photon but since it is located about 60 feet from the Proton, an extender is used to communicate over CAT5 cable. The project is described in much more detail at When it stops working, the Google sheet is just recording zero quantities. I’m new to this stuff but given datasheets and a few examples, I can get by but my trouble shooting skills are pretty weak. The Photon code is as follows:

#define hmc5883l_address 0x1E
#define publish_delay 300000


unsigned long last_publish = 0;
unsigned long now = 0;
unsigned int crossings = 0;

int new_val = 0;
int old_val = 0;

boolean changed = false;

char resultstr[64];

int16_t x;
int16_t z;
int16_t y;

void setup() {
    // expose your char buffer to the Cloud API
    Particle.variable("result", resultstr, STRING); 
    // set up the HMC5883L
    Wire.write(0x00); // Select Configuration Register A
    Wire.write(0x38); // 2 Averaged Samples at 75Hz

    Wire.write(0x01); // Select Configuration Register B
    Wire.write(0x20); // Set Default Gain

    Wire.write(0x02); // Select Mode Register
    Wire.write(0x00); // Continuous Measurement Mode

void loop() {
    now = millis();
    Wire.write(0x03); // Select register 3, X MSB Register
    Wire.requestFrom(hmc5883l_address, 6); delay(4);
    if(Wire.available() >= 6) {;;;; 
        y = << 8;  // Y MSB
        y |=;      // Y LSB

    old_val = new_val;
    new_val = map(y, 0, 300, -150, 150);
    changed = (old_val < 0 && new_val > 0) || (old_val > 0 && new_val < 0);
    if(changed) {
        crossings ++;

    if((now - last_publish) >= publish_delay)  {
       // format your data as JSON, don't forget to escape the double quotes
       sprintf(resultstr, "{\"crossings\" :%d}", crossings);
       // publish to Particle dashboard
       String stringY =  String((crossings), DEC);  
       Particle.publish("Readings ", stringY, 60, PRIVATE);
       crossings = 0;
       last_publish = now;

It stopped working again. The Photon was slowing blinking cyan in that state. Unplugging and plugging it back in brought it back.