Blynk.virtualWrite Error -> Login Timeout

Hello,

A new user here…having a blast with Arduino and Blynk…but also not without some noob frustrations. Having some trouble trying to do a simple data push from Andruino Uno to a virtual display on the Blynk App.
Using Blynk 0.4.6.
Arduino Uno R3 with ESP8266-01 (on version 1.1 and set baud rate to 9600)

Her is my code:

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#define BLYNK_DEBUG // Optional, this enables lots of prints
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <SimpleTimer.h>
#include <NewPing.h>

//constants to set pin numbers
const int wifiConnectedLED = 8;     // the number of LED pin

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

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

//LED variables
int wifiLEDState = 0;  //variable for reading LED pin status

//UltraSonic Sensor Variables
#define TRIGGER_PIN  7  // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN     11  // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 400 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
int distance;
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.

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

// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600

ESP8266 wifi(&EspSerial);

SimpleTimer timerCheckConnectionStatus;
SimpleTimer timerDistancePing;

void setup()
{
  // Set console baud rate  
  Serial.begin(9600);
  delay(10);
  
  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);

  //init LED pin 8
  pinMode(wifiConnectedLED, OUTPUT);
    
  //connect to blynk servers via wifi - easy way
  Serial.println("connecting to Blynk...");
  Blynk.begin(auth, wifi, ssid, pass); 

  //set timer interval and function to call for Connection Status LED
  Serial.println("Init App LED timer");
  timerCheckConnectionStatus.setInterval(3000L, blinkConnectedBoardLed);
  Serial.println("App LED timer Initialized");

  //set timer interval and function to call for Distance Ping for UltraSonic Sensor
  Serial.println("Init Ultra Sonic ping timer");
  timerDistancePing.setInterval(3500L, getDistanceTimerFunction);
  Serial.println("App Ultra Sonic ping timer Initialized");
}

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

//Check if blynk is connected and set board led accordingly.
void getDistanceTimerFunction()
{
  //unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).
  //distance = uS / US_ROUNDTRIP_IN / 12; // Convert ping time to distance and print result (0 = outside set distance range, no ping echo)
  //Serial.print("Ping: ");
  //Serial.print(uS / US_ROUNDTRIP_IN / 12); 
  //Serial.println("FT");
  **Blynk.virtualWrite(V3, millis() / 1000);**
}

If I comment out the last line Blynk.virtualWrite(V3, millis() / 1000); and uncomment all the other lines above it in that function, everything works as expected. But as soon as I uncomment the line Blynk.virtualWrite(V3, millis() / 1000);, Blynk is reporting Login timeout errors.

On my app project, I have a Virtual Display. The input is set to V3. The min and max values are 0, 1023 respectively, and the Read Rate is set to PUSH.

Serial Monitor Output:
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ / '/
/
//_, /////_
/
__/ v0.4.6 on Arduino Uno

[129] Free RAM: 565
[649] Connecting to 8675309_ofc
[3835] AT version:1.1.0.0(May 11 2016 18:09:56)
SDK version:1.5.4(baaeaebb)
Ai-Thinker Technology Co. Ltd.
Jun 13 2016 11:29:20
OK
[11136] 
[11137] Connected to WiFi
[21356] <[02|00|01|00] <auth token here>
[21558] >[00|00|01|00|C8]
[21558] Ready (ping: 24ms).
[21559] <[11|00|01|00]fver[00]0.4.6[00]h-beat[00]10[00]buff-in[00]256[00]dev
[31718] Cmd error
[31763] Login timeout
[47000] <[02|00|01|00] <auth token here>
[47201] >[00|00|01|00|C8]
[47201] Ready (ping: 24ms).
[47202] <[11|00|02|00]fver[00]0.4.6[00]h-beat[00]10[00]buff-in[00]256[00]dev
[57362] Cmd error
[57407] Login timeout
[72647] <[02|00|01|00] <auth token here>
[72858] >[00|00|01|00|C8]
[72858] Ready (ping: 24ms).
[72859] <[11|00|03|00]fver[00]0.4.6[00]h-beat[00]10[00]buff-in[00]256[00]dev
[83020] Cmd error
[83064] Login timeout

this keeps repeating…

Incidentally, a couple of noob questions I could find concrete answers for:

  1. is the first argument for virtualWrite supposed to be an integer (so 3 in this case) or V3?..I’ve seen it both ways in the code examples.
  2. In the app, for the Virtual DIsplay Settings, what are the min and max values (the default is 0 and 1023)…what does that mean, or how do they need to be adjusted?

Thanks in Advance,
Chad

On a first glance, did you replace your Auth token just for posting here or are you actually using that ddddd value?

You need the auth token so that blynk can work properly with your project

This issue is hidden in this debug line

[21559] <[11|00|01|00]fver[00]0.4.6[00]h-beat[00]10[00]buff-in[00]256[00]dev

h-beat = heartbeat

You have code which is blocking Blynk’s heartbeat counter.

Info here on how to fix: http://docs.blynk.cc/#blynk-main-operations-devices-online-status
If you need more info, please search the forums for heartbeat as its been covered loads of times before with similar UNO serial ESP setups.

1 Like

I did just change it for the post and do have a valid auth token. But thanks for looking.

Thanks Jamin, but the assumption that the debug output of [21559] <[11|00|01|00]fver[00]0.4.6[00]h-beat[00]10[00]buff-in[00]256[00]dev means there is a heartbeat counter block seems to be off, as you get the same type of message when the app is working. Furthermore, I do not get an explicit Heartbeat Timeout error reported.

There is a Cmd error line, but it’s not very informative…what command?

And the ONLY thing that makes this sketch go from working to not working is to execute line Blynk.virtualWrite(V3, millis() / 1000);. So it doesn’t seem there is some code that is blocking the heartbeat except this line, which is being called correctly, from what I can tell.

And I did search for Uno + Heartbeat and it only came up with a few results and there was no consistent theme or solution that I could determine.

I just tried the example, and it works, so starting with that and building up the sketch from there to see what breaks it and will report back.

1 Like

Thanks for posting this. I encountered this in my latest Uno project to build a WiFi-to-IR translator to emulate a NEC remote control.
Mike S.