Dear all
I'm trying to build a set using photon particle to activate 6 relays and measure ambient temperature and humidity. I'm using Blynk to control via iPhone. The system worked very well for a few days. However, after a few days it started to go offline frequently and the photon LED flashes green.
I would like to know if there is something wrong in my sketch that could cause this, or possibly a firmware problem. Thank you in advance.
// This #include statement was automatically added by the Particle IDE.
#include <PietteTech_DHT.h>
SYSTEM_THREAD (ENABLED);
// This #include statement was automatically added by the Particle IDE.
#define BLYNK_TEMPLATE_ID ""
#define BLYNK_TEMPLATE_NAME ""
#define BLYNK_AUTH_TOKEN ""
// This #include statement was automatically added by the Particle IDE.
#include <blynk.h>
#define BLYNK_PRINT Serial
#define BLYNK_DEBUG
char auth[] = BLYNK_AUTH_TOKEN;
#define DHTTYPE DHT11
//#define DHTTYPE DHT22
#define DHTPIN D6
PietteTech_DHT DHT(DHTPIN, DHTTYPE);
double serverTempMax = 81;
double serverHumidityMax = 60;
double serverTemp;
double serverHumidity;
bool overheatDetected = false;
bool tooHumid = false;
const int relay_0 = 0;
const int relay_1 = 1;
const int relay_2 = 2;
const int relay_3 = 3;
const int relay_4 = 4;
const int relay_5 = 5;
BLYNK_WRITE(V0)
{
int value = param.asInt();
digitalWrite(0,value);
Serial.println(value);
}
BLYNK_WRITE(V1)
{
int value = param.asInt();
digitalWrite(1,value);
}
BLYNK_WRITE(V2)
{
int value = param.asInt();
digitalWrite(2,value);
}
BLYNK_WRITE(V3)
{
int value = param.asInt();
digitalWrite(3,value);
}
BLYNK_WRITE(V4)
{
int value = param.asInt();
digitalWrite(4,value);
}
BLYNK_WRITE(V5)
{
int value = param.asInt();
digitalWrite(5,value);
}
BlynkTimer timer;
void sendSensor()
{
//int result = DHT.acquireAndWait(2000);
int result = DHT.acquireAndWait(500);
serverHumidity = DHT.getHumidity();
serverTemp =DHT.getCelsius();
Serial.println(serverHumidity);
Serial.println(serverTemp);
Blynk.virtualWrite(V6, serverTemp);
Blynk.virtualWrite(V7, serverHumidity);
}
void setup()
{
Serial.begin(9600);
Blynk.begin(auth);
pinMode(0,OUTPUT);
pinMode(1,OUTPUT);
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
digitalWrite (0,HIGH);
digitalWrite (1,HIGH);
digitalWrite (2,HIGH);
digitalWrite (3,HIGH);
digitalWrite (4,HIGH);
digitalWrite (5,HIGH);
Particle.variable("serverTemp", &serverTemp, DOUBLE);
Particle.variable("serverHumidity", &serverHumidity, DOUBLE);
timer.setInterval(1000L, sendSensor);
}
void loop()
{
Blynk.run();
timer.run();
}
The Blynk library is blocking so you need to make sure you test for Particle connected before Blynk.run. If particle tests not connected do blynk.disconnect otherwise it blocks the code running. This may not be the issue but I always test this condition. I had problems with the DHT11 library and stopped using that device years ago and use the SHT31. I suspect that to be your problem but others may have more advice having used it more recently. Maybe increase your timer from 1 second to 5 and see if it works better.
I am a little late to the discussion, so please ignore my comment if you have already solved the problem.
You can of course use webhooks (API) instead, negating the need for the library. It is more challenging to get going but it seems to be quite robust. I used it in this tutorial with a Photon 2 to establish bi-directional communication between Particle and Blynk.
There is on caveat though - Blynk will show your device as OFFLINE and there seems to be no solution this problem at present. To make matters worse, it will also prompt you that your device is offline each time you hit a button on Blynk dashboard to send data to the Photon.
I stand to be corrected, but at the time of the tutorial, this was still the case. Hoping someone can prove otherwise as I also have some Blynk projects pending
I have more than ten Particle devices (two are Photon2) that are connected to Blynk with no issues using the Blynk library. They run 24/7 in critical roles and can't have any downtime. I run my network on a cellular hotspot so I will occasionally have my devices go offline but they come back up immediately. I have found with Blynk you need the code to be clean using their examples.
HHmm... from what I remember, the Blynk documents state that with cellular devices the Blynk API should be used and not the library. I am not sure whether this came into play since Blynk 2.0 though or whether this is a must, but I opted to follow the recommendation. What I can say is that I have been running multiple B524 devices with Blynk using the API for months now posting data every two minutes and have not missed a post yet
I am by no means a expert in anything Blynk so please consider my comments as advices/findings, not law
This whole analysis seems reasonable enough, but I recently noticed that something interesting happens. Whenever I use a complete sketch with the DHT22, the range of the photon for the internet link decreases. By removing DHT22 the range increases. Next to the server seems to work very well with the Blynk libraries. However, I intend to do more testing before concluding anything.