emilsedgh / modem Goto Github PK
View Code? Open in Web Editor NEWSend and receive messages and make ussd queries using your GSM modems
Send and receive messages and make ussd queries using your GSM modems
Solition of specials character?
Hello Emil,
I found that after a certain execution time, the modem no longer responds? Is it a full buffer problem? or other?
I have to restart regularly features to the catcher sms works.
Have you already seen this problem? Did you reference a modem that everything is working properly?
Happy holidays to you, Hervé
I have connected a FAX modem and connected the land line phone.
The connect function works fine for the modem.
But the on ring event is not triggered when I call the land line phone.
But I can see from the debug feature that the caller id is working fine on my modem.
This is what I get on the console.log when I call at the line line which is connected in my modem:
DEBUG modem: COM19 <----
RING
DEBUG modem: Unhandled command:
NMRB = 6945076867
DATE = 0218
TIME = 2042
MESG = 0000
etc
And below you can see my code.
function onRing(number) {
console.log('onring'+number);
}
var modem1 = new Modem({
ports : ['COM19'],
debug : true
});
modem1.on('ring', onRing);
modem1.connect(function (err) {
if (err) {
console.error('Error connecting modem: ', err);
return;
}
});
Hey,
The delivery event works well but I would appreciate to have the index of the corresponding SMS so that I can remove it from my Inbox
Thanks
Hi everyone, excuse my English, I'm french,
So I do use this library to send USSD from up to three different sim cards.
So I have three gsm modems connected to my computer and
I'm also able to send USSD over one of them (using Huawei E3131) but the others modems (Alcatel X602D and ) give me this error :
+CME ERROR: operation not allowed.
What should I do? Is there any kind of authorization I should give to my app?
var device = '/dev/ttyUSB0';
var message = {
text : 'Hello',
receiver: '+91xxxx',
encoding: '7bit'
};
modem.open(device, function(){
console.log('OPEN!!');
});
/*
OUTPUT:
node gsm_modem.js
OPEN!!
It can't send sms. 'delivery' method is also not working.
I ma failing to use modem with nodejs cluster, l get the following error
/home/chris/SoftWyze/node-prjt/bhora-api/node_modules/modem/lib/modem.js:176
this.queue[0]['end_time'] = new Date();
^
TypeError: Cannot set property 'end_time' of undefined
at EventEmitter. (/home/chris/SoftWyze/node-prjt/bhora-api/node_modules/modem/lib/modem.js:176:43)
at Array.forEach (native)
at EventEmitter.modem.dataReceived (/home/chris/SoftWyze/node-prjt/bhora-api/node_modules/modem/lib/modem.js:123:15)
at SerialPort.EventEmitter.emit (events.js:95:17)
at Object.module.exports.raw as parser
at Object.SerialPort.options.dataCallback (/home/chris/SoftWyze/node-prjt/bhora-api/node_modules/modem/node_modules/serialport/serialport.js:167:15)
at SerialPortFactory.SerialPort._emitData (/home/chris/SoftWyze/node-prjt/bhora-api/node_modules/modem/node_modules/serialport/serialport.js:349:20)
at afterRead (/home/chris/SoftWyze/node-prjt/bhora-api/node_modules/modem/node_modules/serialport/serialport.js:325:20)
at /home/chris/SoftWyze/node-prjt/bhora-api/node_modules/modem/node_modules/serialport/serialport.js:341:9
at Object.wrapper as oncomplete
This is what my bin/www looks like
var cluster = require('cluster');
var http = require('http');
var numCPUs = require('os').cpus().length;
var debug = require('debug')('bhora-api');
var app = require('../app');
if (cluster.isMaster) {
// Fork workers.
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}
cluster.on('exit', function(worker, code, signal) {
console.log('worker ' + worker.process.pid + ' died');
});
} else {
// Workers can share any TCP connection
// In this case its a HTTP server
app.set('port', process.env.PORT || 3000);
var server = app.listen(app.get('port'), function() {
debug('Express server listening on port ' + server.address().port);
});
}
app.js is where l try to initialize the modem
Hi, I see you're not maintaining this package anymore. Can you add a license and maybe transfer ownership?
I have connected my nokia phone with a usb cable. I have no idea how to get the device path. please help.
Huawei E3131.
var modem = require('modem').Modem();
modem.open('/dev/ttyUSB0', function(){
console.log('open');
modem.on('sms received', function(){
console.log('rcvd');
});
});
When sending sms to the modem number, nothing happens. Modem is opened successfully, as I can send sms. Any idea why and how to debug that?
Hello Emil,
Thanks for the excellent work.
I am trying simple code to send and receive sms on raspberry pi using e303 modem.
I am able to send the message. But read message returns no messages. Also receive message does not receive any.
If I check the messages with gammu -getallsms, I see all of them on SIM inbox folder.
Regards, Imtiyaz
Hi,
can this lib be extended to read incoming callerid information for voice supporting modems?
thanks in advance
Hello :) its my first time with node modules and i'm sorry to say "i confused with node modules error generally"
my problem is : after instaling modem node's console log show me an error
Uncaught Error: Cannot find module 'C:\myapps\test-modem\node_modules\modem\node_modules\serialport\build\serialport\v1.7.4\Release\node-webkit-v0.12.2-win32-ia32\serialport.node'
i have a try with renaming path folders to be right and it show me error
Uncaught Error: Invalid access to memory location.
C:\myapps\test-modem\node_modules\modem\node_modules\serialport\build\serialport\v1.7.4\Release\node-webkit-v0.12.2-win32-ia32\serialport.node
thanks and hope to help :)
hi, i just installed this and whenever i run this
var modem = require('modem').Modem();
modem.open("/dev/sg1", function(err){
if(err){
throw err;
}else{
console.log("Modem is ready");
}
})
i get this error
../node_modules/modem/lib/modem.js:84
parser: sp.parsers.raw
^
TypeError: Cannot read properties of undefined (reading 'raw')
Any solution?
on: modem.sms()
give error : +CMS ERROR: 304
why???
Document of Running custom AT commands
should be
I'm executing following program:
var modem = require('modem').Modem();
modem.open('COM4', function() {
modem.execute('AT+CMGS="03028461532"\rHello World\r'+String.fromCharCode(26)+'\r',
function(err, result){
if(err) console.log(err);
console.log('Result: ' + result);
});
});
this.queue is empty. Witch raises an error.
First , I'd like to thank you for this great module ,
Second , I can't notify when new sms received ..
I tried changing the AT+CNMI command to another value like AT+CNMI=2,1,0,2,0 , but it still the same ..
thanks in advance ..
npm install modem
does not work
Hey,
First thanks for your cool package. I use it to send and receive SMS but sometimes, the app stop receiving SMS (no event is emited when a new sms arrives). I have to stop and restart the app in order to receive them?
Have you ever experiences this behaviour ?
hi emilsedgh !
well, i dont understand how work the callback for :
job = modem.execute(at_command, [callback], [priority], [timeout])
have u an exemple ?
i want the response for : 'AT+CUSD=1,"*137#",15'
thanx in advance ! Great job !
Hi,
gsm.js
`
function err(message) {
console.log('Usage: node send_sms.js /path/to/device xxxxyyzz "Foo Bar"');
process.exit();
}
var device = process.argv[2];
var receiver = process.argv[3];
var text = process.argv[4];
if(!device || !receiver || !text) err();
var modem = require('modem').Modem();
modem.open('/dev/ttyS0', function() {
modem.sms({
receiver:receiver,
text:text,
encoding:'7bit'
}, function(err, sent_ids) {
console.log('>>', arguments);
if(err)
console.log('Error sending sms:', err);
else
console.log('Message sent successfully, here are reference ids:', sent_ids.join(','));
});
});
`
console error:
node gsm.js /dev/ttyS0 +359894587672 "test node"
DEPRECATION: Please userequire('serialport')
instead ofrequire('serialport').SerialPort
^C
modem.js
1: var pdu = require('pdu');
2: var sp = require('serialport');
3: var EventEmitter = require('events').EventEmitter;
......
81: modem.open = function(device, callback) {
82: modem.port = new sp.SerialPort(device, {
83: parser: sp.parsers.raw
84: });
Cant find that DEPRECATION error!
Hi Emil,
Please, what multi sim modem (minimum 3) advise you for your system? or one you advice?
Thank you in advance for your answer.
hi
modem.open('COM6', function(){
say
E:\node\ussd\node_modules\modem\lib\modem.js:82
modem.port = new sp.SerialPort(device, {
^
TypeError: sp.SerialPort is not a constructor
i use windows 10 and this is my COMs
PS E:\node\ussd\node_modules\serialport\bin> node .\list.js
COM6 USB\VID_2077&PID_A000&MI_00\6&F9B7265&1&0000 W-Card
COM4 USB\VID_2077&PID_A000&MI_01\6&F9B7265&1&0001 W-Card
I can identify, send and read sms with gammu.
But using this module, getMessages and sms callback is seemed to be never called.
I'm trying to run the following code on Windows 7:
/* Usage: node send_sms.js /path/to/device xxxxyyzz "Foo Bar" */
function err(message) {
console.log('Usage: node send_sms.js /path/to/device xxxxyyzz "Foo Bar"');
process.exit();
}
var device = 'COM11';
var receiver = '5562XX1685XX';
var text = 'ola mundo';
console.log('iniciando');
var modem = require('modem').Modem();
modem.open(device, function() {
modem.sms({
receiver:receiver,
text:text,
encoding:'7bit'
}, function(err, sent_ids) {
console.log('>>', arguments);
if(err)
console.log('Error sending sms:', err);
else
console.log('Message sent successfully, here are reference ids:', sent_ids.join(','));
});
});
But I'm getting the error:
D:\serialport>node app4.js
>> { '0': null, '1': [ '' ] }
Message sent successfully, here are reference ids:
D:\serialport\node_modules\modem\lib\modem.js:176
this.queue[0]['end_time'] = new Date();
^
TypeError: Cannot set property 'end_time' of undefined
at EventEmitter.<anonymous> (D:\serialport\node_modules\modem\lib\modem.js:176:43)
at Array.forEach (native)
at EventEmitter.modem.dataReceived (D:\serialport\node_modules\modem\lib\modem.js:123:15)
at SerialPort.emit (events.js:95:17)
at Object.module.exports.raw [as parser] (D:\serialport\node_modules\serialport\parsers.js:8:13)
at SerialPort.options.dataCallback (D:\serialport\node_modules\serialport\serialport.js:143:15)
Trying to debug the module, I've realized that the line 176 is performed 3 times but the error happens just on the 3rd time.
Kleyson Rios.
How use phones like +7912xxxxxxx. Russian style.
But 8912xxxxxxx is ok.
Modem HUAWEI E1715. SMS sends ok.
modem.open('COM5', function(){
modem.on('sms received', function(smsc, sender, time, text) {
console.log('sms in');
console.log('sender:'+sender+' text:'+text);
});
modem.getMessages(function(messages) {
console.log(messages);
});
});
setInterval(function(){}, 1000);
getMessages return empty arr
events.js:85
throw er; // Unhandled 'error' event
^
Error: Serialport not open.
at SerialPortFactory.SerialPort.close (/Users/terry/Desktop/iRXBot/modem/node_modules/modem/node_modules/serialport/serialport.js:476:17)
at EventEmitter.modem.close (/Users/terry/Desktop/iRXBot/modem/node_modules/modem/lib/modem.js:110:19)
at SerialPort.<anonymous> (/Users/terry/Desktop/iRXBot/modem/node_modules/modem/lib/modem.js:104:19)
at SerialPort.emit (events.js:107:17)
at SerialPort.callback (/Users/terry/Desktop/iRXBot/modem/node_modules/modem/node_modules/serialport/serialport.js:101:16)
at /Users/terry/Desktop/iRXBot/modem/node_modules/modem/node_modules/serialport/serialport.js:224:11
modem.parseResponse = function(response) {
var plain = response.slice(response.indexOf(':')+1).trim();
var parts = plain.split(/,(?=(?:[^"]|"[^"]*")*$)/);
for(i in parts)
parts[i] = parts[i].replace(/\"/g, '');
return parts;
}
modem.parseResponse = function(response) {
var plain = response.slice(response.indexOf(':')+1).trim();
var parts = plain.split(/,(?=(?:[^"]|"[^"]*")*$)/);
for(var i=0;i<parts.length;i++)
parts[i] = parts[i].replace(/\"/g, '');
return parts;
}
modem.close = function(device) {
this.port.removeAllListeners();
this.port.close();
this.port = null;
this.isOpened = false;
this.emit('close');
}
modem.close = function(device) {
for(var k in timeouts) clearTimeout(timeouts[k])
this.port.removeAllListeners();
try{this.port.close()}catch(e){};
this.port = null;
this.isOpened = false;
this.emit('close');
}
if(this.queue[0] && this.queue[0]['command'].trim().slice(0, data.length) === data) {
this.queue[0]['command'] = this.queue[0]['command'].slice(data.length); <= Why you do that ?
return ;
}
Please.. any update ?
Hello @emilsedgh first of all nice work.
I have been testing this package and I have found one problem.
Text is disappearing from the end of the message.
In my tests I have detected that 6 characters disappear. Can You Please check this?
When using the modem.sms function I am experiencing that the last few characters are cut of when viewing the sms message on the receiving phone.
function sendSMS() {
console.log('Attempting to send SMS');
modem.sms({
receiver: '0761234567',
text: 'Test text from app.js on Mac.',
encoding: '7bit'
}, function (err, sent_ids) {
console.log('>>', arguments);
if (err)
console.log('Error sending sms:', err);
else
console.log('Message sent successfully, here are reference ids:', sent_ids.join(','));
});
}
For instance: Test text from app.js on Mac. gets cut off toTest text from app.js on M
Have you experienced this?
Thanks
Leon
Hey, sorry me again...
When I send 2 long SMS (ie 3 messages concatenated in one) to same recipient almost simultaneously, my messages are received upside down, ie the beggining of the 1st message is concatenated with the end of the second and so on...
I don't know if this is due to the sender SIM card, the receiver SIM card, the modem.js programm, the phone itself
Any idea of how to avoid that?
thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.