3.4.0 • Published 4 years ago

@pake/serialport-gsm v3.4.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

Node SerialPort-GSM

NPM

Intro

SerialPort-GSM is a simplified plugin for communicating with gsm modems, primarily for sms. (This library is focused in 'PDU' mode)


Table of Contents


Installation Instructions

npm install serialport-gsm

Example

A full example can be found in the example directory.

Usage

Methods

List Available Ports

let serialportgsm = require('serialport-gsm')

serialportgsm.list((err, result) => {
    console.log(result)
})

Opening a Port

Call other functions after the port has been opened. open(path, options, callback) When opening a serial port, specify (in this order) 1. Path to Serial Port - required. 2. Options (see sample options on code).

SerialPort openOptions

NameTypeDefaultDescription
baudRatenumber9600The port's baudRate.
dataBitsnumber8Must be one of: 8, 7, 6, or 5.
stopBitsnumber1Must be one of: 1 or 2.
highWaterMarknumber16384The size of the read and write buffers defaults to 16k.
paritystring"noneMust be one of: 'none', 'even', 'mark', 'odd', 'space'.
rtsctsbooleanfalseflow control setting
xonbooleanfalseflow control setting
xoffbooleanfalseflow control setting
xanybooleanfalseflow control settings

SerialPort-GSM additional openOptions

NameTypeDefaultDescription
autoDeleteOnReceivebooleanfalseDelete from 'sim' after receiving.
enableConcatenationbooleanfalseReceive concatenated messages as one.
incomingCallIndicationbooleanfalseReceive 'onNewIncomingCall' event when receiving calls.
incomingSMSIndicationbooleantrueEnables the modem to notify that a new SMS message has been received.
deliveryReportbooleanfalseEnables SMS delivery report.
pinstringIf your SIM card is protected by a PIN provide the PIN as String and it will be used to unlock the SIM card during initialization (empty, means "no PIN existing on the SIM card").
customInitCommandstringIf your device needs a custom initialization command it can be provided and will be used after PIN check. The command is expected to return 'OK' (empty, means "no custom command for init").
loggerProvide a logger instance, currently 'debug' is used only to output written and received serial data. Use 'console' for debugging purposes.
let serialportgsm = require('serialport-gsm')
let modem = serialportgsm.Modem()
let options = {
    baudRate: 115200,
    dataBits: 8,
    stopBits: 1,
    parity: 'none',
    rtscts: false,
    xon: false,
    xoff: false,
    xany: false,
    autoDeleteOnReceive: true,
    enableConcatenation: true,
    incomingCallIndication: true,
    incomingSMSIndication: true,
    deliveryReport: true,
    pin: '',
    customInitCommand: '',
    logger: console
}

modem.open('COM', options, callback[Optional])

Initialize Modem

This function starts the modem. (If your port fails to work or does not respond to commands, don't forget to call initializeModem after opening the port.)

modem.on('open', data => {
    modem.initializeModem(callback[optional])
})

Close Modem

Closes an open connection close(callback[optional])

modem.close()

Set Modem Mode

setModemMode(callback, type)

  • type can be 'PDU' or 'SMS'
  • Note: This module is focused on PDU mode as it is more supported in most GSMs.
modem.on('open', data => {	
    modem.setModemMode(callback, 'PDU')	
})	

Check Modem Communication

Send simple command to check communication with device

modem.checkModem(callback)

Send Message

Sends sms. sendSMS(recipient, message, alert, callback)

NameTypeDefaultDescription
recipientstringThe recipient number should start with the location code or '+' then the location code (Ex. '63999XXXXX19', '+63999XXXXX19' ).
messagestringThe text message to send.
alertbooleanfalseEnable to send as class 0 message (flash message), or Disable to send as a normal sms.
callbackfunctionThe callback is called twice. First time when queued for sending and second time when message was really send out.
modem.sendSMS('63999XXXXX19', 'Hello there Zab!', true, callback)

Get Sim Inbox

Shows messages of sim inbox

modem.getSimInbox(callback)

Delete Sim Message

Delete a sim message by message object (Use Sim Inbox data)

modem.deleteMessage(messageObj, callback)

Delete All Sim Messages

modem.deleteAllSimMessages(callback)

Get Modem Serial

modem.getModemSerial(callback)

Get Network Signal

modem.getNetworkSignal(callback)

Get Own Number

modem.getOwnNumber(callback)

Set Own Number

setOwnNumber('number', callback, name[optional || default 'OwnNumber'])

modem.setOwnNumber(number, callback)

Hangup Call

modem.hangupCall(callback)

Execute AT Command

For executing a complex custom command with multi-line responses, you need your own parsing logic - see examples

modem.executeCommand(command, callback, priority, timeout)

Other Usage

Events

open

modem.on('open', result => { /*do something*/ })

close

modem.on('close', result => { /*do something*/ })

error

modem.on('error', result => { /*do something*/ })

onSendingMessage

modem.on('onSendingMessage', result => { status, request, data })

onNewMessage

modem.on('onNewMessage', messageDetails)

onNewMessage Indicator

modem.on('onNewMessageIndicator', result => { sender, timeSent })

onNewIncomingCall

modem.on('onNewIncomingCall', result => { number, numberScheme })

onMessageDelivered

modem.on('onMessageDelivered', result => { sender, timeDelivered, index, reference })

onMemoryFull

modem.on('onMemoryFull', result => { status, data })

Errors

When errors are returned and the error originated from the device, then in the error message, an error code should be listed, e.g. "+CMS ERROR: 500". An (incomplete) list of possible error codes and their meanings can be found e.g. at https://www.activexperts.com/sms-component/gsm-error-codes/

SerialPort

Access base serialport. Please refer to SerialPort Docs for documentation

let serialportgsm = require('serialport-gsm')
let serialport = serialportgsm.serialport

Access modem serialport.

modem.port.SERIAL_PORT_PROTOTYPES

Contributors

Thanks goes to these wonderful people who contributed a lot in this project:

Made with contributors-img.

License

SerialPort-GSM is MIT licensed and all it's dependencies are MIT or BSD licensed.