This one keeps re-connecting to blynk-cloud.
Some times it will work most of the day and then just start reconnecting.
When I do a RESET it will start working correctly, but it never last.
//********** Blynk_ESP8266 **********
//*************************************
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
//#define BLYNK_DEBUG
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
char auth[] = "c5537fa8e1474d7fb49c4f8dff53c249";
SimpleTimer timer;
//********** Dallas Temp **********
//***********************************
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
//********** Adafruit MCP9808 **********
//***************************************
#include <Wire.h>
#include "Adafruit_MCP9808.h"
// Create the MCP9808 temperature sensor object
Adafruit_MCP9808 tempsensor = Adafruit_MCP9808();
//********** LiquidCrystal_I2C **********
//*****************************************
#include <LiquidCrystal_I2C.h>
// Set the LCD address
LiquidCrystal_I2C lcd(0x3F, 20, 4);
byte thermometer[8] = //icon for thermometer
{
B00100,
B01010,
B01010,
B01010,
B01110,
B11111,
B11111,
B01110
};
byte waterDroplet[8] = //icon for water droplet
{
B00100,
B00100,
B01010,
B01010,
B10001,
B10001,
B10001,
B01110,
};
int officeTemp;
int officeHumd;
int shopTemp;
int shopHumd;
int garageTemp;
int mainDoor;
int thirdDoor;
int shopDoor;
int sideDoor;
int ledPin = 14;
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "*************";
char pass[] = "***************";
IPAddress device_ip (192, 168, 1, 52);
IPAddress dns_ip ( 8, 8, 8, 8);
IPAddress gateway_ip (192, 168, 1, 1);
IPAddress subnet_mask(255, 255, 255, 0);
void setup()
{
Serial.begin(9600);
// Setup WiFi network
WiFi.config(device_ip, gateway_ip, subnet_mask);
WiFi.begin(ssid, pass);
// Setup Blynk
Blynk.config(auth);
while (Blynk.connect() == false) {
}
timer.setInterval(10000L, temp);
timer.setInterval(2000L, checkDoors);
sensors.begin();
// Make sure the sensor is found, you can also pass in a different i2c
// address with tempsensor.begin(0x18) for example
if (!tempsensor.begin()) {
Serial.println("Couldn't find MCP9808!");
while (1);
}
// initialize the LCD
lcd.begin();
// Turn on the blacklight
lcd.backlight();
lcd.clear();
lcd.createChar(1,thermometer);
lcd.createChar(2,waterDroplet);
pinMode (ledPin, OUTPUT);
}
//********** Get and Print Temp Readings **********
//**************************************************
void temp()
{
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
// Serial.print("Requesting temperatures...");
sensors.requestTemperatures(); // Send the command to get temperatures
// Serial.println("DONE");
float outTemp = sensors.getTempFByIndex(0)+1.7;
// After we got the temperatures, we can print them here.
// We use the function ByIndex, and as an example get the temperature from the first sensor only.
Serial.print("Dallas DS18B20 Temp: "); Serial.println(outTemp, 1);
Blynk.virtualWrite(1, outTemp); // virtual pin
// Serial.println("wake up MCP9808.... "); // wake up MSP9808 - power consumption ~200 mikro Ampere
tempsensor.shutdown_wake(0); // Don't remove this line! required before reading temp
// Read and print out the temperature
float inTemp = tempsensor.readTempC() * 9.0 / 5.0 + 32;
Serial.print("Adafruit MCP9808 Temp: "); Serial.println(inTemp, 1);
delay(250);
// Serial.println("Shutdown MCP9808.... ");
tempsensor.shutdown_wake(1); // shutdown MSP9808 - power consumption ~0.1 mikro Ampere
Blynk.virtualWrite(2, inTemp); // virtual pin
lcd.setCursor(0,0);
lcd.print ("Out ");lcd.write(1);lcd.print (" ");
lcd.print (outTemp, 0); lcd.print((char)223); // print degree symbol
lcd.print ("F");
lcd.print (" In "); lcd.write(1);lcd.print (" ");
lcd.print (inTemp, 0); lcd.print((char)223); // print degree symbol
lcd.print ("F");
lcd.setCursor(0,1);
lcd.print ("Office "); lcd.write(1);lcd.print (" ");
lcd.print (officeTemp); lcd.print((char)223); // print degree symbol
lcd.print ("F ");
lcd.write(2);lcd.print (" "); lcd.print (officeHumd);lcd.print ("% ");
lcd.setCursor(0,2);
lcd.print ("Shop "); lcd.write(1);lcd.print (" ");
lcd.print (shopTemp); lcd.print((char)223); // print degree symbol
lcd.print ("F ");
lcd.write(2);lcd.print (" "); lcd.print (shopHumd);lcd.print ("%");
lcd.setCursor(0,3);
lcd.print ("Garage "); lcd.write(1);lcd.print (" ");
lcd.print (garageTemp); lcd.print((char)223); // print degree symbol
lcd.print ("F");
}
//********** Reading from Office **********
//*******************************************
BLYNK_WRITE(V11){
officeTemp = param.asInt(); //pinData variable will store value that came via Bridge
// Serial.print ("Office Temp: "); Serial.println (officeTemp);
}
BLYNK_WRITE(V12){
officeHumd = param.asInt(); //pinData variable will store value that came via Bridge
// Serial.print ("Office Humd: "); Serial.println (officeHumd);
}
//********** Reading from Shop **********
//*****************************************
BLYNK_WRITE(V13){
shopTemp = param.asInt(); //pinData variable will store value that came via Bridge
// Serial.print ("Shop Temp: "); Serial.println (shopTemp);
}
BLYNK_WRITE(V14){
shopHumd = param.asInt(); //pinData variable will store value that came via Bridge
// Serial.print ("Shop Humd: "); Serial.println (shopHumd);
}
//********** Reading from Garage **********
//*******************************************
BLYNK_WRITE(V15) {
garageTemp = param.asInt(); //pinData variable will store value that came via Bridge
// Serial.print ("Garage Temp: "); Serial.println (garageTemp);
}
//********** Shop Door **********
//********************************
BLYNK_WRITE(V16) {
shopDoor = param.asInt(); //pinData variable will store value that came via Bridge
}
//********** Main Door **********
//********************************
BLYNK_WRITE(V17) {
mainDoor = param.asInt(); //pinData variable will store value that came via Bridge
}
//********** 3rd Door **********
//*******************************
BLYNK_WRITE(V18) {
thirdDoor = param.asInt(); //pinData variable will store value that came via Bridge
}
//********** Shop Side Door **********
//*************************************
BLYNK_WRITE(V19) {
sideDoor = param.asInt(); //pinData variable will store value that came via Bridge
}
void checkDoors (){
if (mainDoor == 1 || thirdDoor == 1 || shopDoor == 1){
digitalWrite (ledPin, HIGH);
}
else {
digitalWrite (ledPin, LOW);
}
}
void loop()
{
Blynk.run();
timer.run();
}