Last active
August 5, 2017 16:23
-
-
Save raullucero/2328d2f12d9b5d31b32a3c25d6d90d9f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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