Need help with ESP-01s and Arduino Nano

Yes the default is for an ESP to get all the details automatically even when used as a shield for an Arduino Nano.

Costas - and why mine is not capable to do that?

OR how to make it to do it automaticaly?

At home i use actually 4 esp-01 and my DHCP don’t work very well with us (give IP when he want). I think there are problem with some router.

I see that lots of examples are using ESP8266WiFi.h library but i am missing one, i can’t compile.

So what library is that? Who wrote it,where i canfind it? in Arduino library manager the list is long with diferent ESP8266 libraries, which is the right one?

In reference to Blynk Libraries (seeing how this is a Blynk forum :stuck_out_tongue_winking_eye: ) It depends on what hardware you use, and in what configuration…

http://help.blynk.cc/how-to-connect-different-hardware-with-blynk/arduino/esp8266-standalone

http://help.blynk.cc/how-to-connect-different-hardware-with-blynk/arduino/esp8266-with-at-firmware

I like to pick and chose my hardware and connection type in the Sketch Builder and see that Blynk Libraries are used in the examples.

U did not explain too much…

For example i will try to be more specific, on this link:

How to compile example!??
Costas wrote some code…but i can not compile it, Where,HOW, which library for my setup?
ESP8266 - (ESP-01) - Arduino (Nano)?

I answered the specific question you asked… basically “it depends” :stuck_out_tongue_winking_eye:

That particular example is for ESP as a standalone, using actual Blynk library and code (aka firmware) uploaded on the ESP itself. No Arduino.

But when an ESP is used with AT firmware (not Blynk code, just simple AT command code) then it simply acts as a WiFi to serial adapter for the Arduino… and the Arduino runs the Blynk library and code… but a different Blynk library, one that is not compatible with some of the files required for that example; ESP8266WiFi.h library Blynk.connectWiFi() & Blynk.config() commands, etc.

hehe… so that code in example is impossibe torun in my setup…

Ok… so how i can achieve same result as written in this example?
is there any blynk. methods?

Well, I haven’t been following this topic in detail… so start by telling me exactly what you want to accomplish… using the ESP linked to Arduino.

ok. i will try…

To run Blynk.run(); only when wifi connection is established…
Check if wifi connection is established and if not try to establish it manually (with some timeout).
Check if blynk is connected to cloud…

some methods used there:

Blynk.connectWiFi(ssid, pass);
Blynk.config(auth, server, port);
Blynk.connect() ;
Blynk.connected()

For my Mega and ESP-01, I use the following… It may not be perfect, but it works (I think I got it all here… :slight_smile: … very tired :sleeping: )

char auth[] = "xxxxxxxxxx";
char ssid[] = "xxxxxxxxxx";
char pass[] = "xxxxxxxxxx";
//char server[] = "xxx.xxx.xxx.xxx"; // For Local Server
//Blynk.begin(auth, wifi, ssid, pass, server, 8442);  // For Local Server
Blynk.begin(auth, wifi, ssid, pass, "blynk-cloud.com", 8442);  // For Cloud Server
BLYNK_CONNECTED() {
Blynk.syncAll();  // runs whenever Blynk reconnects to server.
}


void loop()
{
  timer.run();
  if (Blynk.connected()) {
    Blynk.run();
  } else {  // if not connected
    reconnectBlynk();
  }
}


void reconnectBlynk() {
  Blynk.connect(60);  // reconnect to server
  if (Blynk.connected()) {
  } else {
    softReset(); // Should? work with most Arduinos.
  }
}


void softReset() {
  asm volatile ("  jmp 0");  // resets Arduino
}

I also tie my Arduino reset pin to the ESP reset… not sure how much that is required… but I do it.

common reconnection to wifi and blynk server with reseting arduino!??

Arduino is executing main program, its not sollution to reset whole program only to establish connection to Wifi and blynk…is there any better way!?

What do you expect? This whole IoT thing is predated by the basic Arduino by a few years or so :wink:

In AT mode the WiFi portion is just a simple WiFi to Serial adapter hacked onto the Arduino brains, so any “Am I connected? What do I do?” process happens in the Arduino.

