I have two Arduinos communicated through I2C. One executes critical tasks and the other only takes care of the Blynk connection. The first one sends two data every 3 seconds to the second. The second one receives them and updates the Blynk application. It works correctly for hours and then the arduino that controls Blynk hangs up. The message that shows is Redirecting to 45.55.96.156:8080. Somebody could help me? Thank you!
My Sketch:
#define BLYNK_PRINT Serial
#include <SoftwareSerial.h>
#include <Wire.h>
#include <avr/wdt.h>
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
const int ledPin = 13; // the number of the LED pin
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = “XXX”;
// Your WiFi credentials.
// Set password to “” for open networks.
//char ssid[] = “XXX”;
//char pass[] = “XXX”;
//char ssid[] = “XXX”;
//char pass[] = “XXX”;
char ssid[] = “XXX”;
char pass[] = “XXX”;
//char server[] = “blynk-cloud.com”;
//unsigned int port = 80;
// Hardware Serial on Mega, Leonardo, Micro…
#define EspSerial Serial1
// or Software Serial on Uno, Nano…
//#include <SoftwareSerial.h>
//SoftwareSerial EspSerial(2, 3); // RX, TX
#define ESP8266_BAUD 9600
ESP8266 wifi(&EspSerial);
boolean EstadoComCasa2 = 1;
boolean EstadoComFrente2 = 0;
boolean EstadoAutoMan2 =1;
boolean EstadoTanqueBajo2 = 1;
uint8_t PorcentajeNivelTanque2=10;// De nivel de tanque de agua
uint8_t PresionAgua2=10;
int inByte[] = { 0, 0}; // incoming serial byte
WidgetLED LED1(V2);//EstadoComCasa2
WidgetLED LED2(V3);//EstadoComFrente2
WidgetLED LED3(V4);//EstadoAutoMan2
WidgetLED LED4(V5);//EstadoTanqueBajo2
BlynkTimer timer; // Create a Timer object called “timer”!
//void(*resetFunc)(void)=0;//declare reset function @address 0
//long ContadorReset=0;
void setup()
{
wdt_disable();
// Debug console
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
Wire.begin(1);
// Registramos el evento al recibir datos
Wire.onReceive(EventoRecepcion);
delay(1000);
Serial.begin(9600);
// Set ESP8266 baud rate
EspSerial.begin(ESP8266_BAUD);
delay(10);
//wdt_enable(WDTO_8S);
Blynk.begin(auth, wifi, ssid, pass);
//wifi.setDHCP(1, 1, 1); //Enable dhcp in station mode and save in flash of esp8266
//Blynk.connectWiFi(ssid, pass); // used with Blynk.connect() in place of Blynk.begin(auth, ssid, pass, server, port);
// line below needs to be BEFORE Blynk.connect()
timer.setInterval(1000L, sendUptime); // Here you set interval (1sec) and which function to call
timer.setInterval(20000L, CheckConnection); // Here you set interval (1sec) and which function to call
timer.setInterval(10000L, EnviarSolicitudDatos); // Here you set interval (1sec) and which function to call
wdt_enable(WDTO_8S);
Serial.println(“Inicializacion Completa!”);
}
void CheckConnection(){ // check every 11s if connected to Blynk server
if(!Blynk.connected()){
Serial.println(“No Conectado al Servidor Blynk”);
//Blynk.connect(); // try to connect to server with default timeout
}
else{
Serial.println(“Conectado al Servidor Blynk”);
//Blynk.syncAll();
}
}
void EnviarSolicitudDatos(){
digitalWrite(ledPin, HIGH);
Wire.beginTransmission(2);
Wire.write(4);//codigo para solicitar datos 4
Wire.endTransmission();
}
void loop()
{
wdt_reset();
if(Blynk.connected()){
Blynk.run();
}
timer.run(); // BlynkTimer is working…
// You can inject your own code or combine it with other sketches.
// Check other examples on how to communicate with Blynk. Remember
// to avoid delay() function!
}
void sendUptime()
{
// This function sends Arduino up time every 20 second to Virtual Pin (V5)
// In the app, Widget’s reading frequency should be set to PUSH
// You can send anything with any interval using this construction
// Don’t send more that 10 values per second
//Serial.println(“ENTRO AL TIME”);
digitalWrite(ledPin, LOW);
if(EstadoComCasa2==1) LED1.on();
if(EstadoComCasa2==0) LED1.off();
if(EstadoComFrente2==1) LED2.on();
if(EstadoComFrente2==0) LED2.off();
if(EstadoAutoMan2==1) LED3.on();
if(EstadoAutoMan2==0) LED3.off();
if(EstadoTanqueBajo2==1) LED4.on();
if(EstadoTanqueBajo2==0) LED4.off();
Blynk.virtualWrite(V0, PresionAgua2);
Blynk.virtualWrite(V1, PorcentajeNivelTanque2);
//ContadorReset++;
}
void EventoRecepcion(int howMany) {
// Si hay 2 bytes disponibles, cual variable y valor
if (Wire.available() == 2) {
inByte[0] = Wire.read();
}
if (Wire.available() == 1)
{
inByte[1] = Wire.read();
//Serial.print(“Codigo:”);
//Serial.print(inByte[0]);
//Serial.print(", ");
//Serial.print(“Valor:”);
//Serial.println(inByte[1]);
GuardarVariable();
}
}
void GuardarVariable(){
if(inByte[0] == 1) PorcentajeNivelTanque2=inByte[1];
if(inByte[0] == 2) PresionAgua2=inByte[1];
if(inByte[0] == 3) EstadoComCasa2=inByte[1];
if(inByte[0] == 4) EstadoComFrente2=inByte[1];
if(inByte[0] == 5) EstadoAutoMan2=inByte[1];
if(inByte[0] == 6) EstadoTanqueBajo2=inByte[1];
}