Seroma is a all-in-one server room manager that allows users to check on the status of the servers (temperature and humidity), the access logs of the server room, as well as monitor the server room itself for any security breaches.
Name: RaspberryPiSecurityPolicy
Action: iot:*
Resource ARN: *
Effect: Allow
Next, go to the “Certificates” tab that is also under “Security”, and attach your policy to the certificate you created previously.
On the next page, click on your policy and then click “Attach”.
In the Details page of the thing you created, under the “Interact” tab, there is a REST API endpoint which should be copied and saved.
AWS should now have a Thing that is attached to a policy and has a certificate.
SSH into Raspberry Pi and install AWS CLI using following pip command:
sudo pip install awscli
AWS CLI includes command completion feature but it is not installed by default. Use following command to install command completion feature on Raspberry Pi’s CLI interface:
complete -C aws_completer aws
Configure AWS CLI with Access Key ID, Secret Access Key, AWS Region Name and Command Output format using the following command:
aws configure
The console will then prompt you to fill in the following information:
pi@raspberrypi:~ $ aws configure AWS Access Key ID [None]: "Put your User's Access Key ID here" AWS Secret Access Key [None]: "Put your User's Secret Access Key here" Default region name [None]: eu-central-1 Default output format [None]: json pi@raspberrypi:~ $
Change the protocol to “Email” and enter your email at the end point.
Head over to your email where you typed your endpoint, click on the confirmation link to confirm your email subscription to subscribe to the topic.
Navigate to “AWS IoT” services, on the navigation menu at the left, click on “Act”. This page is where your rules are displayed and available for you to view and edit. Currently, there is no rules for your IoT thing, click on “Create a rule”.
Search for S3 in the AWS search bar.
In the Amazon S3 page, click on the “Create Bucket” button to get started.
Type of Policy: S3 Bucket Policy
Effect: Allow
Principal: *
AWS Service: Amazon S3
Actions: GetObject
Amazon Resource Name (ARN): arn:aws:s3:::seroma-bucket
Click on the “Generate Policy” button.
This section contains the code for roomstatus.py, which writes all data regarding the server room itself every minute. This includes the temperature, humidity, motion (images and videos if true), and access logs. It also writes data to a Google Spreadsheet, data to DynamoDB, images and videos (if any) to S3, display information on the LCD screen, sends an SMS and Email when there is a suspected breach, or when the temperature or humidity is irregular.
To run python files, change directory to where the file is located and type in console: "sudo python <filename>"
Pic 2: Functions declared to allow SMS and Email alerts, and uploading to S3
Pic 3: Variables declared for functions and RPi to work
Pic 4: Start of the loop that gets the temperature and humidity values from the RPi. It also writes the data to a Google spreadsheet
Pic 5: Security part of the loop. It will only activate from 7pm to 7am (off hours). It will check for motion in a one minute span. If motion is detected, it will take an image and video, uploads it to S3, while also writing information to DynamoDB for reference later. Afterwards, it will send an SMS and Email if anything is irregular.
Pic 6: The end of the loop. It also writes data to DynamoDB and sends alerts accordingly. The last line of the loop will make the script sleep until the next minute is reached.
This section contains the code for rfid.py, which adds the functionaity to track when a member of staff accesses the server room. It is also part of the security aspect of Seroma, where a member of staff is not allowed to access the server room after office hours, to prevent a data breach. It also send an Email and SMSs all staff if a breach is suspected.
Pic 2: Start of the RFID reader logic. Whenever a card is scanned against the reader, the unique id (uid) of the card is taken. Afterwards, we try to find the uid value of the card in the staffdata table to see if the card belongs to any of the staff.
Pic 3: If the uid of the card exists in the database, it will check if it is during office off-hours. If it is, it will alert the rest of the employees through SMS and Email the subscribed email addresses. If it is still during office hours, it will write a row to the accesslog table in the database with the relevant data. It will also display a welcome message on the LCD display.
This is the server.py file. We will be using the Flask framework for the web portal. The HTML files to be put in /templates are attached as well.
Pic 1: First route for Flask defined. It will redirect the user to the login page if they're not logged in, and the dashboard page if they are. Also defines a function to be used in the livestream feature
Pic 2, 3, 4: Routes for Flask. It gets data from the DynamoDB table and then returns them to the HTML files so that they can be used there.
Pic 5: Last 2 routes for Flask. It handles the logout function and the livestream function. It also specifies the port the website will run at.
This section includes the code for Seroma’s telegram bot. It uses the telepot library to tap on Telegram’s Bot API. It works by accepting the queries it gets and displaying the respective information to the user. The user can type ‘help’ for a full list of commands.
Pic 1, 2: To set up a telegram bot, you need to use BotFather. Just run through the instructions to get the HTTP API that we need in our code.
Pic 4: Example of a function that takes a certain number of rows of data from the database based on the user's request
Pic 5: How we take the user's input and decide what to run accordingly.
We have implemented a new feature for our server room monitoring system, a live stream of what is going on in the Server Room, this can be accessed at any point of time, anywhere.
How this live stream works: It is a feature that is done in Flask, together with the Pi Camera. Video frames are downloaded as it is happening in real life, so you can actually see that there is a slight delay (1-2 seconds) as video frames are downloaded and pieced together. This could not be done without threading, as the background thread reads frames from the camera and storing the current frame. Piecing all this frames together would then output a live stream.
Pic 2: This is a separate file where all the video frames are stored and as you can see, we are using picamera module to access our raspberry pi camera as that is what we are most familiar with. We have a class Camera so that we could import function as if it is a livestream and not multiple images piecing together, hence in the main application file would take it as a live stream without having to worry about what is happening behind the scenes.
Pic 3:This is part of our server.py file where the live stream part is coded. The main class we imported for this is the Camera from our camera_pi.py file at the top of our server.py file. We defined a function at our root directory, gen, however it is only comes into use when we head over to /video_feed where our live stream is at, where it will loop through this function and return the live stream on the webpage.