Hello, first of all, I am new to programming and I had also tried for a week to solve this problem. In addition, english is not my native language, so I am really sorry for my bad english.
I am working on a project, but there are several problem occurred. The first problem is how to indicate the WiFi connection status, not Blynk.connected()
status. I had read many topics regarding this issue but there are no solution for my problem because all the solution is using #include <ESP8266WiFi.h>
library. Here is the story…
I am using WEMOS ATMega2560 with an embedded esp8266 WiFi chip on it. Here is the link of the board " https://opencircuit.shop/Product/MEGA-plus-WiFi-R3-ATmega2560-plus-ESP8266. ".
By following the instructions on how to configure the board from this youtube link " https://www.youtube.com/watch?v=i6dPyuWtdpU&t=335s ", the #include <library.h>
code used from the youtube tutorial is #include <ESP8266_Lib.h>
. Not #include <ESP8266WiFi.h>
. Board selected on Arduino IDE is Arduino Mega. Therefore, if I #include <ESP8266WiFi.h>
, there are errors, library not found since the #include <ESP8266WiFi.h>
only available if i compile using ESP8266 board.
So, this code while (WiFi.status() != WL_CONNECTED)
is not workable when I used #include <ESP8266_Lib.h>
. I guess it need #include <ESP8266WiFi.h>
… correct me if i’m wrong. The idea behind this problem is, I want to make 2 indicators which indicates the connection of the board to the router, and the connection with the blynk… So, what can I do now when to indicate the wifi status ??
The 2nd problem. Same project, but this problem happen when I’m doing void connection_check()
for every 5 seconds interval. Look at my snipped code first.
void loop(){
timer.run();
Blynk.run();
if ( Serial3.available() ) { //
Serial.write( Serial3.read() );} //
// I dont know, I just followed youtube code
if ( Serial.available() ) { //
Serial3.write( Serial.read() );} //
}
void connection_check(){
if(Blynk.connected() == true){
digitalWrite(blynk_connect_pin, HIGH);
digitalWrite(blynk_disconnect_pin, LOW);
Blynk.run();
Serial.println("Blynk Connected");}
if(Blynk.connected() == false){
Serial.println("Reconnecting...");
digitalWrite(blynk_connect_pin, LOW);
digitalWrite(blynk_disconnect_pin, HIGH);
Blynk.connect();
}
}
There are 2 Blynk.run()
in the code. 1 is inside void loop()
and the other is when if (Blynk.connected() == true) "
. Why I did this ?? because, if I erase the Blynk.run()
at void loop, some alien language appeared in the serial. I’m sure it is not about the baud rate… here is the serial monitor output… But, i wanted to run Blynk.run()
whenever blynk is connected
Blynk Connected
Blynk Connected
Blynk Connected
+IPD,1,5 //(alien symbol)
Reconnecting...
Blynk Connected
Blynk Connected
after 3 to 4 times void connection_check()
… blynk will always disconnect and trying to reconnect… however, it does reconnect… but it disconnect again after several void connection_check()
…
If i put Blynk.run()
inside void loop()
. it works fine. What am i missing here ? Please help and teach me… Here is the full code… THANKS IN ADVANCE
Regards, Hamdan
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
char auth[] = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
char ssid[] = "MyWiFi";
char pass[] = "MyWiFi12345";
BlynkTimer timer; // Blynk timer library
#define EspSerial Serial3
#define ESP8266_BAUD 115200
ESP8266 wifi(&EspSerial);
#define blynk_connect_pin 3 // green led connected indicator
#define blynk_disconnect_pin 2 // red led disconnected indicator
void setup() {
Serial.begin(115200); //
Serial3.begin(115200); // I dont know, I just followed youtube code
EspSerial.begin(ESP8266_BAUD); //
pinMode(blynk_connect_pin, OUTPUT);
pinMode(blynk_disconnect_pin, OUTPUT);
Serial.println("Getting Started..."); //
digitalWrite(blynk_connect_pin, HIGH); // both LED indicator on for 2 seconds
digitalWrite(blynk_disconnect_pin, HIGH); //
delay(2000);
digitalWrite(blynk_connect_pin, LOW); //
digitalWrite(blynk_disconnect_pin, LOW); // both LED indicator turn off
delay(1000); //
digitalWrite(blynk_disconnect_pin, HIGH); // after 1 second, disconnect pin turned on
Serial.print("Connecting to: "); //
Serial.println(ssid); //
Blynk.begin(auth, wifi, ssid, pass); //
digitalWrite(blynk_disconnect_pin, LOW); // turning off disconnect led
digitalWrite(blynk_connect_pin, HIGH); // turning on connected led
Serial.println("Connected"); //
delay(1000); //
Serial.println("ALL READY !!!");
timer.setInterval(5000L, connection_check); } // check connection every 10 seconds
void loop(){
timer.run();
Blynk.run();
if ( Serial3.available() ) { //
Serial.write( Serial3.read() );} //
// I dont know, I just followed youtube code
if ( Serial.available() ) { //
Serial3.write( Serial.read() );} //
}
void connection_check(){
if(Blynk.connected() == true){ // if blynk is connected
digitalWrite(blynk_connect_pin, HIGH); // connected led turned on
digitalWrite(blynk_disconnect_pin, LOW); // disconnected led turned off
Blynk.run(); // runs blynk communication
Serial.println("Blynk Connected");} //
if(Blynk.connected() == false){ // if blynk is not connected
Serial.println("Reconnecting..."); //
digitalWrite(blynk_connect_pin, LOW); // connected led turned off
digitalWrite(blynk_disconnect_pin, HIGH); // disconnected led turned on
Blynk.connect(); // trying to connect to led
}
}