If you found the contents in this blog useful, then please make a donation to keep this blog running. You can make donations via Skrill with email address

Tuesday, November 8, 2016

RFID Parking Solution using Raspberry Pi

Sri Lanka has a lot of Parking Lots Managed by RDA (Road Development Authority) but almost all use paper receipts to maintain Timings of Parked Vehicles. This process is error prone and difficult to keep on days where vehicle come and go out frequently.

This motivated me to do a small PoC on a Low Cost RFID based Parking Solution. I had a HZ-1050 RFID Reader lying around in my Hack Space and 1 RFID Card with 2 RFID Tags so I decided to use those.

Above is the Setup which is really simple, Just need to wire up Raspberry Pi 5v -> HZ-1050 5v, Raspberry Pi Ground -> HZ-1050 Ground, HZ-1050 D0 -> Raspberry Pi Pin 14, HZ-1050 D1 -> Raspberry Pi Pin 15

Finally the Code.

Reading RFID Card/Tag and Storing in Database

I used PiGPIO Library with a Small a Python Script modified from their Example to read the Wiegand Format RFID No and Store it in a SQLite3 Database.

Displaying in Dashboard

I wrote a small Dashboard which has a PHP backend and runs on Light Web Server and connect to the same SQLite3 Database to display data. The Front End Bootstrap with JQuery and Javascript.

Following is a Demonstration on everything working together. I will upload code once I clean those up. This can store different Vehicle Types and their Charges for the First Hour and Additional Hours and Calculate the Duration and Charge. Which will be great for the Parking Operator.

Parts can be bought at IoT Researcher Shop
  1. HZ-1050 RFID Reader -
  2. RFID Card -
  3. RFID Tag -
  1. Hackaday -
  2. BricoGeek -

Tuesday, November 1, 2016

Real Time Streaming Data Processing with Arduino + Raspberry Pi + Apache Kafka + Apache Spark + MQTT

World is constantly going towards a fully automated environment where Smart Industries to Self Driving Cars coming into the scene everyday with the hype of Internet of Things (IoT). Almost all of these automation generate Gigabytes if not Terabytes of sensor data which needs to be processed to make sense of what is happening in the automation.

So for me the most important thing of this would be the ability to develop Scale-able backend systems which could process these data and make them into information which can be used to make strategic decisions whether it be in a Smart Industry to predict which part needs to be replaced and for Self Driving Cars when to hit the Garage for a Service.

With this in mind I researched on how to build these types of backend and found out that Apache Spark is a go to open source framework tailor made for this. It has the capability to process data in Batch, Real Time and to make sense of those data with its Machine Learning and Graphing capabilities.
This made me intrigued to learn more about it and this is my attempt on trying to implement an end to end system from pushing sensor data to real time processing of it.

For this I am using a hypothetical Smart Home with a Thermostat which sends data to a backend  server which then processes and understands what's going on. For Demo purpose I will be sending Temperature and Humidity readings from My home hall to the Backend Server via the following flow and calculate in real time the minimum, maximum and average readings of Temperature and Humidity in every 30 second window. 

System Architecture 

Arduino with Ethernet Shield and DHT22 Sensor


In the demonstration I show how the DHT22 Sensor Readings are coming into Apache Kafka and then finally being processed in Apache Spark. To differentiate the Temperature and Humidity I placed a Tub of Ice Cream near the DHT22 Sensor.


Saturday, September 24, 2016

Advanced Arduino Programming : Threads, Semaphores and Mutexs with ChibiOS-Arduino

Arduino is a great tool for rapid prototyping. It has a good Hardware and Software platform to quickly get started. But when it comes to Advanced Software concepts like Threads, Semaphores and Mutexes the Vanilla Arduino IDE doesn't have much to offer.

That is where ChibiOS comes in. ChibiOS is Real Time Operating System (RTOS) which is intended for Embedded system. Likely ChibiOS has a port for Arduino which can be used in Arduino IDE as a Library.

