Community discussions

MikroTik App
 
lhoem
just joined
Topic Author
Posts: 4
Joined: Tue Feb 25, 2025 12:28 pm

Items Registration Table

Tue Feb 25, 2025 12:39 pm

Hello,
I would like to use the API via HTML to display the current number of entries, how many items are currently displayed in the registration table...

http://192.168.XXX.X/rest/interface/wir ... tion-table

shows all entries in the table, but is there a query that only shows the number of registered items?
Thanks in advance...
Greetings
Lothar
 
lhoem
just joined
Topic Author
Posts: 4
Joined: Tue Feb 25, 2025 12:28 pm

Re: Items Registration Table

Mon Mar 03, 2025 12:21 pm

Hello can someone help me how to add the “count-only” to the URL so that I can query the Begehl via URL? I don't understand it...

http://192.168.188.8/rest/interface/wir ... able/print --data '{“.query”: [“disabled=yes”, “#|”], “count-only”: true}

What is wrong?
Thank you.
Regards
Lothar
 
eltikpad
Member Candidate
Member Candidate
Posts: 124
Joined: Sun Jan 12, 2025 10:54 pm

Re: Items Registration Table

Mon Mar 03, 2025 8:29 pm

It is possible if you use some kind of valid query, such as:
 curl -s -k -u ${USERNAME}:${PASSWORD} -X POST http://192.168.1.1/rest/interface/wireless/registration-table/print --data '{".query": ["management-protection=false"], "count-only": true}' -H "content-type: application/json" | jq -c
{"ret":"1"}
For anything more complex than the trivial example above its probably better to dump all the table data and post process it with a scripting language like this naive python example
 curl -s -k -u ${USERNAME}:${PASSWORD} -X POST http://192.168.1.1/rest/interface/wireless/registration-table/print -H "content-type: application/json"  | python -c "import sys,json; print(len(json.load(sys.stdin)))"
1
 
lhoem
just joined
Topic Author
Posts: 4
Joined: Tue Feb 25, 2025 12:28 pm

Re: Items Registration Table

Tue Mar 04, 2025 8:04 am

Hello and thank you,

I am just trying to see the number of registrations via my browser or I am using iobroker to display this. Unfortunately this is not offered in the iobroker instance. In the browser I only get an error message after entering your scripts.

{"detail":"no such command prefix","error":400,"message":"Bad Request"}

Regards
Lothar
 
eltikpad
Member Candidate
Member Candidate
Posts: 124
Joined: Sun Jan 12, 2025 10:54 pm

Re: Items Registration Table

Tue Mar 04, 2025 5:54 pm

If you have a terminal on whatever computer you are working on, cut and paste the first comment into the CLI, change the username and password and you will have your answer.

AFAIK there is no easy way to create a POST request from your browser.

I am not familiar with ‘iobroker’. It seems to be an open source project, so so could request this feature from them in their GitHub, or add the code yourself.
 
lhoem
just joined
Topic Author
Posts: 4
Joined: Tue Feb 25, 2025 12:28 pm

Re: Items Registration Table

Wed Mar 19, 2025 3:18 pm

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();