Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. Curl einbinden? json danach abfragen

    NEWS

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    • Monatsrückblick - April 2025

    Curl einbinden? json danach abfragen

    This topic has been deleted. Only users with topic management privileges can see it.
    • B
      bluppdiwupp last edited by

      Ich benötige mal ein paar Tips.
      Ich habe eine ECU für einen Wechselrichter und würde aus diesen gerne Werte erhalten um sie später mit Grafana darzustellen.
      IO und Grafana laufen bereits. Auch läuft die Script Engine.

      Jetzt habe ich 2 Abfragen gefunden und kann damit leider nicht viel anfangen, da ich sehr neu in dem Thema bin.

      Erste Curl Abfrage:

      
      curl -H "Content-Type: application/x-www-form-urlencoded" http://api.apsystemsema.com:8073/apsema/v1/ecu/getPowerInfo -d ecuId=<ECU ID> -d filter=power -d date=<date> -o <date>.json
      

      dann soll noch folgendes eingebunden werden:

      
      const fs = require('fs');
      
      // usage: node json2csv <file.json>, so filename is 3rd parameter
      let filename = process.argv[2];
      
      // read and parse input JSON file
      let contents = fs.readFileSync(filename, 'utf8');
      let data = JSON.parse(contents);
      let timestamps = JSON.parse(data.data.time);
      let values = JSON.parse(data.data.power);
      
      // iterate through two arrays and combine the i'th element of each into one CSV line
      for(let i = 0; i < timestamps.length; i++) {
        console.log(`"${timestamps[i]}","${values[i]}"`);
      }
      

      Ich bekomme leider keine Ergebnisse oder nur Errors im Log.

      Viele Grüße

      Thomas Braun UncleSam 2 Replies Last reply Reply Quote 0
      • Thomas Braun
        Thomas Braun Most Active @bluppdiwupp last edited by

        @bluppdiwupp Umd die Fehler im Log unterliegen der Geheimhaltung?

        B 1 Reply Last reply Reply Quote 0
        • UncleSam
          UncleSam Developer @bluppdiwupp last edited by

          @bluppdiwupp Hast du dir mal den Parser Adapter angeschaut?

          Und sonst: anstatt curl aus JavaScript aufzurufen, würde ich die Bordmittel von NodeJS verwenden:

          const http = require('http');
          

          oder wenn du es ganz "nobel" willst, gibt es noch Axios: https://www.npmjs.com/package/axios

          B 1 Reply Last reply Reply Quote 0
          • B
            bluppdiwupp @Thomas Braun last edited by

            @Thomas-Braun

            anbei der Log:

            
            javascript.0	2021-01-11 17:10:55.839	error	(676) at processTicksAndRejections (internal/process/task_queues.js:97:5)
            javascript.0	2021-01-11 17:10:55.839	error	(676) at runMicrotasks (<anonymous>)
            javascript.0	2021-01-11 17:10:55.838	error	(676) at /opt/iobroker/node_modules/standard-as-callback/built/index.js:19:49
            javascript.0	2021-01-11 17:10:55.838	error	(676) at tryCatcher (/opt/iobroker/node_modules/standard-as-callback/built/utils.js:11:23)
            javascript.0	2021-01-11 17:10:55.837	error	(676) at /opt/iobroker/node_modules/iobroker.js-controller/lib/states/statesInRedis.js:616:17
            javascript.0	2021-01-11 17:10:55.837	error	(676) at /opt/iobroker/node_modules/iobroker.javascript/main.js:1140:17
            javascript.0	2021-01-11 17:10:55.836	error	(676) at /opt/iobroker/node_modules/iobroker.javascript/main.js:1559:17
            javascript.0	2021-01-11 17:10:55.836	error	(676) at prepareScript (/opt/iobroker/node_modules/iobroker.javascript/main.js:1503:37)
            javascript.0	2021-01-11 17:10:55.836	error	(676) at createVM (/opt/iobroker/node_modules/iobroker.javascript/main.js:1280:28)
            javascript.0	2021-01-11 17:10:55.835	error	(676) at Object.createScript (vm.js:261:10)
            javascript.0	2021-01-11 17:10:55.835	error	(676) at new Script (vm.js:88:7)
            javascript.0	2021-01-11 17:10:55.834	error	(676) SyntaxError: Unexpected string
            javascript.0	2021-01-11 17:10:55.831	error	(676) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            javascript.0	2021-01-11 17:10:55.830	error	(676) curl -H "Content-Type: application/x-www-form-urlencoded" http://api.apsystemsema.com:8073/apsema/v1/ecu/getPowerInfo -d ecuId=<ECU ID> -d filter=power -d date=<date> -o <date>.json
            javascript.0	2021-01-11 17:10:55.829	error	at script.js.common.APSystem:1
            javascript.0	2021-01-11 17:10:55.829	error	(676) script.js.common.APSystem compile failed:
            
            1 Reply Last reply Reply Quote 0
            • B
              bluppdiwupp @UncleSam last edited by

              @UncleSam
              das klingt interessant.
              Leider komme ich nicht mir der Umschreibung der URL klar.
              Hier habe ich ja noch etwas vor und nach der URL stehen. Wo kommt dies dann hin?

              UncleSam 1 Reply Last reply Reply Quote 0
              • UncleSam
                UncleSam Developer @bluppdiwupp last edited by

                @bluppdiwupp sagte in Curl einbinden? json danach abfragen:

                Hier habe ich ja noch etwas vor und nach der URL stehen. Wo kommt dies dann hin?

                Für axios ist hier zum Beispiel eine Erklärung:
                https://stackoverflow.com/a/64351892

                Oder etwas ausführlicher:
                https://flaviocopes.com/axios-urlencoded/

                B 1 Reply Last reply Reply Quote 0
                • B
                  bluppdiwupp @UncleSam last edited by bluppdiwupp

                  @unclesam
                  ich habe die halbe Nacht gesucht und gemacht. Leider ohne Erfolg...

                  dies wäre mein Ergebnis mit dem Log:

                  const response: any = await axios.post(http://api.apsystemsema.com:8073/apsema/v1/ecu/getPowerInfo -d ecuId=<xxx> -d filter=power -d date=<date> -o <date>.json, {
                                  headers: {
                                      'Content-Type': 'application/x-www-form-urlencoded'
                                  }
                              });
                  
                  const fs = require('fs');
                  
                  // usage: node json2csv <file.json>, so filename is 3rd parameter
                  let filename = process.argv[2];
                  
                  // read and parse input JSON file
                  let contents = fs.readFileSync(filename, 'utf8');
                  let data = JSON.parse(contents);
                  let timestamps = JSON.parse(data.data.time);
                  let values = JSON.parse(data.data.power);
                  
                  // iterate through two arrays and combine the i'th element of each into one CSV line
                  for(let i = 0; i < timestamps.length; i++) {
                    console.log(`"${timestamps[i]}","${values[i]}"`);
                  }
                  
                  javascript.0	2021-01-12 08:22:54.566	error	(758) at processTicksAndRejections (internal/process/task_queues.js:97:5)
                  javascript.0	2021-01-12 08:22:54.566	error	(758) at runMicrotasks (<anonymous>)
                  javascript.0	2021-01-12 08:22:54.565	error	(758) at /opt/iobroker/node_modules/standard-as-callback/built/index.js:19:49
                  javascript.0	2021-01-12 08:22:54.564	error	(758) at tryCatcher (/opt/iobroker/node_modules/standard-as-callback/built/utils.js:11:23)
                  javascript.0	2021-01-12 08:22:54.564	error	(758) at /opt/iobroker/node_modules/iobroker.js-controller/lib/states/statesInRedis.js:616:17
                  javascript.0	2021-01-12 08:22:54.564	error	(758) at /opt/iobroker/node_modules/iobroker.javascript/main.js:1140:17
                  javascript.0	2021-01-12 08:22:54.563	error	(758) at /opt/iobroker/node_modules/iobroker.javascript/main.js:1559:17
                  javascript.0	2021-01-12 08:22:54.563	error	(758) at prepareScript (/opt/iobroker/node_modules/iobroker.javascript/main.js:1503:37)
                  javascript.0	2021-01-12 08:22:54.563	error	(758) at createVM (/opt/iobroker/node_modules/iobroker.javascript/main.js:1280:28)
                  javascript.0	2021-01-12 08:22:54.562	error	(758) at Object.createScript (vm.js:261:10)
                  javascript.0	2021-01-12 08:22:54.562	error	(758) at new Script (vm.js:88:7)
                  javascript.0	2021-01-12 08:22:54.562	error	(758) SyntaxError: Missing initializer in const declaration
                  javascript.0	2021-01-12 08:22:54.561	error	(758) ^^^^^^^^
                  javascript.0	2021-01-12 08:22:54.561	error	(758) const response: any = await axios.post(http://api.apsystemsema.com:8073/apsema/v1/ecu/getPowerInfo -d ecuId=<216000043804> -d filter=power -d date=<date> -o <date>.json, {
                  javascript.0	2021-01-12 08:22:54.560	error	at script.js.common.APSystem:1
                  javascript.0	2021-01-12 08:22:54.560	error	(758) script.js.common.APSystem compile failed:
                  
                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post

                  Support us

                  ioBroker
                  Community Adapters
                  Donate

                  987
                  Online

                  31.7k
                  Users

                  79.6k
                  Topics

                  1.3m
                  Posts

                  javascript
                  3
                  7
                  668
                  Loading More Posts
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes
                  Reply
                  • Reply as topic
                  Log in to reply
                  Community
                  Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
                  The ioBroker Community 2014-2023
                  logo