Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def on_message(client, userdata, msg):
- try:
- mqtt_message = str(msg.payload.decode('utf-8'))
- # Inside the json message object should be a client id
- mqtt_object = json.loads(mqtt_message)
- mqtt_client_id = mqtt_object["client_id"]
- if " " in mqtt_client_id or len(mqtt_client_id) < 3:
- print("Received an incorrect message, continuing")
- print(f"New message from - {mqtt_client_id}, msg - {mqtt_message}.")
- except KeyError:
- print("Received an incorrect message, continuing")
- pass
- except Exception as error:
- print(error)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement