This Spoon will let you publish to MQTT. It's intention is a utility function to be used elsewhere; it doesn't do much by itself.
Largely based on hammerspoon-mqtt-sleepwatcher which showed me how to use mqtt and mosquitto. I wanted a separate mqtt spoon so I've borrowed the parts I needed heavily (Thank you!)
- Hammerspoon
mosquitto_pub
from the Mosquitto installation.
- Install mosquitto with
brew install mosquitto
- Copy this repo to
~/.hammerspoon/Spoons/Mqtt.Spoon
directory - Edit your main
init.lua
and set the startup variables appropriately.
Your init.lua
file can remain largely unchanged. Just add the Spoon startup code and configuration to it.
hs.loadSpoon('SleepWatch')
spoon.Mqtt.host = 'YOUR MQTT HOST'
spoon.Mqtt.user = 'YOUR MQTT USERNAME'
spoon.Mqtt.pass = 'YOUR MQTT PASSWORD'
spoon.Mqtt.topic = 'MQTT TOPIC TO PUBLISH ON'
spoon.SleepWatch:start()
Change the port if you're not using the default port 1883 or 8883. Required for CloudMQTT.
spoon.Mqtt.port = 'YOUR MQTT PORT'
This will force a TLS connections and change the connection port to 8883. MacOS keeps certificates in the keychain. If you are using brew
then the openssl makes these available in /usr/local/etc/openssl/cert.pem
spoon.Mqtt.certFile = 'CERT FILE'
or
spoon.Mqtt.certPath = 'CERT PATH'