• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Split MQTT messages to AWS IoT Core

Resolved: Split MQTT messages to AWS IoT Core

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

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!

mqtt python
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: How to efficient create SimpleITK image?

01/04/2023

Resolved: How can I write CSS selector(s) that apply to table rows for all td elements on that row after a td with a certain class?

01/04/2023

Resolved: How do I use SetWindowText with Unicode in Win32 using PowerShell?

01/04/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.