# Activating MQTT client services?

**URL:** <https://community.openenergymonitor.org/t/activating-mqtt-client-services/22819>\
**Category:** emonSD\
**Tags:** mqtt, emonpi\
**Created:** [9 February 2023 21:29 UTC](https://community.openenergymonitor.org/t/activating-mqtt-client-services/22819 "2023-02-09T21:29:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![sroof](https://community.openenergymonitor.org/letter_avatar_proxy/v4/letter/s/76d3ee/32.png) [@sroof](https://community.openenergymonitor.org/u/sroof)\
**Post date:** [9 February 2023 21:29 UTC](https://community.openenergymonitor.org/t/activating-mqtt-client-services/22819/1 "2023-02-09T21:29:35Z")

</div>

I am trying to follow the instruction for “Test publishing and subscribing on a test topic” at [MQTT — OpenEnergyMonitor 0.0.1 documentation](https://docs.openenergymonitor.org/emoncms/mqtt.html). 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?

---

<div class="post-metadata">

**Author:** ![borpin](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/borpin/32/193_2.png) [@borpin](https://community.openenergymonitor.org/u/borpin)\
**Post date:** [10 February 2023 07:22 UTC](https://community.openenergymonitor.org/t/activating-mqtt-client-services/22819/2 "2023-02-10T07:22:01Z")

</div>

Yes, you need to install the package

```auto
sudo apt install -y mosquitto-clients

```

I’ll amend the Docs.

---

<div class="post-metadata">

**Author:** ![borpin](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/borpin/32/193_2.png) [@borpin](https://community.openenergymonitor.org/u/borpin)\
**Post date:** [10 February 2023 07:29 UTC](https://community.openenergymonitor.org/t/activating-mqtt-client-services/22819/3 "2023-02-10T07:29:48Z")

</div>

> <https://github.com/emoncms/emoncms/pull/1840>
>
> re https://community.openenergymonitor.org/t/activating-mqtt-client-services/228…19/

---

<div class="post-metadata">

**Author:** ![sroof](https://community.openenergymonitor.org/letter_avatar_proxy/v4/letter/s/76d3ee/32.png) [@sroof](https://community.openenergymonitor.org/u/sroof)\
**Post date:** [10 February 2023 14:16 UTC](https://community.openenergymonitor.org/t/activating-mqtt-client-services/22819/4 "2023-02-10T14:16:33Z")

</div>

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:

```auto
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)

```

---

<div class="post-metadata">

**Author:** ![borpin](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/borpin/32/193_2.png) [@borpin](https://community.openenergymonitor.org/u/borpin)\
**Post date:** [10 February 2023 15:30 UTC](https://community.openenergymonitor.org/t/activating-mqtt-client-services/22819/5 "2023-02-10T15:30:30Z")

</div>

> [@sroof](#):
>
> 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

Or use the Mosquitto Python library 🤣

---

<div class="post-metadata">

**Author:** ![sroof](https://community.openenergymonitor.org/letter_avatar_proxy/v4/letter/s/76d3ee/32.png) [@sroof](https://community.openenergymonitor.org/u/sroof)\
**Post date:** [10 February 2023 16:33 UTC](https://community.openenergymonitor.org/t/activating-mqtt-client-services/22819/6 "2023-02-10T16:33:06Z")

</div>

Yes, I’m playing with the Mosquitto Python library now. This works:

```auto
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](https://community.openenergymonitor.org/t/re-ram-use-increases-continuously-to-failure/18069/2)

---

<div class="post-metadata">

**Author:** ![borpin](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/borpin/32/193_2.png) [@borpin](https://community.openenergymonitor.org/u/borpin)\
**Post date:** [10 February 2023 16:58 UTC](https://community.openenergymonitor.org/t/activating-mqtt-client-services/22819/7 "2023-02-10T16:58:26Z")

</div>

That link doesn’t work.

Currently no issue with RAM unless you have built that on Ubuntu 22.04.
