12

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?

Bence Kaulics
  • 7,843
  • 8
  • 42
  • 90
MLu
  • 221
  • 2
  • 4

1 Answers1

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.

hardillb
  • 12,813
  • 1
  • 21
  • 34