Commit 13c3fff78e10d8272a7f8c3946a5cedca3eec559

Authored by Adhidarma Hadiwinoto
1 parent a00767a73b
Exists in master

More data on register-modem

Showing 1 changed file with 4 additions and 1 deletions Inline Diff

lib/register-modem.js
1 'use strict'; 1 'use strict';
2 2
3 const path = require('path'); 3 const path = require('path');
4 const request = require('request'); 4 const request = require('request');
5 5
6 const locks = require('locks'); 6 const locks = require('locks');
7 7
8 const config = require('komodo-sdk/config'); 8 const config = require('komodo-sdk/config');
9 const logger = require('komodo-sdk/logger'); 9 const logger = require('komodo-sdk/logger');
10 10
11 const mutex = locks.createMutex(); 11 const mutex = locks.createMutex();
12 12
13 function reportUrl() { 13 function reportUrl() {
14 if (config.report_url.register_modem) { 14 if (config.report_url.register_modem) {
15 return config.report_url.register_modem; 15 return config.report_url.register_modem;
16 } 16 }
17 17
18 const baseUrl = path.dirname(config.report_url.incoming_sms); 18 const baseUrl = path.dirname(config.report_url.incoming_sms);
19 return `${baseUrl}/modems/set`; 19 return `${baseUrl}/modems/set`;
20 } 20 }
21 21
22 function sender(modemInfo) { 22 function sender(modemInfo) {
23 if (mutex.tryLock()) { 23 if (mutex.tryLock()) {
24 const requestOptions = { 24 const requestOptions = {
25 url: reportUrl(), 25 url: reportUrl(),
26 qs: { 26 qs: {
27 modem: config.name, 27 modem: config.name,
28 modem_device: config.modem.device, 28 modem_device: config.modem.device,
29 modem_imsi: modemInfo.imsi, 29 modem_imsi: modemInfo.imsi,
30 modem_msisdn: modemInfo.msisdn, 30 // modem_msisdn: modemInfo.msisdn,
31 modem_network_id: modemInfo.networkId, 31 modem_network_id: modemInfo.networkId,
32 modem_network_name: modemInfo.networkName, 32 modem_network_name: modemInfo.networkName,
33 modem_signal_strength: modemInfo.signalStrength, 33 modem_signal_strength: modemInfo.signalStrength,
34 uptime: Math.floor(process.uptime()), 34 uptime: Math.floor(process.uptime()),
35 startTime: modemInfo.startTime,
35 report_port: config.http_command_server.listen_port, 36 report_port: config.http_command_server.listen_port,
36 report_apikey: config.http_command_server.apikey, 37 report_apikey: config.http_command_server.apikey,
37 report_path_sms: '/sms', 38 report_path_sms: '/sms',
39 lastReadTs: modemInfo.lastReadTs,
40 lastWriteTs: modemInfo.lastWriteTs,
38 }, 41 },
39 }; 42 };
40 43
41 logger.info('Sending modem registration to center'); 44 logger.info('Sending modem registration to center');
42 request(requestOptions, (err, res) => { 45 request(requestOptions, (err, res) => {
43 mutex.unlock(); 46 mutex.unlock();
44 47
45 if (err) { 48 if (err) {
46 logger.warn(`Error registering modem. ${err.toString()}`); 49 logger.warn(`Error registering modem. ${err.toString()}`);
47 } else if (res.statusCode !== 200) { 50 } else if (res.statusCode !== 200) {
48 logger.warn(`SMS center respond with HTTP status code ${res.statusCode}.`); 51 logger.warn(`SMS center respond with HTTP status code ${res.statusCode}.`);
49 } 52 }
50 }); 53 });
51 } 54 }
52 } 55 }
53 56
54 module.exports = sender; 57 module.exports = sender;
55 58