• For a battery operated IoT device which requires infrequent updates, it would be great to enter deep sleep, wake up every so often, connect to an mqtt broker and publish update(s), then disconnect and go back to deep sleep.

    In trying to accomplish this goal, using the 'MQTT' module, the first hurdle is knowing when all the messages have been published so that we can go back to sleep. Even for QOS 0, it's not easy knowing exactly when the code can issue the setDeepSleep(1) command.

    Using QOS 1, I thought I could register a 'puback' handler, and sleep on that, but it turns out the current 'MQTT' module doesn't do anything with a PUBACK.

    I don't know if the forum is the right place to suggest this, but what about emitting a puback if that has been received from the broker? Something like...

    else if (type === TYPE.PUBACK) {
        mqo.emit('puback', data.charCodeAt(2) << 8 | data.charCodeAt(3));
    }
    

    Then in the user code, a handler would be something like...

    mqtt.on('puback', (pid) => {
         mqtt.disconnect();
         wifi.disconnect();
         setDeepSleep(1);
    });
    

    (not doing anything with pid right now, since the user code has no method to get the outgoing pid anyway)

About

Avatar for ScottyMT @ScottyMT started