PublishQueuePosix library help

Has anyone used the PublishQueuePosix library successfully? I am looking for some tips to get this working; it would be super helpful to me to get an offline data caching feature up and running.

The basic issue I have is that stuff enters the cache, but doesn’t seem to leave when the device reconnects. I’ve done some testing over Serial and the code correctly adds new entries to the cache when offline. Our code reads data every 5 minutes, and publishes that data to the console. I looked at some of your examples and unit tests to try and get the library set up. Here’s what I set up -

  • I call PublishQueuePosix::instance().setup() and PublishQueuePosix::instance().withDirPath("/postqueue") in setup() .
  • At the top of loop() I call PublishQueuePosix::instance().loop()
  • Instead of Particle.publish() I am calling PublishQueuePosix::instance().publish("d", data, PRIVATE, NO_ACK) .
  • The only weird thing I’m doing is calling PublishQueuePosix::instance().loop() a second time right after publish . I found that not doing this caused exactly half of the publishes to be lost.

If anyone has experience with this library, I would love any tips or assistance.

@imenninga ,

Yes! I have been using this library and it has been a godsend for my devices with poor cellular connectivity or low solar exposure.

Note: This library requires a 3rd generation Particle device (eg Boron)

Here are my steps:

Up-front in my code:

#include "PublishQueuePosixRK.h"                    // Allows for queuing of messages -

In setup()

// Publish Queue Posix is used exclusively for sending webhooks in order to conserve RAM and reduce writes / wear
  PublishQueuePosix::instance().setup();                               // Tend to the queue
  PublishQueuePosix::instance().withRamQueueSize(0);                   // Writes to memory immediately
  PublishQueuePosix::instance().withFileQueueSize(96);                 // This should last at least two days

in loop()

PublishQueuePosix::instance().publish("Ubidots_Alert_Hook", data, PRIVATE);  // Example publish

PublishQueuePosix::instance().loop();                                // Check to see if we need to tend to the message queue

Perhaps take a look at your setup commands. Mine do three things:

  1. Call setup to start the library
  2. Write to memory immediately - note this preserves data but causes more writes to memory with could cause wear depending on the frequency of your writes
  3. Define the number of messages in the queue

Hope this helps,



Thanks Chip!

It’s super reassuring to hear that someone else is using this library, and that it is working well. I can’t see a whole lot that is different between your code and what I am running, except that it looks like you call loop() after calling publish(). Does that look correct to you?

Re: setup commands - I believe these have default values, and I haven’t messed with them a ton. I will try adding them back in to my code.

@imenninga ,

I don’t think it matters too much if your call to PublishQueuePosix::instance().loop(); is before or after your publishes as long as you run that command each time execution transits the main loop.

When you are observing your code in action, are you using the following:

// For monitoring / debugging, you can uncomment the next line
SerialLogHandler logHandler(LOG_LEVEL_ALL);

If so, you should see how things are connecting as your device connects to the Particle cloud.

Good luck!


Thank you so much for your help. With your debugging tip I was able to identify the issue. It appears the having NO_ACK in the publish causes the library to think all posts are successful. It prints the successful publish logging message even though the device has no connection, and the post never reaches the cloud. From my testing, it appears to be working perfectly now. I run my device it for a period of time with no connection, and upon re-connection it posts all the missing data.

Thanks for helping me with the debugging, I really appreciate it.


This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.