From dd587d830a86cf029eb2f4901c6f14fabf3f92cf Mon Sep 17 00:00:00 2001 From: Pavel Valach Date: Tue, 2 Feb 2021 11:54:51 +0100 Subject: [PATCH] check_modem: check if registered and/or connected, and if there is signal --- check_modem.py | 47 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) mode change 100644 => 100755 check_modem.py diff --git a/check_modem.py b/check_modem.py old mode 100644 new mode 100755 index 4c1f028..2961eff --- a/check_modem.py +++ b/check_modem.py @@ -8,6 +8,40 @@ from pydbus import SystemBus from gi.repository import GLib import sms_functions + +# /** +# * MMModemState: +# * @MM_MODEM_STATE_FAILED: The modem is unusable. +# * @MM_MODEM_STATE_UNKNOWN: State unknown or not reportable. +# * @MM_MODEM_STATE_INITIALIZING: The modem is currently being initialized. +# * @MM_MODEM_STATE_LOCKED: The modem needs to be unlocked. +# * @MM_MODEM_STATE_DISABLED: The modem is not enabled and is powered down. +# * @MM_MODEM_STATE_DISABLING: The modem is currently transitioning to the @MM_MODEM_STATE_DISABLED state. +# * @MM_MODEM_STATE_ENABLING: The modem is currently transitioning to the @MM_MODEM_STATE_ENABLED state. +# * @MM_MODEM_STATE_ENABLED: The modem is enabled and powered on but not registered with a network provider and not available for data connections. +# * @MM_MODEM_STATE_SEARCHING: The modem is searching for a network provider to register with. +# * @MM_MODEM_STATE_REGISTERED: The modem is registered with a network provider, and data connections and messaging may be available for use. +# * @MM_MODEM_STATE_DISCONNECTING: The modem is disconnecting and deactivating the last active packet data bearer. This state will not be entered if more than one packet data bearer is active and one of the active bearers is deactivated. +# * @MM_MODEM_STATE_CONNECTING: The modem is activating and connecting the first packet data bearer. Subsequent bearer activations when another bearer is already active do not cause this state to be entered. +# * @MM_MODEM_STATE_CONNECTED: One or more packet data bearers is active and connected. +# * +# * Enumeration of possible modem states. +# */ +# mm_modem_state +MM_MODEM_STATE_FAILED = -1 +MM_MODEM_STATE_UNKNOWN = 0 +MM_MODEM_STATE_INITIALIZING = 1 +MM_MODEM_STATE_LOCKED = 2 +MM_MODEM_STATE_DISABLED = 3 +MM_MODEM_STATE_DISABLING = 4 +MM_MODEM_STATE_ENABLING = 5 +MM_MODEM_STATE_ENABLED = 6 +MM_MODEM_STATE_SEARCHING = 7 +MM_MODEM_STATE_REGISTERED = 8 +MM_MODEM_STATE_DISCONNECTING = 9 +MM_MODEM_STATE_CONNECTING = 10 +MM_MODEM_STATE_CONNECTED = 11 + # Setup logging logfile = "/opt/sms/sms.log" FORMAT = '%(asctime)-15s %(message)s' @@ -16,6 +50,13 @@ logger = logging.getLogger('check_modem') if __name__ == "__main__": modem = sms_functions.unlock_and_enable_modem() - while not modem.GetStatus().get('signal-quality', None) or not modem.GetStatus()['signal-quality'][1]: - modem = sms_functions.get_modem() - time.sleep(2) + time.sleep(2) + modem = sms_functions.get_modem() + status = modem.GetStatus() + print(status) + + # return code: if registered and signal > 0, return 0 + if modem.State in [ MM_MODEM_STATE_REGISTERED, MM_MODEM_STATE_CONNECTED ] and modem.SignalQuality[0] > 0 and modem.RegistrationState == 1: + exit(0) + else: + exit(1)