Commit 5a00ec06f942d2717f660707c59cff37e338a767
1 parent
772b816fcd
Exists in
master
DEBUG signalStrength
Showing 1 changed file with 10 additions and 2 deletions Side-by-side Diff
lib/modem.js
... | ... | @@ -3,6 +3,7 @@ |
3 | 3 | const INTERVAL_BEETWEN_SIGNAL_STRENGTH_MS = 60000; |
4 | 4 | const DELIMITER_WAIT_FOR_OK = '\nOK\r\n'; |
5 | 5 | |
6 | +const moment = require('moment'); | |
6 | 7 | const SerialPort = require('serialport'); |
7 | 8 | const ParserReadline = require('@serialport/parser-readline'); |
8 | 9 | const ParserDelimiter = require('@serialport/parser-delimiter'); |
... | ... | @@ -27,6 +28,8 @@ const modemInfo = { |
27 | 28 | networkId: null, |
28 | 29 | networkName: null, |
29 | 30 | signalStrength: null, |
31 | + signalStrengthTs: null, | |
32 | + signalStrengthTsReadable: null, | |
30 | 33 | config: config.modem, |
31 | 34 | }; |
32 | 35 | |
... | ... | @@ -107,8 +110,13 @@ parserReadLine.on('data', (data) => { |
107 | 110 | logger.verbose(`* IN: ${data}`); |
108 | 111 | if (data) { |
109 | 112 | if (data.indexOf('+CSQ: ') === 0) { |
110 | - modemInfo.signalStrength = common.extractValueFromReadLineData(data).trim(); | |
111 | - logger.info(`Signal strength: ${modemInfo.signalStrength}`); | |
113 | + const signalStrength = common.extractValueFromReadLineData(data).trim(); | |
114 | + if (signalStrength) { | |
115 | + modemInfo.signalStrength = signalStrength; | |
116 | + modemInfo.signalStrengthTs = new Date(); | |
117 | + modemInfo.signalStrengthTsReadable = moment(modemInfo.signalStrengthTs).format('YYYY-MM-DD HH:mm:ss'); | |
118 | + logger.info(`Signal strength: ${modemInfo.signalStrength}`); | |
119 | + } | |
112 | 120 | } else if (data.indexOf('+CMTI: ') === 0) { |
113 | 121 | onIncomingSMS(data); |
114 | 122 | } else if (data.indexOf('+COPS: ') === 0) { |