プログラム
publish.jl
#! /snap/bin/julia
# --------------------------------------------------------------------
import Pkg
# Pkg.add(url="https://github.com/denglerchr/Mosquitto.jl")
# Pkg.add("JSON")
using JSON
using Mosquitto
println(stderr,"*** 開始 ***")
client = Client("example.com", 1883)
for it =0 : 7
unit_aa = Dict()
unit_aa["ledno"] = it
unit_aa["status"] = true
json_str = JSON.json(unit_aa)
publish(client, "M5Stack", json_str)
sleep(2.0)
unit_aa["status"] = false
json_str = JSON.json(unit_aa)
publish(client, "M5Stack", json_str)
end
disconnect(client)
println(stderr,"*** 終了 ***")
# --------------------------------------------------------------------
実行結果
$ ./publish.jl
*** 開始 ***
Single thread, loop will be blocking, start it manually using loop_start(::Client) or call loop(client) regularly.
*** 終了 ***