Skip to main content

Blynk Python/Micropython library

Project description

Blynk Python Library

This library provides API to connect IoT hardware that supports Micropython/Python to Blynk Cloud and communiate with Blynk apps (iOS and Android). You can send raw and processed sensor data and remotely control anything that is connected to your hardware (relays, motors, servos) from anywhere in the world.

GitHub version GitHub download GitHub stars GitHub issues Build Status License

If you like Blynk - give it a star, or fork it and contribute! GitHub stars GitHub forks

Blynk Banner

Blynk is the most popular Internet of Things platform for connecting hardware to the cloud, designing apps to control them, and managing your deployed devices at scale.

  • With Blynk Library you can connect over 400 hardware models (including ESP8266, ESP32, NodeMCU, all Arduinos, Raspberry Pi, Particle, Texas Instruments, etc.)to the Blynk Cloud. Full list of supported hardware can be found here.

  • With Blynk apps for iOS and Android apps you can easily build graphic interfaces for all of your projects by simply dragging and dropping widgets on your smartphone. It's a purely WYSIWG experience: no coding on iOS or Android required.

  • Hardware can connect to Blynk Cloud (open-source server) over the Internet using hardware connectivity on board, or with the use of various shields (Ethernet, WiFi, GSM, LTE, etc). Blynk Cloud is available for every user of Blynk for free.

Installation of Blynk Python Library

Installation via python pip

  • Check python availability in your system.

    python --version
    

    To exclude compatibility issue preferable versions are Python 2.7.9 (or greater) or Python 3.4 (or greater) If python not present you can download and install it from here.

    NOTE: To run python in "sandbox" you can try virtualenv module. Check this document how to do it.

  • If you’re using preferable versions of python mentioned above, then pip comes installed with Python by default. Check pip availability:

    pip --version
    
  • Install blynk library

    sudo pip install blynklib
    

Manual installation

Library can be installed locally from git sources:

git clone https://github.com/blynkkk/lib-python.git
cd lib-python
pip install --user -e .

# sudo pip install -e .  # if installation needed not for current but for all users

Testing

You can run unit tests on cPython systems using the command:

python setup.py test

NOTE: Unit tests for Micropython ENV are not available yet.

Micropython installation

Some hardware platforms can use Micropython package. This is helpful for preliminary testing and debugging of your code outside of real hardware. Supported platforms and related installation docs can be found here.

Features

This library supports Python2, Python3, and Micropython.

  • Communication with public or local Blynk Server.
  • Exchange any data between your hardware and app
  • Tested to work with: Raspberry Pi (any), ESP32, ESP8266
List of available operations:
  • Subscribe to connect/disconnect events
  • Subscribe to read/write events of virtual pins
  • Virtual Pin write
  • Virtual Pin sync
  • Send mobile app push notifications
  • Send email notifications
  • Send twitter notifications
  • Change widget GUI parameters in Blynk app based on hardware input

Quickstart

  1. Install Blynk python library as described above
  2. Install Blynk App: Google Play | App Store
  • Create new account in Blynk app using your email address
  • Create a new Project in Blynk app
  • You will get Auth Token delivered to your email account.
  • Put this Auth Token within your python script to authenticate your device on public or local
BLYNK_AUTH = '<YourAuthToken>' #insert your Auth Token here

Usage example

import blynklib

BLYNK_AUTH = '<YourAuthToken>' #insert your Auth Token here
# base lib init
blynk = blynklib.Blynk(BLYNK_AUTH)

# advanced options of lib init
# from __future__ import print_function
# blynk = blynklib.Blynk(BLYNK_AUTH, server='blynk-cloud.com', port=80, heartbeat=10, rcv_buffer=1024, log=print)

