Error Handling ⚠️ Must-read ⚠️
These examples will show you how to recover from errors returned by the E32Device
class.
Config Changes
If you get an E32GenericError
exception when changing the module’s config, you will need to follow this procedure.
Expected error:
E32GenericError: The module didn't return the new config !
Resolution procedure:
Catch error in a
try except
block.Reset the module via
E32Device.reset()
.Wait some time for it to restart.
Re-apply the config with
E32Device.update_config()
.Go back into the original mode.
Retry the code that raised the error
Warning:
Failure to follow the procedure WILL result in a module that no longer applies new operating parameters given to it !
1# SPDX-FileCopyrightText: 2023 Herwin Bozet
2#
3# SPDX-License-Identifier: Unlicense
4
5import board
6import time
7
8import ebyte_e32
9import ebyte_e32.exceptions
10
11PIN_M0 = board.B3
12PIN_M1 = board.B4
13PIN_RXD = board.A2 # Pin marked as RX on the module
14PIN_TXD = board.A3 # Pin marked as TX on the module
15PIN_AUX = board.B7
16
17e32 = ebyte_e32.E32Device(PIN_M0, PIN_M1, PIN_AUX, PIN_TXD, PIN_RXD, address=0x1337, channel=0)
18
19# We'll be iterating over each channel
20channel = 0
21while True:
22 print(f"Moving to channel {channel}")
23
24 try:
25 # Can cause errors if the module fails to respond to config request when validating it.
26 e32.channel = channel
27 e32.wait_aux()
28 except ebyte_e32.exceptions.E32GenericError:
29 print("Failed to change !")
30
31 # We reset it and wait more than what AUX indicates.
32 e32.reset(True)
33 time.sleep(2)
34
35 # We re-apply the `E32Device` class' config
36 e32.update_config()
37 e32.wait_aux()
38
39 # Going back to the appropriate mode
40 e32.mode = ebyte_e32.Modes.MODE_NORMAL
41 e32.wait_aux()
42
43 # Retrying to change channels and send the message.
44 time.sleep(1)
45 continue
46
47 e32.send(b'Hello World !')
48 e32.wait_aux()
49
50 time.sleep(2.5)
51
52 channel = channel + 1
53 if channel > ebyte_e32.CHANNEL_MAX:
54 channel = ebyte_e32.CHANNEL_MIN
55
56 time.sleep(2.5)