This works:
const exec = require('child_process').exec;
const USERNAME = 'deinBenutzername';
const PASSWORD = 'deinPasswort';
const URL = '
http://192.168.1.1/rest/interface/wirel ... able/print';
const DATA_POINT = 'javascript.0.WirelessClientCount'; // Ziel-Datenpunkt in ioBroker
function updateWirelessClientCount() {
const command = `curl -s -k -u ${USERNAME}:${PASSWORD} -X POST ${URL} -H "content-type: application/json" | python3 -c "import sys,json; print(len(json.load(sys.stdin)))"`;
exec(command, (error, stdout, stderr) => {
if (error) {
console.error(`Fehler beim Abrufen der Daten: ${stderr}`);
return;
}
const clientCount = parseInt(stdout.trim(), 10);
if (!isNaN(clientCount)) {
setState(DATA_POINT, clientCount, true);
console.log(`Anzahl der verbundenen Clients: ${clientCount}`);
} else {
console.error('Fehler: Konnte die Anzahl der Clients nicht bestimmen.');
}
});
}
// Skript alle 5 Minuten ausführen
schedule("*/5 * * * *", updateWirelessClientCount);
// Direkt beim Start ausführen
updateWirelessClientCount();