11

I've got a device with multiple sensors that publishes each sensor reading separately to topics like

device1-id/sensor1-id = 10.2
device1-id/sensor2-id = 15.5
[...]

We feed it to AWS IoT using Amazon AWS IoT SDK, i.e.

mqtt_params.qos = QOS1;
mqtt_params.payload = payload;
mqtt_params.payloadLen = payload_len;
rc = aws_iot_mqtt_publish(&client, topic, topic_len, &mqtt_params);

Each call generates a separate TCP packet and a separate response from AWS MQTT broker. The problem is that some of our nodes are on a very slow network and waiting for ACK after every packet delays the publishing.

Is there any way to bundle all the sensor readings together, to a single TCP packet, while publishing them into separate topics and keeping the QOS=1?

1 Answer 1

8

It looks like the aws IoT sdk is using a synchronous publish (as it's using a return code) so it's blocking for each message.

There is no reason at the MQTT protocol level that you can't have multiple messages in flight at once so you could look at using the paho asynchronous client so that waiting on the QOS1 response can be done without blocking the publishing of the next message.

Another option would be to publish just one composite message with all the sensor values in one go and splitting it up at the consumer end.

5
  • 1
    Just so long as he isn't worried about the response code. If you get a non 200 OK response, does that mean that both operations failed? Only one? If so, which one? Jul 12, 2017 at 7:52
  • You can s still check the return code, you just need to check it against the token returned from the publish to know which one it relates to.
    – hardillb
    Jul 12, 2017 at 8:15
  • But, unlike SUBSCRIBE, we can't set-up an array of topics and their corresponding messages in the same MQTT message, right? Jun 16, 2018 at 3:55
  • hardillb you told "Another option would be to publish just one composite message with all the sensor values in one go and splitting it up at the consumer end." By this do you mean The multi-level wildcard?
    – user170106
    Apr 24, 2020 at 11:22
  • 1
    @user170106 No, bundling all the updates into a single message would mean you only need to subscribe to a single topic.
    – hardillb
    Apr 24, 2020 at 12:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.