I have an arduino MEGA and an ESP8266-01 connected to wifi and everything works just good ONLY when there’s internet. If for some reason the connection drops nothing, neither the simplest thing, works.
I tried to search a lot in the forum and i saw that this is a common problem (and also that @Gunner is an expert) but every solution give me some error message.
This is my sketch:
LedControl lc = LedControl(30, 34, 32, 1); // Pins: DIN,CLK,CS, # of Display connected
#include <LiquidCrystal.h> // Includi libreria Display LCD
LiquidCrystal lcd(2, 3, 4, 5, 6, 7); // Dichiara Pin Display LCD
#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "b7f8a7490c2a4aa3a5f7f11e7f403ee4";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "argon-2.4GHz-extended";
char pass[] = "1391abconde0294!=?31415";
// Hardware Serial on Mega, Leonardo, Micro...
#define EspSerial Serial1
// or Software Serial on Uno, Nano...
//#include <SoftwareSerial.h>
//SoftwareSerial EspSerial(2, 3); // RX, TX
// Your ESP8266 baud rate:
#define ESP8266_BAUD 115200
ESP8266 wifi(&EspSerial);
BlynkTimer timer;
int livelloacqua = 0;
int umiditaterra = 0;
int notifica = false;
#define LEDV1 8
#define LEDV2 9
#define LEDR1 10
#define LEDR2 11
unsigned long delayTime = 200; // Delay between Frames
// Put values in arrays
byte felice[] =
{
B00111100,
B01000010,
B10100101,
B10000001,
B10100101,
B10011001,
B01000010,
B00111100
};
byte triste[] =
{
B00111100,
B01000010,
B10100101,
B10000001,
B10011001,
B10100101,
B01000010,
B00111100
};
void setup()
{
// Debug console
Serial.begin(9600);
// Set ESP8266 baud rate
EspSerial.begin(ESP8266_BAUD);
delay(10);
Blynk.begin(auth, wifi, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, wifi, ssid, pass, "blynk-cloud.com", 8442);
//Blynk.begin(auth, wifi, ssid, pass, IPAddress(192,168,1,100), 8442);
lcd.begin(16, 2);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
lcd.clear();
lc.shutdown(0, false); // Wake up displays
lc.shutdown(1, false);
lc.setIntensity(0, 5); // Set intensity levels
lc.setIntensity(1, 5);
lc.clearDisplay(0); // Clear Displays
lc.clearDisplay(1);
timer.setInterval(300L, programma); // run programma every 400 millisecond
timer.setInterval(120000L, checknotifica); // run programma every 2 minutes
}
// Take values in Arrays and Display them
void sfelice()
{
for (int i = 0; i < 8; i++)
{
lc.setRow(0, i, felice[i]);
}
}
void striste()
{
for (int i = 0; i < 8; i++)
{
lc.setRow(0, i, triste[i]);
}
}
void checknotifica () {
livelloacqua = analogRead(A0);
livelloacqua = map(analogRead(A0), 0, 300, 0, 100);
if (livelloacqua < 160) {
lcd.setCursor(0, 0);
lcd.print("Riempire acqua ");
Blynk.notify("L'acqua è in esaurimento! Devi riempirla!");
}
if (livelloacqua >= 130) {
lcd.setCursor(0, 0);
lcd.print("Acqua OK ");
}
}
void programma() {
livelloacqua = analogRead(A0);
livelloacqua = map(analogRead(A0), 0, 300, 0, 100);
Blynk.virtualWrite(V1, livelloacqua);
umiditaterra = analogRead(A1);
umiditaterra = map(analogRead(A1), 1024, 0, 0, 100);
Blynk.virtualWrite(V2, umiditaterra);
lcd.setCursor(0, 0);
livelloacqua = analogRead(A0);
if ((livelloacqua < 160 && !notifica)) {
lcd.setCursor(0, 0);
lcd.print("Riempire acqua ");
Blynk.notify("L'acqua è in esaurimento! Devi riempirla!");
notifica = true;
}
if (livelloacqua >= 130) {
lcd.setCursor(0, 0);
lcd.print("Acqua OK ");
notifica = false;
}
umiditaterra = analogRead(A1);
if (umiditaterra > 500) {
lcd.setCursor(0, 1);
lcd.print("Annaffiare ");
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
striste();
delay(100);
}
if (umiditaterra < 500) {
lcd.setCursor(0, 1);
lcd.print("Pianta OKAY ");
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
sfelice();
delay(100);
}
}
void loop() {
timer.run();
Blynk.run();
}