|
1 | 1 | """Used in conjunction with https://github.com/m3wolf/professor_oak |
2 | 2 | (Professor Oak Lab Management System). Script to run on a Raspberry Pi |
3 | 3 | that will send a HTTPrequest to the main inventory server to mark a |
4 | | -certain container_id as empty and hopefully, if it's not too |
5 | | -complicated to program, output a success message to a GPIO LCD |
| 4 | +certain container_id as empty and output a success/failure message to a GPIO LCD |
6 | 5 | display. Questions? Comments? email [email protected]""" |
7 | 6 |
|
8 | | -import re, datetime, requests, json, LOCALSETTINGS as localsettings |
| 7 | +import re, datetime, requests, json, LOCALSETTINGS as localsettings, lcd_16x2 as lcd |
9 | 8 |
|
10 | 9 | import logging |
11 | 10 |
|
@@ -74,23 +73,61 @@ def mark_as_empty(id_number): |
74 | 73 | log.debug("Received response text: %s", r.text) |
75 | 74 |
|
76 | 75 | r = requests.patch(url, json=payload, auth=auth) |
77 | | - |
78 | | - |
79 | | -if __name__ == "__main__": |
| 76 | + return r.status_code |
| 77 | + |
| 78 | +if __name__ == "__main__": |
| 79 | + lcd.lcd_init() |
| 80 | + lcd.lcd_string("Welcome", lcd.LCD_LINE_1, "c") |
| 81 | + lcd.lcd_string("to LabPi", lcd.LCD_LINE_2, "c") |
| 82 | + lcd.GPIO.cleanup() |
| 83 | + lcd.time.sleep(3) |
80 | 84 | while True: |
81 | | - barcode = str(input('input:')) |
82 | | - log.debug("Input received: %s", barcode) |
83 | | - if input == 'EXIT': |
84 | | - log.info("Received 'EXIT' signal. Exiting.") |
85 | | - exit() |
86 | | - if validate(barcode): |
87 | | - if barcode[:2] == 'UL': |
88 | | - status_return = send_notification(barcode[2:], note_type='ULON') |
89 | | - barcode_string = str(barcode) |
90 | | - log.info("ULON# %s %s", str(barcode).zfill(barcode_digit_length), status_return) |
| 85 | + try: |
| 86 | + lcd.GPIO.cleanup() |
| 87 | + lcd.lcd_init() |
| 88 | + lcd.lcd_string("Ready:", lcd.LCD_LINE_1) |
| 89 | + barcode = str(input('input:')) |
| 90 | + log.debug("Input received: %s", barcode) |
| 91 | + if barcode == 'EXIT': |
| 92 | + log.info("Received 'EXIT' signal. Exiting.") |
| 93 | + exit() |
| 94 | + if validate(barcode): |
| 95 | + lcd.lcd_string("Recieved:", lcd.LCD_LINE_1) |
| 96 | + lcd.lcd_string(barcode, lcd.LCD_LINE_2) |
| 97 | + if barcode[:2] == 'UL': |
| 98 | + lcd.lcd_string("Sending...", lcd.LCD_LINE_1) |
| 99 | + status_return = send_notification(barcode[2:], note_type='ULON') |
| 100 | + barcode_string = str(barcode) |
| 101 | + log.info("ULON# %s %s", str(barcode).zfill(barcode_digit_length), status_return) |
| 102 | + if status_return == "200": |
| 103 | + lcd.lcd_string("Email Sent!", lcd.LCD_LINE_1) |
| 104 | + lcd.GPIO.cleanup() |
| 105 | + lcd.time.sleep(2) |
| 106 | + else: |
| 107 | + lcd.lcd_string("Error!", lcd.LCD_LINE_1) |
| 108 | + lcd.GPIO.cleanup() |
| 109 | + lcd.time.sleep(2) |
| 110 | + else: |
| 111 | + lcd.lcd_string("Sending...", lcd.LCD_LINE_1) |
| 112 | + status_return = mark_as_empty(barcode) |
| 113 | + barcode_string = str(barcode).zfill(barcode_digit_length) |
| 114 | + log.info("ID# %s %s", str(barcode).zfill(barcode_digit_length), status_return) |
| 115 | + if status_return == 200: |
| 116 | + lcd.lcd_string("Marked as Empty!", lcd.LCD_LINE_1) |
| 117 | + lcd.GPIO.cleanup() |
| 118 | + lcd.time.sleep(2) |
| 119 | + else: |
| 120 | + lcd.lcd_string("Error!", lcd.LCD_LINE_1) |
| 121 | + lcd.GPIO.cleanup() |
| 122 | + lcd.time.sleep(2) |
91 | 123 | else: |
92 | | - status_return = mark_as_empty(barcode) |
93 | | - barcode_string = str(barcode).zfill(barcode_digit_length) |
94 | | - log.info("ID# %s %s", str(barcode).zfill(barcode_digit_length), status_return) |
95 | | - else: |
96 | | - log.warning("Invalid input: %s", barcode) |
| 124 | + log.warning("Invalid input: %s", barcode) |
| 125 | + lcd.lcd_string("Invalid", lcd.LCD_LINE_1) |
| 126 | + lcd.GPIO.cleanup() |
| 127 | + lcd.time.sleep(2) |
| 128 | + except (KeyboardInterrupt, SystemExit): |
| 129 | + lcd.lcd_string("Goodbye!",lcd.LCD_LINE_1, "c") |
| 130 | + lcd.time.sleep(1) |
| 131 | + lcd.GPIO.cleanup() |
| 132 | + lcd.lcd_init() |
| 133 | + exit() |
0 commit comments