All Projects → xHasKx → Luamqtt

xHasKx / Luamqtt

Licence: mit
luamqtt - Pure-lua MQTT v3.1.1 and v5.0 client

Programming Languages

lua
6591 projects

Projects that are alternatives of or similar to Luamqtt

Broadlink Mqtt
MQTT client to control BroadLink devices
Stars: ✭ 169 (+191.38%)
Mutual labels:  mqtt, mqtt-client, internet-of-things
Paho.mqtt.java
Eclipse Paho Java MQTT client library. Paho is an Eclipse IoT project.
Stars: ✭ 1,620 (+2693.1%)
Mutual labels:  mqtt, mqtt-client, internet-of-things
Hivemq Mqtt Client
HiveMQ MQTT Client is an MQTT 5.0 and MQTT 3.1.1 compatible and feature-rich high-performance Java client library with different API flavours and backpressure support
Stars: ✭ 402 (+593.1%)
Mutual labels:  mqtt, mqtt-client, internet-of-things
WeConnect-mqtt
MQTT Client that publishes data from Volkswagen WeConnect
Stars: ✭ 14 (-75.86%)
Mutual labels:  mqtt, smarthome, mqtt-client
Awesome Mqtt
A curated list of MQTT related stuff. ✨
Stars: ✭ 1,667 (+2774.14%)
Mutual labels:  smarthome, mqtt, internet-of-things
Pjon
PJON (Padded Jittering Operative Network) is an experimental, arduino-compatible, multi-master, multi-media network protocol.
Stars: ✭ 2,615 (+4408.62%)
Mutual labels:  mqtt, protocol, internet-of-things
Psmqtt
Utility reporting system health and status via MQTT
Stars: ✭ 95 (+63.79%)
Mutual labels:  mqtt, mqtt-client, internet-of-things
Mqttclient
A high-performance, high-stability, cross-platform MQTT client, developed based on the socket API, can be used on embedded devices (FreeRTOS / LiteOS / RT-Thread / TencentOS tiny), Linux, Windows, Mac, with a very concise The API interface realizes the quality of service of QOS2 with very few resources, and seamlessly connects the mbedtls encryption library.
Stars: ✭ 234 (+303.45%)
Mutual labels:  mqtt, mqtt-client, ssl
ArduinoMqtt
MQTT client for Arduino
Stars: ✭ 58 (+0%)
Mutual labels:  mqtt, internet-of-things, mqtt-client
Awesome Home Assistant
A curated list of amazingly awesome Home Assistant resources.
Stars: ✭ 3,487 (+5912.07%)
Mutual labels:  smarthome, mqtt, internet-of-things
Paho.mqtt.c
An Eclipse Paho C client library for MQTT for Windows, Linux and MacOS. API documentation: https://eclipse.github.io/paho.mqtt.c/
Stars: ✭ 1,056 (+1720.69%)
Mutual labels:  mqtt, internet-of-things
Redmatic
Node-RED packaged as Addon for the Homematic CCU3 and RaspberryMatic 🤹‍♂️
Stars: ✭ 407 (+601.72%)
Mutual labels:  smarthome, mqtt
Adafruit mqtt library
Arduino library for MQTT support
Stars: ✭ 441 (+660.34%)
Mutual labels:  mqtt, mqtt-client
Homepoint
Espressif ESP32 Based Smarthome screen for MQTT
Stars: ✭ 391 (+574.14%)
Mutual labels:  smarthome, mqtt
Qmqtt
MQTT Client for Qt
Stars: ✭ 409 (+605.17%)
Mutual labels:  mqtt, mqtt-client
Tdm
GUI application to discover and monitor devices flashed with https://github.com/arendst/Sonoff-Tasmota
Stars: ✭ 385 (+563.79%)
Mutual labels:  mqtt, mqtt-client
Haswitchplate
LCD touchscreen for Home Automation
Stars: ✭ 666 (+1048.28%)
Mutual labels:  smarthome, mqtt
Hbmqtt
MQTT client/broker using Python asynchronous I/O
Stars: ✭ 667 (+1050%)
Mutual labels:  mqtt, mqtt-client
Zigbee2mqttassistant
GUI for Zigbee2Mqtt running in docker and HASS.IO
Stars: ✭ 371 (+539.66%)
Mutual labels:  smarthome, mqtt
Mosquitto Php
A wrapper for the Eclipse Mosquitto™ MQTT client library for PHP.
Stars: ✭ 448 (+672.41%)
Mutual labels:  mqtt, mqtt-client

luamqtt - Pure-lua MQTT v3.1.1 and v5.0 client

License Build Status Coverage Status Mentioned in Awesome MQTT

luamqtt logo

forthebadge

MQTT ( 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

  • Full MQTT v3.1.1 client-side support
  • Full MQTT v5.0 client-side support
  • Several long-living MQTT clients in one script thanks to ioloop

Documentation

See https://xhaskx.github.io/luamqtt/

Forum

See flespi forum thread

Source Code

https://github.com/xHasKx/luamqtt

Dependencies

The 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 versions

It's tested to work on Debian 9 GNU/Linux with Lua versions:

  • Lua 5.1 ... Lua 5.3 (i.e. any modern Lua version)
  • LuaJIT 2.0.0 ... LuaJIT 2.1.0 beta3
  • It may also work on other Lua versions without any guarantees

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.

Installation

As 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

LuaRocks page

Examples

Here is a short version of examples/simple.lua:

-- 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 examples/ directory. Also checkout tests in tests/spec/mqtt-client.lua

Also you can learn MQTT protocol by reading tests/spec/protocol4-make.lua and tests/spec/protocol4-parse.lua tests

Connectors

Connector is a network connection layer for luamqtt. There is a three standard connectors included:

The luasocket or luasocket_ssl connector will be used by default, if not specified, according secure=true/false option per MQTT client.

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 & contributing

Please file a GitHub issue if you found any bug.

And of course, any contribution are welcome!

Tests

To 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 coverage

Code 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 version

Currently supported is:

Both protocols has full control packets support.

LICENSE

Standard MIT License, see LICENSE file for full text

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].