Using this allows Parallel code execution, Synchronized code excution and many more possible in Arduino. Previously I have done a small project to show Temperature and Humidity on 8x2 LCD Display.

This project has two parts, a Sensor Input Reading and LCD Output Writing both of which are done inside the void loop() section of the Arduino Sketch. But as we all know Input and Output are tasks can sometimes take longer than expected. For Ex:- During Network Input and Output.

So It is better to Parallelize the Input and Output. This can be achieved with ChibiOS-Arduino Library.

So I used the same setup from the aforementioned post with Threads this time to separate Read and Write. Plus Reading will take place every 200 Milliseconds but Writing will take place every 1000 Milliseconds (1 Second). And Read Thread and Write Thread communication is done via a Semaphore. Write Thread will wait on the Semaphore for data to be available and Read Thread will Signal on the Semaphore whenever data is available. So the Serial output for the Arduino Program will look like following, 1 Output Thread for 5 Input Threads

The full Arduino Sketch is following;


  1. ChibiOS
  2. ChibiOS-Arduino
  3. Getting Started With ChibiOS

Sunday, September 4, 2016

Quick Hack Arduino Marine Fish Feeder

Anyone who owned a pet would know that the biggest worry you have is when you leave your pets at home on vacation is how to feed them.

I am a novice Marine fish keeper with a 32 Litre Nano Saltwater Fish Only Aquarium. The livestock is not much but I have 2 Clarks Clownfish (Amphiprion clarkii) which are common in Sri Lankan waters, 1 Ocellaris clownfish (Amphiprion ocellaris) which is actually not so common in Sri Lankan waters but imported from Pacific Oceanic waters specifically Indonesia and 1 Sand Gobi which usually stays under the rock. 

Sri Lanka has strict policies on handling Live Rock and Corals in order to protect our shores, so it is almost impossible to find a legal pet store having those. Importing also strictly controlled.

Anyway I wanted a way to feed the fish while I was away on Vacation for 2 days and 1 night. So with this intention I put up a quick hack fish feeder within couple of hours which actually managed to do the job and keep my fish fed and alive. I had to come up with this because Automatic Fish Feeders are also not so common in Sri Lanka and one have to import it from online shops if they really want one.

I had some servos and an Arduino UNO Rev 3 hanging around and managed to put a small step up where Arduino pin 9 is connected to Servo's actuating pin and 5v to power pin and ground pin to ground.

With this small setup I took the Example for Servo Sweep and Managed to modify it so that the Servo does 180 Degrees rotation 5 times every 6 hours.

I took a candy container, cut it to make it shorter and put some holes near the bottom with a hot nail. Then went in the fish food. Finally I used to box lid to hold the servo in place and managed to secure it with rubber bands, powered the Arduino using a 12v power adaptor and voila! I have a Quick hack fish feeder.

You can see the feeder in action below in video,



Tuesday, April 26, 2016

Spring Security 4.1.0 Features implemented by Me

Recently I got the chance to contribute to an open source project which I have been using for a really long time. Spring Security is one of the de-facto projects when it comes to protecting Web Applications as well as some Standalone applications.

It provides many features with regards to Authentication and Authorization out of the box and it is highly customizable and extendable to work with any third party, proprietary Security implementations (SSO, OAuth, Openid etc).

I took the dive in by forking the Spring security project available at github and went through the issues and found issues that are interesting to me and sent pull requests. I must thank Rob Winch who is the Spring security Project Lead who instructed me on how things need to work.

Before I knew it I have submitted 4 pull requests which have been merged with of course minor changes based on Project Lead's review. The Spring Security version 4.1.0.RC2 is now available to use if you are using the Milestone repository of the Spring project. Which means the features I implemented are almost available to the rest of the world.

Well I took that opportunity to write about the features I implemented which are also documented in the Spring Security reference guide. Following are the features I partially/fully contributed to Spring Security.


