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. =)