Saturday, October 10, 2015

Stressful month but my mind is still on Home Automation

I finished the article for Linux Magazine about Misterhouse (called King of the House). I didnt get a copy of the magazine, so I've ordered a copy of issue 178, which should be here soon. I've created a web page for the article and I'll add an errata in a short time as it needs a few minor things fixed up. I've been busy for the last month or two with all the things going on at work, around the house and at home. But in the back of my mind is always HA. Lately I've wanted to design a PCB based on the PIC32 chips. This will satisfy my electrical engineering background (I have a degree in electronics). These boards would form the basis for my HA remote nodes. I'll return to that shortly but in the meantime I mean to solve an issue with getting the remote nodes to be as dynamically configurable as possible (as reasonable?). I already have the PIC32/W550io board running a DHCP client. I'd love to see the board connect to a cloud MQTT service from a remote location (such as from IXR at Camp Evan (InfoAge)). The issue is dynamically configuring the topics (and eventually the IO). This requires a bit of coordination between application such as Misterhouse, MQTT and some kind of configuration Manager.

I've written a simple configuration manager in Node-Red/Node.js. The device publishes a hello to a given server and topic (device/hello). The manager then looks up the information and publishes the information to another topic (device/<mac>/cfg). Now I'll need to figure out how the device will interpret the information (then I can format the information properly such that it's easy to handle and easy parse).

I've also decided to setup a bridge between my MQTT and a Cloud MQTT. This will require a bit of planning but I can see this working well to allow remotes to share data and commands with Misterhouse which will only be connected to my local MQTT (not that it has to). While the very basic is working very well in Misterhouse, it does need additional work (error correction and failure recovery). All this means I need to work on my Mosquitto setup so that bridging, SSL/TSL, login/passwords and ACL are working properly.

Sunday, September 20, 2015

Misterhouse controls a traffic light?

Okay, I've taken a bit of liberty with the title. The traffic light part consists of 3 LEDS (red, yellow, and green) on a breadboard with the Fubarino Mini, WIZ550io network interface and a DHT22. The Furbarino uses an Arduino type environment but uses the Microchip PIC32 instead of the AVR. I've mentioned my IoT boards in previous posts and decided it's time I shared a bit. First: pictures of the boards. At the moment I have 2 wired network prototypes working. I'm also working on wireless network prototypes but they're a long ways from being setup. The first working prototype was the simple Chipkit UNO32 with a WIZ550io board and a DHT22 temperature and humidity sensor. The code has the MQTT topics hard coded to specific topics. This board just sends updates about humidity and temperature. It can receive commands but doesn't really do anything with them other than send them to the serial debug port. Between iterations of that and the latest IoT device, the Fubarino Mini, I found all sorts of interesting features in the Chipkit libraries. The one that interested me the most was the createTask() function. It allows me to create tasks that run periodically outside the Arduino loop function. Very cool, I'm using that as a heartbeat function to see if the board has been disconnected or hung up and if necessary reboot. There are various interrupt functions I'll take a look at later so I can do things like push a button and get a reasonable response. But for now, lots of baby steps.

The second working prototype is my Fubarino Mini, in addition to working out the differences with the Arduino, the UNO32 and the Mini I started adding to the code so I could control the Mini from MQTT topics. Again, hard coded topics, but now the Mini is sending periodic updates and monitoring topics for commands. In this case a simple set of commands to turn on 3 LEDS. Since I've already added MQTT to Misterhouse, I wrote a simple routine to issue the commands to turn on the lights in a US traffic light pattern but with much shorter intervals. Other than a few minor glitches (power related?) both boards have been running for weeks with no reset (yea!). I still have a lot more work to do, such as finishing my methods of automatic configuration of the IoT device from MQTT topics. I also need to work on security as I really want to be able to install the devices in remote sections of the internet, subscribe/publish to an MQTT cloud service and still have my local Misterhouse control, configure and monitor these devices. I'm part way there but more thinking and coding needs to be done.

Okay so now I need to put together a web page explaining how to setup Misterhouse, MQTT, and my IoT devices. I'll also have to add to my other IoT publishers and subscribers also. I have a number of them including Node-Red and bash scripts. Most are publishers, get web information, filter what is needed then republish for local subscription. But there is also business (?) logic in things like Misterhouse and the different flows of my Node-Red code. I must say that I'm very excited about the 32 bit microcontroller and the use of MQTT in home automation. While a simple 4 bit processor can flip a bit add networking and security and more resources are required. I really don't need a Linux system such as a Raspberry Pi running a light switch when a PIC32 can handle all the requirements. Boy this is going to be one interesting IoT web page. ;-)