Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

N2 avionics bs api #16

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 0 additions & 54 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,61 +1,7 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# next.js build output
.next
196 changes: 72 additions & 124 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,156 +1,104 @@
# base-station
# Python Flask API For N2 Avionics Base Station

## Necessary steps before running

1. In the client directory, run:

```
npm install
```

installs the necessary dependencies for the client app

2. In the node -server directory, run:

```
npm install
```

installs the necessary dependencies for the server app

## How to run in production environment

In the node-server directory, run:

```
npm run prod
```

## How to run in development environment

In the node-server directory, you can run:

```
npm run dev
```

Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.

## Running with custom environment variables on client

1. In the client directory create a .env.local file

```
touch .env.local
```

2. Add the following values to the .env.local file

```
REACT_APP_SERVER_URL=ws://<server hostname or ip address>:<server port> or http://<server hostname or ip address>:<server port>
You require python 3 to use flask checkout its documentation at https://docs.python.org/3/
### Installing Flask
To install flask, run the command below on the command line in the necessary virtual environment for your application.
```
pip install flask

## Running with custom environment variables on server

1. In the node-server directory create a .env file

```
touch .env
```

2. Add the following values to the .env file

```
BROKER_URL=mqtt://<broker hostname or ip address>:<broker port>
PORT=<server port>
ORIGIN=http://<client hostname or ip address>:<client port>
```

## Running with systemd

Suppose you are in the app directory `/home/$USER/foo`

1. Create file, let's call it foo.service

```
touch foo.service
```

2. In the file add
### Creating the application
Your programming environment set up, You can start using Flask.
A simple flask application can be created in a python file as shown below

```
[Unit]
Description=Foo application
from flask import Flask

[Service]
User=<USER>
WorkingDirectory=/home/<USER>/foo
ExecStart=/usr/bin/npm run prod
Restart=on-failure
app=Flask(__name__)

[Install]
WantedBy=multi-user.target
```

4. Copy unit into systemd folder
@app.route('/')
def hello():
return "Hello world"

```
sudo cp foo.service /etc/systemd/system
### Running the flask app
Save the created file and close.
To run the web application, on your commandline, tell flask where to find the application via setting FLASK_APP environment variable as shown
```
export FLASK_APP=my_flask_file #use 'set' instead of export for linux

5. Reload daemon

```
sudo systemctl daemon-reload
```
running it in development mode

6. Enable start on boot

```
sudo systemctl enable foo.service
```

## systemd on raspberrypi example

Suppose you are in the app directory `/home/pi/Desktop/base-station`

1. Create file, let's call it bs.service
export FLASK_ENV=development #use 'set' instead of export for linux

```
touch bs.service
```

2. In the file add
running the application, use the flask run commmand as shown

```
[Unit]
Description=Nakuja N2 base station software

[Service]
User=pi
WorkingDirectory=/home/pi/Desktop/base-station
ExecStart=/usr/bin/npm run prod
Restart=on-failure
flask run

[Install]
WantedBy=multi-user.target
```

4. Copy unit into systemd folder
Output will be something like this

```
sudo cp bs.service /etc/systemd/system
Output
* Serving Flask app "hello" (lazy loading)
* Environment: development
* Debug mode: on
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: 813-894-335

```

5. Reload daemon
There you go! You have created a Flask application.

```
sudo systemctl daemon-reload
```
Flask is a microframework for building extensible web applications. To learn more about flask you can check its documentation at https://flask.palletsprojects.com/en/2.1.x/

6. Enable start on boot
# PROJECT STRUCTURE

```
sudo systemctl enable bs.service
```
main/__-data_processing/#this directory contains all received data related tasks
|
|
-models/#this directory contains database models
|
|
-routes/__-#cointains routes to api endpoints
| |
| -auth/__#this directory contains api authentication endpoints
| | |
| | -auth_.py #this file contains api authentication end points
| | -authforms.py #this file contains form for endpoints
| |
| -views/__#this directory contains api enpoints to serve data
| |
| -views_.py #this file cointains api data endpoints
| -views_forms_.py #form for views endpoints
|
-utils/__#this directry contains important utilities for the application
| |
| |
| -email/__#this folder contains email related functionalities
| |
| |
| -errors/__#this folder contains not global error handling
| |
| |
| -responses.py#handles api responses
|
|
-tests/__#this folder contains tests related tasks
|
|
|
-avi_app.py#contains the script thats starts the application
-config.py#contains the application configuration
-requirements.txt#contains requirements to run the application
```
Binary file added __pycache__/avi_app.cpython-38.pyc
Binary file not shown.
Binary file added __pycache__/config.cpython-38.pyc
Binary file not shown.
9 changes: 9 additions & 0 deletions avi_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#STARTS UP THE APPLICATION

import os
from main import create_app,db

#Loading environment variables

#Creating application instance. Configuration is set from environment variables or default if there are no environment variables found
app=create_app(os.getenv('FLASK_CONFIG') or 'default')
3 changes: 0 additions & 3 deletions client/.eslintrc.json

This file was deleted.

23 changes: 0 additions & 23 deletions client/.gitignore

This file was deleted.

32 changes: 0 additions & 32 deletions client/.gitignore copy

This file was deleted.

34 changes: 0 additions & 34 deletions client/README.md

This file was deleted.

Loading