Commit 30befba5c765ecbaf6a6ed2d4099ce1c6e29b791

Authored by Adhidarma Hadiwinoto
1 parent aaaf3604ea
Exists in master

Report sender update modemInfo message counter

Showing 2 changed files with 17 additions and 2 deletions Side-by-side Diff

... ... @@ -36,6 +36,8 @@ const modemInfo = {
36 36 signalStrength: null,
37 37 signalStrengthTs: null,
38 38 signalStrengthTsReadable: null,
  39 + messageSentCounter: null,
  40 + messageReceivedCounter: null,
39 41 };
40 42  
41 43 let lastTs = new Date();
lib/register-modem.js
... ... @@ -8,6 +8,8 @@ const locks = require('locks');
8 8 const config = require('komodo-sdk/config');
9 9 const logger = require('komodo-sdk/logger');
10 10  
  11 +const counters = require('./counters');
  12 +
11 13 const mutex = locks.createMutex();
12 14  
13 15 function reportUrl() {
... ... @@ -19,8 +21,15 @@ function reportUrl() {
19 21 return `${baseUrl}/modems/set`;
20 22 }
21 23  
22   -module.exports = (modemInfo) => {
  24 +async function sender(modemInfo) {
23 25 if (mutex.tryLock()) {
  26 + logger.info('Getting message counters before registering modem');
  27 +
  28 + // eslint-disable-next-line no-param-reassign
  29 + modemInfo.messageSentCounter = await counters.get('MESSAGE_SENT', modemInfo);
  30 + // eslint-disable-next-line no-param-reassign
  31 + modemInfo.messageReceivedCounter = await counters.get('MESSAGE_RECEIVED', modemInfo);
  32 +
24 33 const requestOptions = {
25 34 url: reportUrl(),
26 35 qs: {
... ... @@ -35,6 +44,8 @@ module.exports = (modemInfo) => {
35 44 report_port: config.http_command_server.listen_port,
36 45 report_apikey: config.http_command_server.apikey,
37 46 report_path_sms: '/sms',
  47 + counter_sent: modemInfo.messageSentCounter,
  48 + counter_received: modemInfo.messageReceivedCounter,
38 49 },
39 50 };
40 51  
... ... @@ -49,4 +60,6 @@ module.exports = (modemInfo) => {
49 60 }
50 61 });
51 62 }
52   -};
  63 +}
  64 +
  65 +module.exports = sender;