|
23 | 23 | from meshtastic import BROADCAST_ADDR, mt_config, remote_hardware |
24 | 24 | from meshtastic.ble_interface import BLEInterface |
25 | 25 | from meshtastic.mesh_interface import MeshInterface |
26 | | -from meshtastic.powermon import ( |
27 | | - PowerMeter, |
28 | | - PowerStress, |
29 | | - PPK2PowerSupply, |
30 | | - RidenPowerSupply, |
31 | | - SimPowerSupply, |
32 | | -) |
| 26 | +try: |
| 27 | + from meshtastic.powermon import ( |
| 28 | + PowerMeter, |
| 29 | + PowerStress, |
| 30 | + PPK2PowerSupply, |
| 31 | + RidenPowerSupply, |
| 32 | + SimPowerSupply, |
| 33 | + ) |
| 34 | + have_powermon = True |
| 35 | + powermon_exception = None |
| 36 | +except ImportError as e: |
| 37 | + have_powermon = False |
| 38 | + powermon_exception = e |
33 | 39 | from meshtastic.protobuf import channel_pb2, config_pb2, portnums_pb2 |
34 | 40 | from meshtastic.slog import LogSet |
35 | 41 | from meshtastic.version import get_active_version |
@@ -895,16 +901,22 @@ def setSimpleConfig(modem_preset): |
895 | 901 | # we need to keep a reference to the logset so it doesn't get GCed early |
896 | 902 |
|
897 | 903 | if args.slog or args.power_stress: |
898 | | - # Setup loggers |
899 | | - global meter # pylint: disable=global-variable-not-assigned |
900 | | - log_set = LogSet( |
901 | | - interface, args.slog if args.slog != "default" else None, meter |
902 | | - ) |
| 904 | + if have_powermon: |
| 905 | + # Setup loggers |
| 906 | + global meter # pylint: disable=global-variable-not-assigned |
| 907 | + log_set = LogSet( |
| 908 | + interface, args.slog if args.slog != "default" else None, meter |
| 909 | + ) |
| 910 | + |
| 911 | + if args.power_stress: |
| 912 | + stress = PowerStress(interface) |
| 913 | + stress.run() |
| 914 | + closeNow = True # exit immediately after stress test |
| 915 | + else: |
| 916 | + meshtastic.util.our_exit("The powermon module could not be loaded. " |
| 917 | + "You may need to run `poetry install --with powermon`. " |
| 918 | + "Import Error was: " + powermon_exception) |
903 | 919 |
|
904 | | - if args.power_stress: |
905 | | - stress = PowerStress(interface) |
906 | | - stress.run() |
907 | | - closeNow = True # exit immediately after stress test |
908 | 920 |
|
909 | 921 | if args.listen: |
910 | 922 | closeNow = False |
@@ -1101,7 +1113,8 @@ def common(): |
1101 | 1113 | meshtastic.util.support_info() |
1102 | 1114 | meshtastic.util.our_exit("", 0) |
1103 | 1115 |
|
1104 | | - create_power_meter() |
| 1116 | + if have_powermon: |
| 1117 | + create_power_meter() |
1105 | 1118 |
|
1106 | 1119 | if args.ch_index is not None: |
1107 | 1120 | channelIndex = int(args.ch_index) |
|
0 commit comments