virtualWrite is blocking

Hi there!

I have an application running on my Linux desltop machine. Everything worked fine until I tried wrtiting to a virtual pin from the application. The call Blynk.virtualWrite(…) seems to block. I set a value display to virtual pin V4 with a reading rate of 1 second. As soon as Blynk.virtualWrite(V4, val1) gets called, the program hangs there. If i comment this line out, everything works. Did I forgett something or is there a bug in the linux api? Thanks for your help!


#ifdef RASPBERRY
   #include <BlynkApiWiringPi.h>
#else
  #include <BlynkApiLinux.h>
#endif
#include <BlynkSocket.h>
#include <BlynkOptionsParser.h>

static BlynkTransportSocket _blynkTransport;
BlynkSocket Blynk(_blynkTransport);

#include <BlynkWidgets.h>

BLYNK_READ(V4) {
    double val1 = static_cast<double>(rand())/ RAND_MAX * 100.0;
    std::cout << val1 << std::endl;
    Blynk.virtualWrite(V4, val1);
}

int main (int argc, char* argv[]) {

    const char *auth, *serv;
    uint16_t port;
    parse_options(argc, argv, auth, serv, port);
    Blynk.begin(auth, serv, port); 

    while (true) {

        Blynk.run();


    }

    return 0;
}

You need timers I think. They can be made in C programs too, I did so once. And just have blynk.virtualwrite execute every second or so (and set widget to Push).

Hi!
Thanks for your response.
I tried that at the beginning, didn’t work either… as soon as virtualWrite is called, the progam hangs.

And what happens if you log that value to the console? Just for testing to see if it actually runs every 1s. Instead if virtualwrite ofcourse

If I log that value to the console and comment out the call to virtualWrite, everything works, i.e. every second a value is printed. If I uncomment vitualWrite, the value gets printed only once, before the very first call to virtualWrite

@funas1 What library version do you use? Try the latest version