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

(Blynk Python) Intermittent connection

You meen here?

What hardware are you using?

From the python library:

if data:
                    msg_type, msg_id, msg_len = struct.unpack(HDR_FMT, data)
                    if msg_id == 0:
                        self._close('invalid msg id %d' % msg_id)
                        break
                    if msg_type == MSG_RSP:
                        if msg_id == self._last_hb_id:
                            self._last_hb_id = 0
                    elif msg_type == MSG_PING:
                        self._send(struct.pack(HDR_FMT, MSG_RSP, msg_id, STA_SUCCESS), True)
                    elif msg_type == MSG_HW or msg_type == MSG_BRIDGE:
                        data = self._recv(msg_len, MIN_SOCK_TO)
                        if data:
                            self._handle_hw(data)
                    else:
                        self._close('unknown message type %d' % msg_type)
                        break

You can see that if the msg_type is different from MSG_RSP, MSG_PING, MSG_HW , MSG_BRIDGE it will fail. So probably you were receiving a MSG_HW_INFO with id 17 and it closed.

Where would that different msg come from that cause it to intermittently fail

Just to be clear I’m running the example supplied by Blynk not my code

I don’t know the specifications of the messages and when/who is sending them. It seems there is no documentation on that, so a developer might know.

Are we saying the error message is coming from the interaction with Blynk when its running?

The blynk server is sending a message with ID 17 to the python application and the application is reading it via socket but it cannot parse it correctly (probably a bug in the library). Why that message is sent is unknown to me :slight_smile:

This is what I see when I run the example prog in the shell window on my pi, below.

You can see it runs OK updates my app and then fails, then start up again.

This is well out side my knowledge zone but could this intermittent be the reason why I get my other intermittent problems?

Warning: Virtual read from unregistered pin 3
Warning: Virtual read from unregistered pin 3
Warning: Virtual read from unregistered pin 3
Warning: Virtual read from unregistered pin 3
Warning: Virtual read from unregistered pin 3
Warning: Virtual read from unregistered pin 3
Error: unknown message type 17, connection closed
TCP: Connecting to blynk-cloud.com:8442
Blynk connection successful, authenticating…
Access granted, happy Blynking!
Error: unknown message type 17, connection closed
TCP: Connecting to blynk-cloud.com:8442
Blynk connection successful, authenticating…
Access granted, happy Blynking!
Error: unknown message type 17, connection closed
TCP: Connecting to blynk-cloud.com:8442
Blynk connection successful, authenticating…
Access granted, happy Blynking!
Error: unknown message type 17, connection closed
TCP: Connecting to blynk-cloud.com:8442
Blynk connection successful, authenticating…
Access granted, happy Blynking!
Warning: Virtual read from unregistered pin 3
Warning: Virtual read from unregistered pin 3
Warning: Virtual read from unregistered pin 3
Warning: Virtual read from unregistered pin 3
Warning: Virtual read from unregistered pin 3
Warning: Virtual read from unregistered pin 3
Warning: Virtual read from unregistered pin

Seem like after this message your connection is closed. Is that your python script?

The message is coming from your Blynk example you post for down load to show how to read from a python script

Download from Blynk I’m running to get the error:

“”"
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.

Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Social networks: http://www.fb.com/blynkapp
http://twitter.com/blynk_app

This example shows how to display custom data on the widget.

In your Blynk App project:
Add a Value Display widget,
bind it to Virtual Pin V2,
set the read frequency to 1 second.
Run the App (green triangle in the upper right corner).

It will automagically call v2_read_handler.
Calling virtual_write updates widget value.
“”"

import BlynkLib
import time

BLYNK_AUTH = ‘’

Initialize Blynk

blynk = BlynkLib.Blynk(BLYNK_AUTH)

Register virtual pin handler

@blynk.VIRTUAL_READ(2)
def v2_read_handler():
# This widget will show some time in seconds…
blynk.virtual_write(2, time.ticks_ms() // 1000)

Start Blynk (this call should never return)

blynk.run()

17 was changed to BLYNK_CMD_INTERNAL, and it looks like I didn’t add support for this yet.
Now tracked by this issue:

Thanks for the reply, good news. That helps me. Look forward to the fix.

How do I know when the fix is in place and I can retry that example?

You can watch the github issue…

Well done tulo - your answer was correct

I think it is also missing support for other messages.

@tulo please be more specific. do you have any particular problem?

Nope, I’m not using the python library, but in the piece of code I quoted it seems it handle only 4-5 messages ID, but I’ve seen there are much more. But I don’t know the messages specification :wink: so I might be very wrong.

PS: I have a problem instead with the JS library, I’m investigating and I’ll open a new topic about that

Gunner

Thanks for your reply but must add that even if Blynk is in Alpa stage any library issues or intermittent problems can cause the novice user untold problems.

Why bring it up to me two days later? I am not a developer :stuck_out_tongue: … I was just pointing out the clear fact that a “novice user” is more likely to run into “untold problems” with an Alpha product (just the Python part) that is recommended for “EXPERT USE ONLY!”… but your contributions are helpful for the actual developer :smiley: