Skip to content

FitoiuRobert/IoTCA_project

Repository files navigation

Members

Baciu Dragos Marian, Fitou Robert Claudiu



Table of Contents

  1. Quickstart
  2. Project setup
  3. Database
  4. Core module
  5. Web API

Quckstart

$ . venv.sh
$ pip3 install requirements.txt
$ ./fix_firebase_modules.sh # ONLY RUN THIS LINE IF YOU ARE USING python3.7 AND ABOVE
$ ./coremodule.py -s -f <FIREBASE_URL>
$ ./api.py



Project setup

  • coremodule.py - Core module of the project, which is responsible for reading temperature (from senor or generates random values) and storing it to database, writes events in Firebase and graphs temperature data using Plotly.
  • api.py - Web API running on local host on port 5051 with endpoints for fever and temperature.
  • database.py - Sqlite3 databse module which is used by both coremodule.py and api.py .
  • fix_firebase_modules.sh - Fixes some issues related to Firebase module. Only needed to run if you are using python3.7 and above because "async" became a keyword in python3.7.
  • venv.sh - Installs virtualenv python module and activates the virtual environment.
  • requirements.txt - pip3 requirements file

database.py

Database table layout:

timestamp temperature event
1591124008896 37.4 FEVER_FEVER_START
1591124009161 35.2 None
... ... ...
1591124009161 36.8 FEVER_FEVER_END


Creates a database file named TEMPERATURE.db in the same directory with database.py
To view the databse file content you can use: http://inloop.github.io/sqlite-viewer/
The following values can be customized inside database.py:

  • __db_file_name: name of the database file
  • TABLE_NAME: name of the table that is going to be used by sqlite3 module

coremodule.py

Usage

$ ./coremodule.py  --help
usage: coremodule.py [-h] -f FIREBASE_URL [-s] [-v] [-l LOG_PATH] [--sleep SLEEP] [-t FEVER_THRESHOLD]

optional arguments:
  -h, --help            show this help message and exit
  -f FIREBASE_URL, --firebase-url FIREBASE_URL
                        Firebase storage URL
  -s, --simulation      Runs in simulation mode, generating random temperature values instead of reading from sensor
  -v, --verbose         Prints debug messages
  -l LOG_PATH, --log-path LOG_PATH
                        Path to to log. Only valid if 'verbose' is specified
  --sleep SLEEP         Sleep duration between temperature reading
  -t FEVER_THRESHOLD, --fever-threshold FEVER_THRESHOLD
                        Threshold temperature for fever events

Firebase

  • Writes events in Firebase. Receives the events and the current time and while it is an event will be writen along with the current time, in firebase . Replace FIREBASE_URL with your own url.

Firebase


Plotly

  • Graphs temperatures using Plotly. It receive temperature and time and draw an dashed graph using them.Generated plotly file is called test.html.

Plotly



api.py

Falsk API which uses the data from database having 2 endpoints:

temperature:
http://localhost:5051/temperature?start=<timestamp>&end=<timestamp>
http://localhost:5051/temperature?start=<timestamp>&end=<timestamp>&aggregation=<aggregation_type>&operator=<operator_type>
Where the values for the second request are:

  • aggregation_type: HOURLY, DAILY
  • operator_type: AVERAGE, MEDIAN, MAX

fever:
http://localhost:5051/fever?start=<timestamp>&end=<timestamp>

Any other request will return "Bad request 400" response.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published