Skip to content

LamFra/Counting-People

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Counting People application

Introduction

Counting People is a simulator that counts the total number of people inside the main shops of the "Campania" shopping centre. The project is based on an IoT Cloud architecture in which several IoT sectors (an entry and exit sensor for each shop considered) collect data and send them to the Cloud where they are processed via Serverless Computing and stored in a NoSQL database.

Structure

The IoT sensors are structured as follows:

  • for each shop considered there is a sensor at the entrance door capable of detecting when a person enters and another at the exit door capable of detecting when a person leaves the shop.

(back to top)

Architecture

architecture

The purpose of this project is to indicate the number of people inside a shop in order to never exceed the maximum threshold allowed for each shop. Each sensor (entry and exit) sends a message with the number of persons detected to the queue for its shop.

  • Every minute, a time-triggered Servereless function calculates the total number of people for each main shop using the messages stored in the queues. For each queue, the function collects the number of people detected by the entry and exit sensors and calculates the total number of those inside each shop, then uploads the result to a NoSQL database.
  • Every hour, a message-triggered Servereless function calculates the average number of people in all of the shops within the shopping centre and a message is sent to a specific queue. A message sent on the queue Summary triggers a Serverless function that sends an email notifying the daily report.

(back to top)

Installation

Prerequisites

(back to top)

Getting Started

  1. Clone the repository
    git clone https://github.com/LamFra/CountingPeople.git
  2. Launch LocalStack
    docker run --rm -it -p 4566:4566 -p 4571:4571 localstack/localstack
  3. Create a SQS queue for each shop
    aws sqs create-queue --queue-name Carpisa --endpoint-url=http://localhost:4566
    aws sqs create-queue --queue-name Adidas --endpoint-url=http://localhost:4566
    aws sqs create-queue --queue-name Zuiki --endpoint-url=http://localhost:4566
    aws sqs create-queue --queue-name Carrefour --endpoint-url=http://localhost:4566
    aws sqs create-queue --queue-name Sephora --endpoint-url=http://localhost:4566
    aws sqs create-queue --queue-name Summary --endpoint-url=http://localhost:4566
  • Placed on the path of the cloned folder:
    cd CountingPeople
  1. Create the DynamoDB table
    python3 settings/createTable.py
  2. Populate the tables with initial data
    python3 settings/loadData.py
  • Check the value of the entire database with populate tables
    aws dynamodb scan --table-name CentroCommercialeCampania --endpoint-url=http://localhost:4566
  1. Create the time-triggered Lambda function to count the total number of people within each shop
  • Create the role and attach the policy
    aws iam create-role --role-name lambdarole --assume-role-policy-document file://settings/role.json --query 'Role.Arn' --endpoint-url=http://localhost:4566
    aws iam put-role-policy --role-name lambdarole --policy-name lambdapolicy --policy-document file://settings/policy.json --endpoint-url=http://localhost:4566
  • Create the zip file
    zip countFunc.zip settings/countFunc.py
  • Create the lambda function and save the Arn
    aws lambda create-function --function-name countFunc --zip-file fileb://countFunc.zip --handler /settings/countFunc.lambda_handler --runtime python3.6 --role arn:aws:iam::000000000000:role/lambdarole --endpoint-url=http://localhost:4566
  • Invoke manually the function
    aws lambda invoke --function-name countFunc --payload fileb://settings/shop.json out --endpoint-url=http://localhost:4566
  1. Set up a rule to trigger the Lambda function every minute
  • Create the rule and save the Arn
    aws events put-rule --name calculateNumPeople --schedule-expression 'rate(1 minutes)' --endpoint-url=http://localhost:4566
  • Add permissions to the rule
    aws lambda add-permission --function-name countFunc --statement-id calculateNumPeople --action 'lambda:InvokeFunction' --principal events.amazonaws.com --source-arn arn:aws:events:us-east-2:000000000000:rule/countFunc --endpoint-url=http://localhost:4566
  • Add the lambda function to the rule using the JSON file
    aws events put-targets --rule calculateNumPeople --targets file://settings/target.json --endpoint-url=http://localhost:4566
  • Simulate the IoT devices
    python3 IoTDevices.py

Now every minute the function countFunc will be triggered.

(back to top)

Setting IFTT

  1. Go to https://ifttt.com/
  2. Create a new applet.
  3. Click "If This", type "webhooks" and choose the Webhooks service
  4. Select "Receive a web request", write "summary" and create "trigger".
  5. Click Then That, type "email"
  6. Click Send me an email and choosing the topic and the body
  7. Retrive your key and copy it into the summary.py
  8. Zip the file and create the Lambda function
    zip summary.zip  summary.py
    aws lambda create-function --function-name summary --zip-file fileb://summary.zip --handler summary.lambda_handler --runtime python3.6 --role arn:aws:iam::000000000000:role/lambdarole --endpoint-url=http://localhost:4566
  9. Create the event source mapping
    aws lambda create-event-source-mapping --function-name summary --batch-size 5 --maximum-batching-window-in-seconds 60 --event-source-arn arn:aws:sqs:us-east-2:000000000000:Summary --endpoint-url=http://localhost:4566

The output should be more similar to this:

email_output

Usage

  1. Simulate the devices

    python3 IoTDevices.py
  2. Wait or invoke Lambda function manually

  3. Count the total number of people within each shop

    python3 getPeople.py

The output should be more similar to this:

output

(back to top)

Contact

Francesca La Manna - lamannafrancesca.flm@gmail.com

Project Link: https://github.com/LamFra/CountingPeople

(back to top)

About

Counting People application. A project for the Serverless Computing course at University of Salerno.

Topics

Resources

Stars

Watchers

Forks

Languages