Send and receive messages and make ussd queries using your GSM modems
npm install modemModem.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 modem
Instantiate
-----------
``
var modem = require('modem').Modem()
Open modem
----------
``
modem.open(device, callback)
* device String Path to device, like /dev/ttyUSB0Function
* callback called when modem is ready for further action
Send a message
--------------
``
modem.sms(message, callback)
* message ObjectString
* text message body. Longs messages will be splitted andString
sent in multiple parts transparently.
* receiver receiver number.String
* encoding . '16bit' or '7bit'. Use 7bit in case of English messages.
callback Fucntion(err, references) is called when sending is done.Array
* references contains reference ids for each part of sent message. (A message may take up to several parts)
Get delivery reports
--------------------
``
modem.on('delivery', callback)
* callback Function is called with the following arguments:
* details Object detailed status reportString
* smsc Msisdn of SMS SenderString
* reference Reference number of the delivered messageMsisdn of receiver
* sender Delivery status
* status
* index String index of this delivery report in storage
Receive a message
-----------------
``
modem.on('sms received', callback)
* callback Function will be called on each new message with following arguments:Object
* message String
* smsc MSISDN of SMS CenterString
* sender MSISDN of senderDate
* time Send timeString
* text message body
Get stored messages
-------------------
``
modem.getMessages(callback)Function
* callback will be called with a single argumentArray
messages , which contains stores messages
Delete a message
----------------
``
modem.deleteMessage(message_index, callback)
* message_index Int is the message index to be deletedFunction
* callback called when message is deleted
Get notified when memory is full
--------------------------------
``
modem.on('memory full', callback)Function
* callback will be called when modem has no more space
for further messages
Get notified when someone calls
--------------------------------
``
modem.on('ring', callback)Function
* callback will be called on each RING with a single argumentNumber
* msisdn
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 String AT command you would like to executeFunction
* callback called when execution is done, in form of (escape_char, [response])String
* escape_char could be 'OK', 'ERROR' or '>'.String
* response modem's responseBoolean
* prior if set to true, command will be executed immediatelyInteger
* timeout timeout, in milliseconds, defaults to 60 seconds.EventEmitter
* job represents the added job.timeout
* it will emit if executing job times out
USS Sessions
============
> Modem.js allows you ro tun ussd sessions.
Instantiate
-----------
``
var Session = require('modem').Ussd_Session
Create 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;
}
``