Tuesday, September 25, 2012

COSM and smooting

Been quite busy this weekend.  I worked on the C# application that sends the sensors to  COSM   https://cosm.com/feeds/74950.

I also soldered the parts onto a expansion shield and put it out on the front porch.  

The Arduino code was reworked to separate the local base station sensors from the external sensors.  I implemented that with RF24Network, so I could put a few more sensors/radios around the house.

I had to change the C# code to allow for different nodes and send each separable to COSM.  The base station is node 0, the external sensor(s) will be 1-6 or so.

After looking at everyone's jaggies in the lines on all the graphs - I went looking for a smoothing function on the net - you would be amazed haw hard it was to find one and then wrap my mind around once it did. I took  statistics and don't remember this exact algorithm.  But it boils down to:

avg = x * prev_avg + (1 - x) * sample; 

You maintain the prev_avg for each sensor that you want to smooth - and you monkey around with the value of x which is in the range of 0

It gives really strange values on  COSM like 30.166451344586.3 Gota love double precision numbers for the Barometric pressure - but the graph looks a lot better.

Now on to hooking up the rain gauge and the light sensor.

Saturday, September 15, 2012

C# Arduino ThingSpeak and COSM

I bit the bullet and put together a C# app to read the serial from my Arduino weather station and send it to COSM (Pachube) and Thing Speak.  The Ethernet shield library for the Arduino has memory problems and with all the other things going on in the Arduino sketch it locks up after a few minutes. That part of the project is on the back burner for a while

I had tried a few times before to get a serial monitor between the Arduino and the computer using various libraries and languages.  All to no avail.  However if you dig around on the net long enough you can get libraries and code that others have used and cobble it together to get the job done.

I found some Rs232 code here.   I found a ThingSpeak class here. I found some COSM code here. Cobbled it together, got it working and put it up on Google Code.

Believe it or not - Google code was the hardest part - Had to install TortoiseHg/Mecurial and figure that all out and then figure out how to get it into Google.  Let me just say if you want to do the same - it works backwards from what you think.  Build the Google Repository - then clone it to your local machine, copy your source there and push it back to Google.

You have to configure ThingSpeak manually, The settings are a simple check-box for each new graph, and you push the data as field1, field2e.t.c.  However a nice thing about COSM is that it picks up what you send to your channel. and auto creates a data-set to graph.  I plan to exploit that a little more when I get the Radios working again and have sensors all over inside and outside the house.

Please excuse the code - It is incredibly raw, and it will take some time to massage it into reusable classes.

I found some interesting .NET classes for Gauges here and here but haven't taken the time to plug the code in yet.