Make sure you check Particle.connected() before you call Particle.publish(). If you call Particle.publish() while the cloud is enabled but not connected, the function will block until the cloud is actually connected.