Hi,
I’m attempting to get an ESP8266-01 working as a WiFi shield with an Arduino Uno and Blynk but having very little success, could use the guidance from folks here. Setup is similar to here. I’m using the latest version of the AT firmware 1.6.2.0 on the ESP8266-01.
Good news is the same setup already works reliably to upload data to Thingspeak via the WiFiEsp.h library. However I can’t seem to get it to work reliably at all for Blynk. Frankly I’d rather use the WiFiEsp library as it seems more reliable but Blynk insists in managing it’s own connection from most examples I’ve seen. This is based on the standard Blynk example for this setup here and should work, but it doesn’t.
Core of the problem seems to be my AP takes a few tries to connect (sometimes 30-45s) and Blynk seems to time out quite quickly and not retry and fails in the getLocalIP routine in ESP8266.cpp. I’ve tried to pre-connect with the WiFiEsp routines which succeeds as seen below, but it fails thereafter anyhow.
I’ve tried using Blynk.config() routine instead but it does not seem to compile with BlynkSimpleShieldEsp8266.h and ESP8266_Lib.h as seen by the comment below. Is an additional library needed here?
Here is the typical serial debug output:
Connecting to:things
[WiFiEsp] Initializing ESP module
[WiFiEsp] Initilization successful - 2.2.1
[WiFiEsp] Failed connecting to things
[WiFiEsp] Failed connecting to things
[WiFiEsp] Failed connecting to things
[WiFiEsp] Failed connecting to things
[WiFiEsp] Failed connecting to things
[WiFiEsp] Failed connecting to things
[WiFiEsp] Connected to things
Connected!
[132557]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ \/ '_/
/____/_/\_, /_//_/_/\_\
/___/ v0.6.1 on Arduino Uno
[132653] Connecting to things
[135901] AT version:1.6.2.0(Apr 13 2018 11:10:59)
SDK version:2.2.1(6ab97e9)
compile time:Jun 7 2018 19:34:26
Bin version(Wroom 02):1.6.2
OK
[146608] Failed to connect WiFi
Here is the short test code I’ve been using to debug the issue resulting in the above output. SSID, password and auth codes are in Settings.h (not shown).
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include "Settings.h"
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
//#include <BlynkSimpleStream.h> // For Serial communications with Blynk
#include <WiFiEsp.h> // Include support for ESP8266-01 WiFi module
#include <avr/pgmspace.h>
int status = WL_IDLE_STATUS; // the Wifi radio's status
WiFiEspClient client; // Initialize the Wifi client library
// Software Serial on Uno, Nano...
#include <SoftwareSerial.h>
SoftwareSerial Serial1(5, 4); // RX, TX
// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600
// Hardware Serial on Mega, Leonardo, Micro...
#define EspSerial Serial1
ESP8266 wifi(&EspSerial); //Blynk use
//BlynkTimer timer; // Uses lots of SRAM on Uno!!!
void setup()
{
char ssidbuff[strlen_P(ssid) + 1]; // buffer for ssid
char pwdbuff[strlen_P(pwd) + 1]; // buffer for pwd
char authbuff[strlen_P(auth) + 1];
strcpy_P(ssidbuff, ssid);
strcpy_P(pwdbuff, pwd);
strcpy_P(authbuff, auth);
// Debug console
Serial.begin(9600);
delay(100);
Serial.print(F("Connecting to:"));
Serial.println(ssidbuff);
Serial1.begin(9600); // Init ESP Serial link
WiFi.init(&Serial1);
delay(100);
while (status != WL_CONNECTED) { // attempt to connect to WiFi network
status = WiFi.begin(ssidbuff,pwdbuff); // connect to WPA/WPA2 network
delay(3000);
}
Serial.println(F("Connected!"));
// Set ESP8266 baud rate
EspSerial.begin(ESP8266_BAUD);
delay(100);
//Blynk.begin(Serial1, auth); // Does not work
Blynk.begin(authbuff, wifi, ssidbuff, pwdbuff);
//Blynk.config(authbuff, "blynk-cloud.com", 8442); // Does not compile!
Blynk.connect();
delay(100);
Serial.println(F("Blynk connected!"));
}
void loop()
{
Blynk.run();
Blynk.virtualWrite(V0, millis() / 1000);
Serial.print(F("."));
delay(5000);
}
I should have mentioned that I’ve tried numerous times without the WiFiEsp.h calls, but it never connect there either. In any case I need data uploaded to Thingspeak, so they will need to stay, with Blynk as an addition.
Any help much appreciated. Thanks