Widget Displays Incorrect Values

Hello @whughesiii @Blynk_Coeur. Not reproduced for me. Gauge widget has support updating value in real time.

Please provide more details. Datastream settings, gauge widget settings.
Values ​​not updating immediately? Or after some time spent on the device dashboard?

1 Like

Here are screenshots of back to back “bad” readings. We’re not just talking about the widget, but the data that is actually logged. Since the platform is structured such that I can’t see the payload without a top tier account, I can’t tell what’s actually coming across the wire to see if it’s something in my code or something in Blynk.

On the left you’ll see my serial console with the “Weight:” value taken and reported. On the right you’ll see the histogram values and live data widget. One is zero and the other is .56. Neither of those values were taken or reported. I was careful to use the last two events as of the time I took these screenshots to show the weirdness.

I do not use the loop() function, everything is ran in the setup section because I use deep sleep.

setup {....
    float weight = getWeight();
    Serial.print("Weight: ");
    Serial.println(weight);
    sendDataToBlynk();
    delay(2000);

    BlynkEdgent.run();

    Blynk.disconnect();
    Serial.println("Disconnecting Blynk...");
    WiFi.disconnect();
    Serial.println("Disconnecting WiFi...");

    // Go to deep sleep after readings are done
    Serial.println("Going to deep sleep");
    esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
    esp_deep_sleep_start();  

}

This code is declared in the global section of the main ino:

 void sendDataToBlynk() {
  float weight = getWeight();
  Serial.println("Sending data to Blynk");
  Blynk.virtualWrite(WEIGHT_VPIN, weight);
  if (temperature != 0.0 && humidity != 0.0) {
        Blynk.virtualWrite(TEMPERATURE_VPIN, temperature);
        Blynk.virtualWrite(HUMIDITY_VPIN, humidity);
    }
}

I have all my scale functions in a header file. This is an HX711 using the latest library from Rob Tillart. Here is the relevant code:

HX711 myScale;
...
float getWeight() {
    return myScale.get_units(10);  //takes ten consecutive readings to ensure stable value
}


Further data:
global variable for weight pin code:

#define WEIGHT_VPIN V0



The values update immediately or after a page refresh, but they’re not what the device is reporting.

Also, the issue started around 8pm Eastern last night. Before that everything has been solid and consistent for about a week. My last code revision (which made no changes to the weight reading portion) was at 3:25pm yesterday.

@whughesiii Please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Copy and paste these if you can’t find the correct symbol on your keyboard.

Pete.

1 Like

Done - thanks for pointing that out!

@whughesiii Thanks. We need to investigate this case.

1 Like

I don’t think your values are actually getting sent to Blynk before your device goes to sleep.

First of all, starting with the Edgent example isn’t the choice I’d make.
Secondly, the 2 second delay after calling sendDataToBlynk() doesn’t achieve anything. What you should be doing is executing Blynk.run(), or in your case BlynkEdgent.run(), several times before going to sleep.

Pete.

So why would a datapoint be sent at all? If the data isn’t being sent I’d expect the last value shipped to be displayed, not a zero or completely incorrect number not sent.

Also, two other values are being sent after this value, and they make it through just fine as far as I can tell.

The delay of 2 seconds is to give time to send the data before disconnecting. Are you saying that the Blynkedgent.run will hold the thread open until it completes? If so, I can remove that delay and that would make me happy.

All the 2 second delay does is stop all processor execution for 2 seconds. Instead you should be triggering the Blynk library to talk to the server, by executing BlynkEdgent.run()

If you don’t like my advice then feel free to ignore it.

Pete.

//If you don’t like my advice then feel free to ignore it.//

That came across kind of brusque. I’m happy to take advice, and as I said, I’m happy to remove that delay provided the BlynkEdgent.run() function is able to complete synchronously before moving on to the rest of the code.

In my code above, weight gets sent first, then temperature and humidity. These screenshots show the values in my serial console vs the values in my dashboard. You’ll see the temperature and humidity values are perfectly in sync, while the weight values is completely incorrect.
Temp Data
Weight value

That’s because I gave you some advice, and instead of explaining why you’d chosen the Edgent route and undertaking to try my suggestion, you seem to dismiss the advice.

That’s fine by me, I’m just trying to be of assistance, but if you don’t want to take my suggestions onboard you’re free to ignore them.

Pete.

You just said what you wouldn’t do, not what I should do. Unfortunately, I don’t have the coding chops to strip it down. And again, I’m more than happy and eager to accept advice for being more efficient in my coding.

