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.


I have looked through this code step by step and have no idea why i am getting “0%” for humidity and “32°F” for temp published! I am still using the tinker code for testing my project so i can not remove that yet, and the set of code for the DS18B20 sensor I got from somewhere else and do not know much about it. Maybe there is something in there messing up my readings. Thanks for any help.


What platform are you using?
For mesh devices you’d either need to tweak the library as shown here

Or opt for another library like DS18B20

You also should re-read what I wrote above

The first point also applies to all your other Spark.xxxx() calls. Particle.xxxx() is the way to talk nowadays.


I had this exact same issue on a DHT11 sensor a couple of nights ago… In my haste, I forgot to add the 4.7k pull-up resistor on the data line. Check your wiring. Post a pic if you can. The pull up resistor also applies to the DS18B20 sensor as well.


Somehow I got the “Spark” and “Particle” switched in my head as to which one you suggested I use. Fixed now. I interchanged the libraries as recommended, and still nothing. I look at editing the other library and could not find where that other comment was referring to.


SOLVED. Soldering had some how jiggled loose! Thanks,