Sorry this post is a little late, family issues. My misses was taken into hospital on Thursday and ended up having an operation. Everything is fine, she is recovering well. It just throw us off guard and screwed up my timing anyway on with my post.
In my last blog post I brought up an intermittent issue I was having with the EnOcean Pi not connecting to openHAB and an issue with the MySQL binding disconnecting after a while and losing data.
Well I thought I would add a few extra debug lines to the bindings so I could trace the issues. I went though the process of setting up a new Eclipse Workspace and setting up the projects to easily compile the bindings, Added a couple of extra debug lines to help me follow what was happening though the logs, compiled the bindings, copied them over and restarted openHAB and well fixed my issues, Somehow.
Don't ask me how I solved the the EnOcean Pi issue as I don't know. All I know is that every time I've started openhab since its happily connected to the EnOcean Pi. All I changed was I added a few extra debug logging calls, recompiled the jar and my issue has simply gone away. I'm keeping the extra logging calls in the code for now and praying to the Java Gods that it will stay fixed, but now I have said this its bound to stop working again.
My MySQL disconnection issue has been fixed by simply storing data in the database more frequently. The first change I made was to my mysql.persist file so that my items now simply read as follows:-
Items { * : strategy = everyUpdate }
everyChange was doing just that, updating the Database upon every change, but if the value had not changed when the EnOcean sensors sent out their new update packet openHAB didn't note the change in the Database, if nothing changed after a while the connection would stagnate and fail when openHAB actually wanted to make an entry to the Database. everyUpdate does what it says it will do, it will update the database on every update it receives. So when openHAB gets data it gets recorded even if the data is hasn't changed since the last update.
The second change I made was I started recording the CPU temp reported by the Raspberry Pi.
To accomplish this I first created a simple bash script that just simply read and echo's out the temp using vcgencmd
#!/bin/bash tm=`/opt/vc/bin/vcgencmd measure_temp` echo $tm| cut -d '=' -f2 | sed 's/..$//'
I simply put this into a file called temp.sh, made it executable by chmod'ing it with +x and put it in the root directory of openhab. Now this script can be anywhere the user you run openhab with can execute but I put it there just for simplicity. And in my home.items file I added the following line.
Number Cpu_Temp "Cpu Temp [%.1f C]" <temperature> { exec="<[/opt/openhab/temp.sh:900000:REGEX((.*?))]" }
"/opt/openhab/temp.sh" is the path to script and 900000 is the time between script calls in milliseconds so in this case 15 mins. In my home.sitemap file I also included the following line in order to be able to display the Temp on the local site:-
Text item=Cpu_Temp
As soon as openHAB reloads these two files I was presented with the temp of the Raspberry Pi on the local site but openHAB is also adding the temp into the database.
With both of these changes I get information about the Pi's Temp and I am adding data to the database at most every 15 mins keeping the connection fresh and preventing it from going "stale" and dropping the connection. I also added some extra debug lines to the mysql binding to help log the disconnection and force a reconnection but since making the 2 changes above I've not had any issues with the database connection.
So that's 2 issues sorted, one simplify by compiling the binding from source and not using the pre-compiled version and the other just by logging more data.
So what else have I been doing? Reading, drawing up plans on what to spend my parts budget on, planning some of the code I am going to be writing.
One of the things I want to do is create an energy monitor and have that reporting back to the system to monitor usage in the house. Sure I could buy one, but where is the fun in that? I want to build a Home automation system not buy one :-p So basically I've had my nose buried in http://openenergymonitor.org/emon/buildingblocks My plan is to use an "Arduino" for this. The Oscilloscope is going to save me some major headaches here, thank you again Tektronix. When I say Arduino, what I mean is build my own monitor using a ATMega for the microcontroller and use the Arduino compiler to help quickly create the code needed to measure the current usage in my house and wirelessly transmit that data back to the Raspberry Pi.
The reason I am not planning to use the Arduino Bootloader is because I can program the ATMega's via SPI. While I do have a SPI Programmer already for these chips directly, The Raspberry Pi can be used to program these chips directly too. You can use the GPIO mode in AVRDUDE there is also a modded version of AVRDUDE that has SPI Support for the Raspberry Pi included https://github.com/kcuzner/avrdude
For the monitor I still need to get a current transformer sensor, The UK Farnell site does have non-invasive sensors but they max out at 50 amps. Now while my house never use 50 amps at the same time the house is fused for 60 so I'm going to get the sensor that seems be to recommended by the site.
A brief note on the Oscilloscope, due to a miscommunication we got the TBS1052B-EDU which is the 50Mhz little brother to the TBS1202B-EDU. No big deal the TBS1052B-EDU is still more than suitable for my needs. Its the first scope I've had any I'm more than pleased with it. My plan for the scope is to help me build this energy monitor and to help reverse engineering some other off the shelf projects to add them to my project.
One of the products I want to reverse is some off the shelf Power Switches. These normally work off a 433Mhz signal, Using the scope I can quickly sample this signal and figure out the bit's and timing of the signal. I'm still waiting to get some of these sockets but while I wait I've been getting to grips with using the scope I've been using it to analyse some past projects. In the past I've had to use my computers sound card to capture this data, which isn't ideal but I've always just used the tools to hand and hack them when they weren't really designed for the task at hand. So instead of having to mess around with using a sound card I was able to just grab one of my older project and connect to the data line and quickly signal shot the data.
Having the scope connected to a computer I can quickly capture the waveform data and screenshot of the scope to the computer.
As this is a past project I can quickly decode the captured data. So using the same technique I should be able to quickly sample the signal for these switches and add them to my project.
I've also been reading up on API for openHAB, It seems fairly simple. I don't really want to give openHAB an direct open port. While the current version of openHAB does have some authentication options there is yet any roles. So I can either open up the whole system to anyone knowing the IP address or cut off public access with a secure password. My plan here is to throw some PHP into the mix. openHAB will not be accessible directly from the Internet, all requests for live data and controlling elements of my house from the outside world will need to go via PHP first, as long as I don't code like a beginner this should migrate any security issues while also giving the freedom of giving some data away freely while not also giving away the keys to the kingdom.
This brings me onto the issue of privacy. After I started logging the temp data from the EnOcean sensor I decided to plot that data on a graph. It was pretty cool, I could see how the temp of my office changed over the day even to the point where I could pick out when I was asleep, when I was working in my office, when I was in other rooms of the house and when I wasn't in the house. Woah... Hold up a min. A temp sensor in my office can tell when I'm not at home. With just 0.1 degree of actuary I started picking out patterns in the data that followed my activities in my home. Here let me show you.
(This is just a small sample of the data) I was sitting at the pub with some friends and one of them asked me how the project was going, so being the geek I am I pulled out my tablet and pulled up the graph. While talking about the project it hits me like a ton of bricks, this publicly accessible website is broadcasting to the world my household pattern. If you had access to this data for a good period of time you would be able to start picking out the patterns us humans love so much. A Temp drop during the night, most likely they household is in bed, a temp drop during day time, probably no one is at home.
While this data would be great for some machine learning applications (such as automatically figuring out the best time to heat/cool your home) my black hat insistently started thinking of the security implications, what is the best time to go and do something naughty at someone's house? When they are not at home. Sure this data and pattern's can also be learnt by following that person but that involves you staking out their home or actually following the person in question. If their home is willing to just tell you this data it lowers the risk.
I know this is my paranoid/black hat side of me coming out but its something that we are going to really have to think about. Anyway enough of my black hat thoughts, lets get on to what I'll be getting up to this week.
I'm going to continue my work on studying the API of openHAB and creating a PHP based interface for it which I will be able to securely access remotely. My initial parts order has arrived, so I'm going to be experimenting with building some wireless modules to capture more data from around my home and send that data back to the Pi (NOTE TO SELF: Must keep my phone and notebook with me during this process to document my progress for my next blog post. I tend to rush along and forget to document my progress, its a bad habit I need to break).
I've also received an EnOcean EOP350 programmer kit.
This was something I wasn't expecting. Basically it upgrades the starter kit to a developer kit, It will allow me to experiment with creating actuators and sensors based on the EnOcean platform. This was something I was going to attempt to do anyway but the inclusion of this kit will greatly help, it was just unexpected. So I'll be also be reading up on this too. People in my local do tend to read books, thanks to e-readers I tend to read data-sheet's in the pub, thanks EnOcean and Farnell you are not helping my geek reputation
Also in the surprise front. I received another Raspberry Pi Model B+ in the delivery the Oscilloscope and EOP350 came with. (Off Topic Note: The box these came in proved to be an infective cat trap.)
I did contact doctorcdf via e-mail but have yet to hear back if Element14 Will want this extra back. If not I'm sure I can find it a good home. One of my friends has been expressing an interest in the Raspberry Pi so if the Pi doesn't have to be returned to Element14 I will donate it to this friend and spread some Raspberry Pi love.
<EDIT> As michaelwylie points out This extra pi isn't a mistake. So I think I'm just going to surprise my friend who has expressed an interest in the platform with the extra Pi.I might "test" him first, take it to the pub with me, get a few beers down his neck, ask him some questions about what he will use it for and then just hand it over and say "Go Build". I'll try and poke him towards Element14 too and say post what you build here as a thank you. </EDIT>
Any questions feel free to leave them in the comments and I'll get back to you. I'm sure I've missed some things out. On with the fun, I mean building.
Dan.
Top Comments