No. Actualy local network connection almost instant. Blynk connection takes 5secs.
Current setup sketch:
Serial.println("Connecting to local network");
// Setup WiFi network
WiFi.config(ip, gateway, subnet, dns1, dns2);
WiFi.begin(ssid, password, 10, router_mac);
while (WiFi.status() != WL_CONNECTED) {
delay(20);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
// Setup Blynk
Blynk.config(auth, blynk_server_ip);
while (Blynk.connect() == false) {
Serial.print(".");
}
Serial.println("Connected to Blynk server");
And here is the debug output:
Blynk connection takes about 5 seconds.
Connecting to local network
........
Connected to YANIK2
IP address: 192.168.1.77
[425]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ \/ '_/
/____/_/\_, /_//_/_/\_\
/___/ v0.4.3 on ESP8266
[431] Free RAM: 44272
[5001] Connecting to 77.223.144.76
[5058] <[02|00|01|00] APIKEY
[5119] >[00|00|01|00]�
[5119] Ready (ping: 2ms).
[5119] <[11|00|01|00]Gver[00]0.4.3[00]h-beat[00]10[00]buff-in[00]256[00]dev[00]ESP8266[00]build[00]Jan 15 2017 14:58:19[00]
Connected to Blynk server
[5181] >[00|00|01|00]�
This is where connection to server starts.
Yesterday I’ve tried the same with my esp12e and a low power weather station with bme280 and I have your same time results
1 Like
Costas
January 15, 2017, 1:59pm
11
I think you are right but why 5 seconds from showing free RAM to trying to connect to the server?
I found the problem.
This line cause the 5secs delay:
} else if (state == CONNECTING) {
#ifdef BLYNK_USE_DIRECT_CONNECT
if (!tconn)
conn.connect();
#else
if (tconn && (t - lastLogin > BLYNK_TIMEOUT_MS)) {
BLYNK_LOG1(BLYNK_F("Login timeout"));
conn.disconnect();
state = CONNECTING;
return false;
} else if (!tconn && (t - lastLogin > 5000UL)) {
conn.disconnect();
if (!conn.connect()) {
lastLogin = t;
return false;
}
#ifdef BLYNK_MSG_LIMIT
deltaCmd = 1000;
#endif
sendCmd(BLYNK_CMD_LOGIN, 1, authkey, strlen(authkey));
If I change 5000UL to 1000UL delay reducing to 1sec.
5 Likes
Costas
January 15, 2017, 2:10pm
13
@hamityanik nice hack, set mine to 500 so about 550ms to 650ms to connect to the server from reboot.
[301]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ \/ '_/
/____/_/\_, /_//_/_/\_\
/___/ v0.4.4 on ESP8266
[501] Connecting to 192.168.10.229
[625] Ready (ping: 8ms).
Connected to Blynk server
I’ve added
lastLogin = 99999;
after this line, and problem gone. (at least for now )
}
void sendCmd(uint8_t cmd, uint16_t id = 0, const void* data = NULL, size_t length = 0, const void* data2 = NULL, size_t length2 = 0);
private:
int readHeader(BlynkHeader& hdr);
uint16_t getNextMsgId();
protected:
void begin(const char* auth) {
this->authkey = auth;
#if defined(BLYNK_NO_FANCY_LOGO)
BLYNK_LOG1(BLYNK_F("Blynk v" BLYNK_VERSION " on " BLYNK_INFO_DEVICE));
#elif defined(BLYNK_FANCY_LOGO_3D)
BLYNK_LOG1(BLYNK_F("\n"
" ____ ___ __\n"
" /\\ _`\\ /\\_ \\ /\\ \\ _\n"
" \\ \\ \\_\\ \\\\//\\ \\ __ __ ___ \\ \\ \\/ \\\n"
" \\ \\ _ < \\ \\ \\ /\\ \\/\\ \\ /' _ `\\\\ \\ , <\n"
" \\ \\ \\_\\ \\ \\_\\ \\_\\ \\ \\_\\ \\ /\\ \\/\\ \\\\ \\ \\\\`\\\n"
It will be like this:
this->authkey = auth; lastLogin = 99999;
5 Likes
Fantastic work investigating this @hamityanik
1 Like
Dmitriy
January 15, 2017, 9:34pm
16
@vshymanskyy please explain purpose of this 5000L
delay.
1 Like
Yes we limit reconnection time - minimum 5 seconds delay.
for what purpose?
is it OK for Local Server user to bypass this delay?
Yes, you can modify the library as you want.
1 Like
psoro
January 16, 2017, 11:15am
20
@vshymanskyy ,
Are there other tricks like this one for Local Server to do it even better?
Thanks!!
can be possible to convert this reconnection time with an “antiflood like” system?
'cause a battery powered system need 1 connection at xx minutes to make a low energy purpose, instead of a “normal” system that turn on and stay on…
Battery powered systems are recommended to use our HTTP API
3 Likes
I’ve written another code for my project, it uses HTTP API but, I think there is no way to update “last seen” section via HTTP API. Device seems always offline. Is there anyway?
@Dmitriy , check this out…
1 Like