I am new to Blynk, but I have been using Aduino for a few years.
I am using a WeMos D1 mini Pro programmed with the Arduino IDE version 1.6.12 running on a thinkpad laptop T420 with linux Manjaro (just to give you some context).
I downloaded the sample program BlynkPushData.ino from your website, which runs with no apparent problems.
I then added some extra virtual pins, and observed some intermittent gaps in the transmission. So I added some Serial.print() statements and some variables to track what was going on.
With this version using 4 virtual pins, my success rate in pushing data to Blynk-cloud seems to be about 50%, sometimes worse.
Also the time taken for Blynk.begin() can be very long - I have seen over 4 minutes before it returns.
I will attach my code, which I regard as being non-contentious modifications of yours; and a text file which is the result of capturing the Serial.print() output. I have several more such files if they will help.
As near as I can tell by eye, when the “connected” flag is True, I get to see the value on my mobile phone; and when it is False, there is no update of the value on my mobile phone.
My questions are:
a) is there something I am doing wrong, that is causing this intermittent connection?
b) If I am not doing something wrong, is there something I can do to improved the performance (I have tried using Blynk.connect() and will explore that further unless you advise me otherwise).
c) can you explain the multi-minute response time for Blynk.begin()?
Thank you in advance.
I can’t see how to attach files, so I will just paste them in line:
Here is my code, which I have called BlynkPushDataV2.ino:
I have edited out my authorisation code and my WiFi password. I doubt if you need them.
/*************************************************************
Download latest Blynk library here:
https://github.com/blynkkk/blynk-library/releases/latest
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Follow us: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
This example shows how value can be pushed from Arduino to
the Blynk App.
NOTE:
BlynkTimer provides SimpleTimer functionality:
http://playground.arduino.cc/Code/SimpleTimer
App project setup:
Value Display widget attached to Virtual Pin V5
*************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "8xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "tanderra";
char pass[] = "xxxxxxxxxx";
long cycles = 0;
long notConnectedCount0 =0 ;
long notConnectedCount1 =0;
long notConnectedCount2 =0;
long notConnectedCount3 =0;
BlynkTimer timer;
// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void myTimerEvent()
{
// You can send any value at any time.
// Please don't send more that 10 values per second.
cycles ++;
Serial.println ("\nTimer Event triggered");
Serial.print ("sending millis/1000 to Blynk V0 value=");
Serial.print (millis()/1000%1000);
byte yesConnected = Blynk.connected();
if (yesConnected == 0) notConnectedCount0 ++;
Serial.print (" Blynk connection flag=");
Serial.print (yesConnected);
Serial.print (" millis=");
Serial.println (millis());
Blynk.virtualWrite(V0, millis() / 1000 %1000);
Serial.print ("sending millis/1000+1 to Blynk V1 value=");
Serial.print ((millis()/1000+1)%1000);
yesConnected = Blynk.connected();
if (yesConnected == 0) notConnectedCount1 ++;
Serial.print (" Blynk connection flag=");
Serial.print (yesConnected);
Serial.print (" millis=");
Serial.println (millis());
Blynk.virtualWrite(V1, (millis() / 1000+1) %1000);
Serial.print ("sending millis/1000+2 to Blynk V2 value=");
Serial.print ((millis()/1000+2)%1000);
yesConnected = Blynk.connected();
if (yesConnected == 0) notConnectedCount2 ++;
Serial.print (" Blynk connection flag=");
Serial.print (yesConnected);
Serial.print (" millis=");
Serial.println (millis());
Blynk.virtualWrite(V2, (millis() / 1000+2) %1000);
Serial.print ("sending millis/1000+3 to Blynk V3 value=");
Serial.print ((millis()/1000+3)%1000);
yesConnected = Blynk.connected();
if (yesConnected == 0) notConnectedCount3 ++;
Serial.print (" Blynk connection flag=");
Serial.print (yesConnected);
Serial.print (" millis=");
Serial.println (millis());
Blynk.virtualWrite(V3, (millis() / 1000+3) %1000);
Serial.print ("Not Connected counts = ");
Serial.print (notConnectedCount0);
Serial.print (' ');
Serial.print (notConnectedCount1);
Serial.print (' ');
Serial.print (notConnectedCount2);
Serial.print (' ');
Serial.print (notConnectedCount3);
Serial.print (" cycles = ");
Serial.println (cycles);
}
void setup()
{
// Debug console
Serial.begin(9600);
long beginMillis = millis();
Serial.println ("\nBlynk.begin has started "); // added by KH
Serial.println (beginMillis); // added by KH
Blynk.begin(auth, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);
long beginDuration = millis()-beginMillis;
Serial.print ("\nBlynk.begin has returned after "); // added by KH
Serial.print (beginDuration); // added by KH
Serial.print (" ms. millis="); // added by KH
Serial.println (millis()); // added by KH
// Setup a function to be called every 30 seconds
timer.setInterval(30000L, myTimerEvent); // changed to 30s, KH
} // end of setup()
void loop()
{
Blynk.run();
timer.run(); // Initiates BlynkTimer
}
//*********************************************************************
Now here is my last Serial.print() log file
tail 8
chks:���
Blynk.begin has started
17746
[17746] Connecting to tanderra
[24749] Connected to WiFi
[24749] IP: 192.168.0.100
[24749]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ \/ '_/
/____/_/\_, /_//_/_/\_\
/___/ v0.4.7 on Arduino
[24823] Connecting to blynk-cloud.com:8442
[30470] Ready (ping: 979ms).
[35472] Login timeout
[35472] Connecting to blynk-cloud.com:8442
[41691] Connecting to blynk-cloud.com:8442
[48791] Connecting to blynk-cloud.com:8442
[55865] Connecting to blynk-cloud.com:8442
[62915] Connecting to blynk-cloud.com:8442
[69965] Connecting to blynk-cloud.com:8442
[77014] Connecting to blynk-cloud.com:8442
[84064] Connecting to blynk-cloud.com:8442
[91063] Connecting to blynk-cloud.com:8442
[98063] Connecting to blynk-cloud.com:8442
[105162] Connecting to blynk-cloud.com:8442
[112237] Connecting to blynk-cloud.com:8442
[119286] Connecting to blynk-cloud.com:8442
[126386] Connecting to blynk-cloud.com:8442
[133485] Connecting to blynk-cloud.com:8442
[140560] Connecting to blynk-cloud.com:8442
[147684] Connecting to blynk-cloud.com:8442
[154834] Connecting to blynk-cloud.com:8442
[161884] Connecting to blynk-cloud.com:8442
[168983] Connecting to blynk-cloud.com:8442
[176083] Connecting to blynk-cloud.com:8442
[183207] Connecting to blynk-cloud.com:8442
[190282] Connecting to blynk-cloud.com:8442
[197506] Connecting to blynk-cloud.com:8442
[204606] Connecting to blynk-cloud.com:8442
[211680] Connecting to blynk-cloud.com:8442
[218755] Connecting to blynk-cloud.com:8442
[225854] Connecting to blynk-cloud.com:8442
[232879] Connecting to blynk-cloud.com:8442
[240029] Connecting to blynk-cloud.com:8442
[247103] Connecting to blynk-cloud.com:8442
[254253] Connecting to blynk-cloud.com:8442
[256564] Login timeout
[259564] Connecting to blynk-cloud.com:8442
[266327] Connecting to blynk-cloud.com:8442
[273401] Connecting to blynk-cloud.com:8442
[277249] Login timeout
[280249] Connecting to blynk-cloud.com:8442
[281723] Ready (ping: 1293ms).
Blynk.begin has returned after 265136 ms. millis=282882
[297883] Connecting to blynk-cloud.com:8442
[304600] Connecting to blynk-cloud.com:8442
[311724] Connecting to blynk-cloud.com:8442
Timer Event triggered
sending millis/1000 to Blynk V0 value=318 Blynk connection flag=0 millis=318749
sending millis/1000+1 to Blynk V1 value=319 Blynk connection flag=0 millis=318803
sending millis/1000+2 to Blynk V2 value=320 Blynk connection flag=0 millis=318889
sending millis/1000+3 to Blynk V3 value=321 Blynk connection flag=0 millis=318976
Not Connected counts = 1 1 1 1 cycles = 1
[319030] Connecting to blynk-cloud.com:8442
[325948] Connecting to blynk-cloud.com:8442
[333123] Connecting to blynk-cloud.com:8442
[340222] Connecting to blynk-cloud.com:8442
Timer Event triggered
sending millis/1000 to Blynk V0 value=347 Blynk connection flag=0 millis=347272
sending millis/1000+1 to Blynk V1 value=348 Blynk connection flag=0 millis=347326
sending millis/1000+2 to Blynk V2 value=349 Blynk connection flag=0 millis=347412
sending millis/1000+3 to Blynk V3 value=350 Blynk connection flag=0 millis=347499
Not Connected counts = 2 2 2 2 cycles = 2
[347553] Connecting to blynk-cloud.com:8442
[354471] Connecting to blynk-cloud.com:8442
[361571] Connecting to blynk-cloud.com:8442
[368670] Connecting to blynk-cloud.com:8442
Timer Event triggered
sending millis/1000 to Blynk V0 value=375 Blynk connection flag=0 millis=375820
sending millis/1000+1 to Blynk V1 value=376 Blynk connection flag=0 millis=375874
sending millis/1000+2 to Blynk V2 value=377 Blynk connection flag=0 millis=375961
sending millis/1000+3 to Blynk V3 value=379 Blynk connection flag=0 millis=376047
Not Connected counts = 3 3 3 3 cycles = 3
[376101] Connecting to blynk-cloud.com:8442
[382994] Connecting to blynk-cloud.com:8442
[392269] Login timeout
[395269] Connecting to blynk-cloud.com:8442
[402018] Connecting to blynk-cloud.com:8442
Timer Event triggered
sending millis/1000 to Blynk V0 value=409 Blynk connection flag=0 millis=409043
sending millis/1000+1 to Blynk V1 value=410 Blynk connection flag=0 millis=409097
sending millis/1000+2 to Blynk V2 value=411 Blynk connection flag=0 millis=409183
sending millis/1000+3 to Blynk V3 value=412 Blynk connection flag=0 millis=409270
Not Connected counts = 4 4 4 4 cycles = 4
[409324] Connecting to blynk-cloud.com:8442
[416192] Connecting to blynk-cloud.com:8442
[423292] Connecting to blynk-cloud.com:8442
[424727] Ready (ping: 1130ms).
Timer Event triggered
sending millis/1000 to Blynk V0 value=432 Blynk connection flag=1 millis=432882
sending millis/1000+1 to Blynk V1 value=434 Blynk connection flag=1 millis=433036
sending millis/1000+2 to Blynk V2 value=435 Blynk connection flag=1 millis=433179
sending millis/1000+3 to Blynk V3 value=436 Blynk connection flag=1 millis=433966
Not Connected counts = 4 4 4 4 cycles = 5
Timer Event triggered
sending millis/1000 to Blynk V0 value=462 Blynk connection flag=1 millis=462882
sending millis/1000+1 to Blynk V1 value=466 Blynk connection flag=1 millis=465914
sending millis/1000+2 to Blynk V2 value=468 Blynk connection flag=1 millis=466078
sending millis/1000+3 to Blynk V3 value=469 Blynk connection flag=1 millis=466222
Not Connected counts = 4 4 4 4 cycles = 6
Timer Event triggered
sending millis/1000 to Blynk V0 value=492 Blynk connection flag=1 millis=492882
sending millis/1000+1 to Blynk V1 value=498 Blynk connection flag=0 millis=497884
sending millis/1000+2 to Blynk V2 value=499 Blynk connection flag=0 millis=497915
sending millis/1000+3 to Blynk V3 value=500 Blynk connection flag=0 millis=498001
Not Connected counts = 4 5 5 5 cycles = 7
[498056] Connecting to blynk-cloud.com:8442
[504712] Connecting to blynk-cloud.com:8442
[509181] Login timeout
[512181] Connecting to blynk-cloud.com:8442
[516275] Ready (ping: 1981ms).
Timer Event triggered
sending millis/1000 to Blynk V0 value=522 Blynk connection flag=1 millis=522882
sending millis/1000+1 to Blynk V1 value=525 Blynk connection flag=1 millis=524038
sending millis/1000+2 to Blynk V2 value=527 Blynk connection flag=1 millis=525085
sending millis/1000+3 to Blynk V3 value=533 Blynk connection flag=0 millis=530087
Not Connected counts = 4 5 5 6 cycles = 8
[530090] Connecting to blynk-cloud.com:8442
[534521] Ready (ping: 0ms).
Finally, here is the very last section of a much longer log file sample (formatting is slightly different due to evolution of the code, but no content change)
Timer Event triggered, Blynk connection flag=0 millis=1177232
sending millis/1000 to Blynk V0 value=177
sending millis/1000+1 to Blynk V1 value=178 Blynk connection flag=0 millis=1177288
sending millis/1000+2 to Blynk V2 value=179 Blynk connection flag=0 millis=1177375
sending millis/1000+3 to Blynk V3 value=180 Blynk connection flag=0 millis=1177463
Not Connected counts = 81 89 97 104 cycles = 231