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

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:

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.

waitUntil(Particle.connected);
Particle.publish("SETUP", "SETUP DATA");
2 Likes