Open MagnusLii opened 7 months ago
def publishJSONtoMQTT(topic, message):
try:
mqtt.publish(topic, message, qos=mqttQoSLevel)
except:
print(f'Failed to publish to topic: {topic}')
return False
else:
return True
MQTT publish function
Goal
The objective is to develop a robust function capable of accepting a JSON object, an integer representing the Quality of Service (QoS) level, and a topic name. The function tries to publish the JSON message as to the specified topic. The function should not modify the input arguments in any way.
Arguments
Returns
Boolean:
True
if the message is successfully published;False
if any issues occur during the publishing process.Name of function
publishJSONtoMQTT