Hi all,
Ive been using blynk server with ESP12 for a 3 month and it woas working excelent until 2 days ago when it started to reset every few minutes.
Connection to wifi is stable but it drops conn with blynk server and usualy it timesout. So I have to reset it hard to begin conn again. It’s been like this for 2-3 days. Haven’t changed anythign to code or to hardware.
Is there any changes to server connestion ot are there any problems with servers.
I am seriously thinking of running my one stand alone server as my device is dependent on internet now. It would be better not to be.
It home heating and automation system in development.
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <OneWire.h>
#include <DallasTemperature.h>
//#include <IRremote.h>
#include <LiquidCrystal_I2C.h>
#include <DHT.h>
#include <SPI.h>
#define DHTPIN 14 // what digital pin we're connected tonclude <SD.h>
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
//const int RECV_PIN = 1;
//IRrecv irrecv(RECV_PIN);
//decode_results results;
#define chMinus 16753245 // code received from button 1
#define chPlus 16769565 // code received from button 2
#define ch 16736925 // CH button
#define play 16761405 //play green button
#define eqButton 16748655
float temperatura;
float tempRoom;
float tempBoiler;
float tempDebug;
float tempMobile;
int rHum;
float hic;
bool lcdLightFlag = 1;
float tempSet;
float tempMin;
float tempMax;
float tempDifference = 0.6;
float tempSetDay = 22;
float tempMinDay;
float tempMaxDay = 28;
float tempSetNight = 20;
float tempMinNight;
float tempMaxNight = 25;
bool isconnected;
int hours;
int minutes;
int wifiPeriod = 10000;
//unsigned long time_now = 0;
unsigned long lastTime = 0;
unsigned long currentMillis;
unsigned long lastMillis;
bool autoMode;
bool blockMode;
bool manualMode;
bool nightMode;
bool heating = LOW;
bool pump = 0;
int i = 0;
#define relay 16
#define greenLed 24
#define redLed 26
#define yellowLed 9
//#define lcdLight 16
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
//char auth[] = "e48226e5b8b34febbf44cf7238311418"; // samo za mobile temo
char auth[] = "06ef7c80b1b24d68993de96e2baf21af";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "HUAWEI-B315-31B5";
char pass[] = "089HG42D289";
// Create a Onewire Referenca and assign it to pin 6 on your Arduino
OneWire oneWire(12);
// declare as sensor referenec by passing oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
BlynkTimer timer;
DHT dht(DHTPIN, DHTTYPE);
// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
DeviceAddress tempSensorOut = {0x28, 0xFF, 0xF6, 0xA6, 0x62, 0x16, 0x4, 0x1F};
DeviceAddress tempSensorDebug = {0x28, 0xFF, 0x87, 0xA, 0x63, 0x16, 0x4, 0xAF};
void setup()
{
// Debug console
Serial.begin(9600);
//Blynk.begin(auth, ssid, pass);
// You can also specify server:
Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
pinMode(relay, OUTPUT);
digitalWrite(relay, HIGH);
// pinMode(lcdLight, OUTPUT);
// Setup a function to be called every second
dht.begin();
lcd.begin(20, 4);
// irrecv.enableIRIn();
//timer.setInterval(1000L, printTemp);
sensors.setResolution(tempSensorOut, 11);
sensors.setResolution(tempSensorDebug, 11);
Serial.print("Sensor Resolution Out: ");
Serial.println(sensors.getResolution(tempSensorOut), DEC);
timer.setInterval(2000L, checkConn);
timer.setInterval(5000L, reseting);
}
BLYNK_CONNECTED()
{
//Blynk.syncAll();
Blynk.syncVirtual(V8);
Blynk.syncVirtual(V1);
Blynk.syncVirtual(V2);
Blynk.syncVirtual(V3);
Blynk.syncVirtual(V12);
Blynk.syncVirtual(V13);
}
void checkConn()
{
currentMillis = millis() / 1000;
isconnected = Blynk.connected();
//Serial.println("CurrentMillis");
//Serial.println(currentMillis);
modeSelection();
printTemp();
printLcd();
sendToBlynk();
serialPrint();
}
void reseting()
{
if (isconnected == false)
{
Blynk.connect();
i = i + 1;
lcd.setCursor(8, 3);
lcd.print(i);
}
//if (currentMillis == lastMillis) ESP.reset();
/*if (isconnected== true)
{
Blynk.syncAll();
}*/
if (i == 5)
{
i = 0;
if (isconnected == false)
{
i = 0;
lcd.setCursor(6, 3);
lcd.print("Reseting");
Serial.println("Reseting");
ESP.reset();
}
}
Serial.print("i=");
Serial.println(i);
//lastMillis=millis()/1000;
//Serial.print("LastMillis iliti reseting");
//Serial.println(lastMillis);
}
/*void remote()
{
if (irrecv.decode(&results)) //this checks to see if a code has been received
{
unsigned int value = results.value;
switch (value) {
case chMinus:
autoModeF();
break;
case ch:
manualModeF();
break;
case chPlus:
blockModeF();
break;
case play:
nightModeF();
break;
case eqButton:
lcdLightFlag = !lcdLightFlag;
break;
}
Serial.println(value);
irrecv.resume(); //receive the next value
}
}
*/
void sendToBlynk()
{
//send to blynk
Blynk.virtualWrite(V5, millis() / 1000);
Blynk.virtualWrite(V6, tempRoom);
Blynk.virtualWrite(V4, tempBoiler);
Blynk.virtualWrite(V7, pump);
Blynk.virtualWrite(V0, tempSet);
Blynk.virtualWrite(V3, nightMode);
Blynk.virtualWrite(V2, blockMode);
Blynk.virtualWrite(V1, manualMode);
Blynk.virtualWrite(V8, autoMode);
//Blynk.virtualWrite(V11, tempMobile);
Blynk.virtualWrite(V12, tempSetDay);
Blynk.virtualWrite(V13, tempSetNight);
}
void printLcd()
{
//LCD PRINT
//String displayDate = rtc.getDateStr();
//String displayTime = rtc.getTimeStr();
unsigned long upTime = millis() / 1000;
lcd.setCursor(0, 0);
lcd.print("RH");
lcd.setCursor(3, 0);
lcd.print(" ");
lcd.setCursor(3, 0);
lcd.print(rHum);
lcd.setCursor(8, 0);
lcd.print(tempRoom);
lcd.setCursor(15, 0);
lcd.print(tempBoiler);
lcd.setCursor(0, 1);
lcd.print(tempMin);
lcd.setCursor(8, 1);
lcd.print(tempSet);
//lcd.setCursor(15, 1);
//lcd.print(tempMobile);
if (isconnected == true)
{
lcd.setCursor(13, 3);
lcd.print(" ONLINE");
}
else
{
lcd.setCursor(13, 3);
lcd.print("OFFLINE");
}
lcd.setCursor(0, 3);
lcd.print(upTime);
if (autoMode == 1 && nightMode == 0)
{
lcd.setCursor(0, 2);
lcd.print(" ");
lcd.setCursor(8, 2);
lcd.print("AUTO");
}
if (manualMode == 1)
{
lcd.setCursor(6, 2);
lcd.print(" ");
lcd.setCursor(6, 2);
lcd.print("MANUALNO");
}
if (blockMode == 1)
{
lcd.setCursor(6, 2);
lcd.print(" ");
lcd.setCursor(6, 2);
lcd.print("BLOKADA");
}
if (pump == 1)
{
lcd.setCursor(17, 2);
lcd.print(" ");
lcd.setCursor(18, 2);
lcd.print("ON");
}
else
{
lcd.setCursor(17, 2);
lcd.print(" ");
lcd.setCursor(17, 2);
lcd.print("OFF");
}
if (nightMode == 1)
{
lcd.setCursor(6, 2);
lcd.print(" ");
lcd.setCursor(8, 2);
lcd.print("NIGHT");
}
}
void printTemp()
{
//t = rtc.getTime();
//hours = t.hour;
//minutes = t.min;
//Serial.println(isconnected);
// Tell the Sensor to Measure and Remember the Temperature it Measured
sensors.requestTemperaturesByAddress(tempSensorDebug); // Send the command to get temperatures
//tempRoom = sensors.getTempC(tempSensorRoom);
tempRoom = sensors.getTempC(tempSensorDebug);
sensors.requestTemperaturesByAddress(tempSensorOut);
tempBoiler = sensors.getTempC(tempSensorOut);
//feels like
hic = dht.computeHeatIndex(tempRoom, rHum, false);
//tempRoom = dht.readTemperature();
//rHum = dht.readHumidity();
temperatura = tempRoom;
}
//termostat flags
void autoModeF()
{
autoMode = 1;
blockMode = 0;
manualMode = 0;
nightMode = 0;
lcdLightFlag = 1;
}
void blockModeF()
{
blockMode = 1;
autoMode = 0;
manualMode = 0;
nightMode = 0;
}
void manualModeF()
{
manualMode = 1;
blockMode = 0;
autoMode = 0;
nightMode = 0;
}
void nightModeF()
{
nightMode = 1;
manualMode = 0;
blockMode = 0;
autoMode = 0;
lcdLightFlag = 0;
}
void serialPrint ()
{
//print status to serial
//Serial.print(String((char*)rtc.getDateStr()) + ", " + String((char*)rtc.getTimeStr()) + ", ");
Serial.println ("H" + String(rHum) + ", R" + String(tempRoom) + ", M" + (tempMobile) + ", B" + String(tempBoiler) + ", A" + String(autoMode) + ", M" + String(manualMode) + ", B" + String(blockMode) + ", N" + nightMode + ", P" + pump + ", " + (tempSet) + ", " + (tempMin) + ", CONN " + isconnected);
Serial.println(tempDebug);
}
void termostatFunction ()
{
//termostat function
if (tempRoom >= tempSet) //if room temperature is over or = set temp
{
offF();
}
else if (tempRoom <= tempMin) //if room temp is below set temp
{
onF();
}
if (tempRoom >= tempMax) //turn all off is temp is over set absolute max
{
blokada();
}
}
void modeSelection()
{
if (autoMode == 1)
{
dayMode();
termostatFunction();
}
else if (manualMode == 1) manOn();
else if (blockMode == 1) blokada();
else if (nightMode == 1)
{
nightModeSetings();
termostatFunction();
}
}
void dayMode()
{
tempSet = tempSetDay;
tempMin = tempSetDay - tempDifference;
tempMax = tempMaxDay;
//digitalWrite (lcdLight, lcdLightFlag);
}
void nightModeSetings()
{
tempSet = tempSetNight;
tempMin = tempSetNight - tempDifference;
tempMax = tempMaxNight;
// digitalWrite (lcdLight, lcdLightFlag);
}
void offF()
{
heating = LOW;
digitalWrite(relay, HIGH);
pump = 0;
}
void onF()
{
heating = HIGH;
if (tempBoiler >= 45)
{
digitalWrite(relay, LOW);
pump = 1;
}
}
void manOn()
{
if (tempBoiler >= 45)
{
digitalWrite(relay, LOW);
pump = 1;
}
}
void manOff()
{
digitalWrite(relay, HIGH);
digitalWrite(redLed, HIGH);
pump = 0;
}
void blokada()
{
digitalWrite(relay, HIGH);
heating = 0;
pump = 0;
}
void ledControl()
{
digitalWrite(greenLed, autoMode);
digitalWrite(redLed, blockMode);
digitalWrite(yellowLed, manualMode);
}
BLYNK_WRITE(V1)
{
int V2Manual = param.asInt(); // assigning incoming value from pin V1 to a variable
if (V2Manual == 1)
{
manualModeF();
}
// You can also use:
// String i = param.asStr();
// double d = param.asDouble();
Serial.print("Manualno: ");
Serial.println(V2Manual);
}
BLYNK_WRITE(V2)
{
int V2Block = param.asInt(); // assigning incoming value from pin V1 to a variable
if (V2Block == 1)
{
blockModeF();
}
// You can also use:
// String i = param.asStr();
// double d = param.asDouble();
Serial.print("Blokada: ");
Serial.println(V2Block);
}
BLYNK_WRITE(V3)
{
int V3Night = param.asInt(); // assigning incoming value from pin V1 to a variable
if (V3Night == 1)
{
nightModeF();
}
// You can also use:
// String i = param.asStr();
// double d = param.asDouble();
Serial.print("Night: ");
Serial.println(V3Night);
}
BLYNK_WRITE(V8)
{
int v8Auto = param.asInt(); // assigning incoming value from pin V1 to a variable
if (v8Auto == 1)
{
autoModeF();
}
Serial.print("Auto: ");
Serial.println(v8Auto);
}
BLYNK_WRITE(V12)
{
tempSetDay = param.asFloat(); // assigning incoming value from pin V12 to a variable
Serial.print("tempSetDay: ");
Serial.println(tempSet);
}
BLYNK_WRITE(V13)
{
tempSetNight = param.asFloat(); // assigning incoming value from pin V1 to a variable
Serial.print("tempSetNight: ");
Serial.println(tempSetNight);
}
void loop()
{
Blynk.run();
timer.run(); // Initiates BlynkTimer
// remote();
}