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.



References
  1. http://www.penguintutor.com/linux/light-webserver
  2. http://abyz.co.uk/rpi/pigpio/
Parts can be bought at IoT Researcher Shop
  1. HZ-1050 RFID Reader - http://shop.iotresearcher.com/index.php/en/sensors-c-1/hz-1050-rfid-reader-p-9
  2. RFID Card - http://shop.iotresearcher.com/index.php/en/accessories-c-3/rfid-card-p-7
  3. RFID Tag - http://shop.iotresearcher.com/index.php/en/accessories-c-3/rfid-tag-p-6
Trackbacks/Pings
  1. Hackaday - http://hackaday.com/2016/11/21/faulty-parking-meter-tracking-system-rfid-to-the-rescue/
  2. BricoGeek - http://blog.bricogeek.com/noticias/raspberry-pi/control-de-parking-con-rfid-y-raspberry-pi/


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



Demonstration

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.




References
  1. https://github.com/iotresearcher/mqtt-kafka-bridge
  2. https://github.com/iotresearcher/spark-streaming
  3. https://www.infoq.com/articles/apache-spark-introduction
  4. https://kafka.apache.org/quickstart