That being said, I still have a question in need of an answer - and that is why two of the three values come through perfectly fine, but the third value doesn’t? And was there a change made last night around 8pm on the Blynk side that might possibly be involved? If I could see my payloads, I could easily troubleshoot this myself, but I’m in the dark.

I’d suggest you re-read what I said.

You need far more “coding chops” as you call it to get deep sleep working well with Edgent than you do withy a basic non-Edgent static provisioning sketch (of which there are many in the library examples).

I think if you move to a better structured solution (maybe taking-onboard the advice I gave you earlier) the question will answer itself.

Pete.

1st tab dashboard with at least 40 widgets
gauge and label same data-stream

blynk1

New tab with only 3 widgets

blynk2

This issue occurred on November 23, 2023 with the navigation improvement update .

I did what you suggested and added some BlynkEdgent.run() commands after the virtualWrite() commands (three wasn’t enough, but four seems to do the trick). Things seem better, but my question is why does this make a difference, and why would incorrect values be received? I’d like to know the technical reasons for this, please.

setup {
...
    //sendDataToBlynk();
    if (temperature != 0.0 && humidity != 0.0) {
            Blynk.virtualWrite(TEMPERATURE_VPIN, temperature);
                Serial.print("Temperature: ");
                Serial.println(temperature);
            Blynk.virtualWrite(HUMIDITY_VPIN, humidity);
                Serial.print("Humidity: ");
                Serial.println(humidity);
            Blynk.virtualWrite(ABS_HUMIDITY_VPIN, absHumidity);
                Serial.print("Absolute Humidity: ");
                Serial.print(absHumidity);
                Serial.println(" g/m^3");
        }
    
    Blynk.virtualWrite(WEIGHT_VPIN, weight);
    Serial.print("Weight: ");
    Serial.println(weight);

    BlynkEdgent.run();
    BlynkEdgent.run();
    BlynkEdgent.run();
    BlynkEdgent.run();

    Serial.println("Disconnecting Blynk...");
    Blynk.disconnect();
    Serial.println("Disconnecting WiFi...");
    WiFi.disconnect();

    // Go to deep sleep after readings are done
    Serial.println("Going to deep sleep");
    esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
    esp_deep_sleep_start();  
}

As I said before, BlynkEdgent.run() (which in turn triggers Blynk.run()) triggers the Blynk library to perform a data exchange with the Blynk server. This is a two-way communication process, in which the device sends data to the server, and checks to see if there are any incoming messages from the server that need to be processed.
If you turn on BLYNK_DEBUG you’ll see these messages and be able to decipher them by taking a look at this topic…

Pete.

I feel daft right now, but I’m just not getting it.

According to the docs, virtualWrite sends the data:
virtualWrite

While Blynk.run processes commands from the server:

If I use Blynk.virtualWrite(VPIN, variable) in my sketch, this is supposed to send the data to the Blynk server, correct? So why would I need to continue calling Blynk.run to exchange more data that the previous command should have already done? Is it that the virtualWrite command just sends the data and doesn’t care if it actually gets there? What is the process flow for virtualWrite and Blynk.run()? What does “housekeeping of Blynk connection” mean, exactly? Perhaps this is what I’m missing. I’m honestly trying to understand what is happening here. This will help me increase the quality of the code I write for interfacing with Blynk. I appreciate your patience.

You’ll find that all of the Blynk documents are written with the assumption that you are using a regular always-on connection with the servr, and that you are feeding the Blynk library with a Blynk.run() command in the void loop that is executed hundreds if not thousands of times per second…

Accordingly to this article, this loop will execute at a speed of about 117 kHz. This means that everything you put into void loop() , your Arduino will execute about 117,000 times/ second.

As a result, statements like “attempts to send the data to the network immediately” are correct in practice, but is not the same as “virtualWrite sends the data to the Blynk server directly, independent of Blynk.run” which is what you’re inferring from these high-level explanations of the way that Blynk works.

TBH, I’ve never studied the source code to unpick exactly how this works, and as I don’t really use the Blynk library in the majority of my sketches I have very little motivation to do that.
However, my testing and experience with deep sleep + Blynk lead me to know in practice what needs to be done to get this type of sketch to work reliably , which is what I’ve shared with you in my second post in this topic.

So, that’s as much as you’re going to get from me on the subject. Using BLYNK_DEBUG and doing more experimentation will show you more about how the data is being sent to the server, which should allow you to develop a better understanding of what’s happening in the background.

Pete.

1 Like