diff --git a/config.sample.json b/config.sample.json index 832d592..b7a5a7d 100644 --- a/config.sample.json +++ b/config.sample.json @@ -16,6 +16,6 @@ }, "interval_beetwen_signal_strength_ms": 60000, - "wait_for_release_lock_wait_for_command_ms": 2000, + "sleep_after_send_sms_ms": 2000, "disable_delete_inbox_on_startup": false } \ No newline at end of file diff --git a/lib/modem.js b/lib/modem.js index f9b6018..06977fc 100644 --- a/lib/modem.js +++ b/lib/modem.js @@ -1,5 +1,6 @@ 'use strict'; +const DEFAULT_SLEEP_AFTER_SEND_SMS_MS = 2000; const INTERVAL_BEETWEN_SIGNAL_STRENGTH_MS = 60000; const MAX_LAST_DATA_AGE_MS = 3 * 60 * 1000; const REGEX_WAIT_FOR_OK_OR_ERROR = /\n(?:OK|ERROR)\r/; @@ -20,9 +21,7 @@ const common = require('./common'); const sms = require('./sms'); const dbCops = require('./db-cops'); const reportSender = require('./report-sender'); -// const msisdn = require('./msisdn'); const registerModem = require('./register-modem'); -// const counters = require('./counters'); const modemInfo = { device: config.modem.device, @@ -37,8 +36,6 @@ const modemInfo = { signalStrength: null, signalStrengthTs: null, signalStrengthTsReadable: null, - // messageSentCounter: null, - // messageReceivedCounter: null, }; let lastTs = new Date(); @@ -138,7 +135,6 @@ parserReadLine.on('data', (data) => { registerModem(modemInfo); } } else if (data.indexOf('+CMTI: ') === 0) { - // counters.increment('MESSAGE_RECEIVED', modemInfo); onIncomingSMS(data); } else if (data.indexOf('+COPS: ') === 0) { onCOPS(data); @@ -282,12 +278,11 @@ async function sendSMS(destination, msg) { logger.verbose('Waiting for command lock to send message'); await mutex.setLockWaitForCommand(); - logger.info('Sending message', { destination, msg }); - // counters.increment('MESSAGE_SENT', modemInfo); + logger.info('Preparing to send message', { destination, msg }); const correctedDestination = `+${destination}`.replace(/^0/, '62').replace(/^\++/, '+'); - logger.verbose('Waiting for lock before set to text mode'); + logger.verbose('Waiting for lock before set SMS to text mode'); await mutex.setLockWaitForSubCommand(); port.pipe(parser); await writeToPort('AT+CMGF=1\r'); @@ -307,7 +302,7 @@ async function sendSMS(destination, msg) { setTimeout(() => { logger.verbose('Releasing command lock'); mutex.releaseLockWaitForCommand(); - }, config.wait_for_release_lock_wait_for_command_ms || 2000); + }, config.sleep_after_send_sms_ms || DEFAULT_SLEEP_AFTER_SEND_SMS_MS); } /** diff --git a/lib/msisdn.js b/lib/msisdn.js deleted file mode 100644 index 297291d..0000000 --- a/lib/msisdn.js +++ /dev/null @@ -1,10 +0,0 @@ -'use strict'; - -const fs = require('fs'); -const logger = require('komodo-sdk/logger'); - -const db = fs.existsSync('db-msisdn.json') || fs.existsSync('db-msisdn.js') ? require('../db-msisdn') : {}; - -logger.info(`MSISDN database loaded with ${Object.keys(db).length}.`); - -module.exports = db; diff --git a/lib/register-modem.js b/lib/register-modem.js index 01cf957..4cbc810 100644 --- a/lib/register-modem.js +++ b/lib/register-modem.js @@ -8,8 +8,6 @@ const locks = require('locks'); const config = require('komodo-sdk/config'); const logger = require('komodo-sdk/logger'); -// const counters = require('./counters'); - const mutex = locks.createMutex(); function reportUrl() { @@ -23,13 +21,6 @@ function reportUrl() { function sender(modemInfo) { if (mutex.tryLock()) { - // logger.info('Getting message counters before registering modem'); - - // eslint-disable-next-line no-param-reassign - // modemInfo.messageSentCounter = await counters.get('MESSAGE_SENT', modemInfo); - // eslint-disable-next-line no-param-reassign - // modemInfo.messageReceivedCounter = await counters.get('MESSAGE_RECEIVED', modemInfo); - const requestOptions = { url: reportUrl(), qs: { @@ -44,8 +35,6 @@ function sender(modemInfo) { report_port: config.http_command_server.listen_port, report_apikey: config.http_command_server.apikey, report_path_sms: '/sms', - // counter_sent: modemInfo.messageSentCounter, - // counter_received: modemInfo.messageReceivedCounter, }, };