05/07/2016 at 16:45 •
Started some work on the mesh network side of things. Started with the Espressif MESH_DEMO and went from there. It was pretty easy to get up an running. I ripped out a majority of the tests in the demo that weren't necessary. Instead of sending a fixed piece of JSON in the demo, it now just sends a string containing MAC address, temp, humidity, and light level readings. Eventually, I'll re-code this to send it in proper json format or something for better server side processing. The example demo_server.py app was modified to spit out the received data on the command line.
MAC: 5c:cf:7f:80:d3:3b Temp: 19.64 Humidity: 54.65 Light: 35
MAC: 5c:cf:7f:81:06:7b Temp: 19.22 Humidity: 55.90 Light: 26
MAC: 5c:cf:7f:13:91:41 Temp: 20.76 Humidity: 51.52 Light: 60
MAC: 5c:cf:7f:80:13:e7 Temp: 20.13 Humidity: 49.98 Light: 0
Above is output from a 4-node mesh network. Powering down the closest node disconnects the other nodes for no more than about a minute while they time-out and reconfigure the mesh to get back online. Works pretty well so far :)
Next step is to write up some server-side code to collect the data and dump it into a database of some kind. I'm looking at using the TICK stack (Influx DB) for storage.
Current setup is simple: Raspberry Pi 3 using the built in Wifi as an AP.
03/12/2016 at 18:26 •
Finding a low cost CO2 sensor has been a challenge.
Looking on digikey or element14, all of the commercial sensors start at $130 and go up from there...
Unlike all of the cheap MQ-series sensors, which cost <$10 each, the MG-811 CO2 sensor is around $40-50, requires a high impedence op-amp, and generally requires calibration. The MG-811 is a solid electrolyte sensor, so the base voltage can vary over time (however the change in voltage with CO2 concentration remains quite stable).
The better CO2 sensors are the NDIR type - Non-Dispersive Infrared Sensor.
These are generally quite stable over long periods without requiring re-calibration.
Searching for NDIR sensors, I found the MH-Z14 from Winsen Sensor. It operates from 5V, has PWM and Analog outputs, as well as a serial UART interface.
5V isn't suitable for the ESP8266 UART but level shifters could be used.
However, looking at the Winsen website, I also found the MH-Z19. Similar to the MH-Z14, it operates from 5V power, but has 3.3V signal levels. Perfect. Best of all, it's only $35!
The UART interface looks pretty simple. There are three commands: get reading, calibrate zero point and calibrate span. I have no idea what the span calibration does yet.
Data packet sent to get reading is 9 bytes in length. Fixed 0xFF start byte, sensor address (0x01 default), followed by command byte, then zero padded until the last byte which is a checksum value.
Returned data is: fixed 0xff start byte, command byte echo'd, Reading high byte, Reading low byte, 0x47 (fixed? not sure what this is), zero padding, checksum.
I've got one ordered, so will post more details once I get it up and running.
03/12/2016 at 14:54 •
After searching around for a low cost motion detection solution, I've settled on the ubiquitous dual PIR element sensor (D203B) and the BISS0001 motion detection IC option. The BISS0001 can be bought for as little as 10c in 100 quantity, a D203B PIR is around 50c, and a suitable plastic fresnel lens is around 25c. Add a few passive components and you've got yourself a digital output that signals motion detection for under a dollar.
There are also prebuilt modules that you can buy for around $1 from places like Aliexpress or eBay. Adafruit sells a similar one for $9.95 which actually has labelling on the trimpots and jumpers. The ones I bought were devoid of any labelling, but it wasn't hard to figure out which trimpot adjusted time and sensitivity.
The pre-built modules also have a fixed Ti delay period which is approximately 3-4 seconds. This is far too long for my testing needs, so I'll have to trace out the PCB and replace the R-C element that sets the delay. The Ti delay is the time required before the sensor can be retriggered once motion ceases to be detected. This long delay can lead to missed detection events.
I'm aiming to sample detection approximately once per second. The lowest Tx setting via the trimpot is around 3 seconds. Tx is the time the output stays high once motion is detected. I need this to be approximately 1 second.
The idea is to sample once per second and keep a rolling average with periods of 1/5/15min. Then a custom threshold can be set externally from the sensor data for what is a valid "occupancy" event. If motion is only detected for 5 seconds out of 60, then it is unlikely that the room is occupied. Either someone walked past or it is a false detection.
Now, I did purchase all the individual components to make up a working sensor quite a few months ago. I was about to breadboard up a test rig with the required R-C values to get the Tx/Ti times required. Unfortunately I seem to have misplaced the PIR element sensors... Time to search.
03/09/2016 at 22:10 •
Just finished writing up some code to grab Temp / Humidity values from Measurement Specialties HTU21D (and probably Sensiron SHT21) sensors.
Temperature seems pretty close to other measurement gear I have. It's one of those tiny breakout boards from Aliexpress (similar to the Adafruit/Sparkfun boards).
I have a feeling the onboard voltage regulator is putting out a tiny bit of heat making it read a bit high. Won't need an LDO on my final design PCB as it has 3.3V for the ESP8266 anyway. Datasheet also has some good tips on using routing slots to provide some thermal barrier between the IC and the rest of the board.
07/10/2015 at 09:41 •
ThingSpeak is live!
07/08/2015 at 11:54 •
Finished writing the main part of the driver for the AMS/TAOS TSL2561 light sensor tonight. Could do with a few more helper functions and autoranging on the lux conversions, but for now it gives good readings.
Tested a few spots around my apartment and the readings appear reasonable. Will have to see if I can borrow the light meter from work sometime to confirm.
07/07/2015 at 11:35 •
The firmware for the Frank'n'Sense will be natively written for running on the ESP8266 cpu core. There'll be no extra microcontroller to do any of the work to keep both energy use and cost down.
The ESP8266 has more than enough GPIO to handle a few i2c devices. There's no hardware i2c module, so everything will be software (bit-bang) i2c controlled. This means I can have multiple i2c channels if necessary due to conflicting addresses. If I really get stuck, I'll add a Microchip MCP23S08 or MCP23S17 to get some more GPIO.
Most of the datasheets for sensors are quite detailed, and the communications to collect data from them quite simple. Writing code for each should be easy - especially when there are plenty of open-source drivers available for arduino, raspberry pi, etc to get help from (Thanks Sparkfun/Adafruit!).
For collecting data, I am leaning very heavily towards the MQTT protocol. It's well suited to command and control of large networks of devices. Commands can be sent individually to a device, or sent globally to all. Fluentd is a data collector for Hadoop, and has an MQTT data collector plugin available.
Most digital sensors can be configured to collect a sample and then sleep. The idea will be to have the rather power hungry ESP8266 send a request to the sensors to collect a sample, grab the data (usually available within milliseconds), upload it via MQTT, collect any waiting commands from the MQTT server, put the sensors to sleep, then put the ESP8266 to low-power sleep more for "X" minutes until the next data collection cycle begins.
The major benefit of MQTT here, is messages or commands sent to a device are queued on the MQTT server until the sensor wakes up to collect them. Perfect!
07/07/2015 at 11:22 •
The hardware will of course be based around everybody's favourite WiFi SoC - the Espressif ESP8266. As all this data will be feeding back to a storage server via network, it's going to have to connect in somehow. Bluetooth Low Energy is a consideration, but having access to a power source won't be an issue for this project.
Light Sensor: TAOS TSL2561 - i2c interface with two internal light sensing diodes. One is a broadband spectrum diode while the other is an infrared only diode. By subtracting the infrared response from the broadband response, you can approximate the human eye response. TAOS provide the conversion equations to obtain the equivalent Lux figure. This can be calibrated against a real Lux meter for accuracy.
Temperature & Humidity: Measurement Specialties HTU21D - i2c interface with the ability to measure temperature with 14bit resolution and relative humidity with 12bit resolution. That's 0.01°C and 0.04% RH resolution. Claimed absolute accuracy is +/- 0.3°C and 2% RH.
Occupancy Sensing: The most basic form of occupancy sensing would be to use some kind of passive infrared device. However, I want to know the number of people in a room or office. The ESP8266 SDK provides a promiscuous wifi sniffing function which I've tested to detect the presence of my phone by watching for beacon packets. This is in an apartment building with many wifi APs and devices. It may be difficult to obtain an accurate absolute number of occupancy, but with Big Data, relative values can be quite powerful when used in combination with other data sets!
Noise: Not sure where to go with this one. Are there any dedicated noise detection ICs out there that I can poll every minute or so to get an average reading? What about power consumption? How useful is the data? More work to be done on this one...
Pulse Inputs: Most commercial meters provide some form of meter reading output in the form of a pulse. For electricity meters, this is usually an LED that blinks to indicate 1/10th of a kWh or similar. Water and Gas meters provide contacts that close briefly to indicate the consumption of "1 unit".
Our building already has a MODBUS network for the energy meters and a BACNET/IP network for the HVAC systems. I will make an allowance in the design for external inputs though, so I can integrate pulse meters at a later date.
Gas Sensors: CO2 levels and adequate levels of fresh outside air intake are a critical component of HVAC systems and occupant health & wellbeing. I need to do some research on low-cost gas sensors before deciding on anything.
Got any ideas for other sensor types I could include? Leave me a message or comment below.