How to Encode, Send and Receive JSON Data Using the Python MQTT Client

preview_player
Показать описание
-JSON has become a very popular format for sending and storing data.

In this tutorial you will learn how to send and receive JSON data using the Paho Python MQTT client.

We start with a brief description of what JSON is.

We then cover step by step how you take Python dictionary object and encode it as a JSON string and send it over MQTT.

We will then receive the JSOB string in the MQTT client and convert it back to a python dictionary object.

Download demo script used in video
Tutorial on website
Related videos and Tutorials

Related videos
Python MQTT Client The Loop and Callbacks explained
-------------
Simple MQTT Controllable Sensor Using Python
Have a question Use the comments or if you want help then use
If you find these videos useful then you might want to consider buying me a coffee
Рекомендации по теме
Комментарии
Автор

Very good explanation on the topic. Thank you.

evangeloslogaras
Автор

Thank you for explaining it very nicely

nandinisinha
Автор

8 minutes into one sentence. MQTT's publish function allows a JSON object for the message.

client.publish(topic, json_variable)

eksdro
Автор

Hi Steve, i have simple question, if i have raw data from 3Dconnection.com(broker2). Will i able to get the raw data from that broker? or if i have API keys from X, Y, Z will i still get raw data using this logic? please advice im looking at similar example one from this video

gcobanimkontwana
Автор

would you think it is possible to use a RPi4 to read a GEO_JSON file and make the RPi to drive for example 3 leds in function of the instructions in the JSON FILE??

marcelverhoeven
Автор

Hi Steve. Is the IP address for broker 1 mandatory? Can I instead use actual values for my dictionary such as Car: ""Honda"?. Just want to find out whether all the values in broker_out are required to establish the mqtt connection?

janicensunzu
Автор

Thanks for your tutorial|! I am trying to send an autodiscovery topic ro homeassistant mosquitio add-on for your virtual switch python program. PLease can you show me how to send the json payload?

sujitvasanth