check_modem: check if registered and/or connected, and if there is signal

This commit is contained in:
Pavel Valach 2021-02-02 11:54:51 +01:00
parent b532bd621d
commit dd587d830a
No known key found for this signature in database
GPG Key ID: 5B4C9E8526682172

47
check_modem.py Normal file → Executable file
View File

@ -8,6 +8,40 @@ from pydbus import SystemBus
from gi.repository import GLib from gi.repository import GLib
import sms_functions 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 # Setup logging
logfile = "/opt/sms/sms.log" logfile = "/opt/sms/sms.log"
FORMAT = '%(asctime)-15s %(message)s' FORMAT = '%(asctime)-15s %(message)s'
@ -16,6 +50,13 @@ logger = logging.getLogger('check_modem')
if __name__ == "__main__": if __name__ == "__main__":
modem = sms_functions.unlock_and_enable_modem() modem = sms_functions.unlock_and_enable_modem()
while not modem.GetStatus().get('signal-quality', None) or not modem.GetStatus()['signal-quality'][1]: time.sleep(2)
modem = sms_functions.get_modem() modem = sms_functions.get_modem()
time.sleep(2) 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)