ebswifty
Posts: 22
Joined: Mon Jul 16, 2012 10:35 pm

Indoor Environmental Sensor

Wed Mar 06, 2019 10:14 am

I thought I'd share my little project that is going to be used for research, I've actually been developing it over some years now, and I got the new build together with the Raspberry Pi Zero W just today. This unit measures:
  • CO2
    Decibels (max level per minute)
    Humidity
    Temperature
    Dewpoint (calculated)
    Movement (movement yes/no in the last minute)
I used these sensors:
  • Paradox PDX-525DM motion sensor
    SHT31 temperature/humidity sensor
    SenseAir S8 CO2 sensor
    WENSN1361 decibel meter
I reverse engineered the WENSN meter myself so I could read decibel values straight from USB:

https://www.ebswift.com/reverse-enginee ... l-usb.html

All the code is in Python built into class libraries, I've started developing a lot of the code in c# but for now the Python version is running rock solid so it won't be changing for a while. Logging (every minute) is sent to Google Sheets, and a dashboard self updates with last recorded values, along with the reported IP address for the unit. I run a watchdog that will reset the unit if the python app fails and I implement timeouts on functions that can hang. After the sheet max's out after a few months it automatically emails a list of recipients stored in a sheet cell on the dashboard for the unit with an attached excel file of the log and clears the online sheet so it can resume logging.

The dashboard has a dropdown for sending remote commands to the units where I don't have direct access, like inside a remote corporate network. I can tell an individual unit to update the codebase, it will download all the code files from Google Drive. Changing a timestamp on Google Drive triggers all units to automatically grab the new code base and reboot. I can tell a unit to reboot remotely, and clear the log data. I can also tell it to run a custom shell script, I save the script to Google Drive, it downloads it and runs that specific script. The custom script can perform any operation, I can do things such as telling it to upload a log file back to Google Drive or make it update a particular module. The dashboard runs a timer script that checks the health of units automatically (have they reported data recently?) and grabs the latest recorded data for a snapshot overview. The dashboard is secured with sharing so I can let people view it but they can't control the remote unit.

I designed the case in Autodesk Inventor with the final print done on the Intamsys Funmat HT. Chamber temperature set to 70 degrees C was critical for the box so it wouldn't warp as it built up (ABS print). This is the second case version, the first was done in Blender which was pretty challenging. Inventor is much easier for case design in my opinion. I use a 12V supply for the motion sensor and regulate it down to 5V (generic AliExpress regulator) for the Raspi.

The research will be to assist sleep studies (as in environmental factors that might affect sleep) and room comfort monitoring. It took a very long time to get it to the point where it could run non-stop without some kind of reboot intervention, these things truly do not stop now unless they lose power - then they come right back up and keep going when they get power back. They are robust against connection loss, they keep logging locally until the connection comes back, then they will catch up whatever data they are behind onto the online sheet and resume logging normally. I actually execute a remote GAS script to get the sheet line count as there isn't an efficient remote client way of doing that especially as you hit a couple of hundred thousand rows.

Dashboard:
Dash.PNG
Dash.PNG (190.79 KiB) Viewed 398 times
Recorded Log - Note the SenseAir has been offline for a while so it is slowly self-calibrating at this point, right now with nobody in the office it is reporting a solid 400PPM CO2:
Log.PNG
Log.PNG (81.74 KiB) Viewed 398 times
Inside of the unit, minus the WENSN board:
IMG_20190306_103359 (Small).jpg
IMG_20190306_103359 (Small).jpg (189.68 KiB) Viewed 398 times
Last edited by ebswifty on Wed Mar 06, 2019 10:32 am, edited 2 times in total.

ebswifty
Posts: 22
Joined: Mon Jul 16, 2012 10:35 pm

Re: Indoor Environmental Sensor

Wed Mar 06, 2019 10:14 am

Completed sensor unit:
IMG_20190306_105223 (Small).jpg
IMG_20190306_105223 (Small).jpg (219.68 KiB) Viewed 397 times

energyi
Posts: 119
Joined: Tue Mar 24, 2015 9:39 pm

Re: Indoor Environmental Sensor

Thu Jun 13, 2019 5:37 pm

Very nice work for your sleep study. Are you planning to open source the code and packaging? Could be valuable for other applications. I like the idea of monitoring car indoor conditions, and possibly have a pm 2.5 sensor added. Using BME280's for humidity control on a swamp cooler. Also BME680s are interesting inexpensive for indoor air quality comparisons.

Also just noted this Coral device with a screen output, just FYI, https://coral.withgoogle.com/products/environmental

Again, nice work.
energyi

ebswifty
Posts: 22
Joined: Mon Jul 16, 2012 10:35 pm

Re: Indoor Environmental Sensor

Fri Jun 14, 2019 8:37 am

Thanks for looking energyi, the sleep study isn't mine, I designed and built this for a researcher, it has been a fun little project. Since I built it at work I won't be open sourcing it unless they allow it, but I'm happy to give advice on specifics such as where timeouts might be needed. I have continued work in c# on another data acquisition project though I have run into difficulties with memory leaks in the mono environment when executing calls to the Google API's. For that I think I will need to create separate applications that are called externally so that they release all memory when 'done'. I just need to see if I can serialize the credentials to be passed across those apps so it's not logging in again on every call.

I have found it very difficult to get projects that work 24/7/365 though I have succeeded. I also have a c# based sprinkler system running off a raspi that uses Google Calendar for the scheduling (including around 1 second delay event-based handling of schedule changes from the calendar back to the app), that one hasn't failed in many months of use, the calendar API doesn't seem to suffer the same memory leaks as sheets and drive...

energyi
Posts: 119
Joined: Tue Mar 24, 2015 9:39 pm

Re: Indoor Environmental Sensor

Mon Jun 17, 2019 7:03 am

Thumbs up, great work on the sprinkler.
energyi

Return to “Automation, sensing and robotics”