Multiple "display value" widgets doesn't work with python lib

I am using IOS BLynk app. Hardware is Raspberry pi. Software is Python 3.5.
The test code to highlight the problem is very simple: it’s just two VP events handlers: one for VP0 and one for VP1. The two of them do the same very simple thing: display a random number on a “display value” widget on the app. The two “display value” widgets have a refresh interval of 1s.
It’s impossible to have the two widget display their respective random number. One doesn’t display any thing.
Any idea ?

BLYNK_AUTH = 'e198d12e7f8443c4a97ac1f4b0ac43cc'
blynk = blynklib.Blynk(BLYNK_AUTH)

# register handler for virtual pin V0 reading 
@blynk.handle_event('read V0')
def read_virtual_pin_handler(pin):
    blynk.virtual_write(pin, random.randint(0, 255))

# register handler for virtual pin V1 reading
@blynk.handle_event('read V1')
def read_virtual_pin_handler(pin):
    blynk.virtual_write(pin, random.randint(0, 255))
while True:

I have the same problem, blynklib version 0.2.6, blynk android app

Here is the simplest code that reproduces the error

blynk = blynklib.Blynk(BLYNK_AUTH, log=print)

@blynk.handle_event('read V*')
def read_virtual_pin_handler(pin):
    blynk.virtual_write(pin, "Pin"+str(pin))

while True:

The debug output confirms that “read V0”…“read V32” handlers are registered.

No matter how many “display value” widgets I add in the blynk app (for V1, V2…etc pins), only one of them actually get displayed. If I delete the widget which displays the value, another widget becomes active and so on, but never more than one of them. Again, the debug output from the python script confirms that only one pin’s value actually gets requested.

Ok, so I tracked this to a bug in

    rsp_data = self.receive(self.rcv_buffer, self.SOCK_TIMEOUT)
    if rsp_data:
        self._last_rcv_time = ticks_ms()
        msg_type, msg_id, h_data, msg_args = self.parse_response(rsp_data, self.rcv_buffer)
        self.process(msg_type, msg_id, h_data, msg_args)

The piece of code above assumes that rsp_data always contains a single message, but if there are multiple “display value” widgets, the server sends multiple messages simultaneously, and this code only processes the first message disregarding the rest, which results in only one widget’s value being updated.

And a quick hack to fix this problem until is updated to account for this server behavior.

In the “def receive” function replace the following line:

d_buff += self._socket.recv(length)

With the following code

d_buff += self._socket.recv(5)
msg_type, _msg_id, data_len = struct.unpack('!BHH', d_buff)
if not msg_type in (self.MSG_RSP, self.MSG_PING):
    d_buff += self._socket.recv(data_len)

This will make sure the “receive” function will only read a single message from the socket.

i try this method but even also that not work for me to get multiple value??

to read multiple virtual pin any another solution???

Hello do you know if a fix has been released for this issue ?

Seems not to be fixed yet in my (MicroPython lib, downloaded 2020 december 10th) I still see the initial lines.

Soon I’ll need to receive multiple values from the app, and I’ll try the fix by @asdf1. Will post an update then.

1 Like