Spring Security ships alot of Password encoders such as MD5, SHA which the developers can use to encode the password before storing in the database. This gives added security in case of Security breaches because all the hackers will be getting is an hash not a clear text password.

Scrypt is a similar encoding algorithm and I implemented the PasswordEncoder implementation using the Bouncy Castle library to be used in Spring Security.


AuthenticaionSuccessHandlers give the ability to extend the capabilities of the Spring Security to allow the developers to do a task after a successful login by a user. This can be auditing, etc. In order to forward to a URL after the successful authentication the user had to write custom implementation of AuthenticationSuccessHandler. Well not any more.


AuthenticaionFailureHandlers give the ability to extend the capabilities of the Spring Security to allow the developers to do a task after a failed login by a user. This can be auditing, locking out etc. In order to forward to a URL after the failed authentication the user had to write custom implementation of AuthenticationFailureHandler. Well not any more.


Since creating and initializing ForwardAuthenticationSuccessHandler can be cumbersome at times. The lead wanted a convenient method to set successForwardUrl in a fluid API way. Now the same thing can be accomplished using XML as well using authentication-success-forward-url under form-login XML tag.


Since creating and initializing ForwardAuthenticationFailureHandler can be cumbersome at times. The lead wanted a convenient method to set failureForwardUrl in a fluid API way. Now the same thing can be accomplished using XML as well using authentication-failure-forward-url under form-login XML tag.


LogoutSuccessHandlers are an extension in Spring Security where an action can be performed based on Success of the logout. For this there can be different use cases for example. If a request came from a web browser the logout may redirect to a web page after logout. But if the request came from within an AJAX can there seems to be no point of redirecting to page but better to return a status code alone. This implementation takes care of that in a configurable way. A request matcher and logout success handler is mapped based on the request criteria.

The complete source codes for the examples is available at and following image shows the example in action.

Sunday, March 13, 2016

Home Security using Raspberry Pi + Web Cam + PIR Sensor and Telegram Bot

I saw a post in which was about using Telegram API to control LEDs attached to a Raspberry Pi. Telegram is a messaging service similar to Watsapp but it allows a unique bot API to support its non human machine to machine communication. 

Because of this feature it is hacker friendly because the possibilities are only limited by imagination. I had a PIR sensor and a USB web camera lying around and thought it would be cool to put together something related to Telegram bot API using those.

In Sri Lanka CCTV cameras selling like hot cake and office and home security surveillance has become a high priority in the last couple of years. Because of this I thought it would be cool to put a Home security service for me using the aforementioned components. 

Thus came up with the following schematic.

And attached the USB camera to the Raspberry Pi's USB port. 

Finally a little bit of coding 

After installing all important Telegram messenger and creating a bot by going through the Documentation of Telegram, finally I managed to get the whole thing working together. You can see the application in action in the following video.

  1. Telegram on Raspberry Pi
  2. Raspberry Pi + PIR
  3. Telegram Bot Python Library
  4. Telegram Bots Introduction
  5. Standard Web Cam usage in Raspberry Pi

Thursday, March 3, 2016

Temperature and Humidity Measuring using Arduino + DHT Sensor

Oven, the somewhat correct word which can be used explain Sri Lankan climate at the moment. It becomes so hot during the day and somewhat similar in the nights. Sleeping is impossible without taking a shower. Ideal time to do a project to measure the Humidity and Temperature.

Had the DHT sensor and a 8x2 LCD (GDM0802A) lying around in my electronics collection and thought to put up a small project. 

Unfortunately the LCD didn't have pins so I had to do a bit of soldering. To be honest not the most experienced man when it comes to soldering, so was a bit worried to get started and going. But anyway went on with it and finally managed to do a pretty decent job with the hot iron and it came out well enough to work.

And managed to get the following schematic in place for the project. 

And a bit of Arduino coding to get the sketch done. 

Finally the whole project in working mode.

And video of humidity changing when a cold water bottle is placed near.

  1. DHT Library -
  2. GDM0802A Datasheet -