rtc (ds3231) on a raspberry pi

Sometimes you raspberry pi (or other boards: arduino, olimex) has no Internet access but you want to keep time between reboots.  A rtc (real time clock) will do the job.

  1. First, get one!  They can be found on popular sites and ebay.  The DS3231 is a bit more accurate than the other rtc’s but they all will do the job.
  2. when you have an rtc module you have to connect with you raspberry.  You can find a picture of the raspberry pi pinout here http://pinout.xyz/pinout/i2c
    – rtc pin GND > raspberry pin 9 (GND)
    – rtc pin VCC > raspberry pin 1 (VCC)
    – rtc pin SDA > raspberry pin 3 (SDA)
    – rtc pin SCL > raspberry pin 5 (SCL)
  3. now that everything is connected, you still need to enable the rtc.  To do so , open /boot/config.txt :
sudo nano /boot/config.txt

now you’ve opened the file, put this text at the bottom and save the file.


this will load the correct modules for the rtc at boot time.
The next  step will read the clock at boottime, you do this by editing the /etc/rc.local file

sudo nano /etc/rc.local

Add this text before exit 0:

hwclock -s

it will look like this:

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
hwclock -s
exit 0

now save the file and reboot.

Login and check if the rtc is working, type:

sudo hwclock -D

if everything goes well, the output will be something like this:

hwclock from util-linux 2.25.2
Using the /dev interface to the clock.
Last drift adjustment done at 1451215751 seconds after 1969
Last calibration done at 1451215751 seconds after 1969
Hardware clock is on UTC time
Assuming hardware clock is kept in UTC time.
Waiting for clock tick...
/dev/rtc does not have interrupt functions. Waiting in loop for time from /dev/rtc to change
...got clock tick
Time read from Hardware Clock: 2015/12/27 13:39:28
Hw clock time : 2015/12/27 13:39:28 = 1451223568 seconds since 1969
Sun 27 Dec 2015 14:39:28 CET  -0.856325 seconds

If this is the first time you use your rtc, you need to save the time to it.
Check if your system time is correct by typing:


the time will show up (this is mine when I was writing the article):
Sun, 27 Dec 2015 14:34:11 +0100
If this the correct time show’s up, you are ready to save the time to your rtc.

this can be done by typing:

hwclock -w -D

the following will show up (time&date may differ)

hwclock from util-linux 2.25.2
Using the /dev interface to the clock.
Last drift adjustment done at 1451215751 seconds after 1969
Last calibration done at 1451215751 seconds after 1969
Hardware clock is on UTC time
Assuming hardware clock is kept in UTC time.
Waiting for clock tick...
/dev/rtc does not have interrupt functions. Waiting in loop for time from /dev/rtc to change
...got clock tick
Time read from Hardware Clock: 2015/12/27 13:44:53
Hw clock time : 2015/12/27 13:44:53 = 1451223893 seconds since 1969
missed it - 1451223892.505637 is too far past 1451223892.500000 (0.005637 > 0.001000)
1451223893.500000 is close enough to 1451223893.500000 (0.000000 < 0.002000)
Set RTC to 1451223893 (1451223892 + 1; refsystime = 1451223892.000000)
Setting Hardware Clock to 13:44:53 = 1451223893 seconds since 1969
ioctl(RTC_SET_TIME) was successful.
Not adjusting drift factor because it has been less than a day since the last calibration.

this should be it! Your clock is set en ready for use!
If you should have question’s, leave a comment bellow of email me philip -at- vanmontfort.be


the quest for a wireless antenna

At our lan party we use yagi antenna’s to connect to fon-hotspots.  But they are quite large difficult to mount indoors.  And I was curios how antenna’s worked.

Well, there are a lot of different antenna types, I discovered.
I wanted a:

  • cheap antenna
  • easy to build

First idea was to build a cantenna.  But a bi-quad looks even more interesting!  The corner antenna is the simplest of them all!


I’ll post more news when i’m done makeing some antenna’s.


global wifi antenna info sites





cantenna calculator – http://www.changpuak.ch/electronics/cantenna.php






use a wok to boost your wifi – https://en.wikipedia.org/wiki/WokFi


cacti & wmi (windows statistics)


after a few hours of searching and testen i’ve got it working!  Cacti can now shows disk io of our windows 2008 servers!

