(Blynk Python) Intermittent connection

I have posted in the past about intermittent connection. My Python Program can run for days then it fails with a connection timed out using “request”

I have been trying a different approach and experimenting with the 02_virtual_read_test01.py and find that it intermittently connects and disconnects

One message was “unknown message type 17, connection closed”

Anybody else had an intermittent connection problems. In my case its making my easy app hard work.

You may be one of the few Blynk Pythons users around :slight_smile:

Blynk Python is in Alpha stage… AKA much work :stuck_out_tongue:

Googling your error implies a Python related issue, not necessarily a Blynk one??

That is probably a bug on the python library, not able to handle the messagge with ID 17.

This is on the library:
self._close(‘unknown message type %d’ % msg_type)

The library is not handling the MSG_HW_INFO (which is ID 17) message as well as other messages.

@Johnuready can you post your entire script here… not that many will understand it :wink: but we still need to see it, else we are just tossing out WAG :stuck_out_tongue_winking_eye:

To eliminate any Python Code errors I’m using the example supplied:

02_virtual_read_test01.py which users the BlynkLib

I’m not using my code and its the example which intermittently fails

You meen here?

https://github.com/vshymanskyy/blynk-library-python/blob/master/examples/02_virtual_read.py

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