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.");
}
}