Skip to main content

Blynk Python/Micropython library

Project description

Blynk Python Library

Provides API for Blynk Server communication and messaging on IoT/desktop systems with Micropython/Python support.

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 is the most popular Internet of Things platform for connecting hardware to the cloud, designing apps to control them, and managing your deployed products 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. Direct connection over Bluetooth is also possible.

Blynk Banner

Download

Blynk App: Google Play | App Store

Optionally you can install Blynk Local Server and run everything locally. However, Blynk Cloud is free for anyone who is using Blynk for personal (non-commercial) use.

Blynk Architecture

Installation

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. Examine this link 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 currently not implemented

Micropython installation

For some platforms it is possible to install Micropython package. This maybe helpful to do preliminary testing and debugging of your code outside real hardware. Supported platforms and related installation docs can be found here.

Features

Library allows to communicate with public or local Blynk Server.

Supports Python2/Python3/Micropython.

HW support of RaspberryPi/ESP32

List of available operations:
  • connect/disconnect events subscribe
  • read/write virtual pins events subscribe
  • virtual pin write
  • virtual pin sync
  • internal app notifications
  • email notifications
  • twitter notifications
  • widget properties modification

Quickstart

Install Blynk python library Download Blynk App (GooglePlay | Apple) and register within it. When you create a new project in Blynk app, you will get Auth Token delivered to your inbox. Use this Auth Token within your python scripts to authenticate your device on public or local

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
# for example when a widget in Blynk App asks Virtual Pin data from server within given interval    
@blynk.handle_event('read V22')
def read_virtual_pin_handler(pin):

    # user code for this event goes here
    # ...
    # Example: calculate, get sensor values, current time etc
    sensor_data = '<YourCalculatedSensorData>'
    critilcal_data_value = '<YourCriticalSensorValue>'

    # update current Virtual Pin value on server 
    blynk.virtual_write(pin, sensor_data)
    # or any other pin if needed
    # blynk.virtual_write(24, sensor_data)

    # actions if calculated value become CRITICAL
    if sensor_data >= critilcal_data_value
        # set red color for widget that performs periodical virtual pin read operations
        blynk.set_property(pin, 'color', '#FF0000')
        # send internal notification to Blynk App and notification to defined e-mail 
        blynk.notify('Warning critical value')
        blynk.email(<Your e-mail>, 'Device alarm', 'Critical value!')

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

More Examples

Examine more_examples to be familiar with basic features usage.

Examples List:

Core operations:
  • 01_write_virtual_pin.py (virtual pin write event handling)
  • 02_read_virtual_pin.py (App read virtual pin events handling)
  • 03_connect_disconnect.py (library connect/disconnect events handling)
  • 04_email.py(send email support)
  • 05_set_property_notify.py (changing App widget properties and send internal notifications)
  • 06_terminal_widget.py (App communication with device through terminal widget)
  • 07_tweet_and_logging.py (Tweet messaging and library logging options)
Raspberry:
  • 01_weather_station_pi3b.py (DHT22; BMP180 sensors usage)
ESP32
  • 01_touch_button.py (TTP223B sensors usage)

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.4.tar.gz (14.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.4-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

blynklib-0.2.4-py2-none-any.whl (9.0 kB view details)

Uploaded Python 2

File details

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

File metadata

  • Download URL: blynklib-0.2.4.tar.gz
  • Upload date:
  • Size: 14.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.1.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.2

File hashes

Hashes for blynklib-0.2.4.tar.gz
Algorithm Hash digest
SHA256 437a4b117c926e96c1361c04afd41b2efec4370c13c16b5715b1559da071a20c
MD5 cf46e4537a926b804c057d21e6da0d56
BLAKE2b-256 dca5527ccbb9b94bc68d88a8e5a7f8fdb88154335d95edc0693ae34675eda138

See more details on using hashes here.

File details

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

File metadata

  • Download URL: blynklib-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.1.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.2

File hashes

Hashes for blynklib-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 591978639fa67ef57afeb04730a9c3e4cfe6e0a7ff5e267fc6f377a645348b20
MD5 a8356ecd365a05e0a3cef198ffbb2701
BLAKE2b-256 0b2d1eea0467849f94d9ff6b695bbe4a1034f61a96706a710ae6d1a574b7d557

See more details on using hashes here.

File details

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

File metadata

  • Download URL: blynklib-0.2.4-py2-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/2.7.13

File hashes

Hashes for blynklib-0.2.4-py2-none-any.whl
Algorithm Hash digest
SHA256 b487a2204058235ae226d1107aa7beced1b518530d30cf7ccc3259ea10253d27
MD5 1e937c73649ea2ddc5f0e04de6d01d30
BLAKE2b-256 a65b89e6483c3ca6122633e666530e6b4afe304b6cfa628f6aa484eeb0d90e51

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