Hello!
I am using Arduino Uno and ESP-01 wifi module to send the data to blynk but even after changing both module and board, I am facing the same problem that the system is shown offline even though the module is still conned to the wifi.System is showing online and again showing offline continuously.
#define BLYNK_TEMPLATE_ID "TMPL3_lgyRLMN"
#define BLYNK_TEMPLATE_NAME "EDI"
#define BLYNK_AUTH_TOKEN "vb7EhhJqAtqLhRwfjsaSc95MnD_CazqC"
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
// Your WiFi credentials
char ssid[] = "Name";
char pass[] = "12345678";
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // RX, TX
#define ESP8266_BAUD 115200
ESP8266 wifi(&EspSerial);
const int mainldrpin = 4;
const int LIGHT1 = 9;
const int LIGHT2 = 10;
const int trigPin = 7;
const int echoPin = 8;
const int brightness = 255;
const int rainSensor = A0;
const int testldr = A1;
const int buzz = 4;
BlynkTimer timer;
String s5 = "faulty Street light";
void setup() {
pinMode(mainldrpin, INPUT);
pinMode(LIGHT1, OUTPUT);
pinMode(LIGHT2, OUTPUT);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(rainSensor, INPUT);
pinMode(testldr, INPUT);
pinMode(buzz, OUTPUT);
// digitalWrite(LIGHT1,LOW);
// digitalWrite(LIGHT2,LOW);
timer.setInterval(1000L, sensorData);
// Debug console
Serial.begin(9600);
delay(10);
// Set ESP8266 baud rate
EspSerial.begin(ESP8266_BAUD);
delay(10);
Serial.print("Connecting to ");
Serial.println(ssid);
Blynk.begin(BLYNK_AUTH_TOKEN, wifi, ssid, pass);
while (Blynk.connect() == false) {
// Wait until connected
}
}
void sensorData() {
int mainldrReading = digitalRead(mainldrpin);
int rainSensorValue = analogRead(rainSensor);
int testldrval = analogRead(testldr);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
long duration = pulseIn(echoPin, HIGH);
long distance = (duration / 2) / 29.1;
if (mainldrReading == 0) {
digitalWrite(LIGHT1, LOW);
digitalWrite(LIGHT2, LOW);
Serial.println("Day detected!");
Blynk.virtualWrite(V2, mainldrReading);
String s1 = "Day detected!";
Blynk.virtualWrite(V3, s1);
Blynk.virtualWrite(V4, testldrval);
} else if (mainldrReading == 1 && rainSensorValue < 850) {
Serial.println("It's raining and night detected ");
Serial.print("Rain sensor readings:");
Serial.println(rainSensorValue);
digitalWrite(LIGHT1, HIGH);
digitalWrite(LIGHT2, HIGH);
if (testldrval > 1000) {
Serial.println("Faulty Light");
Blynk.virtualWrite(V3, s5);
tone(buzz, 1000);
delay(1000);
}
Blynk.virtualWrite(V1, rainSensorValue);
Blynk.virtualWrite(V2, mainldrReading);
String s2 = "It's raining and night detected";
Blynk.virtualWrite(V3, s2);
Blynk.virtualWrite(V4, testldrval);
} else if (mainldrReading == 1 && distance <= 15) {
Serial.println("Motion and night detected! ");
digitalWrite(LIGHT1, HIGH);
digitalWrite(LIGHT2, HIGH);
Blynk.virtualWrite(V0, distance);
Blynk.virtualWrite(V2, mainldrReading);
String s3 = "Motion and night detected! ";
if (testldrval > 1000) {
Serial.println("Faulty Light");
Blynk.virtualWrite(V3, s5);
tone(buzz, 1000);
delay(1000);
}
Blynk.virtualWrite(V3, s3);
Blynk.virtualWrite(V4, testldrval);
} else {
analogWrite(LIGHT1, brightness / 6);
analogWrite(LIGHT2, brightness / 6);
Serial.println("Night detected!");
String s4 = "Night detected";
if (testldrval > 1000) {
Serial.println("Faulty Light");
Blynk.virtualWrite(V3, s5);
tone(buzz, 1000);
delay(1000);
}
Blynk.virtualWrite(V3, s4);
Blynk.virtualWrite(V2, mainldrReading);
Blynk.virtualWrite(V4, testldrval);
}
}
BLYNK_WRITE(V5) {
int value = param.asInt();
Serial.print("Button Value: ");
Serial.println(value); // Print the value to the serial monitor for debugging
if (value == 1) {
digitalWrite(LIGHT1, HIGH); // Turn the LED ON
Serial.println("LED turned ON");
} else {
digitalWrite(LIGHT1, LOW); // Turn the LED OFF
Serial.println("LED turned OFF");
}
}
void loop() {
Blynk.run();
timer.run();
}
``
Serial monitor output:
16:49:24.416 -> [678] Connecting to Name
16:49:37.448 -> [13710] AT vession:1.2.0.0(Jul 1 2016 20:04:45)
16:49:37.482 -> SDK version:1.5.4.1(39cb2
16:49:43.567 -> [19818] +CIFSR:STAIP,"192.168.223.201"
16:49:43.602 -> +CIFSR:STAMAC,"c8:c9:a3:b8:5c:81"
16:49:43.628 -> [19830] Connected to WiFi
16:49:49.015 -> [25263] Ready (ping: 17ms).
16:50:24.579 -> [60840] Ready (ping: 53ms).
16:51:00.064 -> [96320] Ready (ping: 11ms).
16:52:01.212 -> [157441] Ready (ping: 12ms).
16:53:12.375 -> [228587] Ready (ping: 11ms).
16:53:37.959 -> [254183] Ready (ping: 11ms).
It displays 'Ready' message when the system is shown as online on blynk. I have cross checked wifi connectivity and template details. How can I solve this?