Hello Blynkers !
Firstly, I really want to thank the Blynk team for their App : so powerful !
I am using an ESP8266 module version with an Arduino UNO and my coding knowledge is limited, I will need your help with a “Login Timeout” error. Here is my code, I tried to made it as clear as possible:
#define BLYNK_PRINT Serial
#include <Wire.h>
#include <SPI.h>
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <DHT.h>
#include <SoftwareSerial.h>
#include "RTClib.h"
#include <LiquidCrystal_I2C.h>
//**********TOKEN (OK)**********//
char auth[] = "*********************";
//**********WIFI (OK)**********//
//char ssid[] = "**********";
//char pass[] = "*********";
char ssid[] = "***********";
char pass[] = "***********";
//**********PIN**********//
const int btnPin = 4;
const int HeatPin = 5;
//**********RTC**********//
char daysOfTheWeek[7][12] = {"Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi"};
char dateBuffer[12];
//**********CUSTOM CHAR LCD**********//
byte thermo[8] = {
0b00100,
0b01010,
0b01010,
0b01110,
0b01110,
0b11111,
0b11111,
0b01110
};
byte drop[8] = {
0b00100,
0b00100,
0b01010,
0b01010,
0b10001,
0b10001,
0b10001,
0b01110
};
byte heat[8] = {
0b10010,
0b10101,
0b10101,
0b10101,
0b10101,
0b10101,
0b10101,
0b01001
};
SoftwareSerial EspSerial(2, 3); // RX, TX
#define ESP8266_BAUD 9600
#define DHTPIN 7
#define DHTTYPE DHT22
ESP8266 wifi(&EspSerial);
WidgetLED led1(V1);
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;
RTC_DS1307 rtc;
LiquidCrystal_I2C lcd(0x27,20,4);
void HeatButton();
int ledState = HIGH;
int btnState;
int lastButtonState = LOW;
// the following variables are unsigned long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
unsigned long lastDebounceTime = 0; // the last time the output pin was toggled
unsigned long debounceDelay = 50; // the debounce time; increase if the output flickers
// Every time we connect to the cloud...
BLYNK_CONNECTED() {
// Request the latest state from the server
Blynk.syncVirtual(V20);
// Alternatively, you could override server state using:
//Blynk.virtualWrite(V2, ledState);
}
// When App button is pushed - switch the state
BLYNK_WRITE(V20) {
ledState = param.asInt();
digitalWrite(HeatPin, ledState);
}
//**********HEAT PUSH BUTTON (OK)**********//
void HeatButton()
{
// read the state of the switch into a local variable:
int reading = digitalRead(btnPin);
// check to see if you just pressed the button
// (i.e. the input went from LOW to HIGH), and you've waited
// long enough since the last press to ignore any noise:
// If the switch changed, due to noise or pressing:
if (reading != lastButtonState) {
// reset the debouncing timer
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
// whatever the reading is at, it's been there for longer
// than the debounce delay, so take it as the actual current state:
// if the button state has changed:
if (reading != btnState) {
btnState = reading;
// only toggle the LED if the new button state is HIGH
if (btnState == HIGH) {
ledState = !ledState;
}
}
}
// set the LED:
digitalWrite(HeatPin, ledState);
// save the reading. Next time through the loop,
// it'll be the lastButtonState:
lastButtonState = reading;
if (digitalRead(btnPin) == LOW) {
// btnState is used to avoid sequential toggles
if (btnState != LOW) {
// Toggle LED state
ledState = !ledState;
digitalWrite(HeatPin, ledState);
// Update Button Widget
Blynk.virtualWrite(V20, ledState);
}
btnState = LOW;
} else {
btnState = HIGH;
}
}
//**********LCD 4x20 DISPLAY**********//
void LCDisplay(){
DateTime now = rtc.now();
lcd.setCursor ( 0, 0 ); // go to the top left corner
sprintf(dateBuffer,"%02u:%02u ",now.hour(),now.minute());
Serial.println(dateBuffer);
lcd.print(dateBuffer);
}
//**********DHT TO BLYNK (OK)**********//
void sendSensor()
{
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Blynk.virtualWrite(V18, h);
Blynk.virtualWrite(V17, t);
}
void setup()
{
//**********DEBUG CONSOLE**********//
Serial.begin(9600);
delay(10);
//**********ESP SETUP (OK)**********//
EspSerial.begin(ESP8266_BAUD);
delay(10);
Blynk.begin(auth, wifi, ssid, pass);
//**********DHT SENSOR (OK)**********//
dht.begin();
timer.setInterval(30000L, sendSensor);
//**********SWITCH HEAT ON/OFF (OK)**********//
pinMode(HeatPin, OUTPUT);
pinMode(btnPin, INPUT_PULLUP);
digitalWrite(HeatPin, ledState);
timer.setInterval(500L, HeatButton);
//**********LCD 4x20 BACKGROUND**********//
lcd.init(); //initialize the lcd
lcd.backlight(); //open the backlight
lcd.createChar(0, thermo);
lcd.createChar(1, drop);
lcd.createChar(2,heat);
lcd.setCursor ( 0, 1 );
lcd.write(byte(0));
lcd.setCursor ( 0, 2 );
lcd.write(byte(1));
lcd.setCursor ( 0, 3 );
lcd.write(byte(2));
lcd.setCursor ( 12, 0 );
lcd.write(byte(1));
lcd.print(" Period");
lcd.setCursor ( 6, 0 );
lcd.print("AUTO");
//timer.setInterval(5000L, LCDisplay);
//**********RTC SETUP**********//
// following line sets the RTC to the date & time this sketch was compiled
//rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
//rtc.adjust(DateTime(2017, 4, 5, 19, 30, 0));
}
void loop()
{
Blynk.run();
timer.run();
}
So, everything is working well except the “live” display of Real Time (with a RTC) on Hardware LCD 2004. Every time I uncomment //timer.setInterval(5000L, LCDisplay);
I get an error like this :
[10060] Connected to WiFi
[20591] Ready (ping: 23ms).
[30726] Login timeout
[46495] Ready (ping: 243ms).
[56630] Login timeout
I have no idea why, I am aware of flood issues that may cause Timeout, but in my case, the period is quite long, and the LCDisplay()
function doesn’t even requires/sends data from/to Blynk server … Maybe I made a wrong use of timer function, but I don’t how to do it in another way.
If you have an idea why I get this Login timeout, and maybe a solution to my issue, you are welcome !