0

I know AWS IOT supports QOS 0 and QOS 1. But I did not find anything regarding quality of service in node SDK. Can anyone tell me how can I publish with QOS 1.

device.on("connect", function() {
  console.log("connect");
  device.subscribe("topic_2");
  device.publish("topic/simer", JSON.stringify({ newTempature: "-48C" }));
  // device.publish("topic/simer", JSON.stringify({ newTempature: "-48C" }));
  // device.publish("topic/simer", JSON.stringify({ newTempature: "-48C" }));
});

device.on("message", function(topic, payload) {
  console.log("message", topic, payload.toString());
});`

Thanks

JoshMc
  • 10,239
  • 2
  • 19
  • 38

1 Answers1

1

The syntax looks like you are using the node MQTT.js library.

From https://www.npmjs.com/package/mqtt#publish the third parameter is a set of options that include the QOS level.

To publish with QOS 1:

device.publish("topic/simer",
  JSON.stringify({ newTempature: "-48C" }),
  { qos: 1 }
);
Ben T
  • 4,656
  • 3
  • 22
  • 22
  • Thanks Ben. My understanding of qos is saying there could be duplicate reports with qos 1. But its not sending report more than once with qos 1. – simerpreet jassal Mar 17 '20 at 15:31
  • 1
    Yes there *could* be duplicate messages with QoS 1. In this case it is dependent on whether the message acknowledgement is received by the publisher. https://stackoverflow.com/a/55624149/1373856 – Ben T Mar 17 '20 at 22:14