MQTT and API implementation¶
MQTT clients and related functionality¶
MQTT-class for communication between Gateway and ReCalc/Cloud at ReMoni¶
- Platform
Python 3.5.10 on Linux
- Synopsis
This module implements a class for MQTT Client
- Authors
Steffen Breinbjerg, Janus Bo Andersen
- Latest update
18 November 2020
- Version
1.2
Ver. 1.0: Setup MQTT class with loaded settings.
Ver. 1.1: Implement support functions for return codes and better printout for on_connect.
Ver. 1.2: Implemented TLS and better handling of reason codes.
MqttClient class¶
-
class
mqtt.MqttClient.MqttClient(name, on_message, on_publish, param_settings='mqtt_local')[source]¶ This class wraps a Paho MQTT client and sets it up using a profile from settings/secrets.yaml. On instantiation, all setup steps run up to and including connect.
-
__init__(name, on_message, on_publish, param_settings='mqtt_local')[source]¶ Handles all setup and connection when object is initialized.
-
static
on_connect(client: paho.mqtt.client.Client, userdata, flags, rc)[source]¶ on_connect callback rc argument value meaning:
0: Connection successful
1: Connection refused - incorrect protocol version
2: Connection refused - invalid client identifier
3: Connection refused - server unavailable
4: Connection refused - bad username or password
5: Connection refused - not authorised 6-255: Currently unused.
-
Supporting functions¶
-
mqtt.MqttClient.connection_rc_str(rc: Tuple) → str[source]¶ Returns text description of return codes for a connection attempt to server. Based on return code spec. from Paho MQTT. Alternatively, use mqtt.connack_string().
API implementation¶
API compliant messages¶
- Synopsis
Implements functionality to send and receive correctly formatted messages as spec’ed by ReMoni API v2.
- Authors
Jakob, Steffen, Janus
- Last update
18 Nov. 2020.
-
mqtt.api.build_api_message_from_log_obj(m: meter.MeterMeasurement.MeterMeasurement) → List[Any][source]¶ Due to bug in ReCalc, this currently only returns a list of Python dicts. In the future, should return the same dumped to JSON.