Of course… use an ESP as a standalone device :stuck_out_tongue_winking_eye: Full control over the Wifi interface and running sketch.


There is always the possibility of other hacking methods… someone just sent a car into space, so anything is possible with enough effort :smiley: But I suspect you have only the two Blynk based choices as mentioned before…


Nappy time for me… :sleeping:

sory but in copy paste indentitation is lost…btw how to copycodehere with indentation?

Blynk - FTFC

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>

BlynkTimer timer;

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "MyAuth";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "MyNetwork";
char pass[] = "MyPass";


// Hardware Serial on Mega, Leonardo, Micro...
//#define EspSerial Serial1

// or Software Serial on Uno, Nano...
#include <SoftwareSerial.h>
//SoftwareSerial ESPserial(2, 3); // RX | TX
SoftwareSerial EspSerial(2, 3); // RX, TX

// Your ESP8266 baud rate: 115200
#define ESP8266_BAUD 9600

ESP8266 wifi(&EspSerial);
 
void setup()
{  
  // Debug console
  Serial.begin(9600);
  delay(10);

  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);
  
  Blynk.begin(auth, wifi, ssid, pass);
   timer.setInterval(11000L, CheckConnection); // check if still connected every 11s  and reconnect if not
}

void loop()
{
  if(Blynk.connected()){
    Blynk.run();
  }
  timer.run();  
}


void CheckConnection(){
    if (!Blynk.connected()) {
        // if not connected
        if(WiFiStatus())
            Blynk.connect(60);
        else{
            Blynk.connectWiFi(ssid, pass);
            Blynk.connect(5000); 
        }          
     }

}

bool WiFiStatus()
    
{   String response = "";
    EspSerial.print("AT+CIPSTATUS");
    long int time = millis();
    while( (time+2000) > millis())
    {
       if(EspSerial.available()) // check if the esp is sending a message 
          {   
            char c = EspSerial.read(); // read the next character.
            response+=c;
            
          }
    }
  Serial.print(response);  
    if(response.indexOf("STATUS:5")>-1){ Serial.println ("Not Connected -> false");return false;}
    if(response.indexOf("STATUS:2")>-1){ Serial.println ("Connected -> true");return true;}  
}

Does it work??

I don’t think one has any normal access to WiFi control with an ESP in AT mode… which is part of the whole issue.

But I also wonder if processing AT commands, while in script, over the same serial line that Blynk uses for link and communication, will interfere… as it can with USB-link and serial prints to the IDE monitor.

There is at least one more way to reset connection with WIFI without resetting Atmega, which I’m using:

  • I’m checking periodically (in my case 5 sec) blynk.connected()
  • If result is false, then do a hardware reset (RESET pin) on ESP.
  • wait a while, and do an initialization by means of Blynk.begin as usual…

I tried with Blynk.disconnect() but all it did was to crash my Atmega… I see no issue when using another instance of Blynk.begin()

It shouldn’t. I haven’t tried it with Blynk, but many, many days ago (or years now…) I did it with a plain UNO cloe and a BT receiver. No issue on serial comm. But it MIGHT depend on paired Serial companion. BT was working, while ESP doesn’t have to…

No, it doesn’t work as expected…
But the problem is not in AT commands,or part of the code which is sending them,Esp responds on them as expected…

  1. First problem is that Blynk.begin(auth, wifi, ssid, pass); if there is no network available,or router is turned down,or non existing ssid, halts,freaze arduino.

2.Second problem is that Blynk.connectWiFi(ssid, pass); doesn’t work.

I’m trying to make work arround but the problem i encountered is that
compiler dont accept Blynk.config(auth);…

no matching function for call to ‘BlynkWifi::config(const char [33])’

…bla…bla…bla…“candidate expects 4 arguments, 1 provided”

so i looked in BlynkSimpleEsp8266.h and found :

                const char* domain = BLYNK_DEFAULT_DOMAIN,
                uint16_t    port   = BLYNK_DEFAULT_PORT)
    {
        Base::begin(auth);
        this->conn.begin(domain, port);
    }

The right call of function would be :

Blynk.config(wifi,auth, BLYNK_DEFAULT_DOMAIN,BLYNK_DEFAULT_PORT);

So i will try and test it further…