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

New! Alpha version of the blynk-library for Python!

Hi all.

Here’s an alpha version of what is Blynk library for Python (this one uses a bi-directional TCP connection, not HTTP API).

Please note that it’s not production ready and I hope for active contributions from our community - unfortunately I don’t have too much time to develop it.
EXPERT USE ONLY! :wink:
Anyway, this is inline with Blynk ideas (as you would expect): simple to use, extensible API, good hardware support (no dependencies), etc.

What do you think?

5 Likes

i like the idea, and would choose any day the python language over the arduino “language”.

but the reality is, that compared to arduino, very few people are using python for embedded stuff, so the chance to find libs / info / support for random sensors / modules is low. the same goes for mcu compatibility. thus, the usability is reduced.

2 Likes

@Gunner
I seem to have a new problem…
I can’t import BlynkLib.
It says, "ImportError : No module named ‘BlynkLib’
Im not sure if anything’s missing or something, but I followed all the steps from here, https://github.com/vshymanskyy/blynk-library-python

@Muhammad_Fitri Sorry, I know nothing about Python. I have moved your question here instead.

Be aware, this is an Alpha test and for…

:tired_face::tired_face::tired_face:

thanx @Gunner

@vshymanskyy, from the code you gave at github, how do i set the virtual pin i need to use??

import BlynkLib
import time

BLYNK_AUTH = 'YourAuthToken'

# Initialize Blynk
blynk = BlynkLib.Blynk(BLYNK_AUTH)

# Register Virtual Pins
@blynk.VIRTUAL_WRITE(1)
def my_write_handler(value):
    print('Current V1 value: {}'.format(value))

@blynk.VIRTUAL_READ(2)
def my_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()

@Muhammad_Fitri please pay attention to code formatting when using our forum.
And read this carefully!


I think the code is self-explanatory - what exactly question do you have?

Hi,

it all works fine for Virtual Pin 1 but if I add more pins then I get the following message

Warning: Virtual write to unregistered pin 2

How can I deal with this?

best
mDSP

This is probably becasue you didn’t register pin 2 :stuck_out_tongue_winking_eye:

Start by showing your entire modified & formatted code, otherwise we are guessing at what you did or didn’t do :wink:

Thank you for your reply!

Well. I thought it should work like this (but obviously it doesn’t)

import BlynkLib
import random
import OSC
import time

client = OSC.OSCClient()
client.connect( ( '127.0.0.1', 57120 ) )
msg = OSC.OSCMessage()
msg.setAddress("/print")


BLYNK_AUTH = 'aca20018b97740a59389ca8b47c7baae'

# Initialize Blynk
blynk = BlynkLib.Blynk(BLYNK_AUTH)

# Register Virtual Pins
@blynk.VIRTUAL_WRITE(1)
def my_write_handler(value):
	print('Current V1 value: {}'.format(value))

@blynk.VIRTUAL_WRITE(2)
def my_write_handler(value):
    print('Current V2 value: {}'.format(value))


@blynk.VIRTUAL_READ(2)
def my_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()

I have absolutely no idea how Python works… but as a guess with what looks like the actual defining command… you might try something like (value2) as (value) is already taken for the first pin?

Unfortunately it does not work. I did tried it also before. I am wondering where can I register the pins? Even if I use just pin2 in first place without anything else I get the same error. It seems I can get values only from pin1.

any ideas?

its absolutely mad but is seems it works for pin3! I will check others and report.

Yes, it seems it is just pin2 not working! I randomly tried 2-3 others and it works!

Looking at other examples in the Blynk Python Library (above), it seems that defining a virtual pin is determined by the initial wording, not the word (value)…

def my_write_handler(value):
def v3_write_handler(value):
def v4_write_handler(value):

etc.

Also… you are already using V2 (or just pin 2) in this command… for the uptime display.

Ah I am so silly, I did not pay any attention that I am using already VP2. I just cope/pasted the code and forgot the last lines.

Thank you for pointing it out anyway!

1 Like

Hi again,

I have just noticed that when I use the library the CPU goes 100% on RPi3

Strange isn’t it?