开源软件名称(OpenSource Name):xHasKx/luamqtt开源软件地址(OpenSource Url):https://github.com/xHasKx/luamqtt开源编程语言(OpenSource Language):Lua 97.4%开源软件介绍(OpenSource Introduction):luamqtt - Pure-lua MQTT v3.1.1 and v5.0 clientMQTT ( http://mqtt.org/ ) client library for Lua. MQTT is a popular network communication protocol working by "publish/subscribe" model. This library is written in pure-lua to provide maximum portability. Features
DocumentationSee https://xhaskx.github.io/luamqtt/ ForumSource Codehttps://github.com/xHasKx/luamqtt DependenciesThe only main dependency is a luasocket to establishing TCP connection to the MQTT broker. Install it like this: luarocks install luasocket On Lua 5.1 it also depends on LuaBitOp (bit) library to perform bitwise operations. It's not listed in package dependencies, please install it manually like this: luarocks install luabitop luasec (SSL/TLS)To establish secure network connection (SSL/TSL) to MQTT broker you also need luasec module, please install it manually like this: luarocks install luasec This stage is optional and may be skipped if you don't need the secure network connection (e.g. broker is located in your local network). Lua versionsIt's tested to work on Debian 9 GNU/Linux with Lua versions:
Also I've successfully run it under Windows and it was ok, but installing luarock-modules may be a non-trivial task on this OS. InstallationAs the luamqtt is almost zero-dependency you have to install required Lua libraries by yourself, before using the luamqtt library: luarocks install luasocket # optional if you will use your own connectors (see below)
luarocks install luabitop # you don't need this for lua 5.3
luarocks install luasec # you don't need this if you don't want to use SSL connections Then you may install the luamqtt library itself: luarocks install luamqtt Or for development purposes; # development branch:
luarocks install luamqtt --dev
# or from the cloned repo:
luarocks make ExamplesHere is a short version of -- load mqtt library
local mqtt = require("mqtt")
-- create MQTT client, flespi tokens info: https://flespi.com/kb/tokens-access-keys-to-flespi-platform
local client = mqtt.client{ uri = "mqtt.flespi.io", username = os.getenv("FLESPI_TOKEN"), clean = true }
-- assign MQTT client event handlers
client:on{
connect = function(connack)
if connack.rc ~= 0 then
print("connection to broker failed:", connack:reason_string(), connack)
return
end
-- connection established, now subscribe to test topic and publish a message after
assert(client:subscribe{ topic="luamqtt/#", qos=1, callback=function()
assert(client:publish{ topic = "luamqtt/simpletest", payload = "hello" })
end})
end,
message = function(msg)
assert(client:acknowledge(msg))
-- receive one message and disconnect
print("received message", msg)
client:disconnect()
end,
}
-- run ioloop for client
mqtt.run_ioloop(client) More examples placed in Also you can learn MQTT protocol by reading ConnectorsConnector is a network connection layer for luamqtt. There is a three standard connectors included:
The In simple terms, connector is a set of functions to establish a network stream (TCP connection usually) and send/receive data through it. Every MQTT client instance may have their own connector. And it's very simple to implement your own connector to make luamqtt works in your environment. Bugs & contributingPlease file a GitHub issue if you found any bug. And of course, any contribution are welcome! TestsTo run tests in this git repo you need busted: busted -e 'package.path="./?/init.lua;./?.lua;"..package.path' tests/spec/*.lua There is a script to run all tests for all supported lua versions, using hererocks: ./tests/run-for-all-lua-versions.sh Code coverageCode coverage may be collected using luacov. To collect code coverage stats - install luacov using luarocks and then execute: # collect stats during tests
busted -v -e 'package.path="./?/init.lua;./?.lua;"..package.path;require("luacov.runner")(".luacov")' tests/spec/*.lua
# generate report into luacov.report.out file
luacov MQTT versionCurrently supported is:
Both protocols has full control packets support. LICENSEStandard MIT License, see LICENSE file for full text Version bump checklist
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论