This application is an example of how to build a REST API. The application os a mock IoT device, simulating a Smart Bed. Implemented endpoints:
- Headrest adjustment (at the user's prefference)
- Detection of the bed sheet
- Retrieval of envrionment temperature
This tutorial is based on the official Flask tutorial: https://flask.palletsprojects.com/en/2.0.x/tutorial/
You can check out tools that automate the generation of the specification like: https://openap.is
You should have python3 installed and pip3.
-
cd into this project
-
Install venv if not already installed:
pip install virtualenv
-
Create an environment:
python3 -m venv ./
Windows: python -m venv venv
- Activate environment
macOS/Linux:
source venv/bin/activate
Windows:
.venv\Scripts\activate.bat
-
Install libraries
pip install -r requirements.txt
-
Set environment value for development:
export FLASK_ENV=development
CMD:
set FLASK_ENV=development
PowerShell:
$env:FLASK_ENV = "development"
-
Initialize (or reinitialize) database:
flask init-db
-
Run
flask run
Install and run mosquitto. For this app, we will use the default configurations of mosquitto.
brew install mosquitto
- If restarting the service is needed:
brew services restart mosquitto
Using testing tutorial: https://codethechange.stanford.edu/guides/guide_flask_unit_testing.html