Here is how i did it:

  • wmi-client
  • libwmiclient1
    download them and install at http://www.orvant.com/packages/ (go to bottom)
  • cacti wmi plugin, download the wmi.php and put it in your cacti/scripts/ folder.
    Make sure the webserver you are running can read the file!
  • cacti wmi templates
    Import this file(s) in the webinterface.
    I only imported the ‘all’ template (cacti_host_template_wmi_-_all.xml)
  • create a file password file (credentials used for connecting to the windows server):
    the contents must be in this format:

  • now create a new graph for your device with the (i assume you know how to do this!)
  • select a graph with “(wmi)” behind it.
  • tada!
    i’ve selected the disk io meter:
  • if you want more information, you’ll have to go and see on the cacti forum.
    good luck !


gaming via fon, belgacom|skynet (shorewall & gaming)

Hello interwebs,

The past 2 days i’ve been playing with shorewall’s traffic shaping and reading the lartc.
Long story short: succes!

  • goal: game with a good ping (latency) for everybody on a private lan party (~10 people)
  • problem: when pepole are surfing, gaming becomes impossible due to hig ping
    • bandwith
      we use a fon hotspot to use internet, wich has limited bandwith (~2,8Mbit if we’re lucky)
      If the people who host the fon spot use internet or tv, the fon users get what’s left!
    • me me me!
      everybody want’s to be gaming and surfing and stream footbal matches and updating steam games and downloading pron;
      there is to much traffic and to few bandwidth
  • solution
    since we had an excisting firewall with shorewall (laptop + alfanetwork awus036nh wifi adapter, fully auto reconnecting & login) i chose to investigate the traffic shaper include.

    • first we need to check what the average bandwidth is, as a reference.  This is done via a speedtest.  This was 2,8Mbit download and 2,8Mbit upload! (note: the traffic shaping was still disabled)
    • now we can configure shorewall to do some traffic shaping:
      create 3 files in /etc/shorewall:

      1. tcdevices, this is where we define what interface we will be using for the shaping.  I chose a safe in and out bandwidth (~85% of the bandwidth we got from the speedtest).  Note: this has to be lower then the speedtest bandwidth.  (read notes below)
        wlan1         2400kbit         240kbit
      2. tcclasses, this defines wich priorities i want and how many bandwidth they get guaranteed (RATE), and the maximum bandwith they’ll get if there is room (CEIL).
        note: there has to be one class marked as default, this is where al undefined traffic goes (see next item: tcrules)

        wlan1        1       full/3    full    1           tos-minimize-delay
        wlan1        2       full/4    full    2
        wlan1        3       full/4    full    3           default
      3. tcrules, here you define what port, ip or protocol the packet will use what class.
        you ‘mark’ the packet with a number (ACTION), that corresponds with a class mark (defined in tcclasses)
        This is a very crude example, all echo-request&echo-reply + udp packets will get top priority.  Oh and the tcp/1119 port.
        All other traffic wil go to class 3, wich has the lowes priority; as you read the previous part you will note that this isn’t nessesary because all traffic defaults to class 3 (lowest priority)

        #ACTION  SOURCE       DEST        PROTO   PORT(S)      CLIENT   USER
        #                                                          PORT(S)
        1   icmp       echo-request
        1   icmp       echo-reply
        1   udp
        1   tcp        1119         # blizzard games
        3   tcp


For testing assured the link was not used.  I started quake3 an connected to an internet server.  The average latency was 60ms.  I then started downloading iso files, sending large mail’s, watching youtube, the latency in quake3 stayed below 80ms.
This is good, without the traffic shaping it jumped to 600-1000ms and higher when people started surfing and uploading.


succes!  We now can game and use the internet without the gaming being disturbed!!
For more info/explenations you always can contact me: info <-at-> vanmontfort </dot/> be


  • fon_belgacom hotspots have priorities: the paying customer always gets what he pays for (internet and/or tv), then the fon users get what’s left.  If the user is heavily using torrents and watching HD-tv, fon hotspot might get much less then 2800Mbit.  If this happens you can lower the IN-BANDWITH in tcdevices.
  • all udp traffic is getting high priority, this means dns, torrent, … .  the tcrules could be refined with the correct game ports and removing the all udp rule.