# register handler for Virtual Pin V22 reading by Blynk App.
# when a widget in Blynk App asks Virtual Pin data from server within given configurable interval (1,2,5,10 sec etc) 
# server automatically sends notification about read virtual pin event to hardware
# this notification captured by current handler 
@blynk.handle_event('read V22')
def read_virtual_pin_handler(pin):

    # your code goes here
    # ...
    # Example: get sensor value, perform calculations, etc
    sensor_data = '<YourSensorData>'
    critilcal_data_value = '<YourThresholdSensorValue>'

    # send value to Virtual Pin and store it in Blynk Cloud 
    blynk.virtual_write(pin, sensor_data)

    # you can define if needed any other pin
    # example: blynk.virtual_write(24, sensor_data)

    # you can perform actions if value reaches a threshold (e.g. some critical value)
    if sensor_data >= critilcal_data_value

        blynk.set_property(pin, 'color', '#FF0000') # set red color for the widget UI element 
        blynk.notify('Warning critical value') # send push notification to Blynk App 
        blynk.email(<youremail@email.com>, 'Email Subject', 'Email Body') # send email to specified address

# main loop that starts program and handles registered events
while True:
    blynk.run()

Other Examples

Examples can be found here Check them all to get familiar with main Blynk API features.

Core operations:
Raspberry Pi (any):

Read Raspberry Pi guide first.

ESP32

Read ESP32 guide first.

ESP8266

Read ESP8266 guide first.

Memory size limitations

For hardware with limited memory size (ex. ESP8266) you can use frozen modules or frozen bytecode approaches to load blynklib or any other library to hardware.

Read this document to get more information.

Documentation and other helpful links

Full Blynk Documentation - a complete guide on Blynk features

Community (Forum) - join a 500,000 Blynk community to ask questions and share ideas

Help Center - helpful articles on various Blynk aspects

Code Examples Browser - browse examples to explore Blynk possibilities

Official Website

Social Media:

Facebook Twitter Youtube

Instagram LinkedIn

Blynk libraries for other platforms

Contributing

You are very welcome to contribute: stability bugfixes, new hardware support, or any other improvements. Please.

License

This project is released under The MIT License (MIT)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

blynklib-0.2.5.tar.gz (18.7 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

blynklib-0.2.5-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

blynklib-0.2.5-py2-none-any.whl (11.8 kB view details)

Uploaded Python 2

File details

Details for the file blynklib-0.2.5.tar.gz.

File metadata

  • Download URL: blynklib-0.2.5.tar.gz
  • Upload date:
  • Size: 18.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.2

File hashes

Hashes for blynklib-0.2.5.tar.gz
Algorithm Hash digest
SHA256 ea82deeadfccb4b2666fe9b782c846239a7947f77b11cb168119a8e795807f38
MD5 2164817052af4c7a6f78cbb7c4f3d082
BLAKE2b-256 43121f1a2bdfabcaac27cd0629358d0323e0acdf5430f8a68e68c3f71afe2fb5

See more details on using hashes here.

File details

Details for the file blynklib-0.2.5-py3-none-any.whl.

File metadata

  • Download URL: blynklib-0.2.5-py3-none-any.whl
  • Upload date:
  • Size: 11.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.2

File hashes

Hashes for blynklib-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 9792df679aae4436f085518e63b1fd633eee95ce498961585dece12b2de40c54
MD5 b2cbdd9320cf36759c94af9af4895254
BLAKE2b-256 b823cc0ff5f354a799ca99954907ebdedb43f4bf2e6d9d28d6afafbba008685a

See more details on using hashes here.

File details

Details for the file blynklib-0.2.5-py2-none-any.whl.

File metadata

  • Download URL: blynklib-0.2.5-py2-none-any.whl
  • Upload date:
  • Size: 11.8 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.2

File hashes

Hashes for blynklib-0.2.5-py2-none-any.whl
Algorithm Hash digest
SHA256 b0711cfe3945c65d462695636b8e62475dc9b534bd8ff77e3858fc29e3752abf
MD5 82e1f15c15e155a9676c4035e1976143
BLAKE2b-256 10672849e0b59991173122ef94c4c665a51e2821f9a4799107fe5580b106a4dc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page