From df45012acbfff51d14a090102aeacc30a50719ea Mon Sep 17 00:00:00 2001 From: J Date: Tue, 12 Jan 2021 15:21:11 -0600 Subject: [PATCH 1/4] add accumulated energy monitor feature (AT+GEMON) --- adafruit_rockblock.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/adafruit_rockblock.py b/adafruit_rockblock.py index 018aeda..403a58f 100644 --- a/adafruit_rockblock.py +++ b/adafruit_rockblock.py @@ -420,3 +420,43 @@ def system_time(self): time_now_unix = iridium_epoch_unix + int(secs_since_epoch) return time.localtime(time_now_unix) return None + + @property + def energy_monitor(self): + """Report the current accumulated energy usage estimate in microamp hours. + + Returns an estimate of the charge taken from the +5V supply to the modem, + in microamp hours (uAh). This is represented internally as a 26-bit unsigned number, + so in principle will rollover to zero after approx. 67Ah (in practice this is usually + greater than battery life, if battery-powered). + + The accumulator value is set to zero on a power-cycle or on a watchdog reset. + Note that while +5V power is supplied to the Data Module but the module is powered off + by its ON/OFF control line, it will still be consuming up to a few tens of microamps, + and this current drain will not be estimated in the +GEMON report. + + The setter will preset the energy monitor accumulator to value n (typically, would + be specified as 0, to clear the accumulator). + + Note: Call Processor Version: TA12003 is known to not support the AT+GEMON energy + monitor command. It is however known to work on TA19002 (newer) and TA12003 (older). + You may use the revision function to determine which version you have. Function will + return None if modem cannot retrieve the accumuulated energy usage estimate. + + Returns + int + """ + + resp = self._uart_xfer("+GEMON") + if resp[-1].strip().decode() == "OK": + return int(resp[1].strip().decode().split(":")[1]) + return None + + @energy_monitor.setter + def energy_monitor(self, value): + if 0 <= value <= 67108863: # 0 to 2^26 - 1 + resp = self._uart_xfer("+GEMON=" + str(value)) + if resp[-1].strip().decode() == "OK": + return True + raise RuntimeError("Error setting energy monitor accumulator.") + raise ValueError("Value must be between 0 and 67108863 (2^26 - 1).") From 09e67f55c782b388d7b328c7d8c225209f03d2ab Mon Sep 17 00:00:00 2001 From: J Date: Tue, 12 Jan 2021 15:37:47 -0600 Subject: [PATCH 2/4] correct spelling error in documentation --- adafruit_rockblock.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_rockblock.py b/adafruit_rockblock.py index 403a58f..83e0f65 100644 --- a/adafruit_rockblock.py +++ b/adafruit_rockblock.py @@ -441,7 +441,7 @@ def energy_monitor(self): Note: Call Processor Version: TA12003 is known to not support the AT+GEMON energy monitor command. It is however known to work on TA19002 (newer) and TA12003 (older). You may use the revision function to determine which version you have. Function will - return None if modem cannot retrieve the accumuulated energy usage estimate. + return None if modem cannot retrieve the accumulated energy usage estimate. Returns int From 60bc085cb5cfc4b38901393636a8d7886b47c55b Mon Sep 17 00:00:00 2001 From: J Date: Tue, 12 Jan 2021 18:33:14 -0600 Subject: [PATCH 3/4] update documentation comment with correct version of modem that does not respond to +GEMON, TA16005 --- adafruit_rockblock.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_rockblock.py b/adafruit_rockblock.py index 83e0f65..7d16bb4 100644 --- a/adafruit_rockblock.py +++ b/adafruit_rockblock.py @@ -438,7 +438,7 @@ def energy_monitor(self): The setter will preset the energy monitor accumulator to value n (typically, would be specified as 0, to clear the accumulator). - Note: Call Processor Version: TA12003 is known to not support the AT+GEMON energy + Note: Call Processor/BOOT Version: TA16005 is known to not support the AT+GEMON energy monitor command. It is however known to work on TA19002 (newer) and TA12003 (older). You may use the revision function to determine which version you have. Function will return None if modem cannot retrieve the accumulated energy usage estimate. From cfe2818bc73decbc665113f5d121f74a12667fdd Mon Sep 17 00:00:00 2001 From: J Date: Mon, 18 Jan 2021 19:21:16 -0600 Subject: [PATCH 4/4] update doc string per review --- adafruit_rockblock.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_rockblock.py b/adafruit_rockblock.py index 7d16bb4..57b98e6 100644 --- a/adafruit_rockblock.py +++ b/adafruit_rockblock.py @@ -423,7 +423,7 @@ def system_time(self): @property def energy_monitor(self): - """Report the current accumulated energy usage estimate in microamp hours. + """The current accumulated energy usage estimate in microamp hours. Returns an estimate of the charge taken from the +5V supply to the modem, in microamp hours (uAh). This is represented internally as a 26-bit unsigned number,