I am trying to follow the instruction for “Test publishing and subscribing on a test topic” at MQTT — OpenEnergyMonitor 0.0.1 documentation. But I’m finding my emonPi (a Raspberry Pi 3 Model B Rev 1.2, running emonpiRelease: emonSD-24Jul20) does not recognize either mosquitto_sub
or mosquitto_pub
commands. Does the mosquitto clients need to be activated or installed?
Yes, you need to install the package
sudo apt install -y mosquitto-clients
I’ll amend the Docs.
Yes indeed - thank you!
After installation of mosquitto-clients, this works at command line:
$ mosquitto_pub -u 'emonpi' -P 'emonpimqtt2016' -t 'emon/Node_name/value1' -m '543.21'
This sends the value 543.21 to node “Node_name” with Input name “value1”
Using mosquitto_pub
at the command line may not be practical for routine use, but the command can be called in a Python script using os.system
to pass it as a shell command. Here’s an example:
import os
topic = 'Node_name/value1'
value = 543.21
message = "mosquitto_pub -u 'emonpi' -P 'emonpimqtt2016' -t 'emon/AAA' -m 'NNN'"
message = message.replace('AAA', topic)
message = message.replace('NNN', str(value))
os.system(message)
Or use the Mosquitto Python library
Yes, I’m playing with the Mosquitto Python library now. This works:
import paho.mqtt.publish as publish
# publish a single message
publish.single(topic="emon/test001/value1", payload="789.0", auth={'username':"emonpi",'password':"emonpimqtt2016"})
Fun! Now I will build on this to replace the use of requests
to transmit the Mem and Swap data I’m collecting on my local emoncms server to Inputs that I can save as Feeds, as I documented here:
https://community.openenergymonitor.org/t/re-ram-use-increases-continuously-to-failure/18069/2?u=sroof
That link doesn’t work.
Currently no issue with RAM unless you have built that on Ubuntu 22.04.