# m2m-python Python library for controlling IoT modules (Quectel BG96, BG95, BC66, HiSilicon, etc.). ## Features - **Robust AT Command Parser**: Handles URCs, multi-line responses, and timeouts gracefully. - **Interactive Shell**: A powerful CLI for manual control, diagnostics, and testing. - **Multiple Connectivity Options**: Supports Serial ports (`/dev/ttyUSB0`), TCP sockets (`socket://`), and RFC2217. - **Vendor Agnostic Core**: Abstract base class with specialized implementations for Quectel and HiSilicon. - **Advanced Diagnostics**: Signal quality, cell info, SIM forensics, and network scanning. - **Network Services**: Integrated Ping, DNS, HTTP(S), and Socket (UDP/TCP) support. ## Installation ```bash pip install . ``` ## Quick Start: Interactive Shell The easiest way to get started is using the built-in interactive shell: ```bash # Connect to a physical serial port m2m-shell /dev/ttyUSB0 --type BG96 # Connect to a remote modem via TCP (e.g., using socat) m2m-shell socket://192.168.1.50:3000 --type BG95 ``` ### Available Commands - `info`: Display module IMEI, IMSI, Firmware, and configuration. - `status`: Check registration, signal quality, and current operator. - `nw_info`: Show detailed network and serving cell info. - `cells`: Show serving and neighbor cell information. - `forensics`: Run a deep SIM card analysis. - `scan`: Search for available network operators. - `connect [apn]`: Establish a PDP context. - `disconnect`: Deactivate PDP context. - `operator [act]`: Select operator manually. - `ping [num]`: Ping a remote host. - `dns `: Resolve a hostname. - `http_get `: Perform an HTTP GET request. - `udp_send `: Send a UDP packet. - `udp_listen `: Open a local UDP listener. - `tcp_client `: Connect to a TCP server. - `sockets`: List active sockets and their states. - `close `: Close a socket by ID. - `recv [len]`: Read data from a socket. - `sms_send `: Send an SMS message. - `sms_list [ALL|REC UNREAD]`: List SMS messages. - `radio `: Toggle module radio. - `reboot`: Reboot the module. - `mode `: Set connectivity preference. - `psm `: Control Power Saving Mode. - `edrx `: Configure eDRX settings. - `bands [gsm|catm|nb]`: Show or lock frequency bands. - `gpio set `: Control GPIO pins. - `at `: Send raw AT command to the module. - `clock [show|sync]`: Display or sync system clock via NTP. - `temp`: Read module internal temperature. - `ls [pattern]`: List files on the module filesystem. - `help`: Show all available commands with descriptions. ## Programmatic Usage ```python from m2m.nbiot import factory # Initialize module module = factory("BG95", "/dev/ttyUSB0") with module: # Check signal rssi, ber = module.get_signal_quality() print(f"Signal Strength: {rssi}") # Connect to network if module.connect_network("iot.telefonica.de"): print("Connected!") # Perform DNS lookup ips = module.dns_query("google.com") print(f"Google IP: {ips[0]}") ``` ## Development Install dev dependencies: ```bash pip install -e .[dev] ``` Run tests: ```bash pytest tests/ ```