# Can't Particle.publish() in setup() with CPP file

**URL:** <https://community.particle.io/t/cant-particle-publish-in-setup-with-cpp-file/66688>\
**Category:** Firmware\
**Tags:** argon\
**Created:** [April 8, 2024, 9:26pm UTC](https://community.particle.io/t/cant-particle-publish-in-setup-with-cpp-file/66688 "2024-04-08T21:26:01Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![rickkas7](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rickkas7/32/8681_2.png) [@rickkas7](https://community.particle.io/u/rickkas7)\
**Post date:** [April 9, 2024, 9:25am UTC](https://community.particle.io/t/cant-particle-publish-in-setup-with-cpp-file/66688/3 "2024-04-09T09:25:43Z")

</div>

What ScruffR said. The old template did not enable threading, but the new .cpp one does. It's not a .ino/.cpp difference per se, but rather:

```cpp
SYSTEM_THREAD(ENABLED);

```

When threading is enabled setup runs before cloud connectivity is established and publish may fail.

With threading disabled (or the line is missing), setup and loop only run when cloud connected and publish will generally succeed.

Setting a flag and publishing from loop when cloud connected is the best long-term solution, but you could insert this right before the publish call to make setup wait until cloud connected so the publish works.

```cpp
waitUntil(Particle.connected);
Particle.publish("SETUP", "SETUP DATA");

```

---

_[View the full topic](https://community.particle.io/t/cant-particle-publish-in-setup-with-cpp-file/66688)._
