mbim-sms-sender/check_modem.py
2021-02-02 11:58:22 +01:00

63 lines
2.7 KiB
Python
Executable File

#!/usr/bin/python3
import logging
import os
import sys
import time
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'
logging.basicConfig(format=FORMAT,filename=logfile,level=10)
logger = logging.getLogger('check_modem')
if __name__ == "__main__":
modem = sms_functions.unlock_and_enable_modem()
time.sleep(2)
modem = sms_functions.get_modem()
status = modem.GetStatus()
print(status)
# return code: if registered and signal > 0, return 0
if modem.GetStatus()["state"] in [ MM_MODEM_STATE_REGISTERED, MM_MODEM_STATE_CONNECTED ] and modem.SignalQuality[0] > 0 and modem.RegistrationState == 1:
exit(0)
else:
exit(1)