10

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?

7

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.

  • 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? – Mawg says reinstate Monica Jul 12 '17 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 '17 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? – cogitoergosum Jun 16 '18 at 3:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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