Awesome Open Source
Awesome Open Source

modem

A low level Go driver for AT modems.

Build Status Coverage Status Go Report Card License: MIT

modem is a Go library for interacting with AT based modems.

The initial impetus was to provide functionality to send and receive SMSs via a GSM modem, but the library may be generally useful for any device controlled by AT commands.

The at package provides a low level driver which sits between an io.ReadWriter, representing the physical modem, and a higher level driver or application.

The AT driver provides the ability to issue AT commands to the modem, and to receive the info and status returned by the modem, as synchronous function calls.

Handlers for asynchronous indications from the modem, such as received SMSs, can be registered with the driver.

The gsm package wraps the AT driver to add higher level functions to send and receive SMS messages, including long messages split into multiple parts, without any knowledge of the underlying AT commands.

The info package provides utility functions to manipulate the info returned in the responses from the modem.

The serial package provides a simple wrapper around a third party serial driver, so you don't have to find one yourself.

The trace package provides a driver, which may be inserted between the AT driver and the underlying modem, to log interactions with the modem for debugging purposes.

The cmd directory contains basic commands to exercise the library and a modem, including retrieving details from the modem, sending and receiving SMSs, and retrieving the SIM phonebook.

Features

Supports the following functionality:

  • Simple synchronous interface for AT commands
  • Serialises access to the modem from multiple goroutines
  • Asynchronous indication handling
  • Tracing of messages to and from the modem
  • Pluggable serial driver - any io.ReadWriter will suffice

Usage

The at package allows you to issue commands to the modem and receive the response. e.g.:

modem := at.New(ioWR)
info, err := modem.Command("I")

produces the following interaction with the modem (exact results will differ for your modem):

2018/05/17 20:39:56 w: ATI
2018/05/17 20:39:56 r:
Manufacturer: huawei
Model: E173
Revision: 21.017.09.00.314
IMEI: 1234567
+GCAP: +CGSM,+DS,+ES

OK

and returns this info:

info = []string{
    "Manufacturer: huawei",
    "Model: E173",
    "Revision: 21.017.09.00.314",
    "IMEI: 1234567",
    "+GCAP: +CGSM,+DS,+ES",
    }

Refer to the modeminfo for an example of how to create a modem object such as the one used in this example.

For more information, refer to package documentation, tests and example commands.

Package Documentation Tests Example code
at go.dev reference at_test modeminfo
gsm go.dev reference gsm_test sendsms, waitsms
info go.dev reference info_test phonebook
serial go.dev reference serial_test modeminfo, sendsms, waitsms
trace go.dev reference trace_test sendsms, waitsms

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Go (172,254
Golang (172,254
Driver (18,338
Serial (7,908
Sms (7,375
Golang Library (1,739
Modem (1,126
Gsm (958