0.5.0 • Published 2 years ago

sim800l-node v0.5.0

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

Sim800L-node

SIM800L-node is a modern TypeScript package providing an asynchronous serial interface for SIM800L type GSM modems.

It features a SIM800L Class shielding the user from tedious AT commands configuration and management and implementing a basic FI/FO job queue; it also exposes an interface to plug your own logger in.

An object oriented SMS class provides an abstraction layer for the messaging related logic, eg : multipart formatting, PDU encoding / parsing, and Delivery reports handling.

Due to the asynchronous and unpredictable nature of UART + GSM communication, the package also make a good use of Events.

Due to recent late-night changes, the documentation needs some update, there is a brand new SMS Spooler and a kick-ass detection of rogue delivery-reports

Table of contents

Roadmap

This project is under active development, and new features will be added on the fly.

What's working atm

  • Core initialization from cold boot to ready-state
  • AT commands queuing and execution
  • Network state monitoring and anti-brownout watchdog
  • SMS jobs creation and execution
  • Delivery reports

What's next

  • An extensive documentation
  • SMS object configuration
  • Network methods (Network selection, listing, configuration...)
  • SMS Inbox

Hardware

TBD

Installation

TBD

Usage

TBD

API

Summary

Exported Functions

Classes

Details

new Sim800L(options, simConfig) Returns an object abstracting a SIM800L family serial modem.

ParamTypeDescription
optionsSerialPortOpenOptionsThe options you provide to the "serialport" dependency
simConfigSimConfigThe additional

sim800L.createSms(receipient, text, options) ⇒ Sms A function creating an Sms attached to this particular Sim800L instance

Kind: instance method of Sim800L
Returns: Sms - An instance of the Sms class

ParamTypeDefaultDescription
receipientstringThe number you want to send your sms to (international format by default)
textstringThe content of your SMS (UTF-8 recommended)
optionsSmsCreationOptions{}You can specify various parameters like a special smsc or delivery reports activation.

sim800L.initialize(callback, params) ⇒ Promise.<ModemResponse> | void Initialization routine for the modem. Can be called after cold-boot. The function checks if the modem is online, enables verbose mode, checks if pin is required, unlock the sim and updates the config of the modem

Kind: instance method of Sim800L
Returns: Promise.<ModemResponse> | void - A Promise resolving the ModemResponse. If a callback is provided, the function will use the callback instead and return void

ParamTypeDescription
callbackModemCallback | nulloptional callback to handle ModemResponse the way you entend to. Must be set to null if not provided for type consistency
paramsObjectempty object provided for type consistency

sim800L.checkModem(callback, params) ⇒ Promise.<ModemResponse.<CheckModemResponse>> | void checkModem can be used to make sure the modem is in a ready state to accept AT commands

Kind: instance method of Sim800L
Returns: Promise.<ModemResponse.<CheckModemResponse>> | void - A Promise resolving the ModemResponse. If a callback is provided, the function will use the callback instead and return void

ParamTypeDescription
callbackModemCallback | nulloptional callback to handle ModemResponse the way you entend to. Must be set to null if not provided for type consistency
paramsObjectempty object provided for type consistency

sim800L.checkPinRequired(callback, params) ⇒ Promise.<ModemResponse> | void A function used to determine the SIM current state

Kind: instance method of Sim800L
Returns: Promise.<ModemResponse> | void - A Promise resolving the ModemResponse, containing the current SimStatus. If a callback is provided, the function will use the callback instead and return void

ParamTypeDescription
callbackModemCallback | nulloptional callback to handle ModemResponse the way you entend to. Must be set to null if not provided for type consistency
paramsObjectempty object provided for type consistency

sim800L.unlockSim(callback, params) ⇒ Promise.<ModemResponse> | void unlockSim does exactly what you think it does

Kind: instance method of Sim800L
Returns: Promise.<ModemResponse> | void - A Promise resolving the ModemResponse, containing the result. If a callback is provided, the function will use the callback instead and return void

ParamTypeDescription
callbackModemCallback | nulloptional callback to handle ModemResponse the way you entend to. Must be set to null if not provided for type consistency
paramsObjectan object containing a pin property used to unlock the sim. the pin must be passed as a string

sim800L.updateCnmiConfig(callback, params) ⇒ Promise.<ModemResponse> | void You can call updateCnmiConfig with a custom parameter to change the SMS message indications configuration

Kind: instance method of Sim800L
Returns: Promise.<ModemResponse> | void - A Promise resolving the ModemResponse, containing the result. If a callback is provided, the function will use the callback instead and return void

ParamTypeDescription
callbackModemCallback | nulloptional callback to handle ModemResponse the way you entend to. Must be set to null if not provided for type consistency
paramsObjectan object containing the cnmi string

sim800L.resetModem(callback, params) ⇒ Promise.<ModemResponse> | void resetModem is a function that can save you from a dead-end situation, call it to soft-reset the modem, with the mode configuration you want to reset in (optional) another parameter can be pass to automatically reinitialize the modem afterwards

Kind: instance method of Sim800L
Returns: Promise.<ModemResponse> | void - A Promise resolving the ModemResponse, containing the current SimStatus. If a callback is provided, the function will use the callback instead and return void

ParamTypeDescription
callbackModemCallback | nulloptional callback to handle ModemResponse the way you entend to. Must be set to null if not provided for type consistency
paramsObjectempty object provided for type consistency

