hey,
I use Arduino Mega with esp8266 connected through serial I included all the required libraries and tested them with the test example in Blynk library it showed no error. but when i try to run blink example it shows nothing about connecting to server, it connect to WiFi but not to the Blynk server (not local server but the Blynk cloud server). my android app shows the message “wasn’t online yet”. i checked the token its written correctly here is my arduino code:
This is my base starter sketch for my Arduino Mega with ESP-01
//#define BLYNK_DEBUG // Advanced diagnostic data... also drastically slows entire sketch
#define BLYNK_PRINT Serial // This prints to Serial Monitor
#define BLYNK_USE_128_VPINS
#include <ESP8266_Lib.h> // For ESP-01 Link
#include <BlynkSimpleShieldEsp8266.h> // For ESP-01 Link
ESP8266 wifi(&Serial1); // Pins 18 & 19 on MEGA - For ESP-01 link
BlynkTimer timer;
#define HTB 13 // Set HeartBeat LED pin.
char auth[] = "xxxxxxxxxx"; // Local Server
char ssid[] = "xxxxx";
char pass[] = "xxxxx";
char server[] = "xxx.xxx.xxx.xxx"; // Local Server
// char server[] = "blynk-cloud.com"; // Cloud Server
int port = 8080;
void setup() {
pinMode(HTB, OUTPUT); // Setup HeartBeat pin
Serial.begin(115200); // BLYNK_PRINT data - For Serial Monitor
Serial1.begin(115200); // Set baud rate - For ESP-01 link
wifi.setDHCP(1, 1, 1); //Enable dhcp in station mode and save in flash of esp8266
Blynk.config(wifi, auth, server, port);
if (Blynk.connectWiFi(ssid, pass)) {
Blynk.connect();
}
// Timed Lambda Function - UpTime counter
timer.setInterval(1000L, []() { // Run every second
Blynk.virtualWrite(V127, millis() / 1000); // Display the UpTime in Seconds
}); // END Lambda Function
}
void loop() {
timer.run();
digitalWrite(HTB, !digitalRead(HTB)); // Flash HeartBeat LED every loop() cycle
if (Blynk.connected()) { // If connected run as normal
Blynk.run();
} else {
Blynk.connect(); // Try to reconnect to the server
}
}
I’ll try the code with some edits to fit my needs and let you know the results. Do you think blynk cloud server has limited access or no access at all for some regains in the world ? I’m from Iraq. maybe this is why I can’t connect to the server. Again thanx a lot for your time.
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ \/ '_/
/____/_/\_, /_//_/_/\_\
/___/ v0.5.4 on Arduino Mega
[583] Connecting to XXXXXXX
[3635] WIFI GOT IP
AT version:1.7.0.0(Aug 16 2018 00:57:04)
SDK version:3.0.0(d49923c)
compile time:Aug 23 2018 16:58:12
Bin version(Wroom 02):v1.7.0
OK
[10676] +CIFSR:STAIP,"192.168.16.104"
+CIFSR:STAMAC,"68:c6:3a:a7:42:d3"
[10677] Connected to WiFi
[22531] Ready (ping: 17ms).
[124471] Ready (ping: 17ms).
[156400] Ready (ping: 1856ms).
I think the problem was the connection to the server is interrupted due to bad Internet connection so, we must see if it’s connected to the server if not then connect again. and we must repeat it in the loop. As your code here:
if (Blynk.connected()) {
Blynk.run();
} else {
Blynk.connect();
}
Not like the the example included in the library which run like this:
It is just an example and assumes a solid connection. As for my reconnection method, it is just one way of doing it, thus left for others to find what works for them.