modem2
v1.0.0
Published
Send and receive messages and make ussd queries using your GSM modems
Readme
Modem.js, GSM Modems on Node
Modem.js allows you to use your GSM modems on node. It offers a very simple API. It supports:
- Sending SMS messages
- Receiving SMS messages
- Getting delivery reports
- Deleting messages from memory
- Getting notifications when memory is full
- Getting signal quality
- Making ussd sessions
- 16bit (ucsd messages)
- 7bit (ascii) messages
- Multipart messages
- Getting notifications when someone calls
Installation
npm install modemInstantiate
var modem = require('modem').Modem()Open modem
modem.open(device, callback)- device
StringPath to device, like/dev/ttyUSB0- callback
Functioncalled when modem is ready for further action
- callback
Send a message
modem.sms(message, callback)- message
Object- text
Stringmessage body. Longs messages will be splitted and sent in multiple parts transparently. - receiver
Stringreceiver number. - encoding
String. '16bit' or '7bit'. Use 7bit in case of English messages.
- text
callback Fucntion(err, references) is called when sending is done.
- references
Arraycontains reference ids for each part of sent message. (A message may take up to several parts)
Get delivery reports
modem.on('delivery', callback)callback
Functionis called with the following arguments:details
Objectdetailed status report- smsc
StringMsisdn of SMS Sender - reference
StringReference number of the delivered message - sender
Msisdn of receiver - status
Delivery status
- smsc
index
Stringindex of this delivery report in storage
Receive a message
modem.on('sms received', callback)- callback
Functionwill be called on each new message with following arguments: - message
Object- smsc
StringMSISDN of SMS Center - sender
StringMSISDN of sender - time
DateSend time - text
Stringmessage body
- smsc
Get stored messages
modem.getMessages(callback)- callback
Functionwill be called with a single argument messagesArray, which contains stores messages
Delete a message
modem.deleteMessage(message_index, callback)- message_index
Intis the message index to be deleted - callback
Functioncalled when message is deleted
Get notified when memory is full
modem.on('memory full', callback)- callback
Functionwill be called when modem has no more space for further messages
Get notified when someone calls
modem.on('ring', callback)- callback
Functionwill be called on each RING with a single argument - msisdn
Number
Running custom AT commands
Modem.js allows you to run AT commands in a queue and manage them without messing the modem. API is still quite simple.
Run a command
job = modem.execute(at_command, [callback], [priority], [timeout])- at_command
StringAT command you would like to execute - callback
Functioncalled when execution is done, in form of(escape_char, [response])- escape_char
Stringcould be 'OK', 'ERROR' or '>'. - response
Stringmodem's response
- escape_char
- prior
Booleanif set to true, command will be executed immediately - timeout
Integertimeout, in milliseconds, defaults to 60 seconds. - job
EventEmitterrepresents the added job.- it will emit
timeoutif executing job times out
- it will emit
USSD Sessions
Modem.js allows you to run ussd sessions.
Instantiate
var Session = require('modem').Ussd_SessionCreate a session
var Session = require('modem').Ussd_Session
var CheckBalance = function(c) {
var session = new Session;
session.callback = c;
session.parseResponse = function(response_code, message) {
this.close();
var match = message.match(/([0-9,\,]+)\sRial/);
if(!match) {
if(this.callback)
this.callback(false);
return ;
}
if(this.callback)
this.callback(match[1]);
session.modem.credit = match[1];
}
session.execute = function() {
this.query('*141*#', session.parseResponse);
}
return session;
}