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
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;
}```