This project is an IOT web application developed with Deno and the framework Fresh that provides monitoring for high security rooms. In order to simulate some real life scenarios, some virtual sensors have been implemented using Node-RED. Also some real sensor data are shown on the website. Furthermore, in order to store the data from the virtual and the real sensors a MongoDB database was deployed on the cloud with the MongoDB Atlas service. Finally, the application is deployed online using Deno Deploy
You can either use this application by installing Node-RED and accessing the website at the link presented below or locally by also installing Deno, downloading the source code, creating an account on the mailgun service and creating your own MongoDB database using Atlas.
- To install Node-RED and run it locally follow the instructions for your system specifications on the Running Node-RED locally page on the Node-Red website
- If you want to run the application locally you have to also install Deno by following the instructions for your system specifications found on the Deno Installation page, create an account on the mailgun service and follow the Get Started with Atlas instructions in order to deploy your cluster with your database
After Node-RED has been installed you can run it locally by typing the following command on a terminal:
node-red
Access the Node-RED editor by pointing your browser at http://localhost:1880
Then import the flows found at this repository (flows.json) by following the steps bellow:
- Click on the hamburger icon at the top right of the Node-RED editor page next to the "Deploy" button
- Select Import
- Either copy the all content of the flows.json file and paste it to the clipboard window or if you have the file downloaded click the "select a file to import" button and select the file on your computer
- Click the "Import" button
The flows used for the application are:
- Temperature-Humidity Sensor Flow
- Tag Sensor Flow
- Water Sensor Flow
- Smoke Sensor Flow
- Dust Sensor Flow
- Rack Temperature Sensors Flow
- Door Sensor Flow
- Alert-Check
After Node-RED has been deployed you can use the application as stated above by visiting the online deployed version at:
To log in to the app you can use the following credentials:
- Username: admin
- Password: pass
NOTE: !! The following further instructions are needed only if you want to run the application locally !!
After the cluster has been deployed by following the instructions linked before create a database, with any name, containing the following collections:
- DoorSensor
- DustSensor
- FluidLevelSensor
- RackTemperatureSensors
- RealMove
- RealTempHum
- SmokeSensor
- TagSensor
- TemperatureSensor
- users
NOTE: You shouldn't insert any documents on the Sensor collections. The documents will be created and inserted
by Node-RED which at this point should be installed and deployed
NOTE: Insert any user credentials (username, password) you want to test in the "users" collection.
After the mailgun account has been created you must add the Authorized Recipient you want to receive the alerts from the application to your mailgun domain. To do so follow the Authorized Recipients instructions from the mailgun help center
Some options to install the source code are:
- Clone the repository by following the instructions on the Github Docs
- Download a .zip with the source code
- Click on the green "Code" button
- Click on the "Download ZIP" button
- Select the path where the zip will be downloaded and then extract it
At this point you have your database deployed on MongoDB Atlas, you have successfully deployed Node-RED and you have your domain ready on the mailgun service. In order to run the source code locally you need to create a .env file with the following variables
The environmental variables needed for MongoDB Atlas are:
DB=<DATABASE_NAME>
API_KEY=<ATLAS_API_KEY>
ENDPOINT=<DATABASE_URL_ENDPOINT>
DATA_SOURCE=<CLUSTER_NAME>
NOTE: Be careful to instantly copy and paste ATLAS_API_KEY when you create it on the Data API tab on MongoDB Atlas because afterwards you won't be able to access it, and you'll have to create another one
The environmental variables needed for mailgun are the following:
EMAIL=<SENDER_EMAIL>
RECV_EMAIL=<RECIPIENT_EMAIL>
API_KEY_MAILGUN=<MAILGUN_API_KEY>
MAILGUN_DOMAIN=<MAILGUN_DOMAIN_NAME>
NOTE: The MAILGUN_API_KEY is not the one that is sent to you after you created the account. You must access it form the API keys tab on the Overview page of your domain (Private API key). NOTE The RECIPIENT_EMAIL must be saved as an Authorized Recipient and also be verified.
For this part a code editor is needed (e.g. Visual Studio Code)
- To install Visual Studio Code choose the correct version for your system specifications on the Visual Studio Code Download page
After you have Visual Studio Code installed some changes must be done to the source code in order to access the environmental variables mentioned above found in the .env file provided by us
- mongodb.ts
- Open the "mongodb.ts" file found at model/
- Uncomment the commented lines of code (line 2 to line 8) by removing the '//' from their beginning
- Comment the lines from line 9 to line 12 by adding '//' at their beginning
- alert-email.ts
- Open the "alert-email.ts" file found at routes/api/
- Uncomment the commented lines of code (line 8 and line 61 ot line 65) by removing the '//' from their beginning
- Comment the lines from line 57 to line 60 by adding '//' at their beginning
Finally, after those changes have been completed you can run the source code by typing the following command to a
terminal:
deno task start
The message Listening on http://localhost:8000 should be printed on your terminal. Navigate to localhost and log
in to the application
NOTE: You can log in to the application by using a set of credentials you have inserted as a document (e.g. {username:"test", password:"1234"} ) to the users collection as stated above