$npx -y skills add easyzoom/aix-skills --skill cellular-at-modem-integrationUse when integrating or debugging cellular AT modems (Quectel, SIMCom, u-blox) over UART for CREG/CEREG registration, CGDCONT APN/PDP, TCP/UDP sockets, or URC parsing
| 1 | # Cellular AT Modem Integration |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | Use this skill to drive a 2G/4G/NB-IoT/LTE-M cellular modem from an MCU over UART with the AT command set. The hard parts are parsing unsolicited result codes (URCs) that interleave with command responses on one serial line, choosing the right registration command per radio access technology, using the correct socket command set for the specific module family, and getting PWRKEY boot timing right before any AT works. |
| 6 | |
| 7 | ## When To Use |
| 8 | |
| 9 | Use this skill when: |
| 10 | |
| 11 | - The user integrates Quectel (`EC25`, `BG96`, `BC66`), SIMCom (`SIM7600`, `SIM800C`, `A7670`), or u-blox (`SARA-R4`, `SARA-R5`) over UART. |
| 12 | - The issue involves registration (`AT+CPIN?`, `AT+CSQ`, `AT+CREG?`, `AT+CGREG?`, `AT+CEREG?`), APN/PDP (`AT+CGDCONT`, `AT+CGATT`, `AT+CGACT`), or sockets (`AT+QIOPEN`, `AT+QISEND`, `AT+CIPSTART`/`AT+CIPOPEN`, `AT+USOCO`). |
| 13 | - URCs such as `RING`, `+CMTI`, or `+QIURC` corrupt command parsing, or power saving (`AT+CPSMS`, `AT+CEDRXS`) breaks reachability. |
| 14 | |
| 15 | Do not use this skill when the UART link itself is unproven; confirm the modem echoes `AT` with `OK` at the configured baud first. |
| 16 | |
| 17 | ## First Questions |
| 18 | |
| 19 | Ask for: |
| 20 | |
| 21 | - Exact module and firmware revision (`ATI`, `AT+CGMR`), and radio technology: 2G, LTE Cat-1, Cat-4, Cat-M1, or NB-IoT. |
| 22 | - UART wiring: baud, flow control (RTS/CTS), and whether `PWRKEY`/reset lines are MCU-controlled. |
| 23 | - SIM type and the operator APN (some IoT SIMs need username/password or a specific `<PDP_type>`). |
| 24 | - Transport goal: raw TCP/UDP, or bridging to MQTT/TLS on top of the socket AT layer. |
| 25 | - Current failing command and its literal response or error code. |
| 26 | |
| 27 | ## Integration Checklist |
| 28 | |
| 29 | 1. Bring up the modem. |
| 30 | Assert `PWRKEY` for the module's specified pulse width, wait for boot (often signalled by an `RDY` URC), then confirm `AT` returns `OK` and disable echo with `ATE0`. |
| 31 | |
| 32 | 1. Unlock and check signal. |
| 33 | `AT+CPIN?` must return `+CPIN: READY`; `AT+CSQ` RSSI must be non-`99` (0-31 valid). Set `AT+CFUN=1` if radio is off. |
| 34 | |
| 35 | 1. Confirm registration on the right command. |
| 36 | Use `AT+CREG?` for 2G/CS registration, `AT+CGREG?` for GPRS/PS, and `AT+CEREG?` for LTE/Cat-M1/NB-IoT (EPS). `<stat>` must be `1` (home) or `5` (roaming). |
| 37 | |
| 38 | 1. Define and activate the PDP context. |
| 39 | `AT+CGDCONT=1,"IP","<apn>"`, then `AT+CGATT=1` to attach and `AT+CGACT=1,1` to activate. Verify an assigned IP with `AT+CGPADDR`. |
| 40 | |
| 41 | 1. Open the socket with the correct vendor stack for the module family. |
| 42 | - Quectel (`EC25`/`BG96`/`BC66`): `AT+QIOPEN`, then `AT+QISEND`/`AT+QIRD`/`AT+QICLOSE`. |
| 43 | - SIMCom 2G (`SIM800`-class): `AT+CIPSTART`, then `AT+CIPSEND` (write payload after `>`, terminate with `Ctrl+Z` `0x1A`). |
| 44 | - SIMCom LTE (`SIM7600`/`A76XX`-class): `AT+NETOPEN` first, then `AT+CIPOPEN` to open a socket and `AT+CIPSEND` to send (`AT+CIPSEND=<link>,<len>` takes an explicit length; no `Ctrl+Z` when a length is given). Read buffered data with `AT+CIPRXGET`; close with `AT+CIPCLOSE`/`AT+NETCLOSE`. |
| 45 | - u-blox (`SARA`): `AT+USOCR` to create, `AT+USOCO` to connect, `AT+USOWR` to write, `AT+USORD` to read, `AT+USOCL` to close. |
| 46 | |
| 47 | 1. Build a URC-aware parser. |
| 48 | Run a line-based state machine that classifies each line as echo, intermediate (`>`), final (`OK`/`ERROR`/`+CME ERROR`), or URC (`RING`, `+CMTI:`, `+QIURC:`), and route URCs to callbacks instead of the command waiter. |
| 49 | |
| 50 | ## Common Failures |
| 51 | |
| 52 | - Sending AT before boot completes; commands are dropped until the `RDY` URC or a fixed power-on delay elapses. |
| 53 | - Checking `AT+CREG?` on an LTE-only module that only registers via `+CEREG`, so registration looks stuck at `0,2`. |
| 54 | - Registration fails from wrong APN, disabled radio (`AT+CFUN=0`), locked SIM, or poor signal (`+CSQ: 99,99`). |
| 55 | - Using the wrong socket stack: sending `AT+CIPSTART` to a `SIM7600`/`A76XX` module (which needs `AT+NETOPEN`+`AT+CIPOPEN`), or forgetting `AT+NETOPEN` before `AT+CIPOPEN`. |
| 56 | - Fixed read timeout truncates variable-length responses like `AT+QIRD` or a slow `AT+COPS=?` scan. |
| 57 | - URC (e.g. `+QIURC: "recv"`) arrives mid-response and the parser mistakes it for the command reply, causing a parse race. |
| 58 | - `AT+CIPSEND` on a `SIM800`-class module sent without the `Ctrl+Z` terminator, so the modem waits forever at the `>` prompt. |
| 59 | - After `AT+CPSMS`/`AT+CEDRXS` the module sleeps and drops the socket; sending during PSM fails until wake and re-attach. |
| 60 | |
| 61 | ## Verification |
| 62 | |
| 63 | Before claiming the link works: |
| 64 | |
| 65 | - State the module, technology, APN, and which registration command applies. |
| 66 | - Confirm `+CPIN: READY`, a valid `+CSQ`, and `<stat>=1` or `5` on the correct `CxREG`. |
| 67 | - Confirm `AT+CGPADDR` shows an IP before opening any socket. |
| 68 | - Send a round-trip TCP payload and confirm the receive path for the module family (`+QIURC: "recv"`/`AT+QIRD`, or `+CIPRXGET`, or `+USORD`). |
| 69 | - Prove th |