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

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


#4

@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


#5

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

Be aware, this is an Alpha test and for…


#6

:tired_face::tired_face::tired_face:


#7

thanx @Gunner


#8

@vhymanskyy, 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()

#9

@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?


#10

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


#11

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:


#12

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()

#13

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?


#14

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?


#15

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


#16

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


#17

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.


#18

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


#19

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!


#20

Hi again,

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

Strange isn’t it?


Push widgets update with different frequency using Python set_user_task() or NodeJS
#21

For an alpha version, it is not strange :wink:


#22

Hi vhymanskyy,

first of all thank you so much for providing the library!

I was just wondering if it is something related to my own Pi configuration.

Is it related to very fast refresh rates?

Generally I need to link my Pi to blink cloud in order to forward Virtual Pin data
to SC though OSC (Open Sound communication). This is going to be a non stop
running installation so do you think I should move for now to the node.js version?
Is that more efficient CPU-wise?

Best
mDSP


#23

Node.js is better in 2 ways:

  1. the Blynk library is tested better
  2. JavaScript is event-driven by it’s nature

If you don’t have intensive computations in your code/libraries you use, I wouldn’t be concerned about Node.js or Python usage at all.