Abfrage via Blockly Post

Hallo,

ich versuche eine Post Abfrage via Blockly durchzuführen. Kann mir Jemand bitte helfen oder einen Tipp geben, wie ich das in das Post-Modul in Blockly verpacken kann?

 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"}

Oder wenn es nicht anders geht auch in eine Script.
Ich will damit in meinem Mikrotik WLAN-Router die Anzahl der aktuellen Registrierungen abfragen. Im Mikrotik Forum habe ich dieses Script von einem netten Menschen bekommen, der sich leider nicht mit iobroker auskennt.
Danke Euch für einen Tipp
Gruß
Lothar

1 „Gefällt mir“

Hat keiner `ne Idee?

Die Frage wäre wohl in einem IO-Broker Forum besser aufgehoben.

1 „Gefällt mir“

Habe es mit Hilfe von jayjojayson und ChatGPT hinbekommen:

const exec = require('child_process').exec;
const USERNAME = 'deinBenutzername';
const PASSWORD = 'deinPasswort';
const URL = 'http://192.168.1.1/rest/interface/wireless/registration-table/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();

Das Skript führt die curl -Abfrage aus, zählt die Clients und speichert das Ergebnis in einem ioBroker-Datenpunkt (javascript.0.WirelessClientCount ). Es wird alle 5 Minuten automatisch ausgeführt und direkt beim Start einmalig gestartet.

1 „Gefällt mir“

Das ist hier ein Smart Home Forum. Also auch ioBroker.

<xml xmlns="https://developers.google.com/blockly/xml">
  <variables>
    <variable id="g[_P.ESpa).Q`VJQ3ExG">result</variable>
  </variables>
  <block type="http_post" id="*QJ79r}k,F8M8zQ)!glN" x="113" y="187">
    <field name="TIMEOUT">2000</field>
    <field name="UNIT">ms</field>
    <field name="TYPE">text</field>
    <value name="URL">
      <shadow type="text" id="^Ww~[yk|oQ{c-u!5=B#~">
        <field name="TEXT">http://benutzer:passwort@192.168.1.1/rest/interface/wireless/registration-table/print</field>
      </shadow>
    </value>
    <value name="DATA">
      <shadow type="logic_null" id="{WRN;tG:?0.TQYxkXKY%"></shadow>
      <block type="object_new" id="ga#oV)#EJK--`%/R4GAX">
        <mutation xmlns="http://www.w3.org/1999/xhtml">
          <attribute id="ATTR_0" name=".query"></attribute>
          <attribute id="ATTR_1" name="count-only"></attribute>
        </mutation>
        <value name="ATTR_0">
          <shadow type="text" id=",=;s=xFgV.h8Q*-G[hx8">
            <field name="TEXT"></field>
          </shadow>
          <block type="lists_create_with" id="bJ}b6fztOw%M|mpQGqg5">
            <mutation items="1"></mutation>
            <value name="ADD0">
              <block type="text" id="|}/IzLuML{be9.~,sf2[">
                <field name="TEXT">management-protection=false</field>
              </block>
            </value>
          </block>
        </value>
        <value name="ATTR_1">
          <shadow type="text" id="8LCpu0?ssU,t8bN9Az@(">
            <field name="TEXT"></field>
          </shadow>
          <block type="logic_boolean" id="M(/#9x#1$T]G+Ln6@Sa6">
            <field name="BOOL">TRUE</field>
          </block>
        </value>
      </block>
    </value>
    <statement name="STATEMENT">
      <block type="variables_set" id="ZODj24e4=f`C07.-EUcv">
        <field name="VAR" id="g[_P.ESpa).Q`VJQ3ExG">result</field>
        <value name="VALUE">
          <block type="convert_json2object" id="mIk87?D^7/Z#/:`lrrqy">
            <value name="VALUE">
              <block type="http_response" id="Bz*:kM*P_KH^##b(_YU9">
                <field name="ATTR">response.data</field>
              </block>
            </value>
          </block>
        </value>
      </block>
    </statement>
  </block>
</xml>
2 „Gefällt mir“

Der Matthias regelt wieder :grin:

1 „Gefällt mir“