Commit 7355ad895c439f17aea0586cda44e3fd69ab0de1
1 parent
3ec3e9eb37
Exists in
master
Network information
Showing 2 changed files with 31 additions and 0 deletions Side-by-side Diff
lib/db-cops.js
lib/modem.js
... | ... | @@ -13,6 +13,7 @@ const logger = require('komodo-sdk/logger'); |
13 | 13 | const mutex = require('./mutex'); |
14 | 14 | const common = require('./common'); |
15 | 15 | const sms = require('./sms'); |
16 | +const dbCops = require('./db-cops'); | |
16 | 17 | const reportSender = require('./report-sender'); |
17 | 18 | |
18 | 19 | const modemInfo = { |
... | ... | @@ -20,6 +21,9 @@ const modemInfo = { |
20 | 21 | model: null, |
21 | 22 | imei: null, |
22 | 23 | imsi: null, |
24 | + cops: null, | |
25 | + networkId: null, | |
26 | + networkName: null, | |
23 | 27 | signalStrength: null, |
24 | 28 | config: config.modem, |
25 | 29 | }; |
... | ... | @@ -86,6 +90,19 @@ function onIncomingSMS(data) { |
86 | 90 | readSMS(slot); |
87 | 91 | } |
88 | 92 | |
93 | +function onCOPS(data) { | |
94 | + modemInfo.cops = common.extractValueFromReadLineData(data).trim(); | |
95 | + logger.info(`Connected Network: ${modemInfo.cops}`); | |
96 | + | |
97 | + if (!modemInfo.cops) return; | |
98 | + | |
99 | + [, , modemInfo.networkId] = modemInfo.cops.split(','); | |
100 | + | |
101 | + if (modemInfo.networkId) { | |
102 | + modemInfo.networkName = dbCops[modemInfo.networkId]; | |
103 | + } | |
104 | +} | |
105 | + | |
89 | 106 | parserReadLine.on('data', (data) => { |
90 | 107 | logger.verbose(`* IN: ${data}`); |
91 | 108 | if (data) { |
... | ... | @@ -94,6 +111,8 @@ parserReadLine.on('data', (data) => { |
94 | 111 | logger.info(`Signal strength: ${modemInfo.signalStrength}`); |
95 | 112 | } else if (data.indexOf('+CMTI: ') === 0) { |
96 | 113 | onIncomingSMS(data); |
114 | + } else if (data.indexOf('+COPS: ') === 0) { | |
115 | + onCOPS(data); | |
97 | 116 | } |
98 | 117 | } |
99 | 118 | }); |
... | ... | @@ -200,6 +219,8 @@ function init() { |
200 | 219 | logger.info('Disabling echo'); |
201 | 220 | await writeToPortAndWaitForOK('ATE0\r'); |
202 | 221 | |
222 | + await writeToPortAndWaitForOK('AT+COPS?\r'); | |
223 | + | |
203 | 224 | logger.info('Querying signal strength'); |
204 | 225 | await writeToPortAndWaitForOK('AT+CSQ\r'); |
205 | 226 |