I’m using an Arduino Nano with an ESP-01. I created a QuickStart script using Blynk’s online generator. Here’s the sequence of relevant events that I’ve been able to verify:
- Code loads to Nano
-
setup()
is executed -
Blynk.begin()
is executed - ESP-01 connects to WiFi
- Blynk console (browser) shows Online
- 11 seconds pass
- Blynk console shows Offline
-
setup()
is executed again - repeat steps 3-7
I’ve put in a few println("argh *[X]* ")
to help track down where the problem is occurring.
WARNING!
It's very tricky to get it working. Please read this article:
http://help.blynk.cc/hardware-and-libraries/arduino/esp8266-with-at-firmware
This is a simple demo of sending and receiving some data.
Be sure to check out other examples!
*************************************************************/
// Template ID, Device Name and Auth Token are provided by the Blynk.Cloud
// See the Device Info tab, or Template settings
#define BLYNK_TEMPLATE_ID " *[the template ID]* "
#define BLYNK_DEVICE_NAME "Quickstart Device"
#define BLYNK_AUTH_TOKEN " *[the auth token]* "
// Comment this out to disable prints and save space
#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
char auth[] = BLYNK_AUTH_TOKEN;
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = " *[the wifi router]* ";
char pass[] = " *[the wifi password]* ";
// 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 9600
ESP8266 wifi(&EspSerial);
BlynkTimer timer;
// This function is called every time the Virtual Pin 0 state changes
BLYNK_WRITE(V0)
{
// Set incoming value from pin V0 to a variable
int value = param.asInt();
// Update state
Blynk.virtualWrite(V1, value);
}
// This function is called every time the device is connected to the Blynk.Cloud
BLYNK_CONNECTED()
{
// Change Web Link Button message to "Congratulations!"
Blynk.setProperty(V3, "offImageUrl", "https://static-image.nyc3.cdn.digitaloceanspaces.com/general/fte/congratulations.png");
Blynk.setProperty(V3, "onImageUrl", "https://static-image.nyc3.cdn.digitaloceanspaces.com/general/fte/congratulations_pressed.png");
Blynk.setProperty(V3, "url", "https://docs.blynk.io/en/getting-started/what-do-i-need-to-blynk/how-quickstart-device-was-made");
}
// This function sends Arduino's uptime every second to Virtual Pin 2.
void myTimerEvent()
{
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V2, millis() / 1000);
}
void setup()
{
// Debug console
Serial.begin(115200);
Serial.println("argh");
// Set ESP8266 baud rate
EspSerial.begin(ESP8266_BAUD);
delay(10);
Serial.println("argh2");
Blynk.begin(auth, wifi, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, wifi, ssid, pass, "blynk.cloud", 80);
//Blynk.begin(auth, wifi, ssid, pass, IPAddress(192,168,1,100), 8080);
Serial.println("argh3");
// Setup a function to be called every second
timer.setInterval(1000L, myTimerEvent);
}
void loop()
{
Serial.println("ugh");
Blynk.run();
Serial.println("blynk");
timer.run();
Serial.println("timer");
// You can inject your own code or combine it with other sketches.
// Check other examples on how to communicate with Blynk. Remember
// to avoid delay() function!
}
Here are the messages that are output to Serial Monitor.
08:37:30.607 -> argh
08:37:30.607 -> argh2
08:37:30.607 -> [10]
08:37:30.607 -> ___ __ __
08:37:30.607 -> / _ )/ /_ _____ / /__
08:37:30.607 -> / _ / / // / _ \/ '_/
08:37:30.607 -> /____/_/\_, /_//_/_/\_\
08:37:30.607 -> /___/ v1.0.1 on Arduino Nano
08:37:30.607 ->
08:37:31.106 -> [518] Connecting to *[the wifi router]*
08:37:34.297 -> [3712] AT version:1.2.0.0(Jul 1 2016 20:04:45)
08:37:34.297 -> SDK version:1.5.4.1(39cb9a32)
08:37:34.297 -> v1.0.0
08:37:34.297 -> Mar 11 2018 18:27:31
08:37:34.332 -> OK
08:37:44.463 -> [13846] Failed to connect WiFi
08:37:54.782 -> [24192] Ready (ping: 24ms).
08:38:04.017 -> argh
08:38:04.053 -> argh2
08:38:04.053 -> [10]
08:38:04.053 -> ___ __ __
08:38:04.053 -> / _ )/ /_ _____ / /__
08:38:04.053 -> / _ / / // / _ \/ '_/
08:38:04.053 -> /____/_/\_, /_//_/_/\_\
08:38:04.053 -> /___/ v1.0.1 on Arduino Nano
08:38:04.053 ->
08:38:04.538 -> [518] Connecting to *[the wifi router]*
08:38:05.575 -> [1534] ESP is not responding
08:38:15.909 -> [11878] Ready (ping: 25ms).
08:38:26.307 -> argh
08:38:26.341 -> argh2
08:38:26.341 -> [11]
08:38:26.341 -> ___ __ __
08:38:26.341 -> / _ )/ /_ _____ / /__
08:38:26.341 -> / _ / / // / _ \/ '_/
08:38:26.341 -> /____/_/\_, /_//_/_/\_\
08:38:26.341 -> /___/ v1.0.1 on Arduino Nano
08:38:26.341 ->
08:38:26.834 -> [519] Connecting to *[the wifi router]*
08:38:27.848 -> [1533] ESP is not responding
08:38:38.200 -> [11883] Ready (ping: 25ms).
[repeat]
Edit to add this link to the diagram of my hardware configuration from this post.