Skip to content

Commit

Permalink
give the server a name by env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
BenniWi committed Jun 8, 2024
1 parent 44e8001 commit 9a697aa
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 16 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ This repository provides two [poetry](https://python-poetry.org/) packages
you can easily use the docker container provided at dockerhub [benniwi/airodor-wifi](https://hub.docker.com/r/benniwi/airodor-wifi)

Start the container with the environment variable **VENTILATION_ADDRESS** to connect it to your airodor wifi module
Give the server a custom name with the environment variable **SERVER_NAME**
Enable the testing mode with the environment variable


## install poetry
Expand All @@ -32,7 +34,13 @@ gh net

for more details check this https://github.com/github/gh-net#codespaces-network-bridge

## testing the container




### build the container
```bash
docker build -t benniwi/airodor-wifi:latest --file ./container/Dockerfile .
```
### run the container
```bash
docker run --env TEST_MODE=1 --env VENTILATION_ADDRESS="1.1.1.1" --env SERVER_NAME="My Custom Server Name" --expose=80 --rm -ti benniwi/airodor-wifi
```
2 changes: 1 addition & 1 deletion airodor_web_app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ provide a simple web application and api for the airodor wifi module from limot

To run this application:

```
```bash
poetry run flask run
```

Expand Down
33 changes: 24 additions & 9 deletions airodor_web_app/airodor_web_app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,22 @@

env_variable_venilation_address = "VENTILATION_ADDRESS"
default_IP = ipaddress.ip_address("192.168.2.122")
env_variable_server_name = "SERVER_NAME"
default_server_name = "Ventilation Server"
env_variable_test_mode = "TEST_MODE"

# check if ipadress is given as environment variable
if env_variable_venilation_address in os.environ:
current_ip = ipaddress.ip_address(os.environ[env_variable_venilation_address])
else:
current_ip = default_IP

# check if server name is given as environment variable
if env_variable_server_name in os.environ:
server_name = os.environ[env_variable_server_name]
else:
server_name = default_server_name

lock_timer_dict = threading.Lock()
timer_dict = {"A": airodor.VentilationTimerList(), "B": airodor.VentilationTimerList()}
timezone = pytz.timezone('Europe/Berlin')
Expand All @@ -26,8 +35,13 @@
return_message_queue = Queue(maxsize=10)

# enable/disable real communication with the ventilation device
do_real_communication = True
do_real_communication = False

# check if test mode is given as environment variable
if env_variable_test_mode in os.environ:
do_real_communication = False
else:
do_real_communication = True
app = Flask(__name__)

# status variable to check if the backend thread is running
Expand Down Expand Up @@ -103,6 +117,7 @@ def index():
add_message_to_queue("Success reading status for group B")
return render_template(
'index.html',
server_name=server_name,
ip_address=current_ip,
ventilation_modes=airodor.VentilationModeSet,
status_string_group_A=vent_mode_A.name,
Expand Down Expand Up @@ -145,9 +160,7 @@ def add_timer():
for g in group:
global timer_dict
timer_dict[g.name].add_list_item(datetime.now(timezone) + timedelta(minutes=deltatime), g, mode)
add_message_to_queue(
"Added timer for group {} with mode {}".format(g.name, mode.name)
)
add_message_to_queue("Added timer for group {} with mode {}".format(g.name, mode.name))

check_and_update_timers()
return redirect(url_for("index"))
Expand All @@ -168,9 +181,10 @@ def remove_timer():
remove_indices.reverse()
for remove_index in remove_indices:
add_message_to_queue(
"Removed timer for group {} with mode {}".format(
timer_dict[remove_list_key].timer_list[remove_index].group.name,
timer_dict[remove_list_key].timer_list[remove_index].mode.name)
"Removed timer for group {} with mode {}".format(
timer_dict[remove_list_key].timer_list[remove_index].group.name,
timer_dict[remove_list_key].timer_list[remove_index].mode.name,
)
)
del timer_dict[remove_list_key].timer_list[int(remove_index)]

Expand All @@ -186,8 +200,9 @@ def both_one_dir_max_now_alternate_med_500():
for g in group:
global timer_dict
timer_dict[g.name].add_list_item(datetime.now(timezone), g, airodor.VentilationModeSet.ONE_DIR_MAX)
timer_dict[g.name].add_list_item(datetime.now(timezone) + timedelta(minutes=500),
g, airodor.VentilationModeSet.ALTERNATING_MED)
timer_dict[g.name].add_list_item(
datetime.now(timezone) + timedelta(minutes=500), g, airodor.VentilationModeSet.ALTERNATING_MED
)
add_message_to_queue("Fast action: ONE_DIR_MAX now and ALTERNATING_MED in 500m")

check_and_update_timers()
Expand Down
2 changes: 1 addition & 1 deletion airodor_web_app/airodor_web_app/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</head>
<head>
<!--META HTTP-EQUIV="refresh" CONTENT="1"-->
<h2>Ventilation Server</h2>
<h2>{{server_name}}</h2>

<form action="/updateIP/" method="post">
<label for="IP-Address">IP-Address:</label>
Expand Down
3 changes: 1 addition & 2 deletions airodor_web_app/airodor_web_app/wsgi.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from app import app

from airodor_web_app.app import app

if __name__ == '__main__':
app.run()

0 comments on commit 9a697aa

Please sign in to comment.