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,


#9

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
https://go.particle.io/shared_apps/5cc9ae7aa1cdfe000a63041e


#10

@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?

Did you carefully follow @ScruffR’s and @ninjatill’s advice from before?


#11

You are using DS18B20 v0.1.9 but there now is already v0.1.12 out.


#12

I have followed all of the advice. Nothing has changed.


#13

@Dsradley5, can you share you updated code again?


#14

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