Category Archives: Planning

Arduino Uno to the rescue

Basically I was having all types of trouble trying to get the sensors working on the Pi, different versions of python (mainly due to library limitations) and probably just poor coding. The Lux sensor was the biggest headache, the returning values were all over the place.

So I decided to try the Arduino Uno, since most of the Adafruit tutorials use a Uno to get them working and it uses C programming language, which is a lot less annoying than python. Basically in the space of the weekend I have all four sensors working and even have the interrupt programming done for the rain sensor.

2014-05-04 12.43.15I also order the UV sensor from Pimoroni, which simply returns values for the UV index, which is something I also wanted to capture data for, to see if the index is slightly raising, which might be a sign of global warming/ozone depletion.

SI1145The SI1145 can also read visible light and IR but those returning values are not calibrated, so I am not going to bother with those.

Although I have found out that my RGB Leds that I have are around the wrong way, the common anode needs to be positive and not neutral, so ebay to the rescue again.

Got a little more work to do with code, then I can figure out how to get the Pi talking to the Uno and get the values posted to the web, so I can start getting that sorted.

Moon Phases, Sunrise and Sunset

So I want the web front end to give some other data, that might be of use to people.

Since I am also into astronomy, I would like to know what phase the moon is in (not that we’ve seen all that much of it recently). Turns out some clever bloke has written a php class to tell you what phase the moon is in, source is available via github.

PHP 5.1+ contains functions for calculating sunrise and sunset. As far as I can see there’s 3 functions, date_sunrisedate_sunset and date_sun_info. The latter looks like the best bet as you don’t have to supply as many variables.

Now I just need to get the GPS coords for my flat.

Database Testing

I am going to use a local and remote mysql database to host the weather information. So I had to think about which variables to store and at 1 minute resolution, how much space would I need to accomplish this, as I want to store the information year on year. So I will store the following information:-

  • Date and Time of the reading
  • Humidity Outside
  • Temperature on the Humidity Sensor
  • Temperature on the Barometric Sensor
  • Humidity Inside
  • Temperature Inside
  • Wind Speed Average over 1 Minute
  • Wind Gusting Speed
  • Wind Lowest Speed
  • Light Full
  • Light Visible
  • Light Infrared
  • Barometric (Pressure)

This works out to 1,440 readings a day (60 minutes x 24 hours). Which is 525,600 readings a year, so making the database as small as possible is critical. For this I will be using the DECIMAL data type, so you can specify exactly how much information to store. So the rough table looks something like this:-

So using a local database on a desktop PC via phpMyAdmin, I used a store procedure to generate the dummy information. First create and store the procedure:-

Note: The dummy database name is “pi”. Then you can just call:-

Which will take a few minutes (~10 mins) to finish populating the database. You’ll notice on the stored procedure that I counted for 366 days, rather than 365, just to simulate what a leap year would be.

Final size on disk of the database is ~61MB. Plus a bit more for the unique index on the time_stamp column.

Issues encountered: 1. Day light saving time. I was originally trying to store the timestamp, but on the 30th March 2014 at 2am I would get 60 rows with exactly the same date and time and since the time_stamp field needs to be unique, this was a massive issue, so to cure the problem, I changed the store value to DATETIME and inserted the utc_timestamp() value, so I will probably need to convert the utc timestamp to localised time allowing for day light saving time if I need to refer to a date and time specifically.

2. Log files. During my testing and repeated procedure running, I managed to generate a >600MB log file. So disabling the log files on the testing and production machine will need to be done. Find the following in your my.ini or my.cnf file:-

find the line “log-bin=mysql-bin” and place a # and space in front of it, this will disable the log file generation.

The next step will be see how fast the hour average calls are for the last 24 to 48 hours for the chart mapping.

Charting Libraries

I have been trying to find a decent charting library for displaying the information gathered, but I’ve not been totally successful. Rickshaw was a library I really liked the look of, but it looks like I will use Grafico and build that into the bootstrap front end.

Raspberry Pi did tweet the following

Which is nice, I do want to make the sensor data available, via either a sql dump or php query into a comma or tab delimited format, the idea of having to port it all into Plotly through the api is something I might look at eventually but at the moment, it’s outside the scope of the project.