|
| 1 | +""" |
| 2 | +Full Device and Network Monitoring Script for PicoLTE and PicoLTE 2 |
| 3 | +This script is designed for technical support teams to perform detailed, read-only monitoring of the device and network status. |
| 4 | +
|
| 5 | +Each section includes clear comments explaining: |
| 6 | +- What the code checks |
| 7 | +- Why the check is important |
| 8 | +- What the output can tell you when diagnosing issues |
| 9 | +""" |
| 10 | + |
| 11 | +from pico_lte.core import PicoLTE |
| 12 | +from pico_lte.common import debug |
| 13 | + |
| 14 | +# Initialize PicoLTE core; it internally initializes atcom, base, network, etc. |
| 15 | +pico_lte = PicoLTE() |
| 16 | + |
| 17 | +# Serial counter for numbering debug outputs |
| 18 | +SERIAL_COUNTER = 1 |
| 19 | + |
| 20 | +def numbered_debug(message): |
| 21 | + """Outputs a debug message with a serial number so logs are easier to follow.""" |
| 22 | + global SERIAL_COUNTER |
| 23 | + if message: |
| 24 | + debug.info(f"{SERIAL_COUNTER}. {message}") |
| 25 | + SERIAL_COUNTER += 1 |
| 26 | + |
| 27 | +def safe_check(label, func): |
| 28 | + """ |
| 29 | + Helper function to safely run checks with a label. |
| 30 | + Catches specific errors and outputs a clear debug message. |
| 31 | + """ |
| 32 | + try: |
| 33 | + result = func() |
| 34 | + numbered_debug(f"{label}: {result}") |
| 35 | + except (RuntimeError, ValueError) as e: |
| 36 | + numbered_debug(f"{label}: Error retrieving data — {str(e)}") |
| 37 | + |
| 38 | +# --------------- Device Information Check --------------- |
| 39 | +def get_device_information(): |
| 40 | + """Check device hardware presence and retrieve identifiers.""" |
| 41 | + debug.info("--- Device Information ---") |
| 42 | + safe_check("Device General Info", lambda: pico_lte.atcom.send_at_comm('ATI')) |
| 43 | + safe_check("IMEI (Unique Module ID)", lambda: pico_lte.atcom.send_at_comm('AT+GSN')) |
| 44 | + safe_check("Firmware Version", lambda: pico_lte.atcom.send_at_comm('AT+QGMR')) |
| 45 | + safe_check("Manufacturer Name", lambda: pico_lte.atcom.send_at_comm('AT+CGMI')) |
| 46 | + safe_check("Model Name", lambda: pico_lte.atcom.send_at_comm('AT+CGMM')) |
| 47 | + debug.info("\n\n") |
| 48 | + |
| 49 | +# --------------- SIM Card Status Check --------------- |
| 50 | +def check_sim_information(): |
| 51 | + """Check SIM card presence, ICCID, and readiness.""" |
| 52 | + debug.info("--- SIM Card Information ---") |
| 53 | + safe_check("SIM ICCID (Card Serial Number)", lambda: pico_lte.base.get_sim_iccid()) |
| 54 | + safe_check("SIM Ready Status", lambda: pico_lte.base.check_sim_ready()) |
| 55 | + debug.info("\n\n") |
| 56 | + |
| 57 | +# --------------- Network Configuration Check --------------- |
| 58 | +def check_network_type(): |
| 59 | + """Retrieve network scan modes and IoT optimization settings.""" |
| 60 | + debug.info("--- Network Type Information ---") |
| 61 | + safe_check("Network Scan Mode", lambda: pico_lte.atcom.send_at_comm('AT+QCFG=\"nwscanmode\"')) |
| 62 | + safe_check("IoT Optimization Mode", lambda: pico_lte.atcom.send_at_comm('AT+QCFG=\"iotopmode\"')) |
| 63 | + safe_check("Current Network Technology", lambda: pico_lte.network.get_access_technology()) |
| 64 | + debug.info("\n\n") |
| 65 | + |
| 66 | +# --------------- Signal Quality Check --------------- |
| 67 | +def check_signal_quality(): |
| 68 | + """Retrieve basic signal strength and quality information.""" |
| 69 | + debug.info("--- Signal Quality ---") |
| 70 | + safe_check("Signal Quality (CSQ - RSSI/BER)", lambda: pico_lte.atcom.send_at_comm('AT+CSQ')) |
| 71 | + debug.info("\n\n") |
| 72 | + |
| 73 | +# --------------- Network Status Check --------------- |
| 74 | +def check_network_status(): |
| 75 | + """Retrieve operator, registration, cell, and connection status.""" |
| 76 | + debug.info("--- Network Status ---") |
| 77 | + safe_check("Operator Info + Access Tech", lambda: pico_lte.atcom.send_at_comm('AT+COPS?')) |
| 78 | + safe_check("LTE Network Registration (CEREG)", lambda: pico_lte.atcom.send_at_comm('AT+CEREG?')) |
| 79 | + safe_check("Serving Cell Info", lambda: pico_lte.atcom.send_at_comm('AT+QNWINFO')) |
| 80 | + safe_check("Extended Signal Quality (QCSQ - RSRP/RSRQ/SINR)", lambda: pico_lte.atcom.send_at_comm('AT+QCSQ')) |
| 81 | + safe_check("Signaling Connection Status (QCSCON)", lambda: pico_lte.atcom.send_at_comm('AT+QCSCON?')) |
| 82 | + debug.info("\n\n") |
| 83 | + |
| 84 | +# --------------- Packet Service and APN Check --------------- |
| 85 | +def check_packet_service_status(): |
| 86 | + """Check APN, IP assignment, and data attach status.""" |
| 87 | + debug.info("--- Packet Service and APN Info ---") |
| 88 | + safe_check("PDP Context (APN Settings)", lambda: pico_lte.atcom.send_at_comm('AT+CGDCONT?')) |
| 89 | + safe_check("IP Address Info", lambda: pico_lte.atcom.send_at_comm('AT+CGPADDR')) |
| 90 | + safe_check("Packet Attach Status (CGATT)", lambda: pico_lte.atcom.send_at_comm('AT+CGATT?')) |
| 91 | + debug.info("\n\n") |
| 92 | + |
| 93 | +# ------------------------- QPING Connectivity Check ------------------------- |
| 94 | +def check_qping(): |
| 95 | + """Perform a ping test to check internet connectivity.""" |
| 96 | + debug.info("--- QPING Command ---") |
| 97 | + safe_check("QPING (Single Ping Test)", lambda: pico_lte.atcom.send_at_comm('AT+QPING=1,\"www.google.com\"')) |
| 98 | + debug.info("\n\n") |
| 99 | + |
| 100 | +# --------------- Main Monitoring Function --------------- |
| 101 | +def main(): |
| 102 | + """Run all diagnostic checks sequentially.""" |
| 103 | + global SERIAL_COUNTER |
| 104 | + SERIAL_COUNTER = 1 |
| 105 | + debug.info("========== PicoLTE Device and Network Status Check Start ==========\n\n") |
| 106 | + |
| 107 | + get_device_information() |
| 108 | + check_sim_information() |
| 109 | + check_network_type() |
| 110 | + check_signal_quality() |
| 111 | + check_network_status() |
| 112 | + check_packet_service_status() |
| 113 | + check_qping() |
| 114 | + |
| 115 | + debug.info("========== PicoLTE Device and Network Status Check Complete ==========") |
| 116 | + |
| 117 | +if __name__ == "__main__": |
| 118 | + main() |
0 commit comments