- Requirements
- Environment Setup
- Installation
- Database Setup
- Generating Tables from Models
- Running the Application
- API Documentation
- API Screenshots
- Python 3.x or higher
- For QR code detection, you will need to have a webcam connected to your computer and a webcam permission to access the webcam.
To get the code, open your terminal and go to the directory where you want to download the code. Then run the following command:
git clone https://github.com/Esh07/iGSE-Energy-Management-System.git
NOTE: It is recommended to use a virtual environment to run the application. This will allow you to install the required packages in an isolated environment without affecting your system's global packages. You can use any virtual environment manager of your choice, such as virtualenv, venv, pipenv, etc. For this guide, we will be using the built-in venv module.
You can create a python virtual environment anywhere but the recommended way is to create it inside the project directory.
Go to the project directory
cd iGSE-Energy-Management-System
Create a virtual environment.
NOTE: You can replace
<your-env-name>
with any name you want.
python -m venv <your-env-name>
python3 -m venv <your-env-name>
Activate the environment.
<your-env-name>\Scripts\activate
source <your-env-name>/bin/activate
Run the following command to install the necessary packages:
If you using macOS or Linux, you may need to use
instead of
pip3
; just to avoid dependency issues if you have both Python 2 and Python 3 installed on your system.
pip
pip install -r requirements.txt
Inside the app.py
file, you will find the following line of code that defines the database connection at line 28:
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://api_user:123456@localhost:3306/RestServiceInterface'
This line of code sets the database connection to a MySQL database with the following details:
api_user
as the username123456
as the passwordlocalhost:3306
as the hostRestServiceInterface
as the database name
NOTE: Before running the application, you will need to create the database called RestServiceInterface or give a custom database name and update the
app.py
file (line 28) with your own database credentials.
You can create the database using the following command: (it's one line query in MySQL)
Copy the following query and paste it in your MySQL Query Editor and run it.
CREATE DATABASE RestServiceInterface;
To run queries in MySQL in Windows, press ctrl + Enter to run the query. In MacOS, press command + Enter.
or you can do it by GUI. Execute query in MySQL workbench
NOTE: Make sure you're in the project directory and the virtual environment is activated. Otherwise, you will get an error.
To generate the necessary tables for the application, you will need to run the following command:
Only run this command once to initialize the database migrationsflask db init
flask db migrate
flask db upgrade
NOTE: If you set the
FLASK_APP
environment variable, other thanapp.py
, you will need to configure theFLASK_APP
environment variable toapp.py
before running the application.For example, if you set the
FLASK_APP
environment variable toapp.py
, you will need to run the following command before running the application:export FLASK_APP=app.py
To start the application, run the following command:
Flask run
You can also set the environment variable FLASK_APP
and FLASK_DEBUG
to run the application in debug mode:
Note: A variable is only valid for the current terminal session. If you close the terminal, the variable will be removed. And you will need to set the variable again.
export FLASK_APP=app.py
export FLASK_DEBUG=1 # 1 to enable debug mode, 0 to disable debug mode
set FLASK_APP=app.py
set FLASK_DEBUG=1
setx FLASK_APP app.py
setx FLASK_DEBUG 1 # 1 to enable debug mode, 0 to disable debug mode
This will start the application on http://localhost:5000/
You should now be able to access the application in your browser by navigating to the specified URL. You can also access the application by entering the IP address of your machine on the network.
To change the port, you can set the FLASK_RUN_PORT
environment variable:
export FLASK_RUN_PORT=8000
You can set the following environment variables to configure the application:
Environment Variable | Description |
---|---|
FLASK_APP |
The name of the application file. Default: app.py |
FLASK_ENV |
The environment to run the application in. Default: production |
FLASK_DEBUG |
Enable or disable debug mode. Default: 0 |
FLASK_RUN_HOST |
The host to run the application on. Default: localhost |
FLASK_RUN_PORT |
The port to run the application on. Default: 5000 |
FLASK_RUN_CERT |
The SSL certificate file to use to run the application. Default: None |
The API documentation is available at http://localhost:5000/apidocs/
Endpoint | Method | Description |
---|---|---|
/ |
GET | Home page |
/home |
GET | Home page |
/register |
GET POST | Register a new user |
/login |
GET POST | Login user |
/reset-password |
GET POST | Reset user password |
/logout |
GET | Logout user |
/profile |
GET | View user profile |
/submit-meter-reading |
GET POST | Submit a meter reading |
view_latest_bill |
GET | View the latest bill |
/pay_bill/<int:bill_id> |
GET POST | Pay a bill |
top-up |
GET POST | Top up account |
/admin/register |
GET POST | Register a new admin user |
/admin/login |
GET POST | Login admin user |
/admin |
GET | Admin dashboard |
/admin/logout |
GET | Logout admin user |
/admin/set-tariffs |
GET POST | Set the tariffs |
admin/bills |
GET | View all bills |
/admin/bills/<int:bill_id> |
GET | View a specific bill |
/admin/meter-readings |
GET | View all submitted meter readings |
/admin/energy-statistics |
GET | View energy statistics |
/igse/propertycount |
GET | API endpoint to get the count of properties |
/igse/<property_type>/<num_bedrooms> |
GET | API endpoint to get the average energy consumption for a property type and number of bedrooms |
/check_email |
POST | API endpoint to check if an email address is already registered (AJAX) |
/check_evc_code |
POST | API endpoint to check if an EVC code is valid (AJAX) |