Need help with ESP-01s and Arduino Nano

So you don’t have access to the router, that makes you different to most shield users.

You are supposing DHCP is enabled and that’s a reasonable assumption buy might be something we need to look into.

I want all SM output from a basic sketch as advised by @Gunner (no static IP’s and no IR stuff).

@Nixon, I wonder if you could do the following (as I’m more and more convinced that all this has something to do with your Internet connection - and ISP).
Do you have a possibility to setup Internet sharing from mobile (smart)phone? Then it could give you (and us) a simple answer: If it works with other network setup, or it doesn’t…

2 Likes

Everything you write is Checked

2 Likes

@Nixon worth you trying the suggestion from @marvin7 regarding ISP / router.

Do you use laptops / tablets in addition to smartphones with this ISP?

Do you do anything “special” to connect to the ISP / router or just a regular WiFi connection with PSK etc?

Yes that seems logical,give me a time to make very simple sketch test it with my mobile as AP, and clean serial prints… so i will try that…

only regular connection…i will be back…

And of course use mobile network. Do not use your ISP as a provider for this “test”

Yes ofcourse Marvin7 :slight_smile:

You might have to tweak a few things like SoftSerial pins and of course AUTH & WiFi credentials.

Hopefully I have all the rest correct… I use a MEGA so different config :wink:

//#define BLYNK_DEBUG   // Advanced diagnostic data... also drasticly slows entire sketch
#define BLYNK_PRINT Serial // This prints to Serial Monitor

#include <ESP8266_Lib.h>  // ESP-01 Link
#include <BlynkSimpleShieldEsp8266.h>  // ESP-01 Link

char auth[] = "xxxxx";  // Blynk App Authorization Code.
char ssid[] = "xxxxx";  // WiFi connection
char pass[] = "xxxxx";  // WiFi password
char server[] = "blynk-cloud.com";
int port = 8080;

#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // these are the alternate RX, TX pins used on the Arduino (DON'T use the silk screened RX/TX ones)

// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600

void setup() {
  Serial.begin(9600);  // BLYNK_PRINT data - For Serial Monitor
  EspSerial.begin(9600);  // Set baud rate - For ESP-01 link

  Blynk.begin(auth, wifi, ssid, pass, server, port);  // Connect to Blynk - ESP-01 to Local Server.
}

void loop() {
  Blynk.run();
}

@Gunner, isn’t it 80 for cloud setup?? I’m bit lost with those latest changes…

I think 8080 also works… at least it does for my examples topic posts. and yes, it is all a bit confusing… much to unlearn and the docs & examples need catching up.

I tried forking and editing a Doc once, but it got nuked or something later on? Just not there anymore… so I am avoiding Github before I break something (not that I can… but you never know :wink: )

WOW! I remember filtering through hundreds looking for the right files to upload to my original Thrustmaster FLCS (that’s the stick), TQS (that’s the throttle) and Rudder set(that’s the pedals) for use with EF2000 and Microsoft FlightSim on my PC with a whopping 21 inch monitor.

2 Likes

Here is update and i think i am lost, and that you guys cannot give me straight answer,because if i want you to resolve or how to solve my problem i need to first know where is the problem, and that would be only if i test my setup on couple of different routers and connections on internet.

I tried to connect to my phone as hot spot connected to mobile internet,but the results were non inclusive and erratically different.

I set DHCP on ESP and i managed to connect to my phone lets say 1 time in 5 attempts i tweaked some things in BlynkSimpleShieldEsp8266.h and could connect lets say 1 time in 2 attempts…but connection to blynk server when WiFi to my phone was connected maybe happened 1 time in 10 attempts.

But it did happened.

So i really can not confirm, is the problem in phone,firmware on ESP,or blynk libraries.
So how can you help me?

I do not use blynk.begin for connection because it freezes arduino or reset it. It happens in blynk.begin function in while loop calling checking for connection while(this->connect() != true),i think i understand why this happens,hard to explain, but i’am not sure i can fix it easy in code.

For connecting i call Blynk.config,Blynk.connectWiFi,Blynk.connect to have better control but Blynk.connectWiFi have nasty habit to sometimes freeze the arduino,and sometemes reset it, when it is called 2 times in row, so to avoid that i add transistor switching power of ESP down and back on, and then call functions for connecting…

If i set static IP,gateway,and subnet mask on ESP i still connect to my wifi and blynk server within blink of an aye :slight_smile:

i think i’m lost.

If somebody can test it at home on different router that would or could solve my problem,by detecting where the problem actually is.

Here is my bare bone code:

#define ESP8266_BAUD 9600
#define WI_FI 12 //Esp-01 On/Off 

#if DEBUG
#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG
#endif
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
 
char auth[] = "Blynk token";

char ssid[] = "My SSID";
char pass[] = "My Password";
int btnState = LOW;


#include <SoftwareSerial.h>
SoftwareSerial EspSerial(10, 11); // RX, TX
ESP8266 wifi(&EspSerial);

