05 January, 2019

Raspberry Pi and 3d printed Rain meter - Part 3 - Solution Structure

In this part I will briefly describe my solution / architecture.

Broadly speaking this is my overall use case:The Raspbeery pi will take the measurements. The Contabo (Ubuntu) server will use these measurements and formulate the rainfall, and make it available for consumption onto the internet (Example: Web page, API, SMS Telegram Bot)
Something must be built to check if the Raspberry Pi is up and running, and user (me) alerted when not able to be reached.

In future more more sensor data can be added.
This is my solution for the Raspberry Pi:
  1. SQLite database to store the tips.
  2. Command line program (aka sensorDeamon) that will be systemded to listen and save the tips to the db.
  3. The SensorDeamon will also send out an alert that a tip has occurred.
  4. An nginx hosted API to give remote access to the SQLite data.
This is my solution for the Ubuntu server
  1. An nginx hosted API that will listen for alerts.
  2. On receiving an alert it will go and retrieve all data since last retrieval from the RPi.
  3. Do the calculations, and store data in Postgres database.
  4. Make this data available via:
    1. SMS  (Send me an alert when it starts raining)
    2. Web   (So I am other people can view the info and history)
    3. API    (Other systems can query my data)
    4. Telegram (Get alerts and stats via telegram
  5. I would have loved to have done something for Whats app, but there is no public API available for it.
This is my proposed directory structure on the Pi:
  •  sensorpi
    • configs
    • database
      • scripts
    • sensordeamon
    • webapi
Some notes on the above structure:
  1. sensorpi just holds the whole solution in one place.
  2. configs folder will contain the configuration settings for:
    1. sensordaemon, and
    2. webapi
  3. This will allow me to put the source code onto git without revealing my private passwords and settings.
  4. Since the database only exists on the Pi and I dont have a dev I will put the database script in a sub folder and shell file for me to recreate it as needed.
  5. sensordeamon wfolder will contain the command line app that listens to the tips.
  6. webapi will allow remote access (from the Ubuntu server) to my database.

Raspberry Pi and 3d printed Rain meter - Part 2 - Loading and testing dotnet core

I am a c# developer by day, and although I can kind of work in Python, I dont like it.
Since dotnet core now runs on most Linux systems including the Raspberry Pi, I thought I would give it a go and see how it works. Only problem might be talking to the GPIO pins on the board but I am sure I can find some type of solution

  1. Loading dotnet Core onto the RPi
    I followed the instructions on this page with a few minor changes after I ran into trouble.
    These are the commands I used:
    $ apt-get install wiringpi

    $ sudo apt-get -y update

    $ sudo apt-get -y install libunwind8 gettext

    $ wget https://dotnetcli.blob.core.windows.net/dotnet/Sdk/2.1.300/dotnet-sdk-2.1.300-linux-arm.tar.gz

    $ wget https://dotnetcli.blob.core.windows.net/dotnet/aspnetcore/Runtime/2.1.0/aspnetcore-runtime-2.1.0-linux-arm.tar.gz

    $ sudo mkdir /opt/dotnet

    $ sudo tar -xvf dotnet-sdk-2.1.300-linux-arm.tar.gz -C /opt/dotnet/

    $ sudo tar -xvf aspnetcore-runtime-2.1.0-linux-arm.tar.gz -C /opt/dotnet/

    $ sudo ln -s /opt/dotnet/dotnet /usr/local/bin
  2. SSH Deploy to the rescue.
    I have VS2017 installed on a windows PC, and decided to use that for my development environment but there is a problem ... How do I easily get the code from my Windows PC onto the RPI to test. Luckily I found this program called SshDeploy. This made my life much easier.
    Following the instructions on the site I installed it added the xml tags to my project and tested it. Each time after a successful compile it auto sends the program data to the pi.
  3. Finding a Nuget Package for the GPIO pins.
    Next thing was to proof that I can communicate with the GPIO pins correctly. I did a search on NUGET for GPIO and went to each web site to see how much info there was in case I got stuck. I settled on  Unosquare Raspberry IO.Lots of help and a good description. What sold me on the solution was the ability to use callbacks so no need for a while (true) loop.
  4. Testing the GPIO pins.
    I created a new dotnet core 2.1 command line program, followed the steps of SSH Deploy and added this code:
    using System;
    using Unosquare.RaspberryIO;
    using Unosquare.RaspberryIO.Gpio;

    namespace TestGpio
        class Program
            static void Main(string[] args)
                Console.WriteLine("Gpio Callback Test 3");

                var pin = Pi.Gpio.Pin00;
                pin.PinMode = GpioPinDriveMode.Input;
                pin.InputPullMode =


                pin.RegisterInterruptCallback (


                Console.WriteLine("Press any key to exit...");

            static void Pin00Callback()
                var pin = Pi.Gpio.Pin00;
                var state = pin.ReadValue();
                Console.WriteLine("Pin Activated..." + state);
  1. I compiled the code, and confirmed it SFTPed it to the Raspberry Pi.
  2. I logged into the RaspBerry Pi with my user name and went to the deployed folder and verified the files were recent.
  3. Then I ran the program using this command:
    $ sudo dotnet TestGpio.dll
  4. This is the output:

Raspberry Pi and 3d printed Rain meter - Part 1

See the Introduction.

As a side note:
This is where I buy my components from. Luckily I had them all already.
  1. G T Electronic Components
  2. Roleen Electronic Components
  3. Micro Robotics  (In Centurion) 
Steps as proof of concept
  1. I downloaded Raspbian Stretch Lite  from the official web site.
    I downloaded the lite version as I have no need for a desktop.
  2. I downloaded  Etcher from their web site.
  3. Since my Pi had an existing 4Gig SD Card I just used that, and put the image on the SD card following the instructions from here.
  4. I booted up the pi, and all was well.
  5. I then enabled wifi, and remote ssh login.
  6. I then created a new user for myself to log in with rather than the "pi" user.
  7. I then searched google for "hall sensor raspberry pi" and found this web site. and followed all the instructions there, but will repeat them here for clarity in my own words.
    1. I built my little circuit on a breadboard.
    2.  I then created a new folder in my home folder on the pi called "hallsensortest" by executing this command:
      mkdir hallsensortest
    3.  Go into the folder by
      cd hallsensortest
    4. And then executing the command to get the python script from bitbucket

      wget https://bitbucket.org/MattHawkinsUK/rpispy-misc/raw/master/python/hall.py
    5. Since I had logged in using my own user name (and not pi [good security practice]) I had to execute:
      sudo python hall.py
      The reason for the sudo is to gain access to the GPIO pins with elevated privileges.
    6. Then all that was left to do is test it. I got a magnet and waved it in front of the hall sensor, and the screen updated accordingly.

Next step is to get this working in dotNet core.

04 January, 2019

Raspberry Pi and 3d printed Rain meter - Intro

I decided to try and build something using my Raspbrry Pi.

A work colleague had said he had built a weather station to 80% completion and had 3d printed the rain meter.

I then asked if he would be so kind as to print me one as well and I would build it over the December holiday. As I was busy with other things so I only started this project in the new year (2019).

This is what the 3d printed rain meter looks like:
  1. Is the main container.
  2. Is the tipping bucket
  3. Is the lid that goes on the top to guide the rain drops over the tipping bucket.
  4. Is the outlet hole (one each side)
How it works:
The lid (3) guids the rain drops into the center, which then drips into the tipping bucket (2). A very small amount of rain will make it tip, let out the water through the hole (4) and put the other side of the bucket (2) ready to catch more water. There is a small thin magnet (yellow line) attached to the tipping bucket (2), and this will activate a hall sensor attached to the raspberry pi (see Part 1 for more details)

I suspect I would have to sand the lid (item 3) down a bit to make it smooth for the raindrops. And paint it with a UV resistent paint to guard it against the African sun.

The yellow line I suspect is where the magnet will be attached once I assemble the whole thing.

The plans can be downloaded from thingivers if you want to print your own.

Part 1 - Testing the hall sensor

01 January, 2019

Plans for 2019.

My plan was to build a raspberry pi based robot in 2017.

I bought an extra Raspbery Pi 2 end of 2016 with a camera, and a battery pack.

I never got so far as building it.

My long term plans are to build a grandfather clock, it will be the grandfather clock to end all grandfather clocks. But that finished product is still 10 or so years away. Lots of other things need to take place fist before I get to that project.

I work colleague, has a 3d printer, and has some amazing projects that he is busy with. From 3d printed planes, to cnc machines.

Also Trish and I keep track of the rain fall in our suburb. She takes the reading, then WhatApps it to me and I add it into my Diary (a spreadsheet). We have been keeping track of it for 3 year so far. Btw the rainfall in Isandovale for the last 3 years was:
  1. 2016 - 458 mm
  2. 2017 - 689 mm
  3. 2018 - 593 mm
I have been wanting to do something with my Raspberry pi's again, and when J at work spoke about a weather station he had build to 80% completion, I asked about the rain gauge. After the chat I diced to build one and J offered to 3d print me the housing. The next morning when I arrived at work there was a plastic packed on my desk and it had the 3d printed parts and some electronic chips (The ESP8266) being one of them. This looks like an amazing chip.

However I decided I would first build it using my Raspberry Pi. So after completing a few other (video) projects I started with the Rain meter project. The details will be in a separate blog post.

So my plans for 2019 are:
  1. More blog posts for the 2 people who read them.
    (It actually is just a diary for myself)
  2. Create a rain meter using the Raspberry Pi.
  3. Create a small CNC  pen plotter machine using floppy drives (like this).
  4. Create a bigger CNC using NEMA17 motors like this.
  5. If there is time enhance the rain meter into a weather station.
This is a very tall order since I did not do much of this in 2018.

31 December, 2018

Reviewing 2018.

One of the new year resolutions of 2017 was to build a Raspberry Pi robot.
That never happened.

However the year was not dull and the major highlights are listed below and then further down are some more details about each item.


1) The in-laws moved up to Johannesburg (March),
2) Update the Bathrooms, lounge, and Anya's room (March),
3) Family wedding puzzles (May, June),
4) Wrote 3 HTML games for the Geocaching MEGA event (August, September)
5) I foiled a Smash and Grab in Alexandra (September),
6) Ubuntu server at Contabo in in Germany (October),
7) Telegram Bot (November),
8) Outsurance Pointsman Tribute (December), and
9) Other Youtube videos (December)

  1. Move Mom and Dad up to Johannesburg
    Trish's mom and dad lived all by themselves in PE, with very little family support. After our last renter left, we decided that we had to look at options. One option was to get them here with the help of all the kids, or look for another renter. Long story short ... They got a good deal on their house, and plans were made that they would move up here in March.
    Trish went down for 2 weeks to help get rid of all their things, that could not come up to Johannesburg. Matthew drove down to PE on a Friday, rented a big trailer and loaded everything on. Mom and Dad flew up, while Matthew and Trish drove the late afternoon with Chris to Graaf-Reinett and then from there to Johannesburg the next day. Once the stuff arrived we all jumped in and moved everything into the flat. It was very tight, but got it all in.
    Later on Anya would move out the second flat room, and into a room we made from the dining room. This gave the folks an extra bedroom and a lot more space.
  2. Update the Bathrooms, lounge, and Anya's room We wanted to update the bathrooms, and the lounge, and chatted to the bank about a loan. Soon enough we had the money available, and we first had the kids bathroom redone. It used to have a bath, which was removed, and big shower was added in its place. We then also re-tiled our bathroom, which was in dire need to be done. After the bathrooms, and with enough money left we decided to also re-tile the passage, dining room, and lounge. At the last minute, and after lots of um-ing and ah-ing we removed the chimney as well. This put us over the limit we wanted to spend, but with hindsight, it was a good thing to do.
    We then shortly after modified the dining room and computer room, into a new bedroom for Anya, by adding in a false wall, and removing an archway that separated the two rooms.
  3. Family wedding puzzlesFrom some pictures I saw, and a few other ideas ... It came to me to make a puzzle for our folks with all the weddings. I started on it long before, and battled a bit with finding the right photos, but in the end with using GIMP, got it all sorted, and got my side of the family puzzle printed before my folks wedding anniversary.
    When it was Trish's folks anniversary later on, we kind of had forgotten about it. So it ended up being printed just before Christmas, and thus became a bit of Anniversary slash Christmas present.
  4. Wrote 3 HTML games for the Geocaching MEGA eventFor the geocaching mega event held this year in Johannesburg, I wanted to write an interesting puzzle game. I searched the net for quite some time and eventually found a java-script snake game I could base my game on. Soon this was done and tested, but I wanted to do something more. Since time was short I had to find something basic and that I could modify a bit to get it to work. I then found Michael Hadley's blg post and new this was the game I wanted to modify. I spent far too many hours on it boy was a glad when it all worked out fine.
    The snake (aka GeoSlither) game can be found here.
    And the GeoTreasureHunt game can be found here.
    Some more info on GeoTreasureHunt  games.
  5. Foiled a Smash and Grab in Alexandra
    I foiled a smash and grab in Alexandra. I got home quickly split the video using ffmpeg and uploaded the 1 minute 20 second clip to youtube. I was quite excited that I captured something for once that would be interesting to share. I then sent the link to 5 or so whatapp groups hoping to get the double digit views. The next morning someone asked if they could share the link on some crime group. I said of course they could and I think from there it went viral. I had hoped to get to double (i.e 50 odd) views, but when it went to quadruple (over 1000) I was ecstatic. Never in my dreams did I expect over half a million views. My video has been watched worldwide for over 650 000 minutes (WOW!)

    I am also greatly thankful for the opportunity of experiencing the other side of the story. I got interviewed by SABC ,
    by The Good things guy, and
    Carte Blanch.

    I also had numerous Radio interviews, and even one or 2 from overseas.

    I was also featured on Right this minute. I found it quite a humorous take on the whole event.

    Lots of motorcycle vlogs contacted me and asked if they could feature my clip.
  6. Ubuntu server at Contabo in in GermanyA work colleague was talking about his hosting options and mentioned the company he was with had a server for 4 Euro a month (Less than ZAR 80.00) a month. That is really cheap!
    I was starting to play around with dotNet core and wanted a place to permanently host the solutions I wrote. The cheapest in South Africa at the time was over R800 a month (of what I could find). So I decided to eat one less hamburger a month and rent a server.
    It was like 6 hours after I had paid and the server was ready. I pressed some button and Ubuntu 18.4 was installed, and got a notification all was done a little time later. I logged on and started configuring an loading stuff to my liking.
    A few days later I made a fatal mistake. I did somthing like rm /* and whiped a good portion of Ubuntu. Lukily I could click on that magic button and it reinstalled Ubuntu, and since I had kept a detailed (manual) script of all my steps 40 minutes later I was back where I was before. Only a little wiser this time.
    So, the plan was to rewrite the GeoTreasurehunt game onto dotNet core, but I never completed the rewrite. But what I did do was a lot more interesting than rewriting.
  7. Telegram BotI wrote a bot for Telegram.
    Since October 2016 I have been sending out "Friday Funny OneLiners" (aka FFOL) that I gather from various sources during the week. I decided to get them all and put them into a database and make them available via a bot on Telegram. It was an interesting project to do and is my very first deployed dotnet core app using TLS, and a Postgres database. You can have a look at Funny one liner bot
  8.  Outsurance Pointsman TributeI ride a motorbike to work and back, and pass about 2 points man directing traffic every day. As a way to make my ride more interesting, I started to greet them when I was able to. It took a long time for them to notice, as I am sure they concentrate on the traffic. However the one guy at the London Road on-ramp onto the N3 north, quickly learnd to greet me back, and so I thought I would make a tribute video to him and all his fellow pointsman. You can view the video on youtube.
  9.  Other Youtube videos
    I spent about 10 days of 4 to 6 hours a day going through all my videos I captured on the motorbike, and put most of them into small parts of between 5 and 7 minutes long, of interesting things that happened to me while on the bike. The videos are all listed below.
    1.  Interesting events on the motorbike - 2018, Part 1
    2. Interesting events on the motorbike - 2018, Part 2
    3. Interesting events on the motorbike - 2018, Part 3
    4. Interesting events on the motorbike - 2018, Part 4
    5. Interesting events on the motorbike - 2018, Part 5
    6. Interesting events on the motorbike - 2018, Part 6
    7. Blockhouse to Benoni Northeners Toy Run 2018 
For 2019 I am planning to make a monthly video of the interesting events that happen around  me on the bike. Also plan to make a CNC machine and a rain meter using a raspberry pi.

01 July, 2016

Brexit and the consequences for the next generation

I don’t usually worry or get involved with politics, but this Brexit fascinates me.

If I was a Brit, I think I would have voted to exit.
But that was with very limited info … and the implications now seem much worse.

The one main reason I have changed my mind is this:
Source: (http://www.mnn.com/earth-matters/politics/blogs/why-recent-brexit-vote-should-be-warning-young-americans)

It seems like the older generations that remember a time before the EU were slightly more prone to leave.
The younger generation seem to be part of and identify with the EU.

From the article it seems like if 16 yo were allowed to vote the outcome would possibly have been different.

This means that in 10 years time, or at the most 20 years time, most (of the working class) people in the UK would want to be part of the EU. If they are out then they are out for quite some time to come.

I hope the new UK government takes this into account, as the new millennials that will shortly join the work force, and they feel part of the EU.

Interesting times ahead.