Question:
I am trying to send messages from multiple devices to the same iot/topic in AWS IoT Core using a python script. The script is below:
My flat data file looks like this:
Right now, the code dumps the data from both id’s as a single message payload. But, I want it to loop through the txt file and send one section at a time. Section being defined by {} and not by id (because I can have duplicate id’s). Additionally, I need it to ignore the [] in my data file and send the data as a json payload.
Answer:
Your code is already parsing and then re-encoding the JSON so the simplest approach is probably just iterate through the parsed array sending a message for each element i.e.:
Result:
If that is not what you are looking for then please provide an example of the output you need (but once the JSON has been parsed it’s pretty easy to work with in Python and your question is really about processing JSON not MQTT/Paho/AWS).
If you have better answer, please add a comment about this, thank you!