void setup() {
#if DEBUG
  Serial.begin(9600);
  delay(10);
#endif DEBUG 
    
    pinMode(WI_FI, OUTPUT);
    digitalWrite(WI_FI,HIGH); 
    delay(1000);
    EspSerial.begin(ESP8266_BAUD);

    Serial.println(wifi.setDHCP(1,1,1));//Enable dhcp in station mode and save in flash of esp8266
    //Serial.println(wifi.setStationIp("192.168.1.100","192.168.1.254","255.255.255.0",1));//Enable Static and save in flash of esp8266
}

void loop() {
  
      
       if(CheckConnection()){
          Blynk.run();  
              if (btnState==LOW) btnState=HIGH; else btnState=LOW;
              Blynk.virtualWrite(V2,btnState );
              delay(2000); 
       }
}



bool CheckConnection(){
    if (!Blynk.connected()) {
        // if not connected
        #if DEBUG 
            Serial.println("CheckConnection - Blynk NOT Connected"); 
        #endif
            digitalWrite(WI_FI,LOW); 
            delay(500);
            digitalWrite(WI_FI,HIGH);
            delay(500); 
            Serial.println(wifi.getIPStatus());
            //Serial.println(wifi.setDHCP(1,1,1));//Enable dhcp in station mode and save in flash of esp8266
            Blynk.config(wifi,auth);
            if (Blynk.connectWiFi(ssid, pass)){
                Serial.println(wifi.getIPStatus());
                Blynk.connect();
            }
                  if(!Blynk.connected())
                          return false;
                  
                  else
                          return true;
                  
            
    }
    #if DEBUG 
    Serial.println("CheckConnection - Blynk Connected"); 
    #endif
    return true;        
}```

And this is probably the root of all your “using ESP as shield but trying to act like dedicated ESP” problems… stop trying to run this old farm truck on a racecourse :stuck_out_tongue:

hm…yes…maby i will order bigger esplike node mcu, but iam worried how the rest available free :slight_smile: arduino libraries would work on it…

I would stick with blynk.begin() too for your connection method.

Find another fix for the problem you think blynk.begin() creates, like set Arduino WDT etc.

Most Arduino libraries are fine with an ESP8266.

probably 99%

If not one, then another similar one is always available.

@Nixon, I’d like to try parts of your code, as I was struggling with manual connection handling to ESP shield too… and failed. But in my case the connection is quite stable using default methods (Blynk.begin() with DHCP addressing). It’s just I don’t like this endless waiting in rare cases when (for example) router has power failure That is why I tried it without Blynk.begin(). Strangely enough simple resetting by pulling low RST is sometimes JUST not enough.
Will let you know, but it might be at the end of a week. Unless I gonna find some evening “all free” earlier :slight_smile:

EDIT: Just to be sure (as I recently changed Blynk lib 0.4.8 to 0.5.1), what I’m writing, I made one more test with router “failure”. There had to be some changes to shield handling, as now it reconnects quite quickly!! Anyway will try…

1 Like

@marvin7 I thought someone had provided a sketch for Arduino’s to cope with router power failures with Blynk.

Then I will recheck everything again. My solution is to reset the ESP (which works MOSTLY fine), but will look at everything closer. The problem I had, was that Blynk.disconnect() was not working at all!. Perhaps in 0.5.1 it has changed?
I’m the kind of guy, who mostly READ, rarely ASK for help… :wink:

EDIT: Yes, I’ve found @Gunner’s code. very simple and worth trying too.:

There are few differences to mine (below) :stuck_out_tongue: :

void ConnectBlynk()
{
  display1.setSegments(SEG_WAIT);
  display2.setSegments(SEG_DASH);
  //Blynk.disconnect(); <--- resets MCU?!
  digitalWrite (ESP_RST, LOW);
  delay(100);
  digitalWrite (ESP_RST, HIGH);
  delay(5000);

  Blynk.begin(auth, wifi, ssid, pass, server_ip, port);

  if (!Blynk.connected()) {	//<-- This actually cannot happen, due to Blynk library code
    display1.setSegments(SEG_CONN);
    display2.setSegments(SEG_ERR);
  }
  else {
    display1.setSegments(SEG_CONN);
    display2.setSegments(SEG_GOOD);
    delay(1500);
  }
}
void loop()
{
  Blynk.run();
  timer60.run();

  if (millis() - timer > 6000) {
    timer = millis();
    /* not relevant
    mode *= -1;
    Rh =  (float) Sensor.readFloatHumidity() * 10;
    Tc =  (float) Sensor.readTempC() * 10;
    PMSL = readSealevelPressure(132) / 100;
    display1.displayDec(Tc, false, 4, 3);
    if (mode == 1) display2.displayDec(PMSL, false, 4, 4);
    else display2.displayDec(Rh, false, 3, 4);
    */
    if (!Blynk.connected()) {
      ConnectBlynk();
    }
  }
}