Skip to content

Commit 2e27e91

Browse files
committed
Fixed bugs in status_return
1 parent 5f719e2 commit 2e27e91

File tree

3 files changed

+62
-24
lines changed

3 files changed

+62
-24
lines changed

.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
LOCALSETTINGS.py
2-
<<<<<<< Updated upstream
32
__pycache__/
43
emptied_chemicals.log
5-
=======
64
*~
75
__pycache__
8-
>>>>>>> Stashed changes
6+
__init__.py

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ git clone [email protected]:CabanaLab/LabPi.git
1010

1111
### `empty.py`
1212
Setup `empty.py` to run on startup in a headless commandline environment (no GUI). This script is designed to await input from a barcode scanner on a forever-loop.
13+
14+
### `lcs_16x2.py`
15+
Prints output to a [16x2 character LCD screen](https://www.adafruit.com/products/198). This item has been modified for the purposes here. [The original creator and file can be found here.](http://www.raspberrypi-spy.co.uk/)

empty.py

Lines changed: 58 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
"""Used in conjunction with https://github.com/m3wolf/professor_oak
22
(Professor Oak Lab Management System). Script to run on a Raspberry Pi
33
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
65
display. Questions? Comments? email [email protected]"""
76

8-
import re, datetime, requests, json, LOCALSETTINGS as localsettings
7+
import re, datetime, requests, json, LOCALSETTINGS as localsettings, lcd_16x2 as lcd
98

109
import logging
1110

@@ -74,23 +73,61 @@ def mark_as_empty(id_number):
7473
log.debug("Received response text: %s", r.text)
7574

7675
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)
8084
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)
91123
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

Comments
 (0)