Skip to content

Commit 7a86dd5

Browse files
committed
additional error handling for unexpected errors
1 parent 4a0ebea commit 7a86dd5

File tree

1 file changed

+36
-33
lines changed

1 file changed

+36
-33
lines changed

code.py

+36-33
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,6 @@
2222

2323
pixels = neopixel.NeoPixel(board.NEOPIXEL, 1)
2424

25-
26-
# SKIFF NOTES 2022-11-06
27-
# When testing on the REPL, to paste code segments, ctrl-e puts you into paste mode
28-
# then paste your code with cmd-c/cmd-v
29-
# then hit ctrl-d and hit enter.
30-
31-
# DONE: refactor to skip networking stuff and send SMS instead
32-
# TODO: handle queue
33-
# TODO: SMS receiver
34-
3525
##################
3626
## Set pins to safe values in case the sms board is attached
3727
###################
@@ -272,7 +262,7 @@ def fade_up_status(red=128, green=128, blue=128, fade_length=2, repeat=1):
272262
pixels.fill((0, 0, 0))
273263

274264
## MAIN CODE BLOCK
275-
265+
reading_interval = int(secrets["reading_interval"])
276266
led = digitalio.DigitalInOut(board.LED)
277267
led.direction = digitalio.Direction.OUTPUT
278268

@@ -283,29 +273,38 @@ def fade_up_status(red=128, green=128, blue=128, fade_length=2, repeat=1):
283273
time.sleep(0.5)
284274
for x in range(8):
285275
led.value = not led.value
286-
time.sleep(0.5)
276+
time.sleep(0.25)
287277

288-
print("Blinking done, now startinging the program")
289-
## Set up the realtime clock
290-
r = rtc.RTC()
291-
print(f"Time at start: {r.datetime}")
292278

293-
if (secrets['sms_mode'] == "true"):
294-
init_sms_board()
295-
try:
296-
r.datetime = time.localtime(fona.get_timestamp())
297-
except:
298-
flash_warning()
299-
print(f"Time after getting fona time: {r.datetime}")
279+
try:
280+
print("Blinking done, now startinging the program")
281+
## Set up the realtime clock
282+
r = rtc.RTC()
283+
print(f"Time at start: {r.datetime}")
300284

301-
## Check on the battery
302-
print("LC709203F simple test")
303-
print("Make sure LiPoly battery is plugged into the board!")
285+
if (secrets['sms_mode'] == "true"):
286+
init_sms_board()
287+
try:
288+
r.datetime = time.localtime(fona.get_timestamp())
289+
except:
290+
flash_warning()
291+
print(f"Time after getting fona time: {r.datetime}")
292+
293+
## Check on the battery
294+
print("LC709203F simple test")
295+
print("Make sure LiPoly battery is plugged into the board!")
304296

305-
battery_sensor = LC709203F(board.I2C())
297+
battery_sensor = LC709203F(board.I2C())
306298

307-
print("IC version:", hex(battery_sensor.ic_version))
308-
print("Battery: Mode: %s / %0.3f Volts / %0.1f %%" % (battery_sensor.power_mode, battery_sensor.cell_voltage, battery_sensor.cell_percent))
299+
print("IC version:", hex(battery_sensor.ic_version))
300+
print("Battery: Mode: %s / %0.3f Volts / %0.1f %%" % (battery_sensor.power_mode, battery_sensor.cell_voltage, battery_sensor.cell_percent))
301+
except Exception as e:
302+
flash_warning()
303+
print("\nERROR: Problem during startup.")
304+
print('Error message: {}'.format(e))
305+
print("Check your connections.")
306+
print('Deep sleep for reading interval ({}) and try again'.format(reading_interval))
307+
deep_sleep(reading_interval)
309308

310309
try:
311310
i2c = board.I2C() # uses board.SCL and board.SDA
@@ -317,8 +316,14 @@ def fade_up_status(red=128, green=128, blue=128, fade_length=2, repeat=1):
317316
except ValueError:
318317
print("\nNO SENSOR, not writing to temperatures.txt CIRCUITPY is writeable by computer")
319318
flash_status(0,0,128,1,1)
319+
except Exception as e:
320+
flash_warning()
321+
print("\nERROR: Problem during sensor startup.")
322+
print('Error message: {}'.format(e))
323+
print("Check your connections.")
324+
print('Deep sleep for reading interval ({}) and try again'.format(reading_interval))
325+
deep_sleep(reading_interval)
320326

321-
reading_interval = int(secrets["reading_interval"])
322327
net_connected = False
323328
if (secrets['sms_mode'] != "true"):
324329
try:
@@ -429,9 +434,7 @@ def fade_up_status(red=128, green=128, blue=128, fade_length=2, repeat=1):
429434
# Create an alarm that will trigger at the next reading interval seconds from now.
430435
print('Deep sleep for reading interval ({}) until the next send'.format( reading_interval))
431436
deep_sleep(reading_interval)
432-
except OSError as e: # Typically when the filesystem isn't writeable...
433-
if e.args[0] == 28: # If the file system is full...
434-
print("\nERROR: filesystem full\n")
437+
except Exception as e: # Typically when the filesystem isn't writeable...
435438
flash_warning()
436439
print("\nWARN: not writing temp to file, or sending to Heat Seek")
437440
print("This is likely because sensor is not attached and the filesystem was writable by USB")

0 commit comments

Comments
 (0)