Package: blynklib
Blynk Python LibraryThis 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.If you likeBlynk- give it a star, or fork it and contribute!Blynk isthe most popular Internet of Things platformfor connecting hardware to the cloud, designing apps to control them, and managing your deployed devices at scale.With Blynk Library you can connectover 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 foundhere.With Blynk apps foriOSandAndroidapps 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 Blynkfor free.Installation of Blynk Python LibraryInstallation via python pipCheck python availability in your system.python --versionTo 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 fromhere.NOTE:To run python in "sandbox" you can tryvirtualenvmodule. Checkthis documenthow to do it.If you’re using preferable versions of python mentioned above, thenpipcomes installed with Python by default.
Check pip availability:pip --versionInstall blynk librarysudo pip install blynklibManual installationLibrary 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 usersTestingYou can run unit tests for cPython version of library (blynklib.py) using the command:python setup.py testNOTEBlynklib version <0.2.6 should use pytest-mock<1.11.2. In version 1.11.2 were added restrictions for context manager usageNOTE:Unit tests for Micropython ENV are not available yet.Micropython installationSome hardware platforms can useMicropythonpackage.
This is helpful for preliminary testing and debugging of your code outside of real hardware. Supported platforms
and related installation docs can be foundhere.FeaturesThis library supports Python2, Python3 (blynklib.py) , and Micropython (blynklib_mp.py).Communication with public or localBlynk Server.Exchange any data between your hardware and appTested to work with: Raspberry Pi (any), ESP32, ESP8266List of available operations:Subscribe to connect/disconnect events (ssl connection supported only by cPython lib)Subscribe to read/write events ofvirtual pinsVirtual PinwriteVirtual PinsyncSend mobile app push notificationsSend email notificationsSend twitter notificationsChange widget GUI parameters in Blynk app based on hardware inputQuickstartInstall Blynk python library as described aboveInstall Blynk App:Google Play|App StoreCreate new account in Blynk app using your email addressCreate a new Project in Blynk appYou will get Auth Token delivered to your email account.Put this Auth Token within your python script to authenticate your device onpublicorlocalBLYNK_AUTH='<YourAuthToken>'#insert your Auth Token hereUsage exampleimportblynklib# import blynklib_mp as blynklib # micropython importBLYNK_AUTH='<YourAuthToken>'#insert your Auth Token here# base lib initblynk=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, ssl_cert=None,#                        heartbeat=10, rcv_buffer=1024, log=print)# Lib init with SSL socket connection# blynk = blynklib.Blynk(BLYNK_AUTH, port=443, ssl_cert='<path to local blynk server certificate>')# current blynk-cloud.com certificate stored in project as# https://github.com/blynkkk/lib-python/blob/master/certificate/blynk-cloud.com.crt# Note! ssl feature supported only by cPython# 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')defread_virtual_pin_handler(pin):# your code goes here# ...# Example: get sensor value, perform calculations, etcsensor_data='<YourSensorData>'critilcal_data_value='<YourThresholdSensorValue>'# send value to Virtual Pin and store it in Blynk Cloudblynk.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)ifsensor_data>=critilcal_data_valueblynk.set_property(pin,'color','#FF0000')# set red color for the widget UI elementblynk.notify('Warning critical value')# send push notification to Blynk Appblynk.email(<youremail@email.com>,'Email Subject','Email Body')# send email to specified address# main loop that starts program and handles registered eventswhileTrue:blynk.run()Other ExamplesExamples can be foundhereCheck them all to get familiar with main Blynk API features.Core operations:01_write_virtual_pin.py: How to read incoming data from Blynk app to Virtual Pin and use it in your code02_read_virtual_pin.py: How to update value on Virtual Pin03_connect_disconnect.py: Managing connection with Blynk Cloud04_email.py: How to send send email and push notifications from your hardware05_set_property_notify.py: How to change some of widget UI properties like colors, labels, etc06_terminal_widget.py: Communication between hardware and app through Terminal widget)07_tweet_and_logging.py: How to post to Twitter and log events from your hardware08_blynk_timer.py: How send data periodically from hardware by usingBlynk Timer09_sync_virtual_pin.py: How to sync virtual pin states and properties10_rtc_sync.py: How to perform RTC sync with blynk server11_ssl_socket.py: SSL server connection. Feature supported only by cPython library.12_app_connect_disconnect.py: Managing APP connect/disconnect events with Blynk Cloud.Raspberry Pi (any):ReadRaspberry Pi guidefirst.01_weather_station_pi3b.pyConnect DHT22; BMP180 sensors and send data to Blynk appESP32ReadESP32 guidefirst.01_touch_button.pyConnect TTP223B touch sensor to ESP32 and react to touch02_terminal_cli.pyCommunication between ESP32 hardware and app through Terminal widget03_temperature_humidity_dht22.pyConnect DHT22 sensor to ESP32 and send data to Blynk appESP8266ReadESP8266 guidefirst.01_potentiometer.pyCconnect potentiometer to ESP8266 and send resistance value to the appMemory size limitationsFor hardware with limited memory size (ex. ESP8266) you can usefrozen modulesorfrozen bytecodeapproaches
to loadblynklibor any other library to hardware.Readthis documentto get more information.Documentation and other helpful linksFull Blynk Documentation- a complete guide on Blynk featuresCommunity (Forum)- join a 500,000 Blynk community to ask questions and share ideasHelp Center- helpful articles on various Blynk aspectsCode Examples Browser- browse examples to explore Blynk possibilitiesOfficial WebsiteSocial Media:FacebookTwitterYoutubeInstagramLinkedInBlynk libraries for other platformsC++Node.js, Espruino, BrowsersPython(by Volodymyr Shymanskyy)ParticleLua, OpenWrt, NodeMCUOpenWrt packagesMBEDNode-REDLabVIEWC#ContributingYou are very welcome to contribute: stability bugfixes, new hardware support, or any other improvements. Please.LicenseThis project is released under The MIT License (MIT)