Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Visualisierung
    4. [gelöst] - VIS Intance Id - automatisiert ermitteln

    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] - VIS Intance Id - automatisiert ermitteln

    This topic has been deleted. Only users with topic management privileges can see it.
    • liv-in-sky
      liv-in-sky @BananaJoe last edited by liv-in-sky

      @bananajoe sagte in VIS Intance Id - automatisiert ermitteln:

      Die waitForElement wartet, wenn einfach so rauskopiert, nämlich nur 100 Durchläufe mit je 1ms pause

      das kann natürlich zu wenig sein, wenn man eine "volle" vis hat - ich habe ja ein leeres project - da geht das dann schneller

      @bahnuhr
      habe dein gepostetes beispiel genommen - die widgets angeglichen und es läuft

      probiermal die längere pause - also dasbeispiel von @BananaJoe

      function waitForElement(parent, elementPath, wid, widgetName, callBack, counter = 0, debug = false) {
      
               if (counter < 30) {
      
                   setTimeout(function () {
      
                       if (parent.find(elementPath).length > 0) {
      
                           if (debug) console.log(`[${widgetName} ${wid}] it took ${counter}ms to wait for the element '${elementPath}'`);
      
                           callBack();
      
                       } else {
      
                           if (debug) console.log(`[${widgetName} ${wid}] wait for element '${elementPath}'`);
      
                           counter++
      
                           waitForElement(parent, elementPath, wid, widgetName, callBack, counter, debug);
      
                       }
      
                   }, 1000);
      
               } else {
      
                  if (debug) console.warn(`[${widgetName} ${wid}] stop waiting after ${counter} retries`);
      
                   callBack();
      
              }
      
          }
      
       
      

      da wird 30 mal eine sekunde gewartet - das sollte reichen

      bei meinem beispiel sind es 100 mal 1ms - das ist kurz - da hatt' er recht

      1 Reply Last reply Reply Quote 0
      • liv-in-sky
        liv-in-sky last edited by

        und mir ist noch was aufgefallen:#

        waitForElement($('body'),'vis.instance', 'dummy', 'dummy', function () {
        
                 // Widget ist vollständig geladen, wir können irgendwas damit machen
        
           console.log(vis.instance)
        
            $( "#w00002" ).text( 'Warten auf VIS-Instance Instance ID: '+vis.instance);
        
            }, 0, true);
        

        dieser block funktioniert nicht wirklich - es wird nicht gewartet, bis das object vis.instance da ist - daher war es eine gute idee von @BananaJoe auf das basic -Screen Resolution) Widget zu warten

        @scrounger könntest du mir helfen - kann ich mit deiner waitForElement function auch warten, bis vis.instance verfügbar ist

        bahnuhr 1 Reply Last reply Reply Quote 0
        • bahnuhr
          bahnuhr Forum Testing Most Active @liv-in-sky last edited by

          @liv-in-sky
          @BananaJoe

          Script von @BananaJoe hat geklappt.
          Auch bei edge im Kiosk Modus.

          @bananajoe sagte in VIS Intance Id - automatisiert ermitteln:

          Wegen der IP: Ich meine mich erinnern zu können das es so - mit Absicht - nicht möglich ist.

          Das wäre sehr schade. Im Netz gibt es zahlreiche Scripte.
          Nur bekomme ich dies nicht hin.
          Vielleicht ist ja noch ein Spezi da, der mit liest.

          BananaJoe 1 Reply Last reply Reply Quote 0
          • BananaJoe
            BananaJoe Most Active @bahnuhr last edited by

            @bahnuhr bin gerade am probieren. Aber es wird darauf hinauslaufen das es einen Dienst im Netzwerk geben muss der dir deine eigene IP verrät. Ich suche gerade nach dem einfachsten Weg dafür.

            Ich hab das sonstin PHP als Unterwebseite auf meinem Apache Webserver liegen ... das klingt aber sehr aufwändig für einen Ottonormal-ioBroker-Benutzer ...

            bahnuhr 1 Reply Last reply Reply Quote 0
            • bahnuhr
              bahnuhr Forum Testing Most Active @BananaJoe last edited by

              @bananajoe

              natürlich das Script von @Jey-Cee

              und weitere aus dem Netz:

                  window.RTCPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection;   //compatibility for firefox and chrome
                  var pc = new RTCPeerConnection({iceServers:[]}), noop = function(){};      
                  pc.createDataChannel("");    //create a bogus data channel
                  pc.createOffer(pc.setLocalDescription.bind(pc), noop);    // create offer and set local description
                  pc.onicecandidate = function(ice){  //listen for candidate events
                      if(!ice || !ice.candidate || !ice.candidate.candidate)  return;
                      var myIP = /([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/.exec(ice.candidate.candidate)[1];
                      console.log('my IP: ', myIP);   
                      pc.onicecandidate = noop;
                  };
              
              // cleaned, 363b
              const ip = await new Promise((resolve, reject) => {
                const conn = new RTCPeerConnection()
                conn.createDataChannel('')
                conn.createOffer(offer => conn.setLocalDescription(offer), reject)
                conn.onicecandidate = ice => {
                  if (ice && ice.candidate && ice.candidate.candidate) {
                    resolve(i.candidate.candidate.split(' ')[4])
                    conn.close()
                  }
                }
              })
              
              /**
               * Get the user IP throught the webkitRTCPeerConnection
               * @param onNewIP {Function} listener function to expose the IP locally
               * @return undefined
               */
              function getUserIP(onNewIP) { //  onNewIp - your listener function for new IPs
                  //compatibility for firefox and chrome
                  var myPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection;
                  var pc = new myPeerConnection({
                      iceServers: []
                  }),
                  noop = function() {},
                  localIPs = {},
                  ipRegex = /([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/g,
                  key;
              
                  function iterateIP(ip) {
                      if (!localIPs[ip]) onNewIP(ip);
                      localIPs[ip] = true;
                  }
              
                   //create a bogus data channel
                  pc.createDataChannel("");
              
                  // create offer and set local description
                  pc.createOffer().then(function(sdp) {
                      sdp.sdp.split('\n').forEach(function(line) {
                          if (line.indexOf('candidate') < 0) return;
                          line.match(ipRegex).forEach(iterateIP);
                      });
              
                      pc.setLocalDescription(sdp, noop, noop);
                  }).catch(function(reason) {
                      // An error occurred, so handle the failure to connect
                  });
              
                  //listen for candidate events
                  pc.onicecandidate = function(ice) {
                      if (!ice || !ice.candidate || !ice.candidate.candidate || !ice.candidate.candidate.match(ipRegex)) return;
                      ice.candidate.candidate.match(ipRegex).forEach(iterateIP);
                  };
              }
              
              // Usage
              
              getUserIP(function(ip){
                  alert("Got IP! :" + ip);
              });
              

              Aber wie gesagt, ich glaube das übersteigt meine Kenntnisse.

              liv-in-sky BananaJoe 2 Replies Last reply Reply Quote 0
              • liv-in-sky
                liv-in-sky @bahnuhr last edited by liv-in-sky

                @bahnuhr

                zur not mach dir eine tabelle mit instance und ip`s dazu - dann kannst du je instance id auch die ip ausgeben

                muss halt gepflegt werden

                bahnuhr 1 Reply Last reply Reply Quote 0
                • bahnuhr
                  bahnuhr Forum Testing Most Active @liv-in-sky last edited by

                  @liv-in-sky sagte in VIS Intance Id - automatisiert ermitteln:

                  @bahnuhr

                  zur not mach dir eine tabelle mit instance und ip`s dazu - dann kannst du je instance id auch die ip ausgeben

                  muss halt gepflegt werden

                  genau das geht eben nicht.

                  Hintergrund:
                  Ich wollte auf dem Tablet im Wohnzimmer (win10) edge im kiosk mode einrichten.
                  Nur da wird die Instanz nur erzeugt wenn man klickt. Und diese ändert sich dann ständig.
                  Die IP ist aber immer gleich.

                  Ich müsste also wissen, welche IP die instanz sendet um dann zu beurteilen welcher PC / Laptop neu die VIS aufgebaut hat.

                  liv-in-sky 1 Reply Last reply Reply Quote 0
                  • liv-in-sky
                    liv-in-sky @bahnuhr last edited by liv-in-sky

                    @bahnuhr
                    hast du mal den vis-editor im kioskmode mit dem pc aufgemacht - ich glaube, so bekommt man eine feste instance id - kann mich aber auch täuschen - da gab es doch Browser ID erzeugen als menu punkt im editor

                    BananaJoe 1 Reply Last reply Reply Quote 0
                    • BananaJoe
                      BananaJoe Most Active @liv-in-sky last edited by

                      @liv-in-sky Es geht halt darum zuverlässig zu erkennen welcher Client da kommt. Wenn ich auf meinen PC 3 verschiedene Browser nutze kommen da auch 3 verschiedene Instance ID.

                      Beim Fully Kiosk muss man aufpassen wenn er den Cache löscht / was er löscht.

                      Die Idee hier hinter ist ja das einfach ein paar Datenpunkte hat in denen man nachsehen kann welche ID das Tablet im Wohnzimmer gerade hat. Und das das Tablet die aktualisiert falls di sich ändert 🙂

                      liv-in-sky 1 Reply Last reply Reply Quote 0
                      • liv-in-sky
                        liv-in-sky @BananaJoe last edited by liv-in-sky

                        @bananajoe

                        das habe ich verstanden

                        ein pc , zwei browser - einmal chrome, einmal edge und die id dazu

                        Image 3.png

                        hier ausgewählt

                        Image 5.png

                        sind auch nach neustart noch da

                        BananaJoe 1 Reply Last reply Reply Quote 0
                        • BananaJoe
                          BananaJoe Most Active @bahnuhr last edited by

                          @bahnuhr ja, die Beispiele habe ich alle durch.
                          Was ich zum funktionieren bekomme habe, ist z.B. per

                          $.getJSON('http://internerserver/meineip.php', function(data) {
                                      console.log(JSON.stringify(data, null, 2));
                                      alert(data.ipAddress);
                          

                          Die Adresse zu bekommen. Der Webserver muss dafür als Text

                          { "ipAddress":"192.168.1.99" }
                          

                          zurückgeben was mit einem .php Skript ginge:

                          <?php  
                          echo '{ "ipAddress":"'.$_SERVER['REMOTE_ADDR'].'"}';  
                          ?>  
                          

                          Aber wie gesagt suche ich nach einer "ich hab nur den ioBroker Server und will nicht extra einen Webserver aufsetzen" Lösung

                          1 Reply Last reply Reply Quote 0
                          • BananaJoe
                            BananaJoe Most Active @liv-in-sky last edited by

                            @liv-in-sky jepp. Bis man den Cache löscht. Was Fully meine ich sogar default macht beim Neuladen

                            liv-in-sky 1 Reply Last reply Reply Quote 0
                            • liv-in-sky
                              liv-in-sky @BananaJoe last edited by

                              @bananajoe

                              probiert doch das mal aus - evtl gibt das eine feste id pro gerät zurück -

                              import widget - im widget die widget id noch angleichen !

                              [{"tpl":"tplHtml","data":{"g_fixed":false,"g_visibility":false,"g_css_font_text":true,"g_css_background":true,"g_css_shadow_padding":false,"g_css_border":false,"g_gestures":false,"g_signals":false,"g_last_change":false,"visibility-cond":"==","visibility-val":1,"visibility-groups-action":"hide","refreshInterval":"0","signals-cond-0":"==","signals-val-0":true,"signals-icon-0":"/vis/signals/lowbattery.png","signals-icon-size-0":0,"signals-blink-0":false,"signals-horz-0":0,"signals-vert-0":0,"signals-hide-edit-0":false,"signals-cond-1":"==","signals-val-1":true,"signals-icon-1":"/vis/signals/lowbattery.png","signals-icon-size-1":0,"signals-blink-1":false,"signals-horz-1":0,"signals-vert-1":0,"signals-hide-edit-1":false,"signals-cond-2":"==","signals-val-2":true,"signals-icon-2":"/vis/signals/lowbattery.png","signals-icon-size-2":0,"signals-blink-2":false,"signals-horz-2":0,"signals-vert-2":0,"signals-hide-edit-2":false,"lc-type":"last-change","lc-is-interval":true,"lc-is-moment":false,"lc-format":"","lc-position-vert":"top","lc-position-horz":"right","lc-offset-vert":0,"lc-offset-horz":0,"lc-font-size":"12px","lc-font-family":"","lc-font-style":"","lc-bkg-color":"","lc-color":"","lc-border-width":"0","lc-border-style":"","lc-border-color":"","lc-border-radius":10,"lc-zindex":0,"html":"<script>\nuuid=function(){\nvar u = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g,\nfunction(c) {\nvar r = Math.random() * 16 | 0,\nv = c == 'x' ? r : (r & 0x3 | 0x8);\nreturn v.toString(16);\n});\nreturn u;\n}\n\n\ngetDeviceId = function(){\nvar current = window.localStorage.getItem(\"_DEVICEID_\")\nif (current) return current;\nvar id = uuid();\nwindow.localStorage.setItem(\"_DEVICEID_\",id);   \nreturn id;\n}\n\nconsole.log(getDeviceId())\n $( \"#w00006\" ).text( getDeviceId());\n\n\n</script>\n"},"style":{"left":"838px","top":"180px","color":"#f4e643","background-color":"#b7aeae"},"widgetSet":"basic"}]
                              

                              Image 6.png

                              1 Reply Last reply Reply Quote 0
                              • BananaJoe
                                BananaJoe Most Active last edited by BananaJoe

                                @liv-in-sky nope, pro Browser und inPrivate Sitzung eine eigene
                                JavaScript kann das nicht ... und das ist Absicht

                                liv-in-sky 2 Replies Last reply Reply Quote 0
                                • liv-in-sky
                                  liv-in-sky @BananaJoe last edited by

                                  @bananajoe

                                  also ich bekomme damit einen eindeutigen , nicht vom cache-löschbaren code zurück - getestet mit fully , chrome und edge

                                  ich dachte, dass sucht ihr

                                  1 Reply Last reply Reply Quote 0
                                  • liv-in-sky
                                    liv-in-sky @BananaJoe last edited by

                                    @bananajoe und wer macht die vis im private mode auf - oder warum sollte man das

                                    bahnuhr BananaJoe 2 Replies Last reply Reply Quote 0
                                    • bahnuhr
                                      bahnuhr Forum Testing Most Active @liv-in-sky last edited by

                                      @liv-in-sky sagte in VIS Intance Id - automatisiert ermitteln:

                                      private mode

                                      Ich wollte im Wohnzimmer ein tablet das im Vollbild öffnet und dass man nicht so einfach mit esc oder f11 raus kommt.
                                      Und das ging halt mit edge kiosk.

                                      BananaJoe liv-in-sky 2 Replies Last reply Reply Quote 0
                                      • BananaJoe
                                        BananaJoe Most Active @liv-in-sky last edited by

                                        @liv-in-sky Ich, zum simulieren verschiedener Geräte 🙂
                                        Dein Skript erstellt eine zufällige ID und speichert diese, richtig? Also nichts anderes als die Instanz-ID und wird somit auch kein löschen der Caches überleben.

                                        liv-in-sky 1 Reply Last reply Reply Quote 0
                                        • BananaJoe
                                          BananaJoe Most Active @bahnuhr last edited by

                                          @bahnuhr ich wäre ja schon am Ziel da ich pro Gerät eine eigene VIS habe. Aber ich suche noch.

                                          liv-in-sky 1 Reply Last reply Reply Quote 0
                                          • liv-in-sky
                                            liv-in-sky @bahnuhr last edited by

                                            @bahnuhr

                                            ok - aber dann ist es trotzdem eine eindeutige nummer

                                            bahnuhr BananaJoe 2 Replies Last reply Reply Quote 0
                                            • First post
                                              Last post

                                            Support us

                                            ioBroker
                                            Community Adapters
                                            Donate

                                            523
                                            Online

                                            31.9k
                                            Users

                                            80.1k
                                            Topics

                                            1.3m
                                            Posts

                                            13
                                            126
                                            11168
                                            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