How to use Offline queuing in AWS IoT Core ?

0

Hello

I'm attempting to implement offline queuing in AWS IoT Core using the aws-iot-device-sdk in Node.js. However, it appears that the functionality is not functioning as expected. Specifically, when attempting to publish several messages and subsequently disconnecting the device from the internet, upon reconnecting, the device fails to send the queued messages. I've experimented with setting the qos parameter to 1 in the publish method's options, but the issue persists. Any insights or suggestions on how to address this challenge would be greatly appreciated.

Here is the sample code

// Dependencies
const awsIot = require('aws-iot-device-sdk');

const config = {
    clientId: 'iot_gateway_mac',
    host: 'a3gd7x8cytc09a-ats.iot.us-east-1.amazonaws.com',
    port: 8883,
    keyPath: './private.pem.key',
    certPath: './certificate.pem.crt',
    caPath: './AmazonRootCA1.pem',
    offlineQueueing: true, //
    offlineQueueMaxSize: 500,
    offlineQueueDropBehavior: 'newest',
    debug: true,

}

const device = awsIot.device(config);



const subscribe_topic = "/building/pacs/iot"
const event_topic = "/building/pacs/event"

const get_event_data = (cb) => {
        const event = { event: "reported data" }
        return cb(event)
    }


const send_data = (data) => {
    // Telemetry data
    const iot_device = {
        serialNumber: "SN-D7F3C8947867",
        dateTime: new Date(),
        activated: true,
        device: "IoT Gateway PoC",
        type: "IoT Gateway",
        payload: {}
    }
    const telemetry_data = {
        ...iot_device,
        payload: data
    }
    console.log(`STEP - Sending data to AWS  IoT Core'`, telemetry_data)
    console.log(`---------------------------------------------------------------------------------`)
    return device.publish(event_topic, JSON.stringify(telemetry_data), {qos: 1})
}

// We connect our client to AWS  IoT core. 
device
    .on('connect', function () {
        console.log('STEP - Connecting to AWS  IoT Core');
        console.log(`---------------------------------------------------------------------------------`)

        device.subscribe(subscribe_topic);

    });

device.on('close',  function () {
        console.log('Closing event');

    })

device.on('disconnect',  function () {
    console.log('Disconnect event');

})


// Set handler for the device, it will get the messages from subscribers topics.
device
    .on('message', function (topic, payload) {
        console.log('message', topic, payload.toString());
    });

device
    .on('error', function (topic, payload) {
        console.log('Error:', topic, payload);
    });

//  ( 
// async () =>{
//     for(let i = 0; i <7; i++){

//     await sleep(2000).then(_ => get_event_data(send_data))
// }    
//     // get_event_data(send_data)
// })();
setInterval(() => get_event_data(send_data), 3000);
  • Could you please update with your connection and publish code? That will help troubleshoot.

  • @gavin_A I've updated the question and added sample code.

feita há 6 meses87 visualizações
Sem respostas

Você não está conectado. Fazer login para postar uma resposta.

Uma boa resposta responde claramente à pergunta, dá feedback construtivo e incentiva o crescimento profissional de quem perguntou.

Diretrizes para responder a perguntas