2.9 KiB
2.9 KiB
MyEMS MQTT Publisher Service
Introduction
This service is a component of MyEMS to publish data to MQTT broker.
Prerequisites
simplejson
paho-mqtt
mysql.connector
Installation
Download and Install simplejson
$ cd ~/tools
$ git clone https://github.com/simplejson/simplejson.git
$ cd simplejson
$ sudo python3 setup.py install
Download and install MySQL Connector:
$ cd ~/tools
$ wget https://dev.mysql.com/get/Downloads/Connector-Python/mysql-connector-python-8.0.20.tar.gz
$ tar xzf mysql-connector-python-8.0.20.tar.gz
$ cd ~/tools/mysql-connector-python-8.0.20
$ sudo python3 setup.py install
Download and install paho-mqtt:
$ cd ~/tools
$ git clone https://github.com/eclipse/paho.mqtt.python.git
$ cd ~/tools/paho.mqtt.python
$ sudo python3 setup.py install
Install myems-mqtt-publisher service
$ cd ~
$ git clone https://github.com/myems/myems.git
$ cd myems
$ sudo git checkout master (or the latest release tag)
$ sudo cp -R ~/myems/myems-mqtt-publisher /myems-mqtt-publisher
Eidt the config
$ sudo nano /myems-mqtt-publisher/config.py
Setup systemd service:
$ sudo cp /myems-mqtt-publisher/myems-mqtt-publisher.service /lib/systemd/system/
$ sudo systemctl enable myems-mqtt-publisher.service
$ sudo systemctl start myems-mqtt-publisher.service
Topic
topic_prefix in config and point_id
Example:
'myems/point/3'
Payload
data_source_id, the Data Source ID.
point_id, the Point ID.
object_type, the type of data, is one of 'ANALOG_VALUE'(decimal(18, 3)) , 'ENERGY_VALUE'(decimal(18, 3)) and 'DIGITAL_VALUE'(int(11)).
utc_date_time, the date time in utc when data was acquired. The full format looks like 'YYYY-MM-DDTHH:MM:SS'.
value, the data value in Decimal or Integer.
Example:
{"data_source_id": 1, "point_id": 3, "object_type": 'ANALOG_VALUE', "utc_date_time": "2020-09-28T03:23:06", "value": Decimal('591960276.000')}
References
[1]. http://myems.io