FANDOM


Middle Layers and Listeners

This week I added in the structure for the middle layers to interact with the hardware. Each brand of hardware will need very different code to interact with it but we want the hardware to implement an interface that the Python can interact with easily. Our middle layers are the answer to this.

I gave each item its own thread which checks for changes in state. We want to make the system event driven by delaying the responses to http requests and because of this it makes sense that every item has its own thread since they will often be waiting on the network. For now the middle layers are mocking the hardware but as soon as we get the hardware working they will obviously use that.

Initially, when an event was triggered it would just be passed into the reactToEvent() method that handled the ECA. Whilst this is all we need at the moment I decided that it would be useful to have lots of things happening as the result of events in the future since we want to automate the house as much as possible. I implemented a listener / observer type design so that it is easy to pass around event triggers and notify different sections of the code. This also means that it is possible to send http requests up on a change in state and I am considering adding the option for a user to subscribe URL’s to be “hit” by a request through the REST interface in a similar way to how GitHub has service hooks. Also, if we later decide to add support for plugins then they can easily subscribe to events now.

Hardware

We also got our hands on the majority of hour hardware this week. For me this meant an Arduino Uno with a WiFi shield and a nice big button (https://www.sparkfun.com/products/9181). I took me a while to realise that I had connected the wrong parts since they were covered up but after that small mistake things went smoothly. It was interesting as it was the first time I had dealt with electronics like this (It was very different from using .NET Gadgeteer last term) and I’m looking forward to getting more involved with the hardware.

To take this forward I will be using some library code written by Kinga to interact with the WiFi using a RESTful API. I will also differentiate between a buttons and switches since they should be different in our system but currently aren’t. I will then code the middle layers for the LightwaveRF hardware once it arrives. (Unfortunately there were some problems with ordering it)