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("someString")just works as
- you should (and have to with device OS 0.8.0-rc.4 and after) add the scope parameter (
Particle.publish()- but unless absolutely necessary don’t use PUBLIC
- try to avoid
Stringwherever 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
You also should re-read what I wrote above
The first point also applies to all your other
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,
I am getting the reading of 0% and 32° again for my humidity and temp. I have checked my wiring over and over again… need help please
@Dsradley5, from what I can see, you are reading the DHT on every run of loop(). This sensor should be read no more than once per second.
Is there any reason you are not using the OneWire library from the web IDE which also include a DS18 class for reading DS18b20 devices?
You are using DS18B20 v0.1.9 but there now is already v0.1.12 out.
I have followed all of the advice. Nothing has changed.
@Dsradley5, can you share you updated code again?