2024-09-05 18:12:00 +02:00
# MineQTT
## Installation
2024-09-06 00:25:32 +02:00
### via OPPM
```
oppm register lujoga/oppm
```
```
oppm install mqtt
```
### via interactive Lua shell
2024-09-05 18:12:00 +02:00
```lua
2024-09-05 22:26:43 +02:00
local net = require("internet"); local io = require("io"); local f = io.open("/lib/mqtt.lua", "w"); for line in net.request("https://git.luj0ga.de/luca/mineqtt/raw/branch/main/mqtt.lua") do f:write(line) end; f:flush():close()
2024-09-05 18:12:00 +02:00
```
## Usage
```lua
local mqtt = require("mqtt")
local client, err = mqtt.open("mqtt.example.org", 1883)
if err ~= nil then
error(err)
end
local err = client:connect()
if err ~= nil then
error(err)
end
local err = client:handle()
if err ~= nil then
error(err)
end
print(client.is_connected)
2024-09-05 23:27:21 +02:00
local err = client:publish("test", "Test Message Please Ignore")
if err ~= nil then
error(err)
end
2024-09-05 18:12:00 +02:00
local err = client:disconnect()
if err ~= nil then
error(err)
end
```