Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JSON Werte in Datenpunkte

    NEWS

    • Neuer Blog: Fotos und Eindrücke aus Solingen

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

    • ioBroker goes Matter ... Matter Adapter in Stable

    JSON Werte in Datenpunkte

    This topic has been deleted. Only users with topic management privileges can see it.
    • Kevin
      Kevin @paul53 last edited by

      @paul53 said in JSON Werte in Datenpunkte:

                                                                                                                                  function iter(name, obj) {                                                                                                                                                                               for(let i in obj) {                                                                                                                                                                                  if(typeof obj[i] == 'object') iter(name + '.' + i, obj[i]);                                                                                                                                                                                  else {                                                                                                                                                                                     log(name + '.' + i + ': ' + obj[i]);                                                                                                                                                                                     if(existsState(name + '.' + i) setState(name + '.' + i, obj[i]);                                                                                                                                                                                     else createState(name + '.' + i, obj[i]); // type: "mixed"                                                                                                                                                                                  }                                                                                                                                                                               }                                                                                                                                                                            }                                                                                                                                                                                                                                                                                                                                                         function SendRequest(){                                                                                                                                                                                var options = {                                                                                                                                                                                    url: 'http://URLVON3DRUCKER',                                                                                                                                                                                };                                                                                                                                                                                request(options, function (error, response, body){                                                                                                                                                                                    if (!error) iter('0_userdata.0.3DPrinter', JSON.parse(body));                                                                                                                                                                                    else console.error(error);                                                                                                                                                                                });                                                                                                                                                                            }                                                                                                                                                                                                                                                                                                                                                         schedule('*/5 * * * * *', SendRequest);                                            
      

      Danke schon mal für dein Hilfe 🙂

      Leider hat es nicht ganz funktioniert:

      javascript.0	2020-07-29 22:56:55.543	error	(24214) at process._tickCallback (internal/process/next_tick.js:68:7)
      javascript.0	2020-07-29 22:56:55.543	error	(24214) at promise.then (/opt/iobroker/node_modules/standard-as-callback/built/index.js:19:49)
      javascript.0	2020-07-29 22:56:55.542	error	(24214) at tryCatcher (/opt/iobroker/node_modules/standard-as-callback/built/utils.js:11:23)
      javascript.0	2020-07-29 22:56:55.542	error	(24214) at client.get (/opt/iobroker/node_modules/iobroker.js-controller/lib/states/statesInRedis.js:616:17)
      javascript.0	2020-07-29 22:56:55.542	error	(24214) at adapter.getForeignState (/opt/iobroker/node_modules/iobroker.javascript/main.js:1124:17)
      javascript.0	2020-07-29 22:56:55.541	error	(24214) at createProblemObject (/opt/iobroker/node_modules/iobroker.javascript/main.js:1533:17)
      javascript.0	2020-07-29 22:56:55.541	error	(24214) at prepareScript (/opt/iobroker/node_modules/iobroker.javascript/main.js:1480:37)
      javascript.0	2020-07-29 22:56:55.541	error	(24214) at compile (/opt/iobroker/node_modules/iobroker.javascript/main.js:1257:28)
      javascript.0	2020-07-29 22:56:55.540	error	(24214) at Object.createScript (vm.js:277:10)
      javascript.0	2020-07-29 22:56:55.540	error	(24214) at new Script (vm.js:83:7)
      javascript.0	2020-07-29 22:56:55.540	error	(24214) SyntaxError: Unexpected identifier
      javascript.0	2020-07-29 22:56:55.539	error	(24214) ^^^^^^^^
      javascript.0	2020-07-29 22:56:55.539	error	(24214) if(existsState(name + '.' + i) setState(name + '.' + i, obj[i]);
      javascript.0	2020-07-29 22:56:55.539	error	at script.js.common.Skript_1:6
      javascript.0	2020-07-29 22:56:55.539	error	(24214) script.js.common.Skript_1 compile failed:
      
      paul53 1 Reply Last reply Reply Quote 0
      • paul53
        paul53 @Kevin last edited by

        @Kevin sagte:

        Leider hat es nicht ganz funktioniert:

        existsState(id) wird anscheinend angemeckert. Welche Version des Javascript-Adapters ?

        Kevin 1 Reply Last reply Reply Quote 0
        • Kevin
          Kevin @paul53 last edited by

          @paul53 Sollte eigentlich die aktuellste Version sein: 4.6.21

          paul53 1 Reply Last reply Reply Quote 0
          • paul53
            paul53 @Kevin last edited by paul53

            @Kevin
            Sorry, da fehlt eine schließende Klammer vor setState. Habe sie ergänzt.

            Kevin 1 Reply Last reply Reply Quote 0
            • Kevin
              Kevin @paul53 last edited by

              @paul53 Perfekt danke für die schnelle Hilfe. Genau wie ich es mir vorgestellt habe.

              paul53 1 Reply Last reply Reply Quote 0
              • paul53
                paul53 @Kevin last edited by

                @Kevin sagte:

                Genau wie ich es mir vorgestellt habe.

                Dann markiere bitte das Thema in der Überschrift des ersten Beitrags als [gelöst].

                Kevin 1 Reply Last reply Reply Quote 0
                • Kevin
                  Kevin @paul53 last edited by

                  @paul53 Ich habe noch eine Frage 🙂

                  Lässt sich verhindern, dass die Abfrage durchgeführt wird, wenn der Drucker ausgeschaltet ist?

                  javascript.0	2020-07-31 07:08:11.796	error	(24214) Request error: Error: connect ETIMEDOUT 91.15.159.27:8000
                  javascript.0	2020-07-31 07:08:11.795	error	(24214) script.js.common.3D_Printer: {'errno':'ETIMEDOUT','code':'ETIMEDOUT','syscall':'connect','address':'IP','port':8000}
                  
                  paul53 1 Reply Last reply Reply Quote 0
                  • paul53
                    paul53 @Kevin last edited by paul53

                    @Kevin sagte:

                    wenn der Drucker ausgeschaltet ist?

                    Wie kann man das feststellen ? Nur ping ?

                    Kevin 1 Reply Last reply Reply Quote 0
                    • Kevin
                      Kevin @paul53 last edited by

                      @paul53 Ich könnte es über einen Datenpunkt an der Fritzbox abfragen. Dann wäre Datenpunkt 3Drucker.active auf true sobald er im netzwerk ist

                      paul53 1 Reply Last reply Reply Quote 0
                      • paul53
                        paul53 @Kevin last edited by paul53

                        @Kevin sagte:

                        über einen Datenpunkt an der Fritzbox abfragen

                        Dann mache die Abfrage als erstes in der Funktion SendRequest().

                        function SendRequest(){
                          if(getState('abc.0.xyz.3Drucker.active').val) {
                            var options = {
                                url: 'http://URLVON3DRUCKER'
                            };
                            request(options, function (error, response, body){
                                if (!error) iter('0_userdata.0.3DPrinter', JSON.parse(body));
                                else console.error(error);
                            });
                          }
                        }
                        
                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post

                        Support us

                        ioBroker
                        Community Adapters
                        Donate

                        914
                        Online

                        31.8k
                        Users

                        80.0k
                        Topics

                        1.3m
                        Posts

                        4
                        18
                        4130
                        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