diff --git a/lib/db-cops.js b/lib/db-cops.js new file mode 100644 index 0000000..e5af6eb --- /dev/null +++ b/lib/db-cops.js @@ -0,0 +1,10 @@ +module.exports = { + 51001: 'INDOSAT', + 51008: 'AXIS', + 51009: 'SMART', + 51010: 'TELKOMSEL', + 51011: 'XL', + 51021: 'IM3', + 51028: 'FREN', + 51089: 'THREE', +}; diff --git a/lib/modem.js b/lib/modem.js index e04ebf6..3a8d273 100644 --- a/lib/modem.js +++ b/lib/modem.js @@ -13,6 +13,7 @@ const logger = require('komodo-sdk/logger'); const mutex = require('./mutex'); const common = require('./common'); const sms = require('./sms'); +const dbCops = require('./db-cops'); const reportSender = require('./report-sender'); const modemInfo = { @@ -20,6 +21,9 @@ const modemInfo = { model: null, imei: null, imsi: null, + cops: null, + networkId: null, + networkName: null, signalStrength: null, config: config.modem, }; @@ -86,6 +90,19 @@ function onIncomingSMS(data) { readSMS(slot); } +function onCOPS(data) { + modemInfo.cops = common.extractValueFromReadLineData(data).trim(); + logger.info(`Connected Network: ${modemInfo.cops}`); + + if (!modemInfo.cops) return; + + [, , modemInfo.networkId] = modemInfo.cops.split(','); + + if (modemInfo.networkId) { + modemInfo.networkName = dbCops[modemInfo.networkId]; + } +} + parserReadLine.on('data', (data) => { logger.verbose(`* IN: ${data}`); if (data) { @@ -94,6 +111,8 @@ parserReadLine.on('data', (data) => { logger.info(`Signal strength: ${modemInfo.signalStrength}`); } else if (data.indexOf('+CMTI: ') === 0) { onIncomingSMS(data); + } else if (data.indexOf('+COPS: ') === 0) { + onCOPS(data); } } }); @@ -200,6 +219,8 @@ function init() { logger.info('Disabling echo'); await writeToPortAndWaitForOK('ATE0\r'); + await writeToPortAndWaitForOK('AT+COPS?\r'); + logger.info('Querying signal strength'); await writeToPortAndWaitForOK('AT+CSQ\r');