myems/myems-mqtt-publisher
13621160019@163.com 6514e753d0 updated gitignore files 2021-02-20 20:04:48 +08:00
..
.gitignore updated gitignore files 2021-02-20 20:04:48 +08:00
LICENSE merged myems-mqtt-publisher 2021-02-19 13:21:05 +08:00
README.md merged myems-mqtt-publisher 2021-02-19 13:21:05 +08:00
acquisition.py merged myems-mqtt-publisher 2021-02-19 13:21:05 +08:00
config.py merged myems-mqtt-publisher 2021-02-19 13:21:05 +08:00
main.py merged myems-mqtt-publisher 2021-02-19 13:21:05 +08:00
myems-mqtt-publisher.service merged myems-mqtt-publisher 2021-02-19 13:21:05 +08:00
test.py merged myems-mqtt-publisher 2021-02-19 13:21:05 +08:00

README.md

MyEMS MQTT Publisher Service

Introduction

This service is a component of MyEMS to publish data to MQTT broker.

Codacy Badge Scrutinizer Code Quality Maintainability Total alerts

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

[2]. https://www.eclipse.org/paho/clients/python/

[3]. https://simplejson.readthedocs.io/