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
image from Los Angeles County
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
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
- This repository
git clone https://github.com/aleRizzolo/HealthScan.git
- Docker
- AWS cli
- Node.js (v18.14.2) and npm
- Python3 and pip
- Telegram and a Telegram Bot token
- Optional: WSL2 if you don't have a Unix-like system (useful if you want to automatize the setup process with
run.sh
script)
- 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
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
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
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 indeploy
directory - go inside deploy directory
cd deploy
andnpm 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/Linuxzip 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
, runpip install -r requirements.txt
- start the bot by running
python bot.py
- /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
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
- Open an issue explaining your problem or any idea for improvement
- Fork this repo
- Create a new branch (on your copy) and work on it
- Open a Pull Request