Hi there, I am a newbie here.
I am turning LED on and OFF using ESP8266( esp01) wifi module connected with Arduino UNO.
I am getting CMD error after sending multiple requests to the server.
After CMD error it disconnects and without being reset,it cant be connected again!
How do I solve it?
I am using Blynk library 0.5.4
Arduino IDE version 1.8.7
Using the Blynk Server and Blynk android app
Here is the code
#define BLYNK_PRINT Serial
#define BLYNK_DEBUG
int counter = 0;
#include <ESP8266_Lib.h>
//#include<ESP8266WiFi.h>
#include <BlynkSimpleShieldEsp8266.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxx";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Hakunamatata";
char pass[] = "274987079";
// Hardware Serial on Mega, Leonardo, Micro...
#define EspSerial Serial1
// or Software Serial on Uno, Nano...
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // RX, TX
BlynkTimer timer;
// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600
ESP8266 wifi(&EspSerial);
void doTheWork()
{
Blynk.run();
}
void setup()
{
// Debug console
Serial.begin(9600);
timer.setInterval(500L,doTheWork);
// Set ESP8266 baud rate
EspSerial.begin(ESP8266_BAUD);
Blynk.begin(auth, wifi, ssid, pass);
}
void loop()
{
if(Blynk.connected())
{
timer.run();
}
else if(!Blynk.connected())
{
//I am resetting here, because without this error wont go and cant connect again
Blynk.begin(auth, wifi, ssid, pass);
}
}
When using Blynk.begin() don’t worry to much about re-connection routines until you have better understanding… then look here and at the Documentation about Blynk.config()
Otherwise… just keep a basic void loop()
void loop() {
Blynk.run(); // needed here for Blynk stuff... can be excluded (via logic check) if connection fails, in-order to expedite non connected functionality until re-connection occurs.
timer.run(); // needed here for timers (if used)... never exclude! (if using timers)
}
I have added a button on Blynk app for controlling the D6 pin on arduino. Blynk.run() is taking care of all the things. i.e reading data from server and updating the same on arduino pins.
I all you are doing is using Blynk and App in direct pin control (AKA no virtual pins) then just stick with the Blynk Blink sketch without modifying all the needed stuff.
If however you want to learn how to program more advanced things, then keep reading the Docs and Help Center on how to do it properly.
CMD error (aka bad command, no sprechen Sie binary, wait? what?.. etc. ) may be due to a bad network, possibly even a glitch Serial connection between your Arduino and ESP … who knows.