I wanted to connect to a server using Arduino Uno and an ESP-01 with an adapter that converts it into 4 pins (GND, VCC, TX, RX). It connects to the internet and even to the service itself, and the website shows it as being in “online” mode. I connected it using the quick start guide, where uptime is displayed. However, it connects and immediately disconnects, and the uptime value remains 0
/*************************************************************
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
You’ll need:
- Blynk IoT app (download from App Store or Google Play)
- Arduino Uno board
- Decide how to connect to Blynk
(USB, Ethernet, Wi-Fi, Bluetooth, ...)
There is a bunch of great example sketches included to show you how to get
started. Think of them as LEGO bricks and combine them as you wish.
For example, take the Ethernet Shield sketch and combine it with the
Servo example, or choose a USB sketch and add a code from SendData
example.
*************************************************************/
/* Fill-in information from Blynk Device Info here */
#define BLYNK_TEMPLATE_ID "XXX"
#define BLYNK_TEMPLATE_NAME "XXX"
#define BLYNK_AUTH_TOKEN "XXX"
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "XXX";
char pass[] = "XXX";
// Hardware Serial on Mega, Leonardo, Micro...
#define EspSerial Serial1
// or Software Serial on Uno, Nano...
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // TX, RX
// Your ESP8266 baud rate:
#define ESP8266_BAUD 57600
ESP8266 wifi(&EspSerial);
void setup()
{
// Debug console
Serial.begin(57600); // Serial Monitor at 57600 baud
// Set ESP8266 baud rate
EspSerial.begin(ESP8266_BAUD); // Set ESP baud rate to 57600
delay(10);
Blynk.begin(BLYNK_AUTH_TOKEN, wifi, ssid, pass);
// Handle AT commands from Serial Monitor
Serial.println("Ready to accept AT commands...");
}
void loop()
{
Blynk.run(); // Handle Blynk functions
// Check if data is available from Serial Monitor (Arduino)
if (Serial.available()) {
// Read data from Serial Monitor
String command = Serial.readString();
// Send the command to ESP8266
EspSerial.println(command);
}
// Check if data is available from ESP8266 (AT commands response)
if (EspSerial.available()) {
// Read data from ESP8266 and send it to Serial Monitor (Arduino)
String response = EspSerial.readString();
Serial.print(response); // Output the ESP response to Serial Monitor
}
}