BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Virtual pin value not appearing on App

I am using nodemcu to read battery voltage, send it to Blynk and go into deepsleep for 1 hour. The voltage is read and displayed with serial.printline ok and the app displays ‘Skoda connected’ every 10 seconds(testing time) but nothin displayed in ‘value display’ set for V5, push. I have been searching for about 5 days. I have corrected a couple points in my code but nothing to help this final point. Thanks.

/* 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[] = "**************";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "********";
char pass[] = "*********";
float Volts = 0.0;
    int Sleeptime = 10*1000000;   //microSeconds before next report
void setup()
{
  // defines variables//Battery voltage
    const int BAT = A0;
    float Vread = 0.0;
    float Ratio = 70.42;
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);

    // READ BATTERY VOLTAGE
      Vread = analogRead(BAT);
      Volts = Vread / Ratio;
      Serial.print("Vread: ");
      Serial.println(Vread);
      Serial.print("Volts: ");
      Serial.println(Volts);
      Blynk.run();
      Blynk.virtualWrite(V5, Volts);
}

void loop()
{
   ESP.deepSleep(Sleeptime);
}

[62] Connecting to NET*****
[2566] Connected to WiFi
[2566] IP: 10.0.0.172
[2566]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ / '/
/
//_, /////_
/
__/ v0.6.1 on NodeMCU

[2640] Connecting to blynk-cloud.com:80
[3183] Ready (ping: 251ms).
Vread: 10.00
Volts: 0.14

What happens if you do it like this:

    // READ BATTERY VOLTAGE
      Vread = analogRead(BAT);
      Volts = Vread / Ratio;
      Blynk.virtualWrite(V5, Volts);  // Moved
      Blynk.run();                    // Moved
      Serial.print("Vread: ");
      Serial.println(Vread);
      Serial.print("Volts: ");
      Serial.println(Volts);

Pete.

hi, on the app it’s exactly the same. On the serial monitor, when it 1st rebooted it said
'connecting to network" and nothing after that even though it was running every 10 seconds. I have a lot of trouble connecting from Arduino IDE which I am blaming on the deepsleep mode. Thanks

Which version of the IDE are you using?

You could try adding a delay(100); at the end of void setup.
I suspect that the device is going to sleep before the Blynk.virtualWrite is completed.

You should normally have a delay(2000); after your ESP.deepSleep(Sleeptime); to ensure that the process of going to sleep isn’t interrupted by trying to re-execute the deepsleep command.

Later versions of the IDE allow better re-connection of the serial monitor, which may help.

Also, you should probably avoid using Blynk.begin as it’s a blocking command which will prevent you code going any further if the device can’t connect to WiFi and if you’re running off of a battery then this will drain the battery… Better to use Blynk Config and Blynk Connect, and also to use a static IP address rather than depending on DHCP, as it makes re-connections quicker.

Pete.

@daveblynk, I am using arduino 1.8.13, I just deleted and did a new instal yesterday.
@PeteKnight, I will try making some changes to your suggestions tomorrow (my time) and let you know how I go. Perhaps I should try it without deep sleep first.
Thanks, Fraser

Sorry what I meant was what version of ESP8266 board package? 2.7.1 or 2 ? But if you did a new install you are probably up to date with the board drivers as well.

At last, your suggestion of a delay was correct. I found the secret here:
Blynk.run() is a main Blynk routine responsible for keeping connection alive, sending data, receiving data, etc. When you use a delay() , you most likely are breaking a connection to Blynk Cloud or blocking some functions of Blynk library.

Basically, your sensorValue will never get to the Cloud.
This is something I had seen in my previous searches but not recognised its significance at the time. I didn’t use Delay as that is supposed to stop all processor action whereas millis doesn’t. I can also keep timing more accurate over a long period by taking the 2 seconds off my hour timer.
Thanks for your help. Fraser.