Hello, I am doing my first project with Blynk, it is to move a servo motor and when it moves I send an email and a notification to my cell phone, at the beginning it works and then I get message in the application that the device is offline and it keeps happening while the program is running.
I’ve been trying to solve this for a long time and I do not succeed, I work with a LoLin NodeMCU which is an ESP8266, which connects to a WiFi network and my cell phone connected to the data network, im using the Arduino IDE and a LCD.
If someone can help me, please, thank you.
The code is this:
#define BLYNK_PRINT Serial //Comente esto para desactivar impresiones y ahorrar espacio
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <LiquidCrystal.h>
#include <Servo.h>
LiquidCrystal lcd(5,4,0,2,14,12); //Pin LCD: 4-RS, 6-ENABLE, 11-D4, 12-D5, 13-D6, 14-D7)... (1,3,5- GND, 2-Vcc, );
Servo servo; //cafe - GND, rojo - 5V, amarillo - PIN(3)
int pos = 0; //Posicion del servo
long tiempoEntre = 10000; //10000 ms hours between feeding
long tiempoFinal;
long tiempoActual;
int cont = 0;
bool aux = true;
byte pez[8]{
B00000,
B00000,
B00000,
B10110,
B01111,
B10110,
B00000,
};
byte pez1[8]{
B10110,
B01111,
B10110,
B00000,
B00000,
B00000,
B00000,
};
byte pez2[8]{
B00000,
B00000,
B00000,
B10110,
B01111,
B10110,
B00000,
};
//Su authtoken generado por la aplicacion Blynk
char auth[] = "6454ff8067274e8a8e8403a415a8eddd";
//Datos para la conexion de Red Wifi.
char ssid[] = "wl-fmat-ccei-b"; //Nombre de la red WIFI
char pass[] = ""; //contraseña de la red WIFI
//--------------------------------------------------------------------------------
void setup() {
Serial.println("---- 1----");
Serial.begin(9600);
Serial.println("---- 2 ----");
servo.attach(3); //GPIO10, SD3
lcd.begin(16, 2);
lcd.clear();
lcd.createChar(1,pez);
lcd.createChar(2,pez1);
lcd.createChar(3,pez2);
Serial.println("---- Antes ----");
Blynk.begin(auth, ssid, pass);
Serial.println("---- Despues ----");
// Envia correo electrónico cuando el hardware se conecte al servidor de Blynk
//Parametros por defecto: "Correo electronico", "Asunto", "Mensaje a enviar"
Blynk.email("andrea.ortiz.pavon@gmail.com","INICIO FOODFISH", "Se ha alimentado a los peces :)");
//pinMode(5, INPUT);// pin D1(GPIO5) como entrada del sensor
pinMode(13,OUTPUT);// pin D7(GPIO13) como Salida LED Rojo
pinMode(15,OUTPUT);// pin D8(GPIO15) como Salida LED Verde
}
//--------------------------------------------------------------------------------
void loop() {
FoodFish();
Alarma(aux);// llama a ejecutar la funcion
aux = true;
Blynk.run();
}
void FoodFish(){
Serial.println();
Serial.println("---- Iniciamos ----");
Blynk.notify("INICIAMOS");
lcd.setCursor(2,0);
lcd.print("FOODFISH ");
lcd.setCursor(12,0);
lcd.write(1);
lcd.setCursor(13,0);
lcd.write(2);
lcd.setCursor(14,0);
lcd.write(3);
lcd.setCursor(0,1);
lcd.print("No. de veces: ");
Serial.println("-----------NO. VECES");
tiempoActual = millis();
Serial.print("Tiempo actual: ");
Serial.println(tiempoActual/1000);
Serial.print("* Tiempo entre: ");
Serial.println(tiempoEntre/1000);
tiempoFinal = tiempoActual + tiempoEntre;
Serial.print("-> Tiempo final: ");
Serial.println(tiempoFinal/1000);
while(tiempoActual < tiempoFinal) {
servo.write(0);
delay(1000);
tiempoActual = millis();
}
Serial.print("Tiempo actual: ");
Serial.println(tiempoActual/1000);
for(pos = 0; pos < 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
servo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
Serial.println(".....MOVIO 1");
}
Serial.print("Tiempo actual: ");
Serial.println(tiempoActual/1000);
for(pos = 180; pos>=1; pos-=1) { // goes from 180 degrees to 0 degrees
servo.write(pos); // tell servo to go to position in variable 'pos'
delay(15);
Serial.println(".....MOVIO 2"); // waits 15ms for the servo to reach the position
}
cont = cont + 1;
digitalWrite(13,HIGH);
delay(3000);
digitalWrite(13,LOW);
Serial.println();
Serial.print("No. de veces: ");
Serial.println(cont);
lcd.setCursor(14,1); //1 es la segunda linea
lcd.print(cont);
}
void Alarma(bool aux){
// si la alarma se activa este envia un correo y espera 15 segundos.
if (aux == true) // si aux es true
{
Serial.println("Alarma Activada"); //Imprime por el monitor serial
Blynk.email("andrea.ortiz.pavon@gmail.com","FOODFISH", "Se ha alimentado a los peces :)");
Blynk.notify("SE ALIMENTO");
delay(200);
}
aux = false;