@serialpilot/driver-at
v0.1.0
Published
AT-command framework for serialpilot — cellular modems (SIMCom, Quectel, u-blox), LoRa modems, ESP-AT firmware, any AT-speaking device.
Maintainers
Readme
@serialpilot/driver-at
Generic AT-command framework for SerialPilot. Drives any device speaking the AT command protocol — cellular modems (SIMCom SIM800/SIM7600, Quectel BG95/EC25, u-blox SARA-R5), LoRa modems (RN2483, Murata), and WiFi-via-AT firmware (ESP-AT).
Provides a tiny sendCommand() core, multi-line response handling, automatic dispatch of unsolicited result codes (URCs), and 5 standard 3GPP helpers. Builds on @serialpilot/driver-kit's Device + LineBuffer primitives.
Install
npm install serialpilot @serialpilot/driver-atQuick start
import { SerialPilot } from 'serialpilot'
import { AtModem } from '@serialpilot/driver-at'
const port = new SerialPilot({ path: '/dev/ttyUSB0', baudRate: 115200 })
const modem = new AtModem({ transport: port, echo: false })
modem.on('urc', ({ line }) => console.log('URC:', line))
await modem.open()
console.log('Identity: ', await modem.getIdentity())
console.log('IMEI: ', await modem.getImei())
console.log('ICCID: ', await modem.getIccid())
console.log('Signal: ', await modem.getSignalStrength())
console.log('Registration:', await modem.getNetworkRegistration())
// Send any AT command directly:
const r = await modem.sendCommand('AT+CFUN?')
console.log(r.lines, r.finalResult)
await modem.close()API
class AtModem extends Device
| Method | AT verb | Returns |
| --- | --- | --- |
| sendCommand(cmd, opts?) | (verbatim) | Promise<AtResponse> |
| getIdentity() | ATI | Promise<string> |
| getImei() | AT+CGSN | Promise<string> |
| getIccid() | AT+CCID | Promise<string> |
| getSignalStrength() | AT+CSQ | Promise<SignalStrength> |
| getNetworkRegistration() | AT+CREG? | Promise<NetworkRegistration> |
Constructor options
new AtModem({
transport: Transport, // any @serialpilot/driver-kit-compatible transport
echo?: boolean, // true = strip echoed command lines (default false)
})Events
| Event | Payload | Notes |
| --- | --- | --- |
| 'urc' | {line: string} | One per inbound line received while no command is in flight |
| Inherited | 'open' \| 'close' \| 'state' \| 'error' \| 'data' | From Device |
Errors
sendCommand() and the helpers reject with a typed AtError (Error with .code):
| Code | Meaning |
| --- | --- |
| ERROR | Modem responded with ERROR |
| CME:<n> | Modem responded with +CME ERROR: <n> (extended equipment error) |
| CMS:<n> | Modem responded with +CMS ERROR: <n> (SMS error) |
| TIMEOUT | No final result within timeoutMs (default 1000) |
| CLOSED | Device was closed while the command was in flight |
| WRITE_FAILED | Transport write failed mid-command |
| PARSE_FAILED | Helper could not extract the expected value from the response (e.g. getImei() saw no IMEI line) |
Limitations (v0.1)
- No SMS, no PDP/PPP, no built-in GPS. Send the relevant AT commands via
sendCommand()for now; dedicated minors will add typed helpers. - URC heuristic. Lines while idle are URCs; lines while a command is in flight accumulate as the response. URCs interleaved mid-response will be misclassified — rare but possible. v0.2 will accept an optional URC-pattern list.
- Echo is caller-declared. Pass
echo: trueif your modem echoes commands; v0.1 doesn't auto-detect. - Vendor quirks. Custom URCs and vendor-specific commands (e.g.
AT+QCFG) are sent viasendCommand(); their responses come back asAtResponse.linesfor you to parse.
License
MIT
