#!/usr/bin/env python3 import serial import os import time CONF_PATH = '/run/modem' ser = serial.Serial('/dev/ttyACM0', 115200, timeout=0.5) while True: try: ser.read() break except Exception: pass os.makedirs(CONF_PATH, exist_ok=True) config_file = open(CONF_PATH + '/modem-at.config', 'w') def read_config(cmd, label=''): while True: try: ser.flushInput() ser.write(cmd) ser.write(b'\r') s = ser.read_until(b'OK') if(len(s.decode('utf-8')) < 4): # Avoid empty response just after reset continue break except Exception as e: print("Exception : " + str(e)) time.sleep(1) continue config_file.write(label + '\n') config_file.write(s.decode('utf-8').strip("OK")) read_config(b'AT+CGMI', 'Manufacturer identification'); read_config(b'AT+GMI', 'Manufacturer identification'); read_config(b'AT+CGMM', 'Model identification'); read_config(b'AT+GMM', 'Model identification'); read_config(b'AT+CGMR', 'Firmware version identification'); read_config(b'AT+GMR', 'Firmware version identification'); config_file.write('-' * 80 + '\n' * 2) read_config(b'AT+UCGDFLT?', 'Initial EPS bearer / PDP context'); read_config(b'AT+UBMCONF?', 'Boot mode configuration, 1 = router, 2 = bridge') read_config(b'AT+UUSBCONF?', 'USB profiles configuration')