Hi! After a while working 24/7 (about 4 months) the board is starting to behave wierdly. It’s first connect to the cloud (blue LED fading in and out) and after about 30 to 40 seconds, the led turns green and it doesn’t connect again until a reset is made.
I had made a little software update, but it was just changing some pins definition.
What may I do to fix this issue?
In case it’s need, the code that I’m using is this:
//#include "Adafruit_DHT.h"
#include <Adafruit_DHT.h>
#include <blynk.h>
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
WidgetTerminal terminal(V8);
#define DHTPIN 2 // what pin we're connected to
#define mosfetPin 4
bool mosfetState = false;
// Uncomment whatever type you're using!
//#define DHTTYPE DHT11 // DHT 11
#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor
#define threesholdTemp_SUP 27
#define threesholdTemp_INF 20
DHT dht(DHTPIN, DHTTYPE);
//DANGER - DO NOT SHARE!!!!
char auth[] = "bf5174a178ae417d9f7993a5bc409eaa"; // Put your blynk token here
//DANGER - DO NOT SHARE!!!!
char VERSION[64] = "0.04";
int sampleInterval = 1000;
unsigned long DHTnextSampleTime = 0;
#define threshold 2 //Threshold in temperature/humidity changes to avoid misreadings
int lastT, lastH;
/* TEST BME280*/
// This #include statement was automatically added by the Particle IDE.
#include <Wire.h>
#include <SPI.h>
#include <CE_BME280.h> // //Modified library to match the i2c address on the sensor
//#include <Adafruit_Sensor.h>
//#include <Adafruit_BME280.h>
#define SEALEVELPRESSURE_HPA (1013.25)
CE_BME280 bme; // I2C
void setup() {
Serial.begin(9600);
dht.begin();
pinMode(mosfetPin,OUTPUT);
Blynk.begin(auth);
DHTnextSampleTime = 0;
lastT = dht.getTempCelcius();
lastH = dht.getHumidity();
Blynk.virtualWrite(V3,sampleInterval);
if (!bme.begin()) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}
}
void loop(){
Blynk.run(); // all the Blynk magic happens here
// Check if we need to start the next sample
if (millis() > DHTnextSampleTime) {
getDHT();
//getBME();
terminal.println("sample");
terminal.flush();
}
}
// SLIDER
BLYNK_WRITE(V0) { // reads value from slider, set range of 0-255, and passes it onto PWM pin
//Blynk.syncVirtual(V1);
int value = param.asInt();
analogWrite(mosfetPin, value);
if (value == 0) { // If slider is OFF, make sure button is as well
Blynk.virtualWrite(V1,0);
}else { // If slider is anything equal or higher than 1, set button ON
Blynk.virtualWrite(V1,1);
}
}
// BUTTON
BLYNK_WRITE(V1) {
int value = param.asInt();
digitalWrite(mosfetPin,value);
if (value==0) {
//LOW
// change button to off
Blynk.virtualWrite(V0,0);
}else{ // change button to on
Blynk.virtualWrite(V0,255);
}
}
//cHANGE SAMPLE INTERVAL
BLYNK_WRITE(V4){
Blynk.syncVirtual(V3); //Get Labeled value in V3
int value = param.asInt();
value = value * 1000; // Transform into millisecond
Blynk.virtualWrite(V3,value);
sampleInterval = value;
}
void changeColor(float _t){
if (_t > threesholdTemp_SUP){ //change to red
Blynk.setProperty(V2,"color","#FF0000");
Blynk.setProperty(V6,"color","#FF0000");
}else if (_t < threesholdTemp_INF){ // change to blue
Blynk.setProperty(V2,"color","#0000FF");
Blynk.setProperty(V6,"color","#0080FF");
}else{ //green
Blynk.setProperty(V2,"color","#00FF00");
Blynk.setProperty(V6,"color","#00FF00");
}
}
void getDHT(){
float h = dht.getHumidity();
float t = dht.getTempCelcius();
changeColor(t);
// ADD A CHECK OF THE VALUES TO AVOID DATA CORRUPTION
if (t > lastT + threshold || t < lastT - threshold){
// the reading is outside the admited limits, so, asume the value hasn't changed since last time.
t = lastT;
}else{
lastT = t;
}
if(h > lastH + threshold || h < lastH - threshold){
// the reading is outside the admited limits, so, asume the value hasn't changed since last time.
h = lastH;
}else{
lastH = h;
}
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t)) {
//Blynk.notify("Failed to read sensor");
//Serial.println("Failed to read sensor");
return;
}else{
Blynk.virtualWrite(V5, h);
Blynk.virtualWrite(V7, h);
Blynk.virtualWrite(V6, t);
Blynk.virtualWrite(V2, t);
}
DHTnextSampleTime = millis() + sampleInterval;
}
void getBME(){
float t = bme.readTemperature();
float h = bme.readHumidity();
float p = bme.readPressure() / 100.0F; // hPa
float alt = bme.readAltitude(SEALEVELPRESSURE_HPA); // m
terminal.print("p = ");
terminal.println(p);
terminal.print("Alt = ");
terminal.print(alt);
terminal.flush();
changeColor(t);
// ADD A CHECK OF THE VALUES TO AVOID DATA CORRUPTION
if (t > lastT + threshold || t < lastT - threshold){
// the reading is outside the admited limits, so, asume the value hasn't changed since last time.
t = lastT;
}else{
lastT = t;
}
if(h > lastH + threshold || h < lastH - threshold){
// the reading is outside the admited limits, so, asume the value hasn't changed since last time.
h = lastH;
}else{
lastH = h;
}
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t)) {
//Blynk.notify("Failed to read sensor");
//Serial.println("Failed to read sensor");
return;
}else{
Blynk.virtualWrite(V5, h);
Blynk.virtualWrite(V7, h);
Blynk.virtualWrite(V6, t);
Blynk.virtualWrite(V2, t);
}
DHTnextSampleTime = millis() + sampleInterval;
}
Greetings.