We use MQTT (Message Queuing Telemetry Transport) as one way of passing data between different hardware devices and software components within the OpenEnergyMonitor ecosystem.

The emonPi and emonBase running our emonSD software stack includes a local Mosquitto MQTT server. A device can connect to this server and publish data to a MQTT topic. A script on the emonPi/emonBase then subscribes and receives the data sent by the device.

This Mosquitto server is accessible via authentication on port 1883.
See MQTT Service Credentials.

MQTT Publishers


EmonHub python service decodes the data received from the emonPi/emonBase + RF nodes and publishes to the emonPi/emonBase’s Mosquitto MQTT server using the following two topic formats (both formats are published to parallel):

1. New MQTT Topic Format

Each data key (power) has its own MQTT topic as a sub-topic of the NodeID or NodeName. This MQTT topic structure makes it far easier to subscribe to a particular node key of interest e.g. emontx/power1 using another service e.g. openHAB.


Note: the default base topic is emon/ this is set in /etc/emonhub/emonhub.conf and /var/www/emoncms/settings.ini.



2. Legacy CSV MQTT Topic Format

Used by older version of emonPi and emonPiLCD service. All data from a single node is published in CSV format to a single topic. More compact but does not allow naming of keys and difficult to subscribe to a single key.

emonhub/rx/[nodeID]/values format


emonhub/rx/10/values format

The emonHub service can be restarted with $ sudo service emonhub restart. Latest log file entries can be viewed via the Emoncms web interface admin or with: $ tail /var/log/emonhub/emonhub.log. All the data currently being published to MQTT topic can be viewed in real-time in the EmonHub log.

Emoncms Publisher

Data can be published to an MQTT topic using the Publish to MQTT Emoncms Input Process. In the Input process ‘Text’ box add the topic, for example: house/power/solar.

MQTT Subscribers

Emoncms MQTT Service

The Emoncms MQTT service subscribes to the MQTT base topic (default emon/#) and posts any data on this topic to Emoncms Inputs with the NodeName and KeyName taken from the MQTT topic and sub-topic name.


A power value published to emon/emonpi/power1 would result in an Emoncms Input from Node: emonpi with power1=XX.

Data from any service (internal or external) that connect to the MQTT server (assuming authentication) and publishes to the base topic emon/ will appear in Emoncms. See related blog posts below for example posting temperature data to Emoncms from Weather Underground using NodeRED running locally on the emonPi.

Emoncms MQTT Service is running by default on the emonSD software stack

The MQTT input service can be restarted using $ sudo service emoncms_mqtt restart.The Emoncms MQTT service runs the emoncms_mqtt.php script. Latest log file entries can be viewed via Emoncms web interface admin or with: $ tail /var/log/emoncms/emoncms.log

EmonPiLCD Service

The emonPi’s python LCD Service Script subscribes to the ‘Legacy MQTT Topic’ structure to obtain the real-time data to display on the emonPi LCD.

The emonPiLCD service can be restarted with: $ sudo service emonPiLCD restart. Latest log file entries can be viewed with: $ tail /var/log/emonpilcd/emonpilcd.log.

Testing MQTT

To view all MQTT messages subscribe to emon/# base topic :

$ mosquitto_sub -v -u 'emonpi' -P 'emonpimqtt2016' -t 'emon/#'

To view all MQTT messages for a particular node subscribe to sub-topic:

$ mosquitto_sub -v -u 'emonpi' -P 'emonpimqtt2016' -t 'emon/emonpi/#'

Note: # denotes a wild-card

Test publishing and subscribing on a test topic:

Subscribe to test topic:

$ mosquitto_sub -v -u 'emonpi' -P 'emonpimqtt2016' -t 'test'

Open another shell window to publish to the test topic :

$mosquitto_pub -u 'emonpi' -P 'emonpimqtt2016' -t 'test' -m 'helloWorld'

If all is working we should see helloWord :-)

To avoid connecting via SSH alternately you could use MQTTlens Chrome Extension or any other MQTT client connected to the emonPi IP address on port 1883 with user name: emonpi and password: emonpimqtt2016.