PublishQueueExtRK testing

I am testing some of my old code with the new library: PublishQueueExtRk and withPublishCompleteUserCallback()

In my code, with PublishQueuePosixRK, I was able to pet the Watchdog when publishing was successful. Am I doing something wrong with the new library? I have not used a CloudEvent object yet. Perhaps I should get that going? Thanks for your help!

This log below shows the Watchdog timing out, no refresh:

0000011205 [system] INFO: Cloud connected
0000011206 [system.ledger] INFO: Subscribing to ledger updates
0000011209 [comm] INFO: Forcing a cloud ping
0000011422 [system.ledger] INFO: Subscribed to ledger updates
0000030000 [app] INFO: publish some info
0000060000 [app] INFO: publish some info
0000090000 [app] INFO: publish some info
0000120000 [app] INFO: publish some info
0000150000 [app] INFO: publish some info
0000180000 [app] INFO: publish some info
0000210000 [app] INFO: publish some info
0000240000 [app] INFO: publish some info
0000270000 [app] INFO: publish some info
0000300000 [app] INFO: publish some info

Serial connection closed.

my code:

//  Device OS 6.3.0
//  Particle Argon

#include "Particle.h"

#include "PublishQueueExtRK.h"
//  v(0.0.4)                               

#ifndef SYSTEM_VERSION_v620
SYSTEM_THREAD(ENABLED);
#endif

SYSTEM_MODE(AUTOMATIC);

SerialLogHandler logHandler(LOG_LEVEL_INFO);

const std::chrono::milliseconds g_oneMinuteInterval =     1min;

char g_szPublishEventData[particle::protocol::MAX_EVENT_DATA_LENGTH];    
static retained uint32_t g_magick = 0;

void setup() {

  PublishQueueExt::instance().setup();
  PublishQueueExt::instance().withPublishCompleteUserCallback([](bool succeeded, const char *eventName, const char *eventData) {
    if (succeeded)  {
      Watchdog.refresh();
      Log.info("Refresh the watchdog... an event was successfully published with ACK: %s", eventName);  
    } else  {
      Log.error("Publish failed: %s", eventName); 
    }
  });
  PublishQueueExt::instance().withFileQueueSize(25);

  waitFor(Serial.isConnected, 5000);
  delay(1000);

  uint timeOutInMinutes = 5;
  uint32_t msTimeoutWatchdog = timeOutInMinutes * g_oneMinuteInterval.count();
  Watchdog.init(WatchdogConfiguration().timeout(msTimeoutWatchdog));
  Watchdog.onExpired([]() {
      g_magick++;
  });
  Watchdog.start();

  snprintf(g_szPublishEventData, sizeof(g_szPublishEventData), "timeout=%dmin", timeOutInMinutes);
  PublishQueueExt::instance().publish("hardware_watchdog", g_szPublishEventData);
}

void loop() {
  PublishQueueExt::instance().loop();

  static uint32_t lastLogTime = 0;
  if (millis() - lastLogTime >= 30000)
  {
    lastLogTime = millis();
    Log.info("publish some info");
    PublishQueueExt::instance().publish("some_event", "Some data.");
  }
}

0.0.5 (2025-04-11)

  • Added support for withPublishCompleteUserCallback(). It was not previously implemented, though the call to set it was left over from PublishQueuePosixRK. The new prototype only has a CloudEvent object you can use the determine success or failure, the event name, or the event data.

    /**
     * @brief Adds a callback function to call with publish is complete
     * 
     * @param cb Callback function or C++ lambda.
     * @return PublishQueueExt& 
     * 
     * The callback has this prototype and can be a function or a C++11 lambda, which allows the callback to be a class method.
     * 
     * void callback(const CloudEvent &event)
     * 
     * The parameters are:
     * - event: The CloudEvent object that was just sent
     * 
     * You can determine success/failure, examine the event. or the event data, by using methods of the CloudEvent class
     * 
     * Note that this callback will be called from the background thread used for publishing. You should not
     * perform any lengthy operations and you should avoid using large amounts of stack space during this
     * callback. 
     */
    PublishQueueExt &withPublishCompleteUserCallback(std::function<void(const CloudEvent &event)> cb) { publishCompleteUserCallback = cb; return *this; };

3 Likes