Closed litnimax closed 5 years ago
Same problem here! I think it something similar to this: https://stackoverflow.com/questions/2611858/struct-error-unpack-requires-a-string-argument-of-length-4 But I haven't gotten deep enough to solve it yet.
I am getting the error as well. Its stemming from the fact that he is trying to unpack the received data to a specific header and it appears the header is wrong or is receiving the wrong data for the header. In my case, i am receiving a value of "vw4325" which i am assuming is a virtual write to pin 4 with a value of 325. This, according to python , is a value of 8, whereas he is trying to unpack it as "!BHH" which is a unsigned char and 2 unsigned shorts (1 byte + 2 bytes + 2 bytes) for a value of 5 bytes. So i am not sure if the format of the data received has changed? This is my first day with Blynk, so i will try and investigate further.
Sending a button press from the phone i received a "vw11" which was set up for virtual pin one receiving a value of 1. The had a size of 6. I am guessing that each char is 1 byte and each number is 2 bytes in this case. In the case above , the "vw4325" culd be 1 byte for each char, two bytes for the pin "4", and 4 bytes for the value "325" to give 8 bytes?
Hi, I'm facing the same issue!
It's my first day learning python, so I'm not sure to understand what I really do. Based on the error message :
struct.error: unpack requires a string argument of length 5
I assumed that a message without this is not normal so I changed the code by adding a check on the data length to match the buffer one.
if data and len(data) == HDR_LEN:
msg_type, msg_id, msg_len = struct.unpack(HDR_FMT, data)
I can now read values on my mobile.
I'm pretty sure that it is not a solution but, at least it's a quick fix for me.
Still an issue here on macOS. I have previously used blynk successfully on Ubuntu 18.04.
Same issue here on macOS Sierra using python 3.6.5. How is that quick fix working for you @mehdijouan ?
Please check the latest version from master branch. The library was rewritten, and this issue should not happen anymore
v0.2.0 is released and available via pip: https://github.com/vshymanskyy/blynk-library-python/releases/latest
When I run the example app and press run the project on mobile I get:
Here is the example app - https://gist.github.com/litnimax/16a286b6db725c51c905988396ba647f