/*
SpeedTest.netInstallation:
sudo apt-get install speedtest-cli
*/
const cmd = 'speedtest-cli --simple';
const idPing = 'Speedtest.Ping';
const idDown = 'Speedtest.Download';
const idUp = 'Speedtest.Upload';
createState(idPing, 0, {type: 'number', unit: 'ms'});
createState(idDown, 0, {type: 'number', unit: 'MBit/s'});
createState(idUp, 0, {type: 'number', unit: 'MBit/s'});
function speed() {
exec(cmd, function (error, stdout, stderr) {
if(error) log(stderr, 'error');
else {
var lines = stdout.split('\n');
setState(idPing, parseFloat(lines[0].split(' ')[1]), true);
setState(idDown, parseFloat(lines[1].split(' ')[1]), true);
setState(idUp, parseFloat(lines[2].split(' ')[1]), true);
}
});
}
setTimeout(speed, 500); // Scriptstart
schedule('*/15 * * * *', speed); // alle 15 Minuten