THE FINISHED PRODUCT
The Internet of Things
The internet of things has been a buzzword these last few years. Viewed by some as the future and by others as a fad, it is a topic of much debate. The internet of things refers to smaller devices (eg. household appliances or industrial devices) that connect to a network (such as the internet) to communicate and offer additional features such as monitoring and control. While most people think of products such as the Philips Hue or Smart Coffee makers as IOT, the concept goes far beyond this. I decided to explore the challenges of creating an IOT device, while dealing with the issues of cost and security. After all, how hard could it be?
IOT is meant to provide solutions to common problems or inconveniences. For my IOT implementation, I looked to find a common problem in my household, in this case our dog Lucky. As an aging rescue dog, Lucky is particularly sensitive to temperature drops at night, a common occurrence in our high altitude environment. To determine whether Lucky’s doghouse gets too cold at night (below 10C), I decided to build the world’s first WiFi enabled dog monitoring system, complete with a nightlight, and temperature and humidity monitoring. The application sounds ridiculous (because it is) but more importantly it serves as a proof of concept.
A closer look at IOT
On a more technical level, an IOT device consists of a small embedded computer/microcontroller better known as an SOC (system on a chip) that has basic processing abilities, wireless connectivity, storage and a set of input and output pins (electrical interface). These microcontrollers bundle several components into one, low power and low cost solution. While they don’t run common operating systems such as Windows, they run on custom firmware (code that runs on a very low level) that is custom coded based on the application of the device. The ESP8266 that I will be using (and that is commonly used) runs on FreeRTOS, a Real Time Operating System developed by Espressif Systems (the creator of the ESP8266 SOC)
The primary objective of the project was two fold, to have a web interface that was cross platform compatible and to simultaneously integrate Apple HomeKit compatibility. The former would allow the device to be controlled by Siri and the Apple Home app on iOS and Mac devices.
Before I began I had to decide what I wanted the end result to look like in terms of features. For my application, I will need temperature/humidity monitoring with a light. This implementation needs to be compact, low power and have wireless connectivity to connect to commonly found 2.4 and 5ghz networks. It has to be compatible with all major platforms, mainly web browsers (enabling support for all devices with a browser, HTTP protocol) and with Apple’s HomeKit IOT platform (with support for Siri).
Enough rambling, let’s build an IOT device!
After jotting down some notes on the initial concept and a few rounds of rapid prototyping, I decided on the following features for the finished product.
Compact and Low Power
The device was designed from the ground up to be used in Lucky’s doghouse. Power, space and humid conditions were of concern. As such, the final device was placed in a custom designed weather-proofed case and can run off any old micro USB phone charger. In my case, an old BlackBerry charger (re-used from my box of old chargers).
Ease of Use
Ease of use was critical. WOOF integrates several technologies making the device entirely plug and play. It includes a wireless Access Point and Captive Portal, making it easy to connect to any WiFi network. The mDNS server makes it easy to find on the network, just open a web browser and go to “woof.local” and voila! Furthermore, it runs off a universal micro USB connection.
Cross Platform Compatible
My family uses a variety of desktop and mobile platforms. The final product had to run flawlessly on iOS, Android, Windows, Mac and Linux devices. The solution for a plug and play experience was to create a WebUI as the primary interface with the user.
Support for Wireless Updates
While my first prototypes required the Arduino IDE and a physical connection to update the firmware, this was horribly impractical for the end users (my family). As a result WOOF now supports wireless updates through its web interface. One click and new firmware can be loaded on to the device wireless with no hassle.
Apple HomeKit & Siri Compatible
Despite having a HTML5 based Web UI, I wanted the device to be compatible with Apple HomeKit. I chose HomeKit over Alexa and other platforms due to the fact that most of my family uses iOS in some shape or form. The resulting integration allows for full control of the WOOF from the Home App (on iOS and Mac OS) and via Siri voice commands.
THE BUILD (TUTORIAL)
3D Design and 3D Manufacturing
The initial prototype of WOOF IOT ran in an old supermarket plastic box (reuse, reduce and then recycle). This worked great for the six months I had it running in Lucky’s doghouse. Nevertheless, it was relatively bulky for such a small device and didn’t look like a professional product. Along with my code redesign and update, I designed a custom case in Autodesk Fusion 360 and printed it on my Ender 3 Pro 3D printer. I used black PLA to create a snap together case which houses the NodeMCU and the DHT11 temperature/humidity sensor. With some CAD and 3D printing magic, I was able to drastically reduce the size of the WOOF. It now fits in the palm of your hand. The last step was to print out a vinyl label that included the branding, URL and HomeKit Barcode of the product.
This project is based on a ESP8226 micro-controller board known as the NodeMCU V1.0. The original circuit included a DHT11 temperature/humidity sensor and a high power LED (with a transistor as a switch due to its high current requirements). The finalized design only includes the DHT11 sensor as I found that in real world use no one in my family used the LED “dog nightlight” function, understandably. The end result is a very compact circuit that can be fit in a small enclosure and draw very little power. In future designs, a custom PCB could be made to further decrease its physical footprint and lower standby power consumption.
Software and User Interface Design
WOOF IOT has several pieces of code behind it. On the WOOF IOT micro-controller device itself, an Arduino Sketch runs to provide the device with it’s web interface (HTML5 based on the Bootstrap framework), along with its mDNS resolver, web server, WiFi Credentials Manager with captive portal and other essential features. The device features wireless firmware updates and allows for external server-side applications to read sensor values via a JSON file. By allowing sensor values to be stored in JSON, the project cab quickly be adapted to work with other smart home platforms (HASS.IO and others) and it allows for easy reading of values should I choose to develop an iOS SWIFT app in the future. This firmware code is the core of the entire project.
The second key component is crucial for enabling easy integration with Apple devices in the Apple HomeKit smart home eco-system. A custom JSON configuration file ensures the accessories that run in HomeBridge enable Apple HomeKit functionality for reading temperature & humidity values and turning on the “dog nightlight” . The HomeBridge server (an open source project created by “nfarina”) reads values from the WOOF’s JSON file and parses them to so called “HomeBridge Accessories” that enable HomeKit functionality. The HomeBridge server was hosted on a Raspberry Pi and was later migrated to a VM (virtual machine) on my Proxmox server running Ubuntu 18.04 LTS. Additional testing was carried out in VMs running on my Mac.
For anyone who would like to recreate this project, the following parts are needed:
*Prices are approximated as these vary
Parts List (IOT Device)
1x NodeMCU V1.0 (ESP8266 based) ($1.8)
1x HM11 Temperature Sensor ($1)
1x Breadboard and connector cables ($2)
1x White LED (for nightlight) (~$0.10)
1x 2N2222 NPN Transistor (~$0.10)
2x Resistors (for led and transistor) (~$0.10)
1x Micro-USB phone charger (5V, 500ma) ($5)
HomeKit Server (Optional)
1x Raspberry Pi 3b+ ($35)
1x Power Supply ($7)
Here’s all you need to build your very own WOOF IOT device!
Arduino Code Files with Homebridge Configuration Files
CAD Files for 3D Printing the Woof Case
Building the WOOF IOT device
1. Acquire the required parts from the BOM (bill of materials). The Raspberry Pi is optional, but will be required to enable Apple HomeKit functionality.
2. Install the Arduino IDE (Integrated Development Environment) and the CP2102 drivers (required to communicate with our NodeMCU)
3. Install the required dependencies for the ESP8266 in the Arduino IDE and install the DHT11/22 Library (for temperature/humidity sensing)
4. Download my Arduino Code and modify the parameters for connecting to WiFi
5. Connect the NodeMCU to your computer and flash the Arduino Code to the NodeMCU (be sure to select the right COM Serial Port in the Arduino IDE)
5. Build the circuit in a breadboard (or solder it, if you prefer a more permanent solution). The circuit diagram is available in the resource sidebar.
6. Connect the NodeMCU to your breadboard and the rest of your circuit
7. Install Bonjour Service on your PC (if you are not using a Mac) to be able to use the mDNS service to find your WOOF IOT device.
8. Open a web browser and type in the IP address or use the mDNS service by typing “woof.local” in your address bar. Viola! You now have a WOOF IOT device!
Configuring the HomeBridge Server (for Apple HomeKit support)
1. Install and configure Homebridge on a Raspberry Pi. This process can get lengthy. To keep things tidy I’ve created a separate tutorial available here.
2. Create a new appliance
3. Launch homebridge from your Terminal by typing in “HomeBridge”
4. Scan the barcode with your iPhone and voila! (or add a new device manually with the provided code)
Additional Documentation and References
Here are some of the sites and documents that helped me along the way. If you ever want to understand the project better or see where I got my ideas and snippets of code check these out.
Bootstrap Framework Documentation (Useful if you are new to the Bootstrap framwork. I found it most helpful for identifying their css classes)
Esp8266 Creation of Web Interfaces (Good place to start, but contains errors)
After designing the Web interface and writing the firmware for the NodeMCU (along with a little bit of circuit design) I had the prototype of WOOF IOT, the world’s first dog house monitoring system. A few hours later, I also had my HomeBridge server running on a Raspberry Pi and could control the entire IOT device from my iPhone, iPad and Macbook. Siri did most of the work. Non-Apple devices could still access the device from any web browser, enabling cross platform compatibility.
The project itself cost a total of around $50, including the IOT device itself ($5, the Raspberry Pi Homebridge server ($35) and the power adapters (~$10). Not bad for a home built device that doesn’t leverage mass production or economies of scale. Looking at commercial temperature sensing devices on Amazon, those cost upwards of $30. Making WOOF IOT cost competitive.
From an industrial standpoint, if these components are to be bought in bulk, the entire IOT device (sans server) could cost as little as $3. This includes the MCU and the sensors that can measure temperature. This has applications far beyond dog house monitoring. Change the branding a bit and now you have a temperature/humidty monitoring system for a warehouse. Add some nice stock photos to the packaging and now you have a home temperature monitoring system. The possibilities are endless, while the underlying technology stays the same.
All in all, it is clear that IOT devices aren’t as expensive or complicated to develop. This has lead to a lot of low cost products flooding the market. The relatively low barrier to entry makes me wonder, did they forget anything? What about security? Are they safe? Can they be hacked? How can we protect networks of IOT devices? Arguably, security is one of the biggest concerns when it comes to IOT. No one wants a botnet of IOT devices spreading and taking down services online. I’ll be covering all this in a future post, as I look into the security shortcomings of WOOF IOT and IOT devices in general.