Device came online event too many times

I am testing a photon with a simple program. It is the DS18B20 examples you can find in the webide with a few lines adding relays behaviour depending on the temperaute got I have a relay controlled directly (transistor…) and another 2 controlled by PWM servo library (also taken from webide I think):

// This #include statement was automatically added by the Particle IDE.
#include "Adafruit_PWMServoDriver.h"

#include "DS18B20/Particle-OneWire.h"
#include "DS18B20/DS18B20.h"


#define TEMP_MAX_DAY   29
#define TEMP_MIN_DAY   28
#define TEMP_MAX_NIGHT 27
#define TEMP_MIN_NIGHT 26

#define NIGHT      21
#define NIGHT_MIN  30
#define DAY        10
#define DAY_MIN    30

#define PIN1    0
#define PIN2    1
#define PINTEMP D3

int led = D7;
char szInfo[64];
float pubTemp;
double celsius;
double fahrenheit;
unsigned int Metric_Publish_Rate = 30000;
unsigned int MetricnextPublishTime;
int DS18B20nextSampleTime;
int DS18B20_SAMPLE_INTERVAL = 2500;
int dsAttempts = 0;
DS18B20 ds18b20 = DS18B20(D2); //Sets Pin D2 for Water Temp Sensor


double tempe;
int max_val;
int min_val;


Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x40);

void setup() {
    pinMode(PINTEMP, OUTPUT);
    Time.zone(+2);
    Particle.syncTime();
    pinMode(D2, INPUT);
    Particle.variable("temp", &tempe, DOUBLE);
    Serial.begin(115200);
    
    pwm.begin();
    pwm.setPWMFreq(1600);
}


void loop() {
    
    if(Time.hourFormat12() >= DAY) {
        max_val = TEMP_MAX_DAY;
        min_val = TEMP_MIN_DAY;
        pwm.setPin(PIN1, 4095);
        if(Time.minute() >= DAY_MIN) {
            pwm.setPin(PIN2, 4095);
        }
    } else {
        max_val = TEMP_MAX_NIGHT;
        min_val = TEMP_MIN_NIGHT;
        pwm.setPin(PIN1, 0);
        if(Time.minute() >= DAY_MIN) {
            pwm.setPin(PIN2, 0);
        }
    }
    getTemp();
    tempe = celsius;
    if(tempe > max_val) {
        digitalWrite(PINTEMP, LOW);
    } else if(tempe < min_val) {
        digitalWrite(PINTEMP, HIGH);
    }
    
    

  if (millis() > MetricnextPublishTime){
    Time.zone(+2);
    Particle.syncTime();
    Serial.println("Publishing now.");
    publishData();
  }
}


void publishData(){
  if(!ds18b20.crcCheck()){
    return;
  }
  sprintf(szInfo, "%2.2f", celsius);
  Particle.publish("dsTmp", szInfo, PRIVATE);
  MetricnextPublishTime = millis() + Metric_Publish_Rate;
}

void getTemp(){
    if(!ds18b20.search()){
      ds18b20.resetsearch();
      celsius = ds18b20.getTemperature();
      Serial.println(celsius);
      while (!ds18b20.crcCheck() && dsAttempts < 4){
        Serial.println("Caught bad value.");
        dsAttempts++;
        Serial.print("Attempts to Read: ");
        Serial.println(dsAttempts);
        if (dsAttempts == 3){
          delay(1000);
        }
        ds18b20.resetsearch();
        celsius = ds18b20.getTemperature();
        continue;
      }
      dsAttempts = 0;
      fahrenheit = celsius;
      DS18B20nextSampleTime = millis() + DS18B20_SAMPLE_INTERVAL;
      Serial.println(fahrenheit);
    }
}

I tried to have it working a few hours. 2 days ago, 3-4 hours. Yesterday again 3-4 hours and today (here right now: 13:26) from 7:40. I haven’t checked the logs today until the last 30 minutes and I have found that the message “Device came online” is displayed many times. In 20 minutes maybe 8 or 10 times.

The other 2 days I haven’t seen this message after reflashing the photon.
There is 1 minute between the latest dsTemp value received and the quoted message. After that, maybe 1-2 or 3 dsTemp values received and then again “Device…”

What can be happening? Is the device reseting/rebooting?

1 Like