The idea is to monitor parking slots occupied in a parking arena with the help for two IR sensor modules, raspberry pi 2 and amazon web services. Whenever a certain slots consumed exceeds threshold, mail is sent to admin using Amazon SNS. Two IR sensors are placed at inlet and outlet which helps in detecting when a car enters/leaves parking arena. These sensors requires 5v to operate and a voltage divider is used to make output signal from IR sensor module harmless to Rpi 2 (Refer to Hardware section).
On Rpi 2, C (WiringPi) library is used to monitor output from IR sensor modules. Sparkfun has a very good tutorial on this here.
First let's start with configuring AWS IoT. Create a thing and name it.
After thing is created, time to "connect a device".
I am going to use embedded c SDK which can be downloaded from here. Download certificates and place it in certs/ folder in Rpi 2.
I have modified "shadow_sample" to work with my setup. Next copy the sample code as shown below to "aws_iot_config.h".
Finally you will be left with a "thing", "certificate" and a "policy".
Now copy the code provided in Software section onto "shadow_sample.c" file and "make". Note that Makefile should include "-lWiringPi" flag. C (WiringPi) requires root privileges to access GPIOs. So run sudo ./shadow_sample
Whenever there is any activity, Shadow gets updated as shown below.
Now to create an alert system, Amazon SNS is used. Go to SNS Home and click on " Create Topic".
Give a Topic name and a Display name.
Create subscription to send an Email whenever parking slot consumed threshold is met.
After creating subscription, an email is sent to the email id providing for verification. Click on the link provided in the mail.
Before confirmation, the status would be "Pending confirmation" as shown below.
Provide user, which in my case SNSRx with required privileges.
Attach "AWSIoTFullAccess" and "AmazonSNSFullAccess" policies to the user.
"Create a Rule" which should look similar to below configuration. Query string is "SELECT * FROM '#' WHERE state.reported.Slots_filled > '5'", which means whenever Slots_filled is greater than 5, an email is sent to registered user.
That's it!!!
Comments