Skip to content

Instantly share code, notes, and snippets.

@raullucero
Last active Aug 5, 2017
Embed
What would you like to do?
const crypto = require("crypto");
const NodeTester = require("../index");
// Constants
const TIME_INTERVAL = 15000;
const GATEWAYS = 25;
const MAX_FCOUNT = 10000;
const PACKAGES = 40;
let fcounter = 0;
// Hostname Data
const host = {
hostname: "198.199.97.15",
port: 1700
};
// Device data
const device = {
devaddr: "12412412"
};
// Session data
const session = {
nwkskey: "12412412412412412412412412412412",
appskey: "12412412412412412412412412412412"
};
function emulateGateway() {
host.gateway_id = crypto.randomBytes(8).toString("hex");
console.log('initialize ', host.gateway_id);
const tester = new NodeTester(Object.assign({}, host, device, session));
setInterval(func, TIME_INTERVAL, tester);
}
/**
* function parameter for setInterval
*/
function func(gateway) {
console.log('\x1b[36m%s\x1b[0m', gateway.gateway_id);
if (fcounter === MAX_FCOUNT) {
console.log('\x1b[36m%s\x1b[0m', '----- END -----');
process.exit();
return;
}
for (let index = 0; index < PACKAGES; index++) {
gateway.addRxData(`example ${index} ${fcounter}`, fcounter);
fcounter++;
}
gateway.send();
}
for (let i = 0; i < GATEWAYS; i++) {
setTimeout(function() {
// initialize
emulateGateway();
}, 2000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment