|
Post by sipshowpeers on Jun 19, 2017 6:27:52 GMT -8
First, I love the project! It was a lot of fun to put together and follow the guide to set it all up with PubNub and Freeboard. I even managed to get the data into grafana! So I learned a lot.
I have a question about the HDC1000 Temp/Humidity sensor. It seems to only return values that are >1 degree F apart, which seems awfully far apart. I have a DHT22 sensor on another pi that can report values at about .1 to .2 degrees granularity.
Is this a limitation of the hardware or the software? Ideally I'd like much more precise temperature values.
Thanks for any help or advice!!
|
|
|
Post by SDL on Jun 19, 2017 17:50:49 GMT -8
Happy to help. First of all here is the specification for the HDC1080. It has all the answers! www.switchdoc.com/wp-content/uploads/2017/01/hdc1080.pdfThat being said, from the specification, the specs for the temperature are: +/- 0.2C or +/- 0.4C at the lower resolution. The worst case would be about ~0.7F so that would be close. To make this simpler, cd down into the SDL_Pi_HDC1000 directory and run sudo python testHDC1000.py If the default resolution for the temperature is 11 bits, then your data makes sense. Look at the testHDC1000.py code and you can see how to convert the temperature to 14 bit accuracy. Then add that to the SmartPlantPi code. The beauty of open source. BP
|
|
|
Post by SDL on Jun 19, 2017 17:51:35 GMT -8
Say, why don't you write up a guest blog post for us on connecting it to grafana? That would be really cool!
BP
|
|
dougstrickland
Junior Member

Posts: 54
Raspberry Pi: Yes
Other Device: Wemos, Arduino...
|
Post by dougstrickland on Jun 19, 2017 17:54:57 GMT -8
Say, why don't you write up a guest blog post for us on connecting it to grafana? That would be really cool! BP I second that request!
|
|
|
Post by sipshowpeers on Jun 20, 2017 4:44:02 GMT -8
Thanks for the quick responses! I will hunt around in the code you suggested. I'm a very, very new programmer so I am slow at this!
However I do manage linux systems as part of my job, so setting up InfluxDB and Grafana was not challenging for me - most of my time was spent editing SmartPlayPi.py to send the data to InfluxDB, I just couldn't get the code right! Finally I got it working, but I don't claim that my code is pretty or efficient at all, I only know it gets the job done. But I'd be happy to share that. I'll reach out privately to show you what I've done and you can let me know if you still think it's worth a write-up.
Thank you again!!
|
|
|
Post by sipshowpeers on Jun 26, 2017 5:46:33 GMT -8
Unfortunately I have been unable to get more granular data with the HDC1000 sensor - looking around I'm not sure anyone else can either. You pull two pieces of data from the sensor - d0 & d1, let's call them. These two pieces of data are always the same, and so when you do that math on them you find that you will never get readouts <1 degree F apart. Admittedly I am no programmer! So I concede I could be missing something, and I did learn a bit *trying* to get better data from it, so it wasn't a waste of time, but your own freeboard is the same - big steps in readouts. However I am going to order this: www.seeedstudio.com/Grove-Temperature%26Humidity-Sensor-Pro-p-838.htmlThis is the AM2302 AKA DHT22, which I already have and it outputs very granular measurements (0.2F apart). I'd just be curious if you picked the HDC1000 over the DHT22 for any specific reason that might not be apparent to a beginner like me? Thanks again for your help and advice!! I've learned so much working on this project.
|
|
|
Post by SDL on Jun 26, 2017 13:40:16 GMT -8
I assumed that you set the resolution to the 14 bits and you saw no difference, correct?
Well, lo and behold, I ran the test and I'm not seeing the difference I should. I'm now looking into a bug in the driver. Looks like we are reading the most significant byte twice, so it looks weird.
Working on it. I should have it solved and uploaded to the GitHub library shortly.
BP
|
|
|
Post by sipshowpeers on Jun 26, 2017 14:46:10 GMT -8
Thanks so much for checking yourself! I spent a lot of time on it but I learned a lot. Looking forward to the update.
|
|
|
Post by SDL on Jun 26, 2017 17:18:41 GMT -8
The software (SDL_Pi_HDC1080) is now fixed. Turns out that smbus in the Raspberry Pi has a bug in it and doesn't properly read 16 bit registers. I used a different method of using I2C to fix the 16 bit problem. The problem was that it was reading the top byte first and then reading the top byte again, so you were really only getting kind of 8 bit accuracy on temperature and humidity.
Both SDL_Pi_HDC1080 and SDL_Pi_SmartPlantPi (now version 013) have been updated.
Now both temperature and humidity are happy 14 bit numbers.
Look at these results
I blew on the HDC1080 to change the temperature and humidity:
Test SDL_Pi_HDC1000 Version 1.0 - SwitchDoc Labs
Sample uses 0x40 and SwitchDoc HDC1000 Breakout board Program Started at:2017-06-26 17:50:45
------------ Manfacturer ID=0x5449 Device ID=0x1050 Serial Number ID=0xB50380 configure register = 0x1000 turning Heater On configure register = 0x3000 turning Heater Off configure register = 0x1000 change temperature resolution configure register = 0x1400 change temperature resolution configure register = 0x1000 change humidity resolution configure register = 0x1200 change humidity resolution configure register = 0x1000 ----------------- Temperature = 26.5 C Humidity = 40.3 % ----------------- ----------------- Temperature = 26.5 C Humidity = 40.3 % ----------------- ----------------- Temperature = 26.5 C Humidity = 40.4 % ----------------- ----------------- Temperature = 26.5 C Humidity = 41.5 % ----------------- ----------------- Temperature = 26.4 C Humidity = 41.6 % ----------------- ----------------- Temperature = 26.4 C Humidity = 41.6 % ----------------- ----------------- Temperature = 26.4 C Humidity = 41.5 % ----------------- ----------------- Temperature = 26.4 C Humidity = 41.3 % ----------------- ----------------- Temperature = 26.4 C Humidity = 41.1 % ----------------- BP
|
|
|
Post by sipshowpeers on Jun 27, 2017 5:13:32 GMT -8
I merged your changes and it works great! Thank you!
|
|
|
Post by sipshowpeers on Jun 27, 2017 8:20:07 GMT -8
|
|
|
Post by SDL on Jun 27, 2017 16:52:05 GMT -8
Nice Picture! That shows that I nailed the problem yesterday! Whew! I wrote most of that code so it was my responsibility to nail that bug to the ground.
Remember you promised a tutorial on grafana!
BP
|
|
dougstrickland
Junior Member

Posts: 54
Raspberry Pi: Yes
Other Device: Wemos, Arduino...
|
Post by dougstrickland on Jun 28, 2017 5:52:01 GMT -8
That Grafana page looks awesome! Please share your tutorial soon!
|
|
|
Post by sipshowpeers on Jun 29, 2017 8:27:23 GMT -8
Wellll I'm not such a great writer, nor a good programmer (yet!) - but I happen to administer Linux systems as part of my job so I have some experience there, so for me, setting up InfluxDB and Grafana was not too challenging, but I used this to guide me: www.andremiller.net/content/grafana-and-influxdb-quickstart-on-ubuntuThat is about a year out of date but instructions are very similar. So first caveat is that this is not running on my Pi, it's running on a server up at AWS (t2.micro, does not need to be beefy). I think it could run OK locally on the Pi. It seems to be using only 177mb of RAM (both Grafana and InfluxDB) - but it may need better I/O than an SD card can provide. But for our purposes it's not so much data so I think it'd work. For my Python code to get the data up there, I hacked away at SwitchDoc's code until I got it right First I need to import the right python module for InfluxDB, and tell it about my server: from influxdb import InfluxDBClient client = InfluxDBClient(host='myinfluxdbhost.example.com', port=8086, database='smartplant')
Then I add the job that will be scheduled to run. This crafts the JSON necessary for sending along to InfluxDB. The "Value" I reuse from the existing variables that have polled the sensors, so that was effortless. The "Measurement" field represents the "Series" in the InfluxDB database. Each sensor needs its own "measurement" so that the data is separated into the different "series" in the database. def publishStateToInfluxdb(): timestamp = int(time.time() * 1000000000) # need microseconds! if (DEBUG): print('Publishing data to InfluxDB, time: %s' % datetime.now()) json_body = [ { "measurement": "sunlight_vis", "tags": {}, "time": timestamp, "fields": { "value": state.Sunlight_Vis } }, { "measurement": "sunlight_ir", "tags": {}, "time": timestamp, "fields": { "value": state.Sunlight_IR } }, { "measurement": "sunlight_uv", "tags": {}, "time": timestamp, "fields": { "value": state.Sunlight_UVIndex } }, { "measurement": "airquality", "tags": {}, "time": timestamp, "fields": { "value": state.AirQuality_Sensor_Value } }, { "measurement": "temperature", "tags": {}, "time": timestamp, "fields": { "value": state.Temperature*9/5+32 } }, { "measurement": "humidity", "tags": {}, "time": timestamp, "fields": { "value": state.Humidity } } ] client.write_points(json_body)
Finally, I just add a job to the scheduler: # send state to InfluxDB scheduler.add_job(publishStateToInfluxdb, 'interval', seconds=10)
I'm sorry, I know this is all ugly, but I can attest that it does work! I hope some of this helps but please let me know if I can answer any questions. To clarify, all this code went in SmartPlantPi.py. I don't believe I needed to adjust any of the existing code, just added to it. So I still just run SmartPlantPi.py with everything else it does, except now it also sends the data to InfluxDB!
|
|
|
Post by SDL on Jun 29, 2017 17:50:08 GMT -8
Thank you! It looks like you did it just the way we added the MQTT to Pubnub.
Best,
BP
|
|