sim900

package module
v0.0.0-...-e076539 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 25, 2021 License: MIT Imports: 7 Imported by: 0

README

SIM900 Go's package

This package uses a serialport to communicate with the SIM900 GSM Modem.

How to install

  • You'll need Golang v1.3+
  • SIM900 Package uses the serial package in order to communicate with the modem via AT commands, you will need to install both SIM900 and serial packages.
go get github.com/argandas/serial  # installs the serial package
go get github.com/argandas/sim900  # installs the SIM900 package

How to use

  • You'll need an available serial port, SIM900 boards usually works with 5V TTL signals so you can get a USB-to-Serial TTL converter, I recommend you to use the FTDI Cable for this, but you can use any USB-to-Serial adapters there are plenty of them.

  • Connect carefuly your serialport to your SIM900 board.

Example code

package main
import "github.com/argandas/sim900"

func main() {
	gsm := sim900.New()
	err := gsm.Connect("COM1", 9600)
	if err != nil {
		panic(err)
	}
	defer gsm.Disconnect()
	phoneNumber := "XXXXXXXXXX" // The number to send the SMS
	gsm.SendSMS(phoneNumber, "Hello World!")
}

Reference

  • List of available SIM900 commands can be found here.
  • For more information about available SIM900 methods please check godoc for this package.

Go explore!

License

SIM900 package is MIT-Licensed

Documentation

Index

Constants

View Source
const (
	CMD_AT             string = "AT"
	CMD_OK             string = "(^OK$)"
	CMD_ERROR          string = "(^ERROR$)"
	CMD_CMGF           string = "AT+CMGF?"
	CMD_CMGF_SET       string = "AT+CMGF=%s"
	CMD_CMGF_REGEXP    string = "(^[+]CMGF[:] [0-9]+$)"
	CMD_CMGF_RX        string = "+CMGF: "
	CMD_CTRL_Z         string = "\x1A"
	CMD_CMGS           string = "AT+CMGS=\"%s\""
	CMD_CMGS_RX_REGEXP string = "(^[+]CMGS[:] [0-9]+$)"
	CMD_CMGD           string = "AT+CMGD=%s"
	CMD_CMGR           string = "AT+CMGR=%s"
	CMD_CMGR_REGEXP    string = "(^[+]CMGR[:] .*)"
	CMD_CMGR_RX        string = "+CMGR: "
	CMD_CMTI_REGEXP    string = "(^[+]CMTI[:] \"SM\",[0-9]+$)"
	CMD_CMTI_RX        string = "+CMTI: \"SM\","
)

AT commands

View Source
const (
	PDU_MODE  string = "0"
	TEXT_MODE string = "1"
)

SMS Message Format

Variables

This section is empty.

Functions

This section is empty.

Types

type SIM900

type SIM900 struct {
	// contains filtered or unexported fields
}

A SIM900 is the representation of a SIM900 GSM modem with several utility features.

func New

func New() *SIM900

New creates and initializes a new SIM900 device.

func (*SIM900) CheckSMSTextMode

func (s *SIM900) CheckSMSTextMode(mode int) error

SetSMSMode selects SMS Message Format (0 = PDU mode, 1 = Text mode)

func (*SIM900) Connect

func (s *SIM900) Connect(port string, baud int) error

Connect creates a connection with the SIM900 modem via serial port and test communications.

func (*SIM900) DeleteSMS

func (s *SIM900) DeleteSMS(id string) error

ReadSMS deletes SMS from inbox memory by ID.

func (*SIM900) Disconnect

func (sim *SIM900) Disconnect() error

func (*SIM900) Ping

func (s *SIM900) Ping() error

Ping modem

func (*SIM900) ReadSMS

func (s *SIM900) ReadSMS(id string) (msg string, err error)

ReadSMS retrieves SMS text from inbox memory by ID.

func (*SIM900) SMSMode

func (s *SIM900) SMSMode() (mode string, err error)

SetSMSMode reads SMS Message Format (0 = PDU mode, 1 = Text mode)

func (*SIM900) SendSMS

func (s *SIM900) SendSMS(number, msg string) error

Send a SMS

func (*SIM900) SetSMSMode

func (s *SIM900) SetSMSMode(mode string) error

SetSMSMode selects SMS Message Format ("0" = PDU mode, "1" = Text mode)

func (*SIM900) WaitSMS

func (s *SIM900) WaitSMS(timeout time.Duration) (id string, err error)

WaitSMS will return when either a new SMS is recived or the timeout has expired. The returned value is the memory ID of the received SMS, use ReadSMS to read SMS content.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL