Pyblynk - python helpers for blynk

Hi all!

Just started with blynk and want to let you know that I wrote a tiny python library based on the test-scripts.

It can be found here:

Regards,
Alex

1 Like

Hi @erazor.

Itā€™s very nice that you started to work on this! Please keep us updated!
If you feel you need some support and guidance, letā€™s contact via PM to exchange contacts.
I can see already several potential problems with this (but I realize itā€™s a very early stage).

Thx!

Well, sorry I donā€™t know how to do PMs in this GUIā€¦ itā€™s kinda messy.

I try to describe my intentions concerning the python lib. For about 10 years Iā€™m an embedded soft- and hardware developer and I also code a lot of AVR stuff for companiesā€¦ not using this Arduino-stuff at all cos itā€™s to messy and produces bad code.

Anyway, I also wrote a multi-threaded python service which can connect different buses together and also does some abstraction and has different methods to access bus objects. As a preview I tried to add Blynk as an interface and for example Iā€™m now able to write ModBus/RS485 datapoints via the Blynk android app. And thatā€™s not everything, I can connect Blynk with EnOcean, EIB or whatever now. I also added a webserver which supports websockets, which really kicks ass concerning all the other visualisation stuff out there.

The Python library itself was thought to be a virtual hardware where writing IOā€™s on the Android app can result in anything on the hardware end. That also gives an easy way to support additional hardware without compiling and so on. Imagine a virtual IO which simply starts a shell script on an embedded device. Connection management is bad since I donā€™t handle socket errors right now - not a big deal anyway.

I donā€™t know much about the complete Blynk architecture at the moment, just started yesterday but it looks promising to me. Anyway, I think there should be more functions to allow the hardware describe itself. I also donā€™t like the limitation of digital and analog IOā€™s and even that there are no names for IOs (correct me if Iā€™m wrong).

Well maybe we should do some IRC if you want some ideas.

Have a nice evening :wink:

Hi.
No, the motivation is clear enough :wink:
You may notice many python scripts in the library even today.
Also, there is node.js implementation which can be used for similar scenarios :smile:
I will contact you regarding technical details.
Also, donā€™t worryā€¦ Describing itself IS possible, as well as IO naming )))

Iā€™ve updated some parts of the code. Auto-reconnect on socket errors should work now.

1 Like

Hi Alex,

Thanks for your Python Script, the combination with Blynk is just magic.

Quickly got the python script up and and running, was not too difficult with the provided example. Currently i can Toggle the Pins with the buttons on my Phone. But I wonder if it is possible to send commands upstream, it would be great to activate a led on my phone or send a Hello world to the Display. Is that possible with your script, i cannot figure out how to do that.

Keep up the good work!
Cheers

1 Like

Youā€™re welcome!

Iā€™ll have a look at this these days but as far as i remember the server just polls the data, isnā€™t that the case? So you should simply overload the function callbacks and return correct values.

Cheers

2 Likes

My knowledge of Python is not that good, i put some code in the callback, to see how it works.

def OnVirtualWrite(self,pin,val):
	
	if pin == 0 and val == '1':
                    print('Lightbulb On')
            elif pin ==0 and val == '0':
                    print('Lightbulb Off')
            elif pin ==5:
                    print(val)                
            else:
                    print('OnVirtualWrite',pin,val)

I probably should start my code from the example, but that is even more difficult for me to understand.

For reading youā€™ll have to overload the OnXXXRead() calls. These return a value which will be send to the blynk server.

By default you should get a message on the console and the return value is 0.

Maybe someone will be useful, my time between python: https://github.com/kalipsoaqua/blynk-hardware

2 Likes

Thanks, Alex! Its easy to get in with pyblynk even for newbe.

HI, iā€™m a new user of blynk, and i need to now how can I use python with the aplication

I am having some issues with the authentication of the program,

The shell states ā€œconnectedā€ and then a timeout:

Traceback (most recent call last):
File ā€œ/Users/gvl/Google Drive/Blynk/pyblynk/examples/hw.pyā€, line 18, in
if not cConnection.connect():
File ā€œ/Users/gvl/Google Drive/Blynk/pyblynk/examples/ā€¦/lib/client.pyā€, line 27, in connect
timeout
File ā€œ/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.pyā€, line 575, in create_connection
raise err
timeout: timed out

Same problem on windows and OSX machines, i noticed it today, but is probably causing problems since a few days.

hope someone can help

Found the solution in the Blynk Newsletter,

Cloud.blynk.cc host is no longer supported
Announcements
Dear all, for those of you who still uses old Blynk host - please switch to new one blynk-cloud.com ASAP.

you can find it in client.py

def init(self,server=ā€˜blynk-cloud.comā€™,port=8442):

Hi.

When I give the command sudo ./blynk --token=********** (with blynk-library/linux), my motor is rotating after I push the button. But, when I call the function sudo nano blynk2.py (with pyblynk), my motor is not rotating even though the monitor displays the value of the data. Through the data, I noticed that the coding is perfectly fine, but I donā€™t know why my motor is not working.

I hope you can help me. Thanks in advance. =)