Skip to content

aleRizzolo/SeaScan

Repository files navigation

SeaScan

Internet of Things has revolutionized the way we monitor environment. IoT technology allows us to collect and analyze data in real-time to track all the metrics of the environment around us. This data allows a better awareness by the people about the ecosystem in wich they are

beaches
image from Los Angeles County

Table of Contents

Overview

SeaScan is a simulation of IoT sensors that collect data across multiple beach zones. The project is based on an IoT Cloud architecture where several IoT sensors collect the datas and send them on Cloud where they are processed through Serverless Computing and stored in a NoSQL database to be easily accessible by a Telegram Bot. The IoT sensors are placed directly into the sea and collect datas such as:

  • beach name
  • ph level
  • hydrocarbons level
  • eCholi levels
  • date time
  • a status that indicates if the sensor is on or off

Project's architecture

Sensors write their parameters on SQS queues. A lambda calculates the average parameters and then sends the result in DynamoDB (this function can also be triggered manually). A user can access those informations by interacting with a Telegram bot. The user can also request all the information and the bot sends an email to the specified address. The user can also decide to switch on or off the sensors, by giving command to the bot that triggers another lambda function

architecture

How to run this project

Prerequisites

  1. This repository git clone https://github.com/aleRizzolo/HealthScan.git
  2. Docker
  3. AWS cli
  4. Node.js (v18.14.2) and npm
  5. Python3 and pip
  6. Telegram and a Telegram Bot token
  7. Optional: WSL2 if you don't have a Unix-like system (useful if you want to automatize the setup process with run.sh script)

Get a Telegram bot token and chat id

  • Start Bot father and follow the instruction. Then copy your Telegram Bot API key
  • After copying your Telegram Bot token, start the bot and then open a browser and go to https://api.telegram.org/bot<\API-access-token>/getUpdates?offset=0, send a message to the bot and then refresh the page. In the response, copy the numerical string "id" in "chat" object

Create .env file

If you want to execute this project, you need to create a .env file in the root folder of the project. In this file, you will enter some confidential variables.
After creating this file, write in it the following variables:

  • REGION="the region configured in your cli"
  • ENDPOINT="http://127.0.0.1:4566"
  • BOT_TOKEN="your-bot-token"
  • CHAT_ID="your-chat-id"
  • SENDER_EMAIL="your-email"
  • AWS_ACCESS_KEY_ID="your-aws-access-key"
  • AWS_SECRET_ACCESS_KEY="your-aws-secret-access-key"

After that, copy the .env file in bot directory

Run from script

If you have a Unix-like system (or WSL2), open a terminal in the project's root directory and type: chmod +x run.sh and then type ./run.sh to execute the script.
Under the hood, the script will:

  • start the Docker container used for simulating the AWS environment
  • install all the dependencies required by the project
  • transpile TypeScript into JavaScript
  • start the project
  • start all the secondary scripts
  • setup all the functions
  • install all the dependencies required by the bot

After the script is completed, start the bot by typing in a terminal within the root directory: python bot/bot.py

NOTE: the creation of lambda functions may block the script execution. If the script is stuck, press CTRL+C to execute next step

Manual run

If you want to run this script manually:

  • start the container by typing docker run -d --rm -p 4566:4566 --name aws localstack/localstack:1.4
  • install the dependencies with npm install
  • transpile TypeScript into JavaScript with npm run build
  • create clients and setup db and queues with npm run start
  • from /dist/functions copy all the functions that you want to execute in deploy directory
  • go inside deploy directory cd deploy and npm install after that, go back inside the root directory
  • zip the function with tar -a -c -f functions.zip deploy or if you are on Mac/Linux zip functions.zip deploy
  • create a new aws role with aws iam create-role --role-name lambdarole --assume-role-policy-document file://role_policy.json --query 'Role.Arn' --endpoint-url=http://localhost:4566
  • attach the policy aws iam put-role-policy --role-name lambdarole --policy-name lambdapolicy --policy-document file://policy.json --endpoint-url=http://localhost:4566
  • create the average function and save the Arn aws lambda create-function --function-name average --zip-file fileb://functions.zip --handler deploy/average.lambdaHandler --runtime nodejs18.x --role arn:aws:iam::000000000000:role/lambdarole --endpoint-url=http://localhost:4566
  • create the function for switch all the sensors off and save the Arn aws lambda create-function --function-name offsensors --zip-file fileb://functions.zip --handler deploy/offSensors.lambdaHandler --runtime nodejs18.x --role arn:aws:iam::000000000000:role/lambdarole --endpoint-url=http://localhost:4566
  • create the function for switch all the sensors on and save the Arn aws lambda create-function --function-name onsensors --zip-file fileb://functions.zip --handler deploy/onSensors.lambdaHandler --runtime nodejs18.x --role arn:aws:iam::000000000000:role/lambdarole --endpoint-url=http://localhost:4566
  • create the function for switch a sensor (based on user's preference) on and save the Arn aws lambda create-function --function-name onsensorbeach --zip-file fileb://functions.zip --handler deploy/onSensorBeach.lambdaHandler --runtime nodejs18.x --role arn:aws:iam::000000000000:role/lambdarole --endpoint-url=http://localhost:4566
  • create the function for switch a sensor (based on user's preference) off and save the Arn aws lambda create-function --function-name offsensorbeach --zip-file fileb://functions.zip --handler deploy/offSensorBeach.lambdaHandler --runtime nodejs18.x --role arn:aws:iam::000000000000:role/lambdarole --endpoint-url=http://localhost:4566
  • start the script for populating the Database and for simulating the device npm run setup

After that, you need to start the Telegram bot:

  • inside the bot directory, run pip install -r requirements.txt
  • start the bot by running python bot.py

Bot commands

  • /start: start the bot
  • /help: get a list of available commands
  • Generate Data: triggers a function that calculates average values of ph and hydrocarbons
  • Average PH: get average ph of all the beaches
  • Average hydrocarbons: get average hydrocarbons of all the beaches
  • Send Email: sends an emailto the user with all the informations
  • Switch Sensor On: switches on the specidied sensor
  • Switch Sensor Off: switches off the specidied sensor
  • Activate Sensors: switches on all the sensors
  • Deactivate Sensors: switches off all the sensors

Future developments

For fure developments this project will add more metrics for scanning Sea water quality. Another goal will be to add email and push notifications in case some parameter is worrying

How to contribute

  1. Open an issue explaining your problem or any idea for improvement
  2. Fork this repo
  3. Create a new branch (on your copy) and work on it
  4. Open a Pull Request

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published