Skip to content

Commit

Permalink
Run prettier over code base
Browse files Browse the repository at this point in the history
* Tidy up whitespace
  • Loading branch information
jason-fox committed Feb 7, 2019
1 parent 4dc5d0c commit e49b54a
Show file tree
Hide file tree
Showing 17 changed files with 235 additions and 215 deletions.
17 changes: 9 additions & 8 deletions bin/sigfox-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var clUtils = require('command-node'),

function showParameters() {
console.log('\nCurrent measure parameters:\n\n');
console.log('-------------------------------------------------------')
console.log('-------------------------------------------------------');
console.log(JSON.stringify(parameters, null, 4));
console.log('\n');
clUtils.prompt();
Expand All @@ -52,7 +52,7 @@ function sendMeasure(commands) {

dataOpts.qs.data = commands[0];

request(dataOpts, function (error, response, body) {
request(dataOpts, function(error, response, body) {
if (error) {
console.log('\nError sending data to the Sigfox IoT Agent: ' + error);
} else {
Expand All @@ -70,23 +70,24 @@ function setParameters(commands) {
}

var commands = {
'showParameters': {
showParameters: {
parameters: [],
description: '\tShow the current device parameters that will be sent along with the callback',
description:
'\tShow the current device parameters that will be sent along with the callback',
handler: showParameters
},
'setParameters': {
setParameters: {
parameters: ['name', 'value'],
description: '\tSet the value for the selected parameter',
handler: setParameters
},
'sendMeasure': {
sendMeasure: {
parameters: ['data'],
description: '\tSend a measure to the defined endpoint, with the defined parameters and the data passed to ' +
description:
'\tSend a measure to the defined endpoint, with the defined parameters and the data passed to ' +
'the command',
handler: sendMeasure
}
};

clUtils.initialize(commands, 'SIGFOX Test> ');

1 change: 0 additions & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ config.sigfox = {
port: 17428
};


config.iota = {
/**
* Configures the log level. Appropriate values are: FATAL, ERROR, INFO, WARN and DEBUG.
Expand Down
20 changes: 10 additions & 10 deletions ghpages/javascripts/scale.fix.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
var metas = document.getElementsByTagName('meta');
var i;
if (navigator.userAgent.match(/iPhone/i)) {
for (i=0; i<metas.length; i++) {
if (metas[i].name == "viewport") {
metas[i].content = "width=device-width, minimum-scale=1.0, maximum-scale=1.0";
for (i = 0; i < metas.length; i++) {
if (metas[i].name == 'viewport') {
metas[i].content = 'width=device-width, minimum-scale=1.0, maximum-scale=1.0';
}
}
}
document.addEventListener("gesturestart", gestureStart, false);
document.addEventListener('gesturestart', gestureStart, false);
}
function gestureStart() {
for (i=0; i<metas.length; i++) {
if (metas[i].name == "viewport") {
metas[i].content = "width=device-width, minimum-scale=0.25, maximum-scale=1.6";
for (i = 0; i < metas.length; i++) {
if (metas[i].name == 'viewport') {
metas[i].content = 'width=device-width, minimum-scale=0.25, maximum-scale=1.6';
}
}
}
}
}
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('./lib/sigfox-iotagent');
module.exports = require('./lib/sigfox-iotagent');
16 changes: 7 additions & 9 deletions lib/configService.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,16 @@ function anyIsSet(variableSet) {
}

function processEnvironmentVariables() {
var environmentVariables = [
'IOTA_SIGFOX_PORT'
],
sigfoxVariables = [
'IOTA_SIGFOX_PORT'
];
var environmentVariables = ['IOTA_SIGFOX_PORT'],
sigfoxVariables = ['IOTA_SIGFOX_PORT'];

for (var i = 0; i < environmentVariables.length; i++) {
if (process.env[environmentVariables[i]]) {
logger.info('Setting %s to environment value: %s',
environmentVariables[i], process.env[environmentVariables[i]]);
logger.info(
'Setting %s to environment value: %s',
environmentVariables[i],
process.env[environmentVariables[i]]
);
}
}
if (anyIsSet(sigfoxVariables)) {
Expand All @@ -57,7 +56,6 @@ function processEnvironmentVariables() {
if (process.env.IOTA_SIGFOX_PORT) {
config.sigfox.port = process.env.IOTA_SIGFOX_PORT;
}

}

function setConfig(newConfig) {
Expand Down
1 change: 0 additions & 1 deletion lib/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,4 @@ module.exports = {
this.message = 'The plugin [' + plugin + '] could not be found or loaded';
this.code = 400;
}

};
36 changes: 18 additions & 18 deletions lib/iotagentCore.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ function updateConfigurationHandler(newConfiguration, callback) {
callback();
}

function deviceProvisioningMiddleware(device, callback){
function deviceProvisioningMiddleware(device, callback) {
config.getLogger().debug('device provisioning handler %j', device.internalAttributes);
var mappingFound = false;
if (device.internalAttributes) {
for (var i = 0; i < device.internalAttributes.length; i++) {
config.getLogger().debug('device provisioning handler %s',
device.internalAttributes[i]);
config
.getLogger()
.debug('device provisioning handler %s', device.internalAttributes[i]);
if (device.internalAttributes[i].mapping) {
mappingFound = true;
}
Expand All @@ -67,33 +68,32 @@ function initialize(callback) {

config.getLogger().info(context, 'Agent started');
callback();

}

function start(newConfig, callback) {
config.setLogger(iotAgentLib.logModule);
config.setConfig(newConfig);

async.series([
apply(sigfoxServer.start, config.getConfig()),
apply(iotAgentLib.activate, config.getConfig().iota)
], function(error, results) {
if (error) {
callback(error);
} else {
config.getLogger().info(context, 'IoT Agent services activated');
initialize(callback);
async.series(
[
apply(sigfoxServer.start, config.getConfig()),
apply(iotAgentLib.activate, config.getConfig().iota)
],
function(error, results) {
if (error) {
callback(error);
} else {
config.getLogger().info(context, 'IoT Agent services activated');
initialize(callback);
}
}
});
);
}

function stop(callback) {
config.getLogger().info(context, 'Stopping IoT Agent');

async.series([
sigfoxServer.stop,
iotAgentLib.deactivate
], callback);
async.series([sigfoxServer.stop, iotAgentLib.deactivate], callback);
}

exports.start = start;
Expand Down
1 change: 0 additions & 1 deletion lib/mappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ var errors = require('./errors'),
op: 'IoTAgentSIGFOX.mappigns'
};


function getMapping(type, callback) {
if (mappings[type]) {
callback(null, mappings[type]);
Expand Down
108 changes: 57 additions & 51 deletions lib/sigfoxHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,50 +67,55 @@ function generatePayload(queryParams, device, callback) {
});
}
}
iotAgentLib.update(
device.name,
device.type,
'',
attributes,
device,
function(error) {
if (error) {
config.getLogger().error(context, 'Couldn\'t send the updated values to the Context Broker ' +
'due to an error: %s', error);
} else {
config.getLogger().debug(context, 'Single measure for device [%s] successfully updated',
device.id);
}
}
);
iotAgentLib.update(device.name, device.type, '', attributes, device, function(error) {
if (error) {
config
.getLogger()
.error(
context,
"Couldn't send the updated values to the Context Broker " +
'due to an error: %s',
error
);
} else {
config
.getLogger()
.debug(
context,
'Single measure for device [%s] successfully updated',
device.id
);
}
});
callback();
}

if (device.internalAttributes && device.internalAttributes.length === 1 &&
device.internalAttributes[0].mapping) {
async.waterfall([
apply(decode, queryParams.data, device.internalAttributes[0].mapping),
createPayload
], callback);
} else if (device.internalAttributes && device.internalAttributes.length === 1 &&
device.internalAttributes[0].plugin) {
if (
device.internalAttributes &&
device.internalAttributes.length === 1 &&
device.internalAttributes[0].mapping
) {
async.waterfall(
[apply(decode, queryParams.data, device.internalAttributes[0].mapping), createPayload],
callback
);
} else if (
device.internalAttributes &&
device.internalAttributes.length === 1 &&
device.internalAttributes[0].plugin
) {
var plugin = require(device.internalAttributes[0].plugin);

if (plugin && plugin.parse) {
async.waterfall([
apply(plugin.parse, queryParams.data),
createPayload
], callback);
async.waterfall([apply(plugin.parse, queryParams.data), createPayload], callback);
} else {
callback(new errors.ErrorLoadingPlugin(plugin));
}

} else {
async.waterfall([
apply(mappings.get, device.type),
apply(decode, queryParams.data),
createPayload
], callback);
async.waterfall(
[apply(mappings.get, device.type), apply(decode, queryParams.data), createPayload],
callback
);
}
}

Expand All @@ -124,23 +129,26 @@ function generateLastHandler(res) {
};
}




function handleMeasure(req, res, next) {
config.getLogger().debug(context, 'Handling request with query [%j]', req.query);

async.waterfall([
// Service and subservice should be deduced from Group configuracion
// Group configuration is based in apikey
// apply(iotAgentLib.getConfiguration,
// config.getConfig().iota.defaultResource || '',
// config.getConfig().defaultKey),
apply(iotAgentLib.getDevice, req.query.id,
config.getConfig().iota.service,
config.getConfig().iota.subservice),
apply(generatePayload, req.query),
], generateLastHandler(res));
async.waterfall(
[
// Service and subservice should be deduced from Group configuracion
// Group configuration is based in apikey
// apply(iotAgentLib.getConfiguration,
// config.getConfig().iota.defaultResource || '',
// config.getConfig().defaultKey),
apply(
iotAgentLib.getDevice,
req.query.id,
config.getConfig().iota.service,
config.getConfig().iota.subservice
),
apply(generatePayload, req.query)
],
generateLastHandler(res)
);
return res;
}

Expand All @@ -150,9 +158,7 @@ function handleMeasure(req, res, next) {
* @param {Object} router Express request router object.
*/
function loadContextRoutes(router) {
router.get('/update',
requiredFields,
handleMeasure);
router.get('/update', requiredFields, handleMeasure);
}

exports.loadContextRoutes = loadContextRoutes;
12 changes: 10 additions & 2 deletions lib/sigfoxServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,16 @@ function start(newConfig, callback) {
router: express.Router()
};

config.getLogger().info(context, 'Starting Sigfox server listening on port [%s]', config.getConfig().sigfox.port);
config.getLogger().debug(context, 'Using config:\n\n%s\n', JSON.stringify(config.getConfig(), null, 4));
config
.getLogger()
.info(
context,
'Starting Sigfox server listening on port [%s]',
config.getConfig().sigfox.port
);
config
.getLogger()
.debug(context, 'Using config:\n\n%s\n', JSON.stringify(config.getConfig(), null, 4));

iotServer.app.set('port', config.getConfig().sigfox.port);
iotServer.app.set('host', '0.0.0.0');
Expand Down
1 change: 0 additions & 1 deletion test/testConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

var config = {};


config.sigfox = {
port: 17428
};
Expand Down
Loading

0 comments on commit e49b54a

Please sign in to comment.