pylab_ml.common.mqtt_client.mqtt_deviceattributes
- class mqtt_deviceattributes[source]
Bases:
objectHandle MQTT messages for the instrument (=devices is ‘transmitter’).
- topic for the device:
f’{TOPIC_PREFIX}/’Hostname’/{TOPIC_INSTRUMENT}
- payload:
{“instrumentname”: {“type”: “set/get”, “cmd”: “function/attributename”, “payload”: yourvalues}}
mqtt_all will be overwriten, to uncover attributes for sending mqtt-messages
if you define the function ‘_mqtt2json(value, attributename)’ in your device, than this function will be call if a mqtt message should be send With this function you can translate the value, or it the result ‘nomqtt’ than the message will not be send.
Methods
__init__()close()mqtt_add(client, instrument[, liste, qos])Add the instrument to mqtt.
Remove the instrument from mqtt.
publish(topic, value)Publish topic as type='cmd' with payload=value.
publish_get(function_name, value)Publish function_name as type='get' with paylad=value.
publish_set(function_name, value)Publish function_name as type='set' with paylad=value.
Attributes
commandmqtt_enablemqtt_listGetter for the mqtt_status.
- json = <module 'json' from '/home/runner/miniconda3/envs/test/lib/python3.9/json/__init__.py'>
- mqtt_add(client, instrument, liste='#', qos=0)[source]
Add the instrument to mqtt. Calling from base_instrument, after the instrument (device) has been create. Normally you have not to use this function, only base_instrument use it.
- Parameters:
client (mqtt_init) – The MQTT client instance to which the instrument should be added.
instrument (object) – The instrument to be added to the MQTT client.
liste (list or str) – A list of attributes for which MQTT messages should be sent. If set to “#”, all attributes will be included (default: “#”).
qos (int) – The Quality of Service level for MQTT messages (default: 0).
- Return type:
None
- mqtt_disconnect()[source]
Remove the instrument from mqtt. Calling from base_instrument, if the instrument are closing. Normally you have not to use this function, only base_instrument use it.
- property mqtt_status
Getter for the mqtt_status.
- publish(topic, value)[source]
Publish topic as type=’cmd’ with payload=value.
- Parameters:
topic (str) – The name of the topic to publish.
value (any) – The value to be published.
- Return type:
None