Skip to content

Commit

Permalink
PROD customizing
Browse files Browse the repository at this point in the history
  • Loading branch information
ziehmon committed Aug 16, 2023
1 parent 52004f1 commit cda182b
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 9 deletions.
19 changes: 13 additions & 6 deletions beernary/beernary_counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def shutdown(exception=None):
signal_light.send_command(signal_light.RED_OFF)
signal_light.send_command(signal_light.YELLOW_OFF)

display.clear()
valve.unlocked = False
GPIO.cleanup()

Expand Down Expand Up @@ -75,6 +76,9 @@ def shutdown(exception=None):
gpio_pin_valve_2_enabled = bool(config.get("gpio_pins", "valve_2_enabled"))
gpio_pin_valve_2 = int(config.get("gpio_pins", "valve_2"))

draft_time_unlock = int(config.get("draft", "time_unlock"))
draft_time_warning = int(config.get("draft", "time_warning"))

# Local variables
current_user_id = ""
current_user_pulses_stx = int # pulses before draft
Expand Down Expand Up @@ -202,9 +206,14 @@ def shutdown(exception=None):
sys.exit(1)

signal_light.send_command(signal_light.RED_ON)

display.clear()
display.send_message(" Beernary Counter ", 1,"ljust")
display.send_message(" ", 2,"ljust")
display.send_message(" Please scan tag ",3,"ljust")
display.send_message(" ",4,"ljust")

rfid_reader.flush_queue()
current_user_id = rfid_reader.read_rfid() # blocking/waiting
logger.info(f"Received RFID tag: {current_user_id}")

Expand Down Expand Up @@ -248,16 +257,14 @@ def shutdown(exception=None):

tap_valve.unlocked = True

unlock_time = 10
warning_time = 5
for i in range (unlock_time):
for i in range (draft_time_unlock):
time.sleep(1)

display.send_message(f"Draft time left: {unlock_time-i}s", 4, "ljust")
display.send_message(f"Draft time left: {draft_time_unlock-i}s", 4, "ljust")

if i > warning_time:
if i >= draft_time_warning:
signal_light.send_command(signal_light.GREEN_OFF)
signal_light.send_command(signal_light.YELLOW_ON)
signal_light.send_command(signal_light.YELLOW_BLINK)

tap_valve.unlocked = False

Expand Down
4 changes: 4 additions & 0 deletions beernary/modules/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,7 @@ def send_message(self, message, line, style):
# send message to STDOUT too, if configured
if self.LCD_STDOUT is True:
print(message)

def clear(self):
"""Clears the display."""
self.send_bit(0x01, self.LCD_CMD)
1 change: 1 addition & 0 deletions deployment/ansible/group_vars/all/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
---
os_configuration_ssh_keys:
- "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGinqYjP1jDrEAbWtM1aaznWYELJK5H/ok30rXQz4d2d Ziehmon"
- "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHcqd2xuIJPEjkPQpaaFHDTIdUJVx8jA4elmWXUlY0QK Cyberkai"
2 changes: 2 additions & 0 deletions deployment/ansible/group_vars/production/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ beernary_counter_config_gpio_valve: 6
beernary_counter_config_gpio_flowsensor: 5
beernary_counter_config_gpio_valve_2: 12
beernary_counter_config_gpio_valve_2_enabled: true
beernary_counter_config_draft_time_unlock: 20
beernary_counter_config_draft_time_warning: 15
beernary_database_root_password: "chooj0eT"
beernary_database_password: "Eiraiva0"
os_configuration_apt_upgrade: false
2 changes: 2 additions & 0 deletions deployment/ansible/group_vars/testing/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ beernary_counter_config_gpio_valve: 6
beernary_counter_config_gpio_valve_2: 7
beernary_counter_config_gpio_valve_2_enabled: false
beernary_counter_config_gpio_flowsensor: 5
beernary_counter_config_draft_time_unlock: 20
beernary_counter_config_draft_time_warning: 5
beernary_database_root_password: "changeme"
beernary_database_password: "changeme"
os_configuration_apt_upgrade: true
2 changes: 2 additions & 0 deletions deployment/ansible/roles/beernary-counter/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ beernary_counter_config_gpio_valve_2: 7
beernary_counter_config_gpio_valve_2_enabled: false
beernary_counter_config_gpio_flowsensor: 5
beernary_counter_config_log_level: "DEBUG"
beernary_counter_config_draft_time_unlock: 30
beernary_counter_config_draft_time_warning: 10
1 change: 1 addition & 0 deletions deployment/ansible/roles/beernary-counter/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
mode: "0644"
notify:
- "Restart beernary-counter"
tags: update_app

# Final health check for beernary after deployment

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ WorkingDirectory={{ beernary_counter_destination_path }}
ExecStart=python3 {{ beernary_counter_destination_path }}beernary_counter.py
KillMode=process
Restart=on-failure
RestartSec=60s
RestartSec=5s
User={{ beernary_counter_application_user }}
Group={{ beernary_counter_application_group }}
UMask=007
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ flowsensor = {{ beernary_counter_config_gpio_flowsensor }}

valve_2_enabled = {{ beernary_counter_config_gpio_valve_2_enabled }}
valve_2 = {{ beernary_counter_config_gpio_valve_2 }}

[draft]
time_unlock = {{ beernary_counter_config_draft_time_unlock }}
time_warning = {{ beernary_counter_config_draft_time_warning }}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ INSERT INTO `keg` VALUES
(1,1,50,0,1),
(2,1,50,0,1),
(3,1,50,0,1),
(4,1,50,0,1),
(5,1,50,0,0);
(4,1,50,0,0);
UNLOCK TABLES;

--
Expand Down

0 comments on commit cda182b

Please sign in to comment.