Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. [gelöst] XML in Datenpunkte aufteilen

    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

    [gelöst] XML in Datenpunkte aufteilen

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

      @Zygi
      Ersetze console.dir durch log.

      var parseString = require('xml2js').parseString;
      var xml = "<root>Hello xml2js!</root>"
      parseString(xml, function (err, result) {
          log(result);
      });
      

      xml2js.JPG

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

        @Zygi sagte:

        Client01-Name------------------->hdplus
        Client01-Type--------------------->r
        Client01-Online------------------->1584374911
        Client01-AU----------------------->0

        Damit solltest Du schon mal weiter kommen:

        const fs = require('fs');
        const path = '/opt/iobroker/iobroker-data/files/oscam.xml';
        const parser = require('xml2js').parseString;
         
        fs.readFile(path, function(err, data) {
            parser(data, function (err, result) {
                let clients = result.oscam.status[0].client;
                for(let i in clients) {
                    log(clients[i].$.name);
                    log(clients[i].$.type);
                    log(clients[i].$.au);
                    log(clients[i].times[0].$.online);
                }
            });
        });
        

        19:20:49.295	info	javascript.1 (7265) script.js.common.Test: root
        19:20:49.295	info	javascript.1 (7265) script.js.common.Test: h
        19:20:49.295	info	javascript.1 (7265) script.js.common.Test: 0
        19:20:49.295	info	javascript.1 (7265) script.js.common.Test: 1584374912
        19:20:49.295	info	javascript.1 (7265) script.js.common.Test: hdplus
        19:20:49.295	info	javascript.1 (7265) script.js.common.Test: r
        19:20:49.295	info	javascript.1 (7265) script.js.common.Test: -1
        19:20:49.295	info	javascript.1 (7265) script.js.common.Test: 1584374911
        19:20:49.295	info	javascript.1 (7265) script.js.common.Test: TVH-Server
        19:20:49.295	info	javascript.1 (7265) script.js.common.Test: c
        19:20:49.295	info	javascript.1 (7265) script.js.common.Test: -1
        19:20:49.295	info	javascript.1 (7265) script.js.common.Test: 1584374906
        19:20:49.295	info	javascript.1 (7265) script.js.common.Test: TVH-Wohnzimmer
        19:20:49.295	info	javascript.1 (7265) script.js.common.Test: c
        19:20:49.295	info	javascript.1 (7265) script.js.common.Test: -1
        19:20:49.295	info	javascript.1 (7265) script.js.common.Test: 1584374906
        

        1 Reply Last reply Reply Quote 1
        • Zygi
          Zygi last edited by

          Super Hilfe! Da wäre ich nie im leben drauf gekommen. Hab das ganze gerade ausprobiert und bekomme einen richtigen Output. Wie ich andere Werte ausgelesen bekomme, kriege ich auch schon hin.

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

            @Zygi sagte:

            bekomme einen richtigen Output.

            Bitte das Thema in der Überschrift des ersten Beitrags als [gelöst] markieren.

            1 Reply Last reply Reply Quote 0
            • Zygi
              Zygi last edited by

              Habe gerade mal ausprobiert die xml direkt per wget zu beziehen. Allerdings bekomme ich einen Fehler den ich nicht weg bekomme. Die XML scheint aber passend anzukommen da ich diese im Log angezeigt bekomme.

              Code

                var werte, result;
                  const fs = require('fs');
                      const path = (werte);
                      const parser = require('xml2js').parseString;
                  exec('wget -qO - -q -t=5 --user=admin --password=xxxx "http://192.168.10.1:83/oscamapi.html?part=status"', function (error, result, stderr) {
                      werte = result;
                      console.warn(werte);
                      fs.readFile(path, function(err, data) {
                          parser(data, function (err, result) {
                              let clients = result.oscam.status[0].client;
                              for(let i in clients) {
                                  log(clients[i].$.name);
                                  log(clients[i].$.type);
                                  log(clients[i].$.au);
                                  log(clients[i].times[0].$.online);
                              }
                          });
                      });
              });
              

              Fehler Log

              18:36:48.292	info	javascript.0 (26021) Start javascript script.js.Oscam.Skript_1
              18:36:48.315	info	javascript.0 (26021) script.js.Oscam.Skript_1: registered 0 subscriptions and 0 schedules
              18:36:48.594	warn	javascript.0 (26021) script.js.Oscam.Skript_1: <?xml version="1.0" encoding="UTF-8"?> <oscam version="1.20_svn build r11517" revision="11517" starttime="2020-03-19T16:34:18+0100" uptime="7350" readonly="0"> <status> <client type="s" name="root" desc="" protocol="server" protocolext="" au="0" thid="id_0x597018"> <request caid="0000" provid="000000" srvid="0000" ecmtime="" ecmhistory="" answered=""></request> <times login="2020-03-19T16:34:18+0100" online="7350" idle="1854"></times> <connection ip="127.0.0.1" port="0">OK</connection> </client> <client type="h" name="root" desc="" protocol="http" protocolext="" au="0" thid="id_0x59f758"> <request caid="0000" provid="000000" srvid="0000" ecmtime="" ecmhistory="" answered=""></request> <times login="2020-03-19T16:34:18+0100" online="7350" idle="0"></times> <connection ip="127.0.0.1" port="0">OK</connection> </client> <client type="r" name="hdplus" desc="" protocol="mouse" protocolext="" au="-1" thid="id_0x5a01d8"> <request caid="0000" provid="000000" srvid="0000" ecmtime="" ecmhistory="" answered=""></request> <times login="2020-03-19T16:34:19+0100" online="7349" idle="7349"></times> <connection ip="127.0.0.1" port="0">CARDOK</connection> </client> <client type="c" name="TVH-Wohnzimmer" desc="" protocol="newcamd (Tvheadend)" protocolext="" au="-1" thid="id_0x5b6db8"> <request caid="0000" provid="000000" srvid="0000" ecmtime="" ecmhistory="" answered=""></request> <times login="2020-03-19T16:34:24+0100" online="7344" idle="7344"></times> <connection ip="192.168.10.2" port="57256">OK</connection> </client> <client type="c" name="TVH-Server" desc="" protocol="newcamd (Tvheadend)" protocolext="" au="-1" thid="id_0x5b7838"> <request caid="0000" provid="000000" srvid="0000" ecmtime="" ecmhistory="" answered=""></request> <times login="2020-03-19T16:34:24+0100" online="7344" idle="7344"></times> <connection ip="192.168.10.2" port="42410">OK</connection> </client> </status> <log><![CDATA[ ]]></log></oscam>
              18:36:48.596	error	javascript.0 (26021) script.js.Oscam.Skript_1: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined
              18:36:48.599	error	javascript.0 (26021) at script.js.Oscam.Skript_1:8:12
              
              paul53 1 Reply Last reply Reply Quote 0
              • paul53
                paul53 @Zygi last edited by

                @Zygi sagte:

                xml direkt per wget zu beziehen.

                Wozu soll dann fs.readFile() dienen ?

                const parser = require('xml2js').parseString;
                
                exec('wget -qO - -q -t=5 --user=admin --password=xxxx "http://192.168.10.1:83/oscamapi.html?part=status"', function (error, result, stderr) {
                    let werte = result;
                    console.warn(werte);
                    parser(werte, function (err, result) {
                         let clients = result.oscam.status[0].client;
                         for(let i in clients) {
                               log(clients[i].$.name);
                               log(clients[i].$.type);
                               log(clients[i].$.au);
                               log(clients[i].times[0].$.online);
                         }
                     });
                });
                
                1 Reply Last reply Reply Quote 0
                • Zygi
                  Zygi last edited by

                  Tut mir leid, bin wie gesagt in Sachen Java leider totaler Anfänger und selbst manche Anleitung oder Erklärung in einem Forum ist für mich nicht zu verstehen...

                  Ich habe das "Grundkonstrukt" soweit jetzt fertig. Da wären jetzt nur noch 2 Sachen.

                  "i" hat nicht nur einen Wert sondern die Anzahl der Clients und das wohl als Liste, Array oder so. Wenn ich mir "i" im Log anzeigen lasse sind es zumindest mehrere Zeilen im Log mit jeweils immer nur einer Zahl, aber sortiert. Ich benötige hier den höchsten Wert einzeln. Deshalb hab ich versucht mir den letzten Wert mit "i[i.length-1]" ausgeben zu lassen, was aber nicht zu funktionieren scheint.

                  Jetzt will ich mit dem Höchstwert von "i" eine "If" Logik füttern. Habe ich diese hier an die richtige Stelle gesetzt oder muss diese wo anders hin? Aktuell habe ich nämlich das Problem das selbst wenn ich für "imax" eine Zahl von Hand eintippe, wird immer nur der "else" Teil ausgeführt.

                  var imax
                  const parser = require('xml2js').parseString;
                   
                  exec('wget -qO - -q -t=5 --user=admin --password=xxxx "http://192.168.10.1:83/oscamapi.html?part=status"', function (error, result, stderr) {
                      let werte = result;
                      console.warn(werte);
                      parser(werte, function (err, result) {
                           let clients = result.oscam.status[0].client;
                           for(let i in clients) {
                                 imax = i[i.length-1]	//höchsten i Wert ermitteln
                                 console.warn(imax)	//höchsten i Wert anzeigen
                  //
                  //
                  //Client-01            
                  
                              if (imax >= 1) {
                    	    setState("javascript.0.Oscam.Client01.01-Name"/*Client-01*/, '');
                              setState("javascript.0.Oscam.Client01.02-Type"/*Client-01*/, '');
                              setState("javascript.0.Oscam.Client01.03-Protocol"/*Client-01*/, '');
                              setState("javascript.0.Oscam.Client01.04-AU"/*Client-01*/, '');
                  }
                              setState("javascript.0.Oscam.Client01.01-Name"/*Client-01*/, clients[1].$.name);
                              setState("javascript.0.Oscam.Client01.02-Type"/*Client-01*/, clients[1].$.type);
                              setState("javascript.0.Oscam.Client01.03-Protocol"/*Client-01*/, clients[1].$.protocol);
                              setState("javascript.0.Oscam.Client01.04-AU"/*Client-01*/, clients[1].$.au);
                  //
                  //
                  //Client-02            
                  
                              if (imax >= 2) {
                    	    setState("javascript.0.Oscam.Client02.01-Name"/*Client-02*/, '');
                              setState("javascript.0.Oscam.Client02.02-Type"/*Client-02*/, '');
                              setState("javascript.0.Oscam.Client02.03-Protocol"/*Client-02*/, '');
                              setState("javascript.0.Oscam.Client02.04-AU"/*Client-02*/, '');
                  }
                              setState("javascript.0.Oscam.Client02.01-Name"/*Client-02*/, clients[2].$.name);
                              setState("javascript.0.Oscam.Client02.02-Type"/*Client-02*/, clients[2].$.type);
                              setState("javascript.0.Oscam.Client02.03-Protocol"/*Client-02*/, clients[2].$.protocol);
                              setState("javascript.0.Oscam.Client02.04-AU"/*Client-02*/, clients[2].$.au);
                  //
                  //
                  //werden bis zu 10 Clients
                  //
                  //				
                           }
                       });
                  });
                  

                  Tut mir leid für die ganze Fragerei, aber ich denke/hoffe das dies die letzten Fragen zu dem Skript sind.

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

                    @Zygi
                    clients ist ein Array. Verwende besser die for-Schleife:

                            let clients = result.oscam.status[0].client;
                            for(let i = 0; i < clients.length; i++) {
                                let j = i + 1;
                                if(j < 10) j = "0" + j;
                                setState("javascript.0.Oscam.Client" + j + ".01-Name", clients[i].$.name);
                                setState("javascript.0.Oscam.Client" + j + ".02-Type", clients[i].$.type);
                                setState("javascript.0.Oscam.Client" + j + ".03-Protocol", clients[i].$.protocol);
                                setState("javascript.0.Oscam.Client" + j + ".04-AU", clients[i].$.au);
                            }
                    
                    1 Reply Last reply Reply Quote 0
                    • Zygi
                      Zygi last edited by Zygi

                      Danke für die ganze Hilfe! Es läuft nun wie ich es mir vorgestellt habe.

                      Hier mal der Code falls jemand etwas ähnliches vor hat.

                      var imax, cmax;
                      function myScript() {  // zusätzliche Zeile am Anfang
                      const parser = require('xml2js').parseString;
                      exec('wget -qO - -q -t=5 --user=admin --password=XXXX "http://192.168.10.1:83/oscamapi.html?part=status"', function (error, result, stderr) {
                          let werte = result;
                          parser(werte, function (err, result) {
                               let clients = result.oscam.status[0].client;
                                  for(let i = 0; i < clients.length; i++) {
                                       let j = i + 1;
                                       if(j < 10) j = "0" + j;
                                       imax=j
                                      setState("javascript.0.Oscam.Client" + j + ".01-Name", clients[i].$.name);
                                      setState("javascript.0.Oscam.Client" + j + ".02-Type", clients[i].$.type);
                                      setState("javascript.0.Oscam.Client" + j + ".03-Protocol", clients[i].$.protocol);
                                      setState("javascript.0.Oscam.Client" + j + ".04-AU", clients[i].$.au);   		
                                  }
                              });
                              imax = parseFloat(imax);
                              while (!(imax > 10)) {
                              cmax = ("0" + imax).slice(-2)
                                  setState("javascript.0.Oscam.Client"+cmax+".01-Name", '');
                                  setState("javascript.0.Oscam.Client"+cmax+".02-Type", '');
                                  setState("javascript.0.Oscam.Client"+cmax+".03-Protocol", '');
                                  setState("javascript.0.Oscam.Client"+cmax+".04-AU", '');
                              imax = imax + 1;
                          }
                      });
                      };
                      schedule('*/5 * * * *', myScript);  // zusätzliches CRON
                      
                      1 Reply Last reply Reply Quote 0
                      • Zygi
                        Zygi last edited by

                        @paul53

                        Ich hab mich nachdem das ganze mit Oscam gut läuft mal an TVHeadend gewagt, habe aber ein komisches Problem. Und zwar läuft das Skript und trägt auch alles passend in Objekte ein. Ich bekomme aber im Log Warnungen. Wenn ich statt "setState" die Sachen in der Console ausgebe bekomme ich keine Warnungen.

                        XML input

                        <currentload>
                        <systemload>0.770000,0.550000,0.570000</systemload>
                        <recordings>
                        <recording>
                        <start>
                        <date>2020/03/23</date>
                        <time>19:30</time>
                        <unixtime>1584988200</unixtime>
                        <extra_start>240</extra_start>
                        </start>
                        <stop>
                        <date>2020/03/24</date>
                        <time>06:00</time>
                        <unixtime>1585026000</unixtime>
                        <extra_stop>240</extra_stop>
                        </stop>
                        <title>MediaShop</title>
                        <status>Recording</status>
                        </recording>
                        </recordings>
                        <subscriptions>1</subscriptions>
                        </currentload>
                        

                        Skirpt

                        const parser = require('xml2js').parseString;
                        exec('wget -qO - -q -t=5 --user=TVH --password=xxxx "http://192.168.5.206:9981/status.xml"', function (error, result, stderr) {
                        let werte = result
                        parser(werte, function (err, result) {
                           let xml1 = result.currentload;
                                if (xml1.recordings != '\n') {
                                    let xml2 = result.currentload.recordings[0].recording;
                                    for(let i = 0; i < xml2.length; i++) { 
                                    let j = i + 1;
                                    if(j < 2) j = "0" + j; 
                                        j = ("0" + j).slice(-2)
                                        setState("javascript.0.TVHeadend.Record" + j + ".01-Name", xml2[i].title);
                                        setState("javascript.0.TVHeadend.Record" + j + ".02-Start", xml2[i].start[0].time); 
                                        setState("javascript.0.TVHeadend.Record" + j + ".03-Ende", xml2[i].stop[0].time);     
                                        }
                                }
                         setState("javascript.0.TVHeadend.Zustand.01-Zustand", xml1.subscriptions)   
                        });
                        });
                        

                        Fehler im Log

                        22:35:00.928	info	javascript.0 (3741) Stop script script.js.TVH.Status_abrufen
                        22:35:01.082	info	javascript.0 (3741) Start javascript script.js.TVH.Status_abrufen
                        22:35:01.104	info	javascript.0 (3741) script.js.TVH.Status_abrufen: registered 0 subscriptions and 0 schedules
                        22:35:01.132	warn	javascript.0 (3741) at script.js.TVH.Status_abrufen:12:17
                        22:35:01.137	warn	javascript.0 (3741) at script.js.TVH.Status_abrufen:4:1
                        22:35:01.145	warn	javascript.0 (3741) at script.js.TVH.Status_abrufen:13:17
                        22:35:01.150	warn	javascript.0 (3741) at script.js.TVH.Status_abrufen:4:1
                        22:35:01.157	warn	javascript.0 (3741) at script.js.TVH.Status_abrufen:14:17
                        22:35:01.162	warn	javascript.0 (3741) at script.js.TVH.Status_abrufen:4:1
                        22:35:01.170	warn	javascript.0 (3741) at script.js.TVH.Status_abrufen:17:2
                        22:35:01.175	warn	javascript.0 (3741) at script.js.TVH.Status_abrufen:4:1
                        
                        paul53 1 Reply Last reply Reply Quote 0
                        • paul53
                          paul53 @Zygi last edited by paul53

                          @Zygi
                          Das Log ist wenig aussagekräftig. Mehr Informationen erhält man im Tab "Log".

                          Zu Zeile 10: Eine führende "0" fügt man Zahlen < 10 hinzu.

                          1 Reply Last reply Reply Quote 0
                          • Zygi
                            Zygi last edited by

                            @paul53

                            Hier mal aus dem Log. Er scheint zu versuchen ein Array in einen String zu schreiben, die Frage ist aber wieso ich jetzt ein Array ausgegeben bekomme und bei dem anderen Skript nicht?

                            2020-03-24 17:00:48.099  - info: javascript.0 (726) Start javascript script.js.TVH.Status_abrufen
                            2020-03-24 17:00:48.128  - info: javascript.0 (726) script.js.TVH.Status_abrufen: registered 0 subscriptions and 0 schedules
                            2020-03-24 17:00:48.154  - warn: javascript.0 (726) You are assigning a array to the state "javascript.0.TVHeadend.Record01.01-Name" which expects a string. Please fix your code to use a string or change the state type to array. This warning might become an error in future versions.
                            2020-03-24 17:00:48.159  - warn: javascript.0 (726)     at setState (/opt/iobroker/node_modules/iobroker.javascript/lib/sandbox.js:1404:20)
                            2020-03-24 17:00:48.160  - warn: javascript.0 (726)     at script.js.TVH.Status_abrufen:12:17
                            2020-03-24 17:00:48.160  - warn: javascript.0 (726)     at Parser.<anonymous> (/opt/iobroker/node_modules/xml2js/lib/parser.js:304:18)
                            2020-03-24 17:00:48.161  - warn: javascript.0 (726)     at Parser.emit (events.js:198:13)
                            2020-03-24 17:00:48.161  - warn: javascript.0 (726)     at SAXParser.onclosetag (/opt/iobroker/node_modules/xml2js/lib/parser.js:262:26)
                            2020-03-24 17:00:48.162  - warn: javascript.0 (726)     at emit (/opt/iobroker/node_modules/xml2js/node_modules/sax/lib/sax.js:624:35)
                            2020-03-24 17:00:48.162  - warn: javascript.0 (726)     at emitNode (/opt/iobroker/node_modules/xml2js/node_modules/sax/lib/sax.js:629:5)
                            2020-03-24 17:00:48.162  - warn: javascript.0 (726)     at closeTag (/opt/iobroker/node_modules/xml2js/node_modules/sax/lib/sax.js:889:7)
                            2020-03-24 17:00:48.163  - warn: javascript.0 (726)     at SAXParser.write (/opt/iobroker/node_modules/xml2js/node_modules/sax/lib/sax.js:1436:13)
                            2020-03-24 17:00:48.163  - warn: javascript.0 (726)     at Parser.exports.Parser.Parser.parseString (/opt/iobroker/node_modules/xml2js/lib/parser.js:323:31)
                            2020-03-24 17:00:48.163  - warn: javascript.0 (726)     at Parser.parseString (/opt/iobroker/node_modules/xml2js/lib/parser.js:5:59)
                            2020-03-24 17:00:48.164  - warn: javascript.0 (726)     at exports.parseString (/opt/iobroker/node_modules/xml2js/lib/parser.js:369:19)
                            2020-03-24 17:00:48.164  - warn: javascript.0 (726)     at script.js.TVH.Status_abrufen:4:1
                            2020-03-24 17:00:48.165  - warn: javascript.0 (726)     at ChildProcess.exithandler (child_process.js:285:7)
                            2020-03-24 17:00:48.165  - warn: javascript.0 (726)     at ChildProcess.emit (events.js:198:13)
                            2020-03-24 17:00:48.165  - warn: javascript.0 (726)     at maybeClose (internal/child_process.js:982:16)
                            2020-03-24 17:00:48.166  - warn: javascript.0 (726)     at Socket.stream.socket.on (internal/child_process.js:389:11)
                            2020-03-24 17:00:48.166  - warn: javascript.0 (726)     at Socket.emit (events.js:198:13)
                            2020-03-24 17:00:48.166  - warn: javascript.0 (726)     at Pipe._handle.close (net.js:607:12)
                            2020-03-24 17:00:48.167  - warn: javascript.0 (726) You are assigning a array to the state "javascript.0.TVHeadend.Record01.02-Start" which expects a string. Please fix your code to use a string or change the state type to array. This warning might become an error in future versions.
                            2020-03-24 17:00:48.170  - warn: javascript.0 (726)     at setState (/opt/iobroker/node_modules/iobroker.javascript/lib/sandbox.js:1404:20)
                            2020-03-24 17:00:48.171  - warn: javascript.0 (726)     at script.js.TVH.Status_abrufen:13:17
                            2020-03-24 17:00:48.171  - warn: javascript.0 (726)     at Parser.<anonymous> (/opt/iobroker/node_modules/xml2js/lib/parser.js:304:18)
                            2020-03-24 17:00:48.172  - warn: javascript.0 (726)     at Parser.emit (events.js:198:13)
                            2020-03-24 17:00:48.172  - warn: javascript.0 (726)     at SAXParser.onclosetag (/opt/iobroker/node_modules/xml2js/lib/parser.js:262:26)
                            2020-03-24 17:00:48.173  - warn: javascript.0 (726)     at emit (/opt/iobroker/node_modules/xml2js/node_modules/sax/lib/sax.js:624:35)
                            2020-03-24 17:00:48.173  - warn: javascript.0 (726)     at emitNode (/opt/iobroker/node_modules/xml2js/node_modules/sax/lib/sax.js:629:5)
                            2020-03-24 17:00:48.173  - warn: javascript.0 (726)     at closeTag (/opt/iobroker/node_modules/xml2js/node_modules/sax/lib/sax.js:889:7)
                            2020-03-24 17:00:48.174  - warn: javascript.0 (726)     at SAXParser.write (/opt/iobroker/node_modules/xml2js/node_modules/sax/lib/sax.js:1436:13)
                            2020-03-24 17:00:48.174  - warn: javascript.0 (726)     at Parser.exports.Parser.Parser.parseString (/opt/iobroker/node_modules/xml2js/lib/parser.js:323:31)
                            2020-03-24 17:00:48.174  - warn: javascript.0 (726)     at Parser.parseString (/opt/iobroker/node_modules/xml2js/lib/parser.js:5:59)
                            2020-03-24 17:00:48.175  - warn: javascript.0 (726)     at exports.parseString (/opt/iobroker/node_modules/xml2js/lib/parser.js:369:19)
                            2020-03-24 17:00:48.175  - warn: javascript.0 (726)     at script.js.TVH.Status_abrufen:4:1
                            2020-03-24 17:00:48.175  - warn: javascript.0 (726)     at ChildProcess.exithandler (child_process.js:285:7)
                            2020-03-24 17:00:48.176  - warn: javascript.0 (726)     at ChildProcess.emit (events.js:198:13)
                            2020-03-24 17:00:48.176  - warn: javascript.0 (726)     at maybeClose (internal/child_process.js:982:16)
                            2020-03-24 17:00:48.176  - warn: javascript.0 (726)     at Socket.stream.socket.on (internal/child_process.js:389:11)
                            2020-03-24 17:00:48.177  - warn: javascript.0 (726)     at Socket.emit (events.js:198:13)
                            2020-03-24 17:00:48.177  - warn: javascript.0 (726)     at Pipe._handle.close (net.js:607:12)
                            2020-03-24 17:00:48.178  - warn: javascript.0 (726) You are assigning a array to the state "javascript.0.TVHeadend.Record01.03-Ende" which expects a string. Please fix your code to use a string or change the state type to array. This warning might become an error in future versions.
                            2020-03-24 17:00:48.181  - warn: javascript.0 (726)     at setState (/opt/iobroker/node_modules/iobroker.javascript/lib/sandbox.js:1404:20)
                            2020-03-24 17:00:48.181  - warn: javascript.0 (726)     at script.js.TVH.Status_abrufen:14:17
                            2020-03-24 17:00:48.182  - warn: javascript.0 (726)     at Parser.<anonymous> (/opt/iobroker/node_modules/xml2js/lib/parser.js:304:18)
                            2020-03-24 17:00:48.183  - warn: javascript.0 (726)     at Parser.emit (events.js:198:13)
                            2020-03-24 17:00:48.183  - warn: javascript.0 (726)     at SAXParser.onclosetag (/opt/iobroker/node_modules/xml2js/lib/parser.js:262:26)
                            2020-03-24 17:00:48.184  - warn: javascript.0 (726)     at emit (/opt/iobroker/node_modules/xml2js/node_modules/sax/lib/sax.js:624:35)
                            2020-03-24 17:00:48.184  - warn: javascript.0 (726)     at emitNode (/opt/iobroker/node_modules/xml2js/node_modules/sax/lib/sax.js:629:5)
                            2020-03-24 17:00:48.184  - warn: javascript.0 (726)     at closeTag (/opt/iobroker/node_modules/xml2js/node_modules/sax/lib/sax.js:889:7)
                            2020-03-24 17:00:48.185  - warn: javascript.0 (726)     at SAXParser.write (/opt/iobroker/node_modules/xml2js/node_modules/sax/lib/sax.js:1436:13)
                            2020-03-24 17:00:48.185  - warn: javascript.0 (726)     at Parser.exports.Parser.Parser.parseString (/opt/iobroker/node_modules/xml2js/lib/parser.js:323:31)
                            2020-03-24 17:00:48.185  - warn: javascript.0 (726)     at Parser.parseString (/opt/iobroker/node_modules/xml2js/lib/parser.js:5:59)
                            2020-03-24 17:00:48.186  - warn: javascript.0 (726)     at exports.parseString (/opt/iobroker/node_modules/xml2js/lib/parser.js:369:19)
                            2020-03-24 17:00:48.186  - warn: javascript.0 (726)     at script.js.TVH.Status_abrufen:4:1
                            2020-03-24 17:00:48.187  - warn: javascript.0 (726)     at ChildProcess.exithandler (child_process.js:285:7)
                            2020-03-24 17:00:48.187  - warn: javascript.0 (726)     at ChildProcess.emit (events.js:198:13)
                            2020-03-24 17:00:48.187  - warn: javascript.0 (726)     at maybeClose (internal/child_process.js:982:16)
                            2020-03-24 17:00:48.188  - warn: javascript.0 (726)     at Socket.stream.socket.on (internal/child_process.js:389:11)
                            2020-03-24 17:00:48.188  - warn: javascript.0 (726)     at Socket.emit (events.js:198:13)
                            2020-03-24 17:00:48.189  - warn: javascript.0 (726)     at Pipe._handle.close (net.js:607:12)
                            2020-03-24 17:00:48.190  - warn: javascript.0 (726) You are assigning a array to the state "javascript.0.TVHeadend.Zustand.01-Zustand" which expects a string. Please fix your code to use a string or change the state type to array. This warning might become an error in future versions.
                            2020-03-24 17:00:48.192  - warn: javascript.0 (726)     at setState (/opt/iobroker/node_modules/iobroker.javascript/lib/sandbox.js:1404:20)
                            2020-03-24 17:00:48.193  - warn: javascript.0 (726)     at script.js.TVH.Status_abrufen:17:2
                            2020-03-24 17:00:48.193  - warn: javascript.0 (726)     at Parser.<anonymous> (/opt/iobroker/node_modules/xml2js/lib/parser.js:304:18)
                            2020-03-24 17:00:48.194  - warn: javascript.0 (726)     at Parser.emit (events.js:198:13)
                            2020-03-24 17:00:48.195  - warn: javascript.0 (726)     at SAXParser.onclosetag (/opt/iobroker/node_modules/xml2js/lib/parser.js:262:26)
                            2020-03-24 17:00:48.195  - warn: javascript.0 (726)     at emit (/opt/iobroker/node_modules/xml2js/node_modules/sax/lib/sax.js:624:35)
                            2020-03-24 17:00:48.196  - warn: javascript.0 (726)     at emitNode (/opt/iobroker/node_modules/xml2js/node_modules/sax/lib/sax.js:629:5)
                            2020-03-24 17:00:48.196  - warn: javascript.0 (726)     at closeTag (/opt/iobroker/node_modules/xml2js/node_modules/sax/lib/sax.js:889:7)
                            2020-03-24 17:00:48.196  - warn: javascript.0 (726)     at SAXParser.write (/opt/iobroker/node_modules/xml2js/node_modules/sax/lib/sax.js:1436:13)
                            2020-03-24 17:00:48.197  - warn: javascript.0 (726)     at Parser.exports.Parser.Parser.parseString (/opt/iobroker/node_modules/xml2js/lib/parser.js:323:31)
                            2020-03-24 17:00:48.197  - warn: javascript.0 (726)     at Parser.parseString (/opt/iobroker/node_modules/xml2js/lib/parser.js:5:59)
                            2020-03-24 17:00:48.198  - warn: javascript.0 (726)     at exports.parseString (/opt/iobroker/node_modules/xml2js/lib/parser.js:369:19)
                            2020-03-24 17:00:48.198  - warn: javascript.0 (726)     at script.js.TVH.Status_abrufen:4:1
                            2020-03-24 17:00:48.199  - warn: javascript.0 (726)     at ChildProcess.exithandler (child_process.js:285:7)
                            2020-03-24 17:00:48.199  - warn: javascript.0 (726)     at ChildProcess.emit (events.js:198:13)
                            2020-03-24 17:00:48.200  - warn: javascript.0 (726)     at maybeClose (internal/child_process.js:982:16)
                            2020-03-24 17:00:48.200  - warn: javascript.0 (726)     at Socket.stream.socket.on (internal/child_process.js:389:11)
                            2020-03-24 17:00:48.200  - warn: javascript.0 (726)     at Socket.emit (events.js:198:13)
                            2020-03-24 17:00:48.201  - warn: javascript.0 (726)     at Pipe._handle.close (net.js:607:12)
                            
                            paul53 1 Reply Last reply Reply Quote 0
                            • paul53
                              paul53 @Zygi last edited by paul53

                              @Zygi sagte:

                              You are assigning a array to the state "javascript.0.TVHeadend.Zustand.01-Zustand" which expects a string.

                              Davon gibt es mehrere Zeilen, in denen steht, was falsch ist. Bevor Du einen Wert mit setState() schreibst, schaue den Wert erst einmal per log an.

                              EDIT:

                                              setState("javascript.0.TVHeadend.Record" + j + ".01-Name", xml2[i].title[0]);
                                              setState("javascript.0.TVHeadend.Record" + j + ".02-Start", xml2[i].start[0].time[0]); 
                                              setState("javascript.0.TVHeadend.Record" + j + ".03-Ende", xml2[i].stop[0].time[0]);     
                              
                              1 Reply Last reply Reply Quote 0
                              • Zygi
                                Zygi last edited by

                                @paul53

                                Habe das ganze vorher alles im Log ausgegeben. Dort ist mir aber nicht bewusst aufgefallen das die Sachen wie folgt ausgegeben werden: ['Ausgabewert'] . Warum werden die Werte hier vom Parser anders ausgegeben?

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

                                  @Zygi sagte :

                                  Warum werden die Werte hier vom Parser anders ausgegeben?

                                  Der Parser wandelt das um, was im XML vorhanden ist.

                                  1 Reply Last reply Reply Quote 0
                                  • Zygi
                                    Zygi last edited by Zygi

                                    @paul53
                                    Komisch ist, dass das Skript trotz Warnung richtig läuft. Alle Werte werden korrekt und ohne Klammern und Anführungszeichen in den State geschrieben. Die Warnungen würden aber den Log unnötig zumüllen.

                                    Gibt es eine einfache Methode ein Array in einen String umzuwandeln? Mit String.valueOf() bekomme ich einen Compile Fehler.

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

                                      @Zygi sagte:

                                      Gibt es eine einfache Methode ein Array in einen String umzuwandeln?

                                      So wie ich es hier gezeigt habe: [0] anhängen.

                                      1 Reply Last reply Reply Quote 0
                                      • First post
                                        Last post

                                      Support us

                                      ioBroker
                                      Community Adapters
                                      Donate

                                      815
                                      Online

                                      31.8k
                                      Users

                                      80.0k
                                      Topics

                                      1.3m
                                      Posts

                                      blockly javascript multimedia
                                      2
                                      21
                                      1539
                                      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