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

🔥 Blynk library for Python / MicroPython v0.2.0 is released!

micropython
python
hardware
#1

The new official Blynk library v0.2.0 for Python is released and available via github and pip.

It contains better support for ESP32 boards and Raspberry Pi, API improvements.
In fact, the library was completely rewritten, as previous version had too many problems.

Please check out the new README and examples.

Check it out here: https://github.com/vshymanskyy/blynk-library-python
And of course, do not forget to give it a github star! :wink:

Happy Blynking!

6 Likes

Blynk & Micropython on ESP8266 (Wemos D1 Mini Pro)
Blynk + MicroPython
Python GPIO switches no longer work after upgrade to Raspberry 3
Blynk library "pBlynk" ESP8266 Micropython
New! Alpha version of the blynk-library for Python!
#2

Everything im testing works great. I found once i got into it, it was hard to stop playing :slight_smile:

notes: the timer lib wasnt included with the main lib when i ran the pip install. no big deal, just copied them over.
table.widget support and email would be my only requests from this library.

Thanks @vshymanskyy , nice work!
Larry

0 Likes

#3

I agree… something about Python, it’s syntax, and the speed/simplicity of “edit, save, run/test, edit, save, run/test…” (well, at least on a RPi) is a refreshing change from the Arduino IDE method.

I am finally even able to use Python 3.x

I looks like it is on its way… at least this small part of it is referenced in the library :wink:

image

Like with BlynkTimer, clearly a work in progress, so keep updating as and when it looks like updates are released.

0 Likes

#4

Just a quick note:

In the tweet _notify.py library example (or when checking a response from a button),
if value[0]: # is the the button is pressed?
checks for a string ‘0’ or ‘1’ for being a “list” so, the correct syntax should be
if (value[0] == '1'): # the button is pressed?

For non Python library, the value is an int.

1 Like

#5

Thanks, you’re right

0 Likes

#6

Opps… so looks like I will soon have to change all my previously changed code back :stuck_out_tongue:

After trial and error I was able to get this to work…

if value[0] == str('1'):

0 Likes

#7

@vshymanskyy what do you mean with the note on line 70 of the BlynkLib These are mainly for backward-compatibility you can use “blynk.ON()” instead because blynk.ON doesn’t substitute “VIRTUAL_WRITE/READ”, right?

Also, virtual pins (blynk, pin) are always treated as strings, right?

So, the following code is not correct

v_led_pin = 1
@blynk.VIRTUAL_WRITE(v_led_pin)

while this one is?

v_led_pin = '1'
v_arry = ['1', '2', '3']

@blynk.VIRTUAL_WRITE(v_led_pin)
@blynk.VIRTUAL_WRITE(v_arry[1])
0 Likes

#8

Hi @vshymanskyy, With the following test code I converted the old “@blynk.VIRTUAL_WRITE” function to the new one “@blynk.ON” as per the library’s note

These are mainly for backward-compatibility you can use “blynk.ON()” instead

However, I noticed an inconsistency with the type of variable it can be used. At times an array is admitted and at time it’s not.

#!/usr/bin/python3

#import libraries
from __future__ import print_function
import BlynkLib
from BlynkTimer import BlynkTimer
from subprocess import check_output
import logging, time, gc
from datetime import datetime as dt

logging.basicConfig(filename='/home/pi/blynk.log',level=logging.DEBUG)

BLYNK_AUTH = '****' 

# Initialize Blynkxy
blynk = BlynkLib.Blynk(BLYNK_AUTH)

#virtual pins array
v_arry = ['0','1','V2','V3'] #<--- 'V2' works but not 'V3'

#*** old format ***
@blynk.VIRTUAL_WRITE(v_arry[0])
def btn0_handler(value):
  btn0status = value[0]
  if btn0status == '1':
    print('btn v0 pressed')
    time.sleep(.1)
  else:
    print('btn v0 released')

@blynk.VIRTUAL_WRITE(v_arry[1])
def btn1_handler(value):
  #security check
  #btn1 is activated only when btn0 is being pressed
  if value[0] == '1':
          print('btn v1 pressed')


#*** new format ***
@blynk.ON("connected")
def blynk_connected(ping):
  print('Blynk ready. Ping:', ping, 'ms')

@blynk.ON(v_arry[2])
def btn2_handler(value):
  if(value[0] == '1'):
    print('btn v2 pressed')

@blynk.ON('readV*')    #is this correct?
def uptime_handle(V3): #won't accept an array
  gc.collect()
  #get board total uptime
  cmd = 'uptime -p'
  t = check_output(cmd, shell = True).decode("utf-8")
  t = t.rstrip('\n\r')
  t = t.replace('up','')
  blynk.virtual_write(V3, t)

if __name__ == "__main__":
  while True:
    try:
      blynk.run()
    except IOError as e:
      if(e.errno == errno.EPIPE):
        logging.exception("msg from blynkmain @ " + str(dt.now()))
0 Likes