Monday, June 23, 2014

Design by Teardown: What you will find inside of my Panoptes home monitor basestation

First... It is about time I named this monitoring system.  I'm code naming it "Panoptes".

I'm struggling a bit with the power consumption on my wireless sensors (previously mentioned here).

I've chosen an C8051F912 as the MCU (extra 128 bytes needed for my OTA encryption scheme), but I can't seem to get the sleep mode down below 20uA. (That doesn't sound like a lot of power consumption, but it adds up when considering that I want the batteries to last years.)

So, I am taking a break from low power design to focus a bit on my base station. (For those coming into this blog entry cold, I am designing a Internet-ready home monitoring system with a focus on keeping track of independent elderly people, specifically those who are candidates for nursing homes but aren't quite ready for that transition yet.)

I've decided to approach the base station design from a post-implementation perspective: What would someone find if they did a teardown on my device?

Why come from this perspective?  I would hope that what a savvy engineer would find the implementation sound and even respectable. So, why not base my design decisions on this point of view?

Now, I am not just talking about a hardware teardown, but a software one too. But, I won't get too wrapped up on how my code looks or how it is structured.  I am more interested in interoperability: How does the software interface with the outside world -- in particular, the end user and the Internet.

Let me preface this with one of my primary design goals: Set and Forget. 

This is not a system to be played with or to constantly probe from a web browser.  The typical customer is a caretaker or adult child of an elderly person.  This is about applying modern IoT technology to an old problem.  But, this is not a Nest. This is about the kind of IoT (Internet of Things) that operates discreetly in the background of your life -- you just want to know when interesting things happen, otherwise it isn't on your daily radar.

I have said before that even the base station can host sensors, so for this particular teardown, we will look at a single use: Someone buys the basestation plus a water flood sensor to monitor their laundry room.  This example isn't solely "elderly" oriented but does represent the case where someone would want a true "set and forget" sensor.  (I won't cover "wireless sensor nodes" here, since while necessary, they are bound to a lot more hassle that I'll address later -- things like RF interference/jamming, etc.)

I am trying to bridge the world of industrial strength monitoring with the IoT.  I expect the sensors to be "integrated" with the house. You will want to install them properly (mount them) and permanently. These are devices that should last for years.  The mantra is that they "must work".

The water flood sensor is a good example of a "must work" sensor.

So, this is a long one. Feel free to jump ship here, otherwise, grab a cup of coffee, sit back and ... here we go:

Contents

The water flood sensor is a pair of gold plated probes on a 2x4" plastic plate.  The plate can either rest on the floor, be glued or attached to a baseboard with screws. Two thin wires connect it to the sensor node (in this case the base station).  The base station can be mounted on the wall. It is about the size of a desk of cards. On the side are 6 screw terminals (for 4 sensors plus +DC and ground.  The water flood sensor attaches to two one of the sensor screws and ground.  The user is expected to use the full length of wires or to trim and strip them to a desired length.  You can connects up to 4 water flood sensors if you want to place them strategically in a room (e.g. under the sink/tub, next to the water heater, etc).

(First critical question: Why screw terminals instead of modular connectors?  Answer: This allows the user flexibility in where they mount the base station. It can be several feet away from the sensor. A module jack would fix the length of the wire.  I am assuming either a professional installer or someone comfortable enough to run wires.)

The base station hosts 2 AA batteries for power failure backup (which should run a couple of weeks before needing to be replaced).  Lithium or alkaline are recommended for maximum shelf life.

The base station is normally plugged in to an AC outlet (via a standard USB 5VDC power supply). Since the station uses Wi-Fi, it wouldn't run very long on batteries.

Configuration

The USB port is also used for "configuring" the base station. Once plugged in, it shows up a disk drive.

Then you go to the product website and enter data into a form.
You can associate a screw with a type of sensor (in this case a water flood sensor). You must also enter the SSID and password for your wi-fi router.  Additionally, for notification, you must provide an email address.  None of this data is retained by the website and is all done over https.

Once entered, this data is downloaded as a file. You must save the file (or drag it) to the attached base station.  The LED will blink rapidly and if all goes well it will remain lit.  A slow blink indicates an error.

Once installed and turned on, the base station contacts the wi-fi router and you are sent a "startup successful" email.

Operation

The base station will send you once per week "heartbeat" email to indicate that all is well. If you want check "on demand" you can send it email and it will respond with status.

If water is detected, you are sent email.
That's it. Set and forget.

Hardware Teardown

There are 4 phillips head screws holding the unit together. The case is UL94-5VA flame rated.  Two flanged holes support mounting the enclosure to the wall.  When mounted, the battery compartment flush against the wall. This is a light form of security to prevent someone from taking the batteries out.
The screw terminals are side mounted.  There is a small recessed reset button on the bottom of the enclosure.

Inside there is a small circuit board hosting the three main components: A TI C3000 Wi-fi module, a Nordic nRF24L01P low power RF transceiver (for wireless sensor nodes) and a C8051F381 USB MCU. The Wi-Fi modules is tethered to an antenna that traverses the inside edge of the enclosure.  The screw terminals are connected via  ESD protection diodes to the MCU.
(But, why an 8-bit MCU?  Why not an ARM Cortex? The C8051F381 is essentially an SoC. There are very few outside components needed. Panoptes uses the internal precision oscillator, so there isn't even an external crystal.  There is a built in 5VDC-in regulator and USB support. And, for what the system does, an 8-bit is adequate. Plus, the fewer the parts, the simpler the design.)

There is a small piezo buzzer mounted over a small hole piercing the front of the enclosure. A small red LED next to it pulses every few seconds. This is to indicate that the unit is on and connected. If it cannot connect to the wi-fi router or cannot reach the Internet, the LED blinks rapidly.

Measuring power consumption of the unit shows that it consumes around 105mA when idle (not sending a notification) and peaks at about 250mA, briefly,when sending notification. Most of this current is due to the Wi-Fi module.  The 105mA suggests that the base station maintains a connection to the Internet at all times.

Pouring water upon the floor (thereby triggering the sensor) cause the unit to beep loudly and send a notification email.  After 10 minutes the beeping stops and the unit awaits to be reset. It blinks rapidly red during this time.  You can cease the alarm by pressing (and holding for 3 seconds), the reset button on the bottom of the enclosure.

If the AC power is pulled from the base station (e.g. a power outage), the unit falls back to the battery, sends an alert email, powers down wi-fi and beeps for 5 seconds.  The base station is still fully functional, but is expected to only last a few days without AC power.
The current measures steady at around 500uA at this point.  Any water sensing event will cause both the beeping alarm and an attempt to send an email notice (in case the wi-fi router itself is battery backed).  Every 2 minutes the station beeps to remind anyone near by that the unit is battery powered. 
Pressing and holding reset at this point will cease the beeping but the alert capability remains.

Internet Connectivity

The base station is connected 24x7 to a server running in the "cloud". This connection is via TLS/SSL and it is the cloud host that sends notification emails.  Why not send email directly? The cloud server ensures mail delivery (caching and doing multiple delivery attempts as needed). Plus, for sensors that need correlation outside of simple alerts, the cloud server does all of the logic and interfacing. 

Email is used as the primary notification (and status query) mechanism due to its ubiquitousness. Email is everywhere and doesn't require any special software to be loaded on your PC or smartphone.

No software updates are pushed to the device. Nor can the device be remotely controlled. It is a monitoring sensor. This IoT base station is one way.

In conclusion

Panoptes is designed to be a part of your house. It isn't sexy, but it is indeed a player in the IoT. Outside of 802.11b/g and TLS/SSL , it is bound to no particular Internet standard that may go away in the near future.  You can use it with low power RF based sensors or simply standalone with up to 4 wired sensors.

Despite the low BOM, Panoptes is a high quality product designed to last.  At $100 per base station, $10 - $20 per wireless sensor,  and $2 per month cloud based subscription, it is a worthy investment considering the repair costs of house flooding.

The only thing missing seems to be Zigbee support. But, until low cost wireless sensors are offered in the Zigbee space, the nRF24L01P is adequate.

Thanks for reading!

EDIT: Looking seriously into the Kinetis K20 again as the base station MCU. I could use a little extra help with the Internet protocol side of things and the 8-bitter suffers there.

EDIT2: The TI CC3000 Wi-Fi module has an OTA configuration scheme called SmartLink. This rids me of the need for USB support as I can  configure the AP and password over the air.  I still need to figure out how to send email address and other config stuff, but I should be able to do that over the air too.


Sunday, June 22, 2014

IoT: Real "servers" (PCs) are in your future (as base stations)

While Nest and others using embedded ARMs as base stations for your home "Internet of Things (IoT)", I see a real server in the future. There is only so much you can do with these embedded (usually ARM based) servers when you don't have a disk or memory management.  In particular, with the greater demand for these base stations to talk "native" Internet/Cloud (e.g. more heavy protocols like AMQP, XMPP, etc), it starts to tax an unadorned ARM SoC.

While a "PC" sounds like overkill, I am expecting to see more and more Intel Atom and ARM based, fully solid state, base stations with all the usual bells and whistles we are used to getting with a PC.
What bells and whistles?  Memory protection/management, robust storage, system busses, rich peripheral support, etc.

Let's call them SBCs (Single Board Computers) , which is what they really are.  Until now, SBCs were firmly in the domain of the industrial embedded market.  You don't mess around with unreliable consumer tech like SD cards and low end Chinese market chips (e.g. All Winner, etc) when you are building a security base station for an office building or other 24x7 "install and forget" monitor and control systems.

I've played with the wonderful Olimex ARM boards (like the OLinuXino LIME), but they are "new". There are hardware glitches, limited driver support (I can't just buy a wi-fi  board and expect it to work) and I don't feel that the Linux distribution is fully baked yet. Plus, I have to cross compile (from my Intel based laptop) and I run into all the "this isn't ported yet" problems that come with cross compilation.

With the coming of the Minnow Board MAX, Intel based SBCs are getting cheap enough (and low power enough -- No fan!) to become serious alternatives to the crop of low end ARMs.

What is wrong with the current crop of Cortex A based embedded systems?  The biggest problem is reliability (or at least the perception of) and OS support.  Sure there are Linux based distributions but are they as reliable and mature as their Intel based cousins?  I'm talking about real embedded distributions. I don't need or want X windows with a bunch of media apps.  But, are Intel SBC based Linux distributions any better?  Maybe. But that isn't what I am recommending.

Ubuntu/Debian/Fedora/etc server editions are (perhaps) ideal here.  They, for the most part, are already rock solid (when you have thousands of servers running 24x7 in a data center, you might as well say the OS is "embedded" grade since you can't practically login and deal with OS "issues").

I can see running Ubuntu 14.04 server (stripped down a bit) on a Minnow Board.

Now, the target market for the Minnow Board is for those who want to play with SPI, GPIO, I2C, etc -- they make a point of saying it is an "open hardware embedded platform" and not a PC. But, it seems to have specs to the contrary:  64 bit Atom, 1GB RAM, USB,  SATA2 support, ethernet, etc.

That sounds like a PC to me.  And, if I can run Ubuntu (or Debian) Server on it, it fits my IoT base station needs.   These days, most peripherals I interface to (including my own homebrew ones) can be accessed via UART (via a USB adapter) or native USB.  Do I really need to put my Bluetooth or GPS receiver on SPI these days?  (IMHO, Linux is pretty clumsy when accessing bit banged devices that don't already have kernel support.)

And, at $100, it certainly competes with the current crop of ARM boards.
Then again, if you can accept a Fan in your base station, it is hard to beat a repurposed ASUS Chromebox ($149) which comes with 2GB RAM and a 16GB SSD.


Saturday, June 07, 2014

Building the first (of many) wireless sensor prototype...

I've ordered a bunch of parts, so now I am committed to start building prototypes...

I've been doing X10 (RF sensors) and Linux on an SFF/SBC Intel-based computer (base station) as the prototype for my elderly monitoring system.  Stuff has been running for almost a year now but I am not satisfied with two aspects of this system:


  1. X10. Ugh. Ultimately a dead end.
  2. Intel-based computer.  Too big, too much. Overkill.
So, once again I am looking into a completely home brew solution.

First up: Wireless sensors.

I am throwing together prototypes centered around the ridiculously cheap NRF24L01+ (go ahead, google it and look at the ebay bulk prices -- they are between $1-2 each in lots of 10).  I am pairing these with the ridiculously low power ($1 per unit) C8051F986 (Silabs 8051 w/ 4K flash & 512 bytes RAM).  All these sensor nodes have to do is read some switches (e.g. motion sensors, doors, etc) and transmit a byte or two to the base station. I am coding it using MyForth (which is still my favorite Forth variant).

The BOM for a single wireless sensor node (sans sensors) is about $8 (including generic enclosure).  Add a PIR motion sensor for $17 (low current is expensive!), a magnetic door switch/sensor ($5) and maybe a water level detector (oh, and temperature comes for free with the C8051F986!) and you've got a wireless multi-sensor node for $30.  That's a bargain. I am currently using (screw) terminal blocks so you can hook up short runs of sensors (e.g. monitor the front door AND front hallway from one sensor node).

Next up: Base station

The base station will come in 3 variations:
  1. Wi-Fi
  2. Ethernet
  3. GSM/SMS
I am tackling the Wi-Fi variant first.  I am using a TI CC3000 eval board ($35 from Digikey).

The NRF24L01+ boards in my possession uses a trace antenna, so I am not sure if I'll get the range I need.  For the base station, I ordered a slightly costlier variant that supports an SMA connector.

I am still waffling on the brains for the base station.  Cortex M4 sounds like a no-brainer. In particular, I am fond (and familiar) with the Kinetis K20 series (via the $20 Freedom board).

But, I am NOT happy with the M4 development eco-system.  You either drop a lot of cash (>$1000) or use not-quite-baked free tools.  Yes, GCC has wonderful support for the Cortex processors, but getting down to the vendor specifics requires a lot of work (unless you opt for the IDEs which not only do all the work for you but manages to "hide" most of the hardware from you... I don't want this).  

Kinetis has a free GCC/Eclipse based IDE.  It takes up 1GB on disk, runs slow and isn't fully cooked (it is beta until later this summer). 

And, oh, don't get me started on the debuggers (e.g. OpenSDA, EzPort, OpenBDM, etc). Wow. The chips are amazingly cheap, but the support around the chip is going to cost you (if you don't want to be spoon fed:  mbed, Kinetis IDE, etc -- I am looking at you).

I've been using MPE Forth at my day job when I do Cortex M4 work.  It has worked nicely with the K20 Freedom board.  But, I can't afford MPE Forth right now for my CFT projects.

So, waffle, waffle, waffle.  Last night I threw together a quick base station prototype board (because I need *something* to test the sensor's NRF24L01+ against).  The brains for the prototype is a C8051F930 I had in my junk box.  It has 64KB flash and 4KB RAM. This is quite beefy for an 8051. It also has ridiculously low power needs.

Honestly, it has all the horse power and space I need to do the base station task. Plus I get code sharing with the sensor nodes.  But, an 8051 as the brains?  Shouldn't I go with something more capable?

Well, here is an interesting observation:  My prototypes are already rich with 8051s.  The NRF24L01+ has an 8051 as it's core. The TI CC3000 (Wi-Fi module) does too.  Do I need more horse power than a modern 8051 (Silabs  8051 based CIP-51 cores executes 70% of instructions in 1 or 2 clock cycles)  to just control these two modules and do a little bit of logic?