blynk-library-lua
blynk-library-lua copied to clipboard
Blynk library for Lua. Works with Lua 5.1+, LuaJIT, NodeMCU.
Lua client for Blynk IoT
Note: The library has been updated for Blynk 2.0
If you like Blynk - give it a star, or fork it and contribute!
What is Blynk?
Blynk provides iOS and Android apps to control any hardware over the Internet or directly using Bluetooth. You can easily build graphic interfaces for all your projects by simply dragging and dropping widgets, right on your smartphone. Blynk is the most popular IoT platform used by design studios, makers, educators, and equipment vendors all over the world.

Download
Blynk Mobile App:
Google Play |
App Store
Documentation
Social: Webpage / Facebook / Twitter / Kickstarter
Documentation: https://docs.blynk.io
Community Forum: http://community.blynk.cc
Blynk for Business: http://www.blynk.io
Usage example
local Blynk = require("blynk.socket")
local blynk = Blynk.new("your_auth_token")
-- callback to run when V1 changes
blynk:on("V1", function(param)
print("V1:", tonumber(param[1]), tonumber(param[2]))
end)
-- callback to run when cloud requests V2 value
blynk:on("readV2", function(param)
blynk:virtualWrite(2, os.time())
end)
local sock = getSocketConnection() -- omitted
blynk:connect(sock)
while true do
blynk:run()
end
You can run the full example:
lua ./examples/client.lua <your_auth_token>
Features
- Lua 5.1, Lua 5.2, Lua 5.3, LuaJIT support
Linux,
Windows,
MacOS support
virtualWritesyncVirtualsetPropertylogEvent- events:
Vn,readVn,connected,disconnected,redirect TCPand secureTLS/SSLconnection support- can run on embedded hardware, like
NodeMCUorOpenWrt
OpenWrt installation
opkg update
opkg install lua luasocket luasec
# openssl is needed for wget to handle https://
opkg install wget openssl-util libustream-openssl
# Get blynk-library-lua from github
cd /root
wget --no-check-certificate -qO- https://github.com/vshymanskyy/blynk-library-lua/archive/v0.2.0.tar.gz | tar xvz
cd blynk-library-lua-0.2.0
# Run it
lua ./examples/client.lua <your_auth_token>
NodeMCU installation
It is very easy to get it running on NodeMCU (or any other ESP8266/ESP32-based device):
- Get the latest nodemcu-firmware running on your device.
You can use their online build service.
It is recommended to includeencoder,TLS/SSLmodules. - Edit
nodemcu.luaexample (put yourauth tokenand wifi credentials) - Use
nodemcu-toolor any other method to transfer lua files to the device.
Note: the NodeMCU filesystem is "flat" (folders not supported), but it handles the/symbol nicely.
Be sure to preserve the relative path when copying files:nodemcu-tool upload -mck ./blynk.lua ./blynk/pipe.lua ./blynk/nodemcu.lua nodemcu-tool upload ./examples/nodemcu.lua -n init.lua - Open device terminal and run
dofile("init.lua") blynkobject is global, so you can call it from the interactive console:blynk:virtualWrite(1, tmr.time())
Ubuntu/Linux/Raspberry Pi installation
sudo apt-get install lua5.3 lua-sec lua-socket
Bonus
The Timer is included for demonstration purposes.
Here are also some handy functions:
local function millis()
return math.floor(socket.gettime()*1000)
end
local function delay(msec)
return socket.sleep(msec/1000)
end
Implementations for other platforms
- Arduino
- Particle
- Node.js, Espruino, Browsers
- Python, MicroPython
- OpenWrt packages
- MBED
- Node-RED for Blynk IoT
- LabVIEW
- C#
License
This project is released under The MIT License (MIT)