Publishing Humidity/Temperature


#1

https://go.particle.io/shared_apps/5c64830cec6017000ab1aaa8

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


#2

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)

#3

Okay, thank you.