Publishing Humidity/Temperature


Does anyone know why this would be publishing the Humidity and Temperature twice in a row every time its publishing? Thanks.


You have some return statements between your if (millis() - previousPublish >= publish_delay) and the assignment previousPublish = millis();
If any of these bails out before assigning the new time, your check will trigger again.

BTW, there are some other things you may want to reconsider

  • you are using the old style for Particle.variable() try adopting the new version
  • when providing a string literal there is no use in casting a string to String (e.g. String("someString") just works as "someString")
  • you should (and have to with device OS 0.8.0-rc.4 and after) add the scope parameter (PRIVATE or PUBLIC) to Particle.publish() - but unless absolutely necessary don’t use PUBLIC
  • try to avoid String wherever possible and use C-strings (aka character arrays)


Okay, thank you.