sim800L.checkNetwork(callback, params) ⇒ Promise.<ModemResponse> | void A function that returns the current state of network connection WIP : update to return the carrier name and force connect to it if idling

Kind: instance method of Sim800L
Returns: Promise.<ModemResponse> | void - A Promise resolving the ModemResponse, containing the current network status. If a callback is provided, the function will use the callback instead and return void

ParamTypeDescription
callbackModemCallback | nulloptional callback to handle ModemResponse the way you entend to. Must be set to null if not provided for type consistency
paramsObjectan object containing the -for now- unused force parameter

sim800L.activateCReg() ⇒ void WIP

Kind: instance method of Sim800L
Returns: void - WIP

sim800L.execCommand(callback, params) ⇒ Promise.<ModemResponse> | void execCommand is the core function of the SIM800L class, it handles the AT commands, create and queue the jobs.

Each job is associated with a handler that will hold the job place in the queue until the incoming data appears satisfactory, errors, or tiemout. By default, the handler will only search for OK, ERROR, or > results, you can provide a better handling of specific commands, just remember to call job.ended = true when you want to stop hanging the queue for incoming data

Kind: instance method of Sim800L
Returns: Promise.<ModemResponse> | void - A Promise resolving the ModemResponse, containing the Response. If a callback is provided, the function will use the callback instead and return void

ParamTypeDescription
callbackModemCallback | nulloptional callback to handle ModemResponse the way you entend to. Must be set to null if not provided for type consistency
paramsCommandParamsan object containing all the parameters for creating the job and handling the response, some are required (command, type).

sim800L.setSmsMode(callback, params) ⇒ Promise.<ModemResponse> | void Sets the SMS mode (pass 0 for PDU or 1 to text mode). Please note that the Sms class currently does not support text mode, use at your own discretion

Kind: instance method of Sim800L
Returns: Promise.<ModemResponse> | void - A Promise resolving the ModemResponse, containing the result. If a callback is provided, the function will use the callback instead and return void

ParamTypeDescription
callbackModemCallback | nulloptional callback to handle ModemResponse the way you entend to. Must be set to null if not provided for type consistency
paramsObjectan object containing mode parameter

sim800L.close() ⇒ void Closes the current serialport communication tunnel

Kind: instance method of Sim800L
Returns: void

Sim800L.list() ⇒ Array.<PortInfo> Returns a list of available serial ports, is available statically for config purposes

Kind: static method of Sim800L
Returns: Array.<PortInfo> - An array of serial ports available

parseBuffer(buffer) ⇒ Array.<string> Parses the raw buffer input and returns a filtered array

Kind: global function
Returns: Array.<string> - A filtered array of strings representing the individual buffer lines

ParamTypeDescription
bufferstringthe raw buffer input

isOk(buffer) ⇒ boolean Parsing the buffer to tell if the command has been properly executed

Kind: global function
Returns: boolean - A boolean describing if the command has been properly executed

ParamTypeDescription
bufferstringthe raw buffer input

isWaitingForInput(parsedData) ⇒ boolean Catches the ">" character indicating that the modem waits for an input

Kind: global function
Returns: boolean - A boolean describing if the modem is waiting for an input

ParamTypeDescription
parsedDataParsedDatathe parsed buffer input

getError(buffer) ⇒ ModemErrorRaw

Intercepts the known error reporting patterns of the SIM800L, it also tries to get a formatted message describing the error

Kind: global function
Returns: ModemErrorRaw - The response object containing an isError boolean and the result

ParamTypeDescription
bufferstringthe raw buffer input

new Sms(receipient, text, options, modem) Creates an instance of the Sms class. the Sms is an object abstracting the logic required to handle and send SMS in PDU mode As it's designed to work with a Sim800L modem, an instance of Sim800L must be provided, you can also use the createSms() method from the Sim800L instance directly

ParamTypeDefaultDescription
receipientstringThe receipient number (international format preffered)
textstringThe content of the message
optionsSmsCreationOptions{}an object containing various options like delivery report activation, custom smsc, number format...
modemSim800Lan instance of Sim800L which will send the Sms

sms.id : string

the UUID of the Sms

Kind: instance property of Sms
Read only: true

sms.text : string

the raw text of the SMS, this can be changed as long as the SMS is not in an active or sent state

Kind: instance property of Sms

sms.status : SmsStatus

An aggregated SmsStatus mimicking a single part Status even for multipart Smses

Kind: instance property of Sms
Read only: true

sms.send()

Sending the Sms (each part if multipart). uses an handler that updates the sms status property.

If using the deliveryReport property, the Sms will also listen and handle deliveryreport Events emitted by the Modem

Kind: instance method of Sms

Events

TBD

More advanced concepts

TBD

Contribution

Feel free to contribute to the project by suggesting or developing new features. Please observe these very few rules :

  • Fork the project
  • Create and publish a branch named wip/yourfeature
  • Create a pull request on master
  • Enjoy !
0.5.0

2 years ago

0.4.7

2 years ago

0.4.6

2 years ago

0.4.5

2 years ago

0.4.4

2 years ago

0.4.3

2 years ago

0.4.2

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago

0.3.5

2 years ago

0.3.4

2 years ago

0.3.3

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.3.0

2 years ago

0.1.0

2 years ago