# PublishQueuePosix library help

**URL:** <https://community.particle.io/t/publishqueueposix-library-help/61354>\
**Category:** Libraries\
**Created:** [October 21, 2021, 7:03pm UTC](https://community.particle.io/t/publishqueueposix-library-help/61354 "2021-10-21T19:03:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![imenninga](https://avatars.discourse-cdn.com/v4/letter/i/ea5d25/32.png) [@imenninga](https://community.particle.io/u/imenninga)\
**Post date:** [October 21, 2021, 7:03pm UTC](https://community.particle.io/t/publishqueueposix-library-help/61354/1 "2021-10-21T19:03:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![chipmc](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/chipmc/32/15905_2.png) [@chipmc](https://community.particle.io/u/chipmc)\
**Post date:** [October 21, 2021, 7:47pm UTC](https://community.particle.io/t/publishqueueposix-library-help/61354/2 "2021-10-21T19:47:44Z")

</div>

@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:

```auto
#include "PublishQueuePosixRK.h" // Allows for queuing of messages - https://github.com/rickkas7/PublishQueuePosixRK

```

In setup()

```auto
// 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()

```auto

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,

Chip

---

<div class="post-metadata">

**Author:** ![imenninga](https://avatars.discourse-cdn.com/v4/letter/i/ea5d25/32.png) [@imenninga](https://community.particle.io/u/imenninga)\
**Post date:** [October 21, 2021, 8:29pm UTC](https://community.particle.io/t/publishqueueposix-library-help/61354/3 "2021-10-21T20:29:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![chipmc](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/chipmc/32/15905_2.png) [@chipmc](https://community.particle.io/u/chipmc)\
**Post date:** [October 21, 2021, 9:25pm UTC](https://community.particle.io/t/publishqueueposix-library-help/61354/4 "2021-10-21T21:25:54Z")

</div>

@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:

```auto
// 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!

---

<div class="post-metadata">

**Author:** ![imenninga](https://avatars.discourse-cdn.com/v4/letter/i/ea5d25/32.png) [@imenninga](https://community.particle.io/u/imenninga)\
**Post date:** [October 22, 2021, 8:03pm UTC](https://community.particle.io/t/publishqueueposix-library-help/61354/5 "2021-10-22T20:03:24Z")

</div>

@chipmc

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/3/2/3291e3c9351789fe8620ae5bcec8d3fec67ff221.png) [@system](https://community.particle.io/u/system)\
**Post date:** [December 21, 2021, 8:03pm UTC](https://community.particle.io/t/publishqueueposix-library-help/61354/6 "2021-12-21T20:03:31Z")

</div>

Closed on December 21, 2021, 8:03pm UTC

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