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.


#4

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

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.


#5

What platform are you using?
For mesh devices you’d either need to tweak the library as shown here
https://github.com/particle-iot/device-os/issues/1641#issuecomment-448984605

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.


#6

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.


#7

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.


#8

SOLVED. Soldering had some how jiggled loose! Thanks,