Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. (Echte) Stau-Erkennung mit Bing

    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

    (Echte) Stau-Erkennung mit Bing

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

      Denke es liegt am Widget.

      Nimm mal ein anderes Widget, z.B. basic - string und trag als ID die ID der Fahrzeit ein.

      1 Reply Last reply Reply Quote 0
      • F
        Fitti last edited by

        @ruhr70:

        Nimm mal ein anderes Widget, z.B. basic - string und trag als ID die ID der Fahrzeit ein. `

        <size size="85">__Jaja - fordere mich nur heraus… :shock: 😄

        Hatte doch keine Idee, wie das geht. Aber mit eim bischen Testen und versuchen... :mrgreen:__</size>

        Jup. hier geht es. Grüner Rahmen ist der Basic-string.

        Der orange ist der metro - Tile String

        Und warum geht es bei den anderen… 😢
        578_2ter.png

        1 Reply Last reply Reply Quote 0
        • T
          tesso last edited by

          Bei mir wurde auch meistens keine Fahrzeit angezeigt.

          Zur Zeit habe ich keine Icons, anscheinend ein Problem mit den metro-widgets.

          Metro Widgets sind wieder da.

          Die Fahrzeit wird bei mir aber in vis auch nicht angezeigt, nur im Editor.

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

            Hallo,

            habe mal ein bischen weitergedacht:
            609_bildschirmfoto_2015-08-22_um_01.46.13.png

            *Fehler führen nicht zum Löschen der Datenpunkte

            *Eingabe der Straßennamen/Adressen in Klartext

            *Zwischenpunkte/Wegpunkte möglich

            *Debugausgaben sinnvoll erweitert

            [{"id":"a88491cd.577b7","type":"http request","name":"askBing","method":"GET","ret":"obj","url":"","x":436,"y":2346.9999389648438,"z":"58484835.a7b7b8","wires":[["4b2858cc.b4d7a8","d70d8ba3.28f278","fb724855.048db8"]]},{"id":"990145d0.66feb8","type":"function","name":"extractData","func":"/*\nreturns:\n1\. travelDurationTraffic in min\n2\. travelDuration in min\n3\. traveDelay in min\n4\. trafficJam boolean\n5\. trafficCongestion string\n6\. travelDistance in km\n7\. msg object (for debugging and return to the loop)\n*/\nvar travelDurationTraffic = Math.ceil(msg.payload.resourceSets[0].resources[0].travelDurationTraffic / 60);\nvar travelDuration = Math.ceil(msg.payload.resourceSets[0].resources[0].travelDuration / 60);\n\nvar shortname = msg.name+\":\"+msg.payload.resourceSets[0].resources[0].routeLegs[0].description+\"/\"+msg.payload.resourceSets[0].resources[0].travelDistance+\" km\";\n\nvar msgTraffic = [\n    {\n        topic: msg.topic_prefix + \".name\",\n        payload: msg.name\n    },\n    {\n        topic: msg.topic_prefix + \".travelDurationTraffic\",\n        payload: travelDurationTraffic\n    },\n    {    \n        topic: msg.topic_prefix + \".travelDuration\",\n        payload: travelDuration\n    },\n    {    \n        topic: msg.topic_prefix + \".travelDelay\",\n        payload: travelDurationTraffic - travelDuration\n    },\n    {    \n        topic: msg.topic_prefix + \".trafficJam\",\n        payload: (travelDurationTraffic - travelDuration >= msg.threshold)\n    },\n    {    \n        topic: msg.topic_prefix + \".trafficCongestion\",\n        payload: msg.payload.resourceSets[0].resources[0].trafficCongestion\n    },\n    {    \n        topic: msg.topic_prefix + \".travelDistance\",\n        payload: msg.payload.resourceSets[0].resources[0].travelDistance\n    },\n    {    \n        topic: msg.topic_prefix + \".travelDescription\",\n        payload: msg.payload.resourceSets[0].resources[0].routeLegs[0].description\n    }\n];\n\nreturn [shortname,msgTraffic,msg.payload.resourceSets[0].resources[0].routeLegs,msg];","outputs":"4","noerr":0,"x":273.5555419921875,"y":2642.1110229492188,"z":"58484835.a7b7b8","wires":[["6f13fc3f.90ec04"],["c25038ad.3dafc8","639eeea6.9c611"],["4cb75b47.b348a4"],["154f9236.eab06e"]]},{"id":"32caf48f.cd350c","type":"inject","name":"Trigger","topic":"","payload":"","payloadType":"date","repeat":"600","crontab":"","once":false,"x":157.88883209228516,"y":2091.0000133514404,"z":"58484835.a7b7b8","wires":[["9bc04bf1.643fb8"]]},{"id":"38e4e608.c71b1a","type":"function","name":"defineRoutes","func":"/*\nDefine routes:\nfrom: starting address, encode spaces with %20\nto: destination address, encode spaces with %20\nthreshold: in minutes, if duration with traffic is larger than threshold, set trafficJam to true\nname: name :-)\n*/\n\nmsg.routes = [\n    {\n        way: \".1='Horsterfeld 1,31542 Bad Nenndorf'&\" +\n             \".2='Laatzener Str. 1,30539 Hannover'\",\n        threshold: 5,\n        name: 'Home2Office'\n    },\n    {\n        way: \".1='Horsterfeld 1,31542 Bad Nenndorf'&\" +\n             \"via.2='Mindener Straße 4, 30890 Nordgoltern'&\" +\n             \"via.3='Landwehrkreisel / Frankfurter Allee, 30459 Hannover'&\" +\n             \".4='Laatzener Str. 1,30539 Hannover'\",\n        threshold: 5,\n        name: 'Home2OfficeLandstr'\n    },\n    {\n      way: \".1='Horsterfeld 1,31542 Bad Nenndorf'&\" +\n             \"via.2='Autobahnkreuz Hannover-Buchholz, 30659 Hannover'&\" +\n             \".3='Laatzener Str. 1,30539 Hannover'\",\n        threshold: 5,\n        name: 'Home2OfficeA2'\n    },\n    {\n        way: \".1='Laatzener Str. 1,30539 Hannover'&\" +\n             \"via.2='Landwehrkreisel / Frankfurter Allee, 30459 Hannover'&\" +\n             \"via.3='Mindener Straße 4, 30890 Nordgoltern'&\" +\n             \".4='Horsterfeld 1,31542 Bad Nenndorf'\",\n        threshold: 5,\n        name: 'Office2HomeLandstr'\n    },\n    {\n        way: \".1='Laatzener Str. 1,30539 Hannover'&\" +\n             \".2='Horsterfeld 1,31542 Bad Nenndorf'\",\n        threshold: 5,\n        name: 'Office2Home'\n    },\n       {\n        way: \".1='Laatzener Str. 1,30539 Hannover'&\" +\n             \"via.2='A37, 30655 Gross Buchholz'&\" +\n             \".3='Horsterfeld 1,31542 Bad Nenndorf'\",\n        threshold: 5,\n        name: 'Office2HomeA2'\n    }\n];\n\nreturn msg;","outputs":1,"noerr":0,"x":494.88897705078125,"y":2091.000015258789,"z":"58484835.a7b7b8","wires":[["b095a02e.4f6a6"]]},{"id":"bf34f55f.40cb08","type":"function","name":"prepareIteration","func":"// msg.method = \"GET\";\nmsg.url = encodeURI(\"http://dev.virtualearth.net/REST/v1/Routes?\" + msg.payload.way + \"&optimize=timeWithTraffic&key=\" + msg.config.bing_key);\nmsg.topic_prefix = msg.config.topic_prefix + msg.payload.name;\nmsg.name = msg.payload.name; \nmsg.threshold = msg.payload.threshold;\nreturn msg;","outputs":1,"noerr":0,"x":274.22222900390625,"y":2347.5554809570312,"z":"58484835.a7b7b8","wires":[["a88491cd.577b7","4fcf3346.b030cc"]]},{"id":"9bc04bf1.643fb8","type":"function","name":"setConfig","func":"msg.config = {\n    bing_key: \"AAABBBCCC\",\n    topic_prefix: \"node-red.0.traffic.\"\n};\nreturn msg;","outputs":1,"noerr":0,"x":320.11106872558594,"y":2091.5555572509766,"z":"58484835.a7b7b8","wires":[["38e4e608.c71b1a","1310a9a2.ecef56"]]},{"id":"b095a02e.4f6a6","type":"function","name":"loopRoutes","func":"context.routes = context.routes || msg.routes;\n\n// iterate through all the routes\nif (context.routes.length > 0) {\n    msg.payload = context.routes.shift();\n    return [null, msg];\n}\n\n// Reset routes-context, otherwise we immediately stop in the next run\ncontext.routes = false;\n// we are done with the loop\nreturn [msg, null];","outputs":"2","noerr":0,"x":184.6666259765625,"y":2285.22216796875,"z":"58484835.a7b7b8","wires":[[],["bf34f55f.40cb08"]]},{"id":"1310a9a2.ecef56","type":"debug","name":"","active":false,"console":"false","complete":"true","x":704.6666259765625,"y":2211.22216796875,"z":"58484835.a7b7b8","wires":[]},{"id":"c25038ad.3dafc8","type":"ioBroker out","name":"toIoBroker","topic":"","ack":"true","autoCreate":"true","x":639.6666259765625,"y":2546.22216796875,"z":"58484835.a7b7b8","wires":[]},{"id":"639eeea6.9c611","type":"debug","name":"Variablen","active":true,"console":"false","complete":"payload","x":699.6666259765625,"y":2485.22216796875,"z":"58484835.a7b7b8","wires":[]},{"id":"3759620e.c8a69e","type":"catch","name":"","x":692.6666259765625,"y":2093.2222290039062,"z":"58484835.a7b7b8","wires":[["1310a9a2.ecef56"]]},{"id":"39a69e5d.c65962","type":"comment","name":"Define your config and routes here.           ","info":"Define your config and routes here.","x":398.6666259765625,"y":2054.2222290039062,"z":"58484835.a7b7b8","wires":[]},{"id":"4fcf3346.b030cc","type":"debug","name":"WEB","active":false,"console":"false","complete":"url","x":687,"y":2259,"z":"58484835.a7b7b8","wires":[]},{"id":"4b2858cc.b4d7a8","type":"debug","name":"Answer","active":false,"console":"false","complete":"true","x":697,"y":2313,"z":"58484835.a7b7b8","wires":[]},{"id":"4cb75b47.b348a4","type":"debug","name":"Legs","active":false,"console":"false","complete":"true","x":630,"y":2610.9999389648438,"z":"58484835.a7b7b8","wires":[]},{"id":"154f9236.eab06e","type":"delay","name":"Pause","pauseType":"delay","timeout":"3","timeoutUnits":"seconds","rate":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":349,"y":2519,"z":"58484835.a7b7b8","wires":[["b095a02e.4f6a6"]]},{"id":"d70d8ba3.28f278","type":"switch","name":"Error?","property":"payload.statusCode","rules":[{"t":"neq","v":"200"},{"t":"else"}],"checkall":"true","outputs":2,"x":157,"y":2517,"z":"58484835.a7b7b8","wires":[["154f9236.eab06e"],["990145d0.66feb8"]]},{"id":"fb724855.048db8","type":"debug","name":"StatusCode","active":false,"console":"false","complete":"payload.statusCode","x":676,"y":2357,"z":"58484835.a7b7b8","wires":[]},{"id":"7225c9a2.8dda38","type":"catch","name":"","x":136,"y":2731,"z":"58484835.a7b7b8","wires":[["990145d0.66feb8"]]},{"id":"6f13fc3f.90ec04","type":"debug","name":"Route","active":true,"console":"false","complete":"true","x":697,"y":2439,"z":"58484835.a7b7b8","wires":[]}]
            

            extractData:

            /*
            returns:
            1\. travelDurationTraffic in min
            2\. travelDuration in min
            3\. traveDelay in min
            4\. trafficJam boolean
            5\. trafficCongestion string
            6\. travelDistance in km
            7\. msg object (for debugging and return to the loop)
            */
            var travelDurationTraffic = Math.ceil(msg.payload.resourceSets[0].resources[0].travelDurationTraffic / 60);
            var travelDuration = Math.ceil(msg.payload.resourceSets[0].resources[0].travelDuration / 60);
            
            var shortname = msg.name+":"+msg.payload.resourceSets[0].resources[0].routeLegs[0].description+"/"+msg.payload.resourceSets[0].resources[0].travelDistance+" km";
            
            var msgTraffic = [
                {
                    topic: msg.topic_prefix + ".name",
                    payload: msg.name
                },
                {
                    topic: msg.topic_prefix + ".travelDurationTraffic",
                    payload: travelDurationTraffic
                },
                {    
                    topic: msg.topic_prefix + ".travelDuration",
                    payload: travelDuration
                },
                {    
                    topic: msg.topic_prefix + ".travelDelay",
                    payload: travelDurationTraffic - travelDuration
                },
                {    
                    topic: msg.topic_prefix + ".trafficJam",
                    payload: (travelDurationTraffic - travelDuration >= msg.threshold)
                },
                {    
                    topic: msg.topic_prefix + ".trafficCongestion",
                    payload: msg.payload.resourceSets[0].resources[0].trafficCongestion
                },
                {    
                    topic: msg.topic_prefix + ".travelDistance",
                    payload: msg.payload.resourceSets[0].resources[0].travelDistance
                },
                {    
                    topic: msg.topic_prefix + ".travelDescription",
                    payload: msg.payload.resourceSets[0].resources[0].routeLegs[0].description
                }
            ];
            
            return [shortname,msgTraffic,msg.payload.resourceSets[0].resources[0].routeLegs,msg];
            

            prepareIteration:

            // msg.method = "GET";
            msg.url = encodeURI("http://dev.virtualearth.net/REST/v1/Routes?" + msg.payload.way + "&optimize=timeWithTraffic&key=" + msg.config.bing_key);
            msg.topic_prefix = msg.config.topic_prefix + msg.payload.name;
            msg.name = msg.payload.name; 
            msg.threshold = msg.payload.threshold;
            return msg;
            
            1 Reply Last reply Reply Quote 0
            • sissiwup
              sissiwup last edited by

              @tesso:

              Bei mir wurde auch meistens keine Fahrzeit angezeigt.

              Zur Zeit habe ich keine Icons, anscheinend ein Problem mit den metro-widgets.

              Metro Widgets sind wieder da.

              Die Fahrzeit wird bei mir aber in vis auch nicht angezeigt, nur im Editor. `

              Hallo,

              das kannst du mit einen kleinen Workaraound umgehen:

              Fahrzeit: {node-red.0.traffic.Home2Office.travelDurationTraffic}
              

              Und dafür die ObjectId darunter freilassen

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

                Hallo,

                für eine einfache json Darstellung:
                609_bildschirmfoto_2015-08-22_um_09.57.43.png

                /*
                returns:
                1\. travelDurationTraffic in min
                2\. travelDuration in min
                3\. traveDelay in min
                4\. trafficJam boolean
                5\. trafficCongestion string
                6\. travelDistance in km
                7\. msg object (for debugging and return to the loop)
                */
                var travelDurationTraffic = Math.ceil(msg.payload.resourceSets[0].resources[0].travelDurationTraffic / 60);
                var travelDuration = Math.ceil(msg.payload.resourceSets[0].resources[0].travelDuration / 60);
                
                var shortname = msg.name+":"+msg.payload.resourceSets[0].resources[0].routeLegs[0].description+"/"+msg.payload.resourceSets[0].resources[0].travelDistance+" km";
                var addtime = travelDurationTraffic - travelDuration;
                var json = '[';
                json = json + '{"Title":"'+msg.name+'","Value":"'+msg.payload.resourceSets[0].resources[0].routeLegs[0].description+'"}';
                json = json + ',{"Title":"Dauer","Value":"'+travelDuration+' + '+addtime+' = '+travelDurationTraffic+'"}';
                //json = json + ',{"Title":"Verzoegerung","Value":"'+travelDurationTraffic - travelDuration+'"}';
                json = json + ',{"Title":"Distanz","Value":"'+msg.payload.resourceSets[0].resources[0].travelDistance+'"}';
                //if (travelDurationTraffic - travelDuration >= msg.threshold) {
                //   json = json + ',{"Title":"Stau","Value":"ja"}';
                //}
                json = json + ']'
                
                var msgTraffic = [
                    {
                        topic: msg.topic_prefix + ".name",
                        payload: msg.name
                    },
                    {
                        topic: msg.topic_prefix + ".travelDurationTraffic",
                        payload: travelDurationTraffic
                    },
                    {    
                        topic: msg.topic_prefix + ".travelDuration",
                        payload: travelDuration
                    },
                    {    
                        topic: msg.topic_prefix + ".travelDelay",
                        payload: addtime
                    },
                    {    
                        topic: msg.topic_prefix + ".trafficJam",
                        payload: (addtime >= msg.threshold)
                    },
                    {    
                        topic: msg.topic_prefix + ".trafficCongestion",
                        payload: msg.payload.resourceSets[0].resources[0].trafficCongestion
                    },
                    {    
                        topic: msg.topic_prefix + ".travelDistance",
                        payload: msg.payload.resourceSets[0].resources[0].travelDistance
                    },
                    {    
                        topic: msg.topic_prefix + ".travelDescription",
                        payload: msg.payload.resourceSets[0].resources[0].routeLegs[0].description
                    },
                    {    
                        topic: msg.topic_prefix + ".json",
                        payload: json
                    }
                ];
                
                return [shortname,msgTraffic,msg.payload.resourceSets[0].resources[0].routeLegs,msg];
                
                1 Reply Last reply Reply Quote 0
                • ruhr70
                  ruhr70 last edited by

                  Super Arbeit!

                  Habe mich direkt begeistert darauf gestürzt, bekomme es leider nur nicht zum Laufen:

                  // msg.method = "GET";
                  msg.url = encodeURI("http://dev.virtualearth.net/REST/v1/Routes?" + msg.payload.way + "&optimize=timeWithTraffic&key=" + msg.config.bing_key);
                  msg.topic_prefix = msg.config.topic_prefix + msg.payload.name;
                  msg.name = msg.payload.name; 
                  msg.threshold = msg.payload.threshold;
                  return msg;
                  

                  Meinen Bing-Key hab ich eingetragen und sonst keine Änderungen vorgenommen.

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

                    Hallo,

                    wo hast du deinen bing-key eingetragen?

                    Schau mal in Debug, welcher Fehler kommt (wo).

                    Gestartet wird links oben mit den kleinen Knopf.

                    Ausgaben kannst du aktivieren, indem du die grünen Debug Meldungen aktivierst.

                    Am besten von oben nach unten.

                    Diese ansehen und ggf. posten.

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

                      habe mich gerade über deine Hinweise gewundert 😉

                      bis ich gesehen habe, dass ich die falsche Zwischenablage hier reinkopiert habe

                      bekomme einen Status 400

                      falsche Parameter bei der Route.

                      poste ich noch vom Rechner

                      Gesendet von iPhone mit Tapatalk

                      1 Reply Last reply Reply Quote 0
                      • L
                        looxer01 last edited by

                        Hi,

                        ich bekomme eine Payload message zurück. Den API Key habe ich auf der BING page erneuert, allerdings habe ich keine applikations URL angegeben nur die Applikation iobroker.

                        hast du einen tipp für mich was ich falsch mache ?

                        { "topic": "", "payload": 1440243954834, "_msgid": "50945b99.af6ba4", "config": { "bing_key": "123": "node-red.0.traffic." } }
                        
                        

                        Edit: war dumm, denn ich hatte die Ausgänge nicht alle aktiviert. Nachdem ich das gemacht habe bekomme ich einen anderen Fehler:

                        "waypoint: Parameter is missing"

                        { "topic": "", "payload": { "authenticationResultCode": "ValidCredentials", "brandLogoUri": "http://dev.virtualearth.net/Branding/logo_powered_by.png", "copyright": "Copyright © 2015 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.", "errorDetails": [ "One or more parameters are not valid.", "waypoint: Parameter is missing" ], "resourceSets": [], "statusCode": 400, "statusDescription": "Bad Request", "traceId": "159e3bb3ee154f598b5130616e6775f3|DB40051734|1.0.0.0|" }, "_msgid": "e58ef93c.1a7108", "config": { "bing_key": "1233." }, "routes": [ { "way": ".1='Horsterfeld 1,31542 Bad Nenndorf'&via.2='Mindener Straße 4, 30890 Nordgoltern'&via.3='Landwehrkreisel / Frankfurter Al ....
                        
                        
                        1 Reply Last reply Reply Quote 0
                        • sissiwup
                          sissiwup last edited by

                          in defineroutes:

                          msg.routes = [
                              {
                                  way: "wayPoint.1='Horsterfeld 1,31542 Bad Nenndorf'&" +
                                       "wayPoint.2='Laatzener Str. 1,30539 Hannover'",
                                  threshold: 5,
                                  name: 'Home2Office'
                              },
                          
                          

                          Das sieht bei dir merkwürdig aus.

                          1 Reply Last reply Reply Quote 0
                          • L
                            looxer01 last edited by

                            jap, das war es.

                            Ich hatte das aus dem Post vorher einfach übernommen. War wahrscheinlich auch das Problem von Ruhr.

                            Jetzt sind auch die Datenpunkte da. Super - vielen Dank

                            vG L…

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

                              Ok,

                              es gibt auch noch:

                              {
                                      way: "wayPoint.1='Horsterfeld 1,31542 Bad Nenndorf'&" +
                                           "viaWayPoint.2='Mindener Straße 4, 30890 Nordgoltern'&" +
                                           "viaWayPoint.3='Landwehrkreisel / Frankfurter Allee, 30459 Hannover'&" +
                                           "wayPoint.4='Laatzener Str. 1,30539 Hannover'",
                                      threshold: 5,
                                      name: 'Home2OfficeLandstr'
                                  },
                              

                              falls man ihn zwingen möchte eine Route zu nehmen.

                              1 Reply Last reply Reply Quote 0
                              • S
                                Sven2013 last edited by

                                Hallo, ich finde deine Idden gut mit der festgelegten Route. Ich würd Sie gerne Übernehmen.

                                Ich habe den Ersten Code als "Flow" Importiert und meinen Bin API und die define Routes geändert.

                                Aber was muss ich mit den Beiden Anderen Code Schnipseln machen?

                                Bitte um Kurzen Schubs in die richtige Richtung.

                                Gruß Sven

                                @sissiwup:

                                Hallo,

                                habe mal ein bischen weitergedacht:
                                filename="Bildschirmfoto 2015-08-22 um 01.46.13.png" index="0">~~

                                *Fehler führen nicht zum Löschen der Datenpunkte

                                *Eingabe der Straßennamen/Adressen in Klartext

                                *Zwischenpunkte/Wegpunkte möglich

                                *Debugausgaben sinnvoll erweitert

                                [{"id":"a88491cd.577b7","type":"http request","name":"askBing","method":"GET","ret":"obj","url":"","x":436,"y":2346.9999389648438,"z":"58484835.a7b7b8","wires":[["4b2858cc.b4d7a8","d70d8ba3.28f278","fb724855.048db8"]]},{"id":"990145d0.66feb8","type":"function","name":"extractData","func":"/*\nreturns:\n1\. travelDurationTraffic in min\n2\. travelDuration in min\n3\. traveDelay in min\n4\. trafficJam boolean\n5\. trafficCongestion string\n6\. travelDistance in km\n7\. msg object (for debugging and return to the loop)\n*/\nvar travelDurationTraffic = Math.ceil(msg.payload.resourceSets[0].resources[0].travelDurationTraffic / 60);\nvar travelDuration = Math.ceil(msg.payload.resourceSets[0].resources[0].travelDuration / 60);\n\nvar shortname = msg.name+\":\"+msg.payload.resourceSets[0].resources[0].routeLegs[0].description+\"/\"+msg.payload.resourceSets[0].resources[0].travelDistance+\" km\";\n\nvar msgTraffic = [\n    {\n        topic: msg.topic_prefix + \".name\",\n        payload: msg.name\n    },\n    {\n        topic: msg.topic_prefix + \".travelDurationTraffic\",\n        payload: travelDurationTraffic\n    },\n    {    \n        topic: msg.topic_prefix + \".travelDuration\",\n        payload: travelDuration\n    },\n    {    \n        topic: msg.topic_prefix + \".travelDelay\",\n        payload: travelDurationTraffic - travelDuration\n    },\n    {    \n        topic: msg.topic_prefix + \".trafficJam\",\n        payload: (travelDurationTraffic - travelDuration >= msg.threshold)\n    },\n    {    \n        topic: msg.topic_prefix + \".trafficCongestion\",\n        payload: msg.payload.resourceSets[0].resources[0].trafficCongestion\n    },\n    {    \n        topic: msg.topic_prefix + \".travelDistance\",\n        payload: msg.payload.resourceSets[0].resources[0].travelDistance\n    },\n    {    \n        topic: msg.topic_prefix + \".travelDescription\",\n        payload: msg.payload.resourceSets[0].resources[0].routeLegs[0].description\n    }\n];\n\nreturn [shortname,msgTraffic,msg.payload.resourceSets[0].resources[0].routeLegs,msg];","outputs":"4","noerr":0,"x":273.5555419921875,"y":2642.1110229492188,"z":"58484835.a7b7b8","wires":[["6f13fc3f.90ec04"],["c25038ad.3dafc8","639eeea6.9c611"],["4cb75b47.b348a4"],["154f9236.eab06e"]]},{"id":"32caf48f.cd350c","type":"inject","name":"Trigger","topic":"","payload":"","payloadType":"date","repeat":"600","crontab":"","once":false,"x":157.88883209228516,"y":2091.0000133514404,"z":"58484835.a7b7b8","wires":[["9bc04bf1.643fb8"]]},{"id":"38e4e608.c71b1a","type":"function","name":"defineRoutes","func":"/*\nDefine routes:\nfrom: starting address, encode spaces with %20\nto: destination address, encode spaces with %20\nthreshold: in minutes, if duration with traffic is larger than threshold, set trafficJam to true\nname: name :-)\n*/\n\nmsg.routes = [\n    {\n        way: \".1='Horsterfeld 1,31542 Bad Nenndorf'&\" +\n             \".2='Laatzener Str. 1,30539 Hannover'\",\n        threshold: 5,\n        name: 'Home2Office'\n    },\n    {\n        way: \".1='Horsterfeld 1,31542 Bad Nenndorf'&\" +\n             \"via.2='Mindener Straße 4, 30890 Nordgoltern'&\" +\n             \"via.3='Landwehrkreisel / Frankfurter Allee, 30459 Hannover'&\" +\n             \".4='Laatzener Str. 1,30539 Hannover'\",\n        threshold: 5,\n        name: 'Home2OfficeLandstr'\n    },\n    {\n      way: \".1='Horsterfeld 1,31542 Bad Nenndorf'&\" +\n             \"via.2='Autobahnkreuz Hannover-Buchholz, 30659 Hannover'&\" +\n             \".3='Laatzener Str. 1,30539 Hannover'\",\n        threshold: 5,\n        name: 'Home2OfficeA2'\n    },\n    {\n        way: \".1='Laatzener Str. 1,30539 Hannover'&\" +\n             \"via.2='Landwehrkreisel / Frankfurter Allee, 30459 Hannover'&\" +\n             \"via.3='Mindener Straße 4, 30890 Nordgoltern'&\" +\n             \".4='Horsterfeld 1,31542 Bad Nenndorf'\",\n        threshold: 5,\n        name: 'Office2HomeLandstr'\n    },\n    {\n        way: \".1='Laatzener Str. 1,30539 Hannover'&\" +\n             \".2='Horsterfeld 1,31542 Bad Nenndorf'\",\n        threshold: 5,\n        name: 'Office2Home'\n    },\n       {\n        way: \".1='Laatzener Str. 1,30539 Hannover'&\" +\n             \"via.2='A37, 30655 Gross Buchholz'&\" +\n             \".3='Horsterfeld 1,31542 Bad Nenndorf'\",\n        threshold: 5,\n        name: 'Office2HomeA2'\n    }\n];\n\nreturn msg;","outputs":1,"noerr":0,"x":494.88897705078125,"y":2091.000015258789,"z":"58484835.a7b7b8","wires":[["b095a02e.4f6a6"]]},{"id":"bf34f55f.40cb08","type":"function","name":"prepareIteration","func":"// msg.method = \"GET\";\nmsg.url = encodeURI(\"http://dev.virtualearth.net/REST/v1/Routes?\" + msg.payload.way + \"&optimize=timeWithTraffic&key=\" + msg.config.bing_key);\nmsg.topic_prefix = msg.config.topic_prefix + msg.payload.name;\nmsg.name = msg.payload.name; \nmsg.threshold = msg.payload.threshold;\nreturn msg;","outputs":1,"noerr":0,"x":274.22222900390625,"y":2347.5554809570312,"z":"58484835.a7b7b8","wires":[["a88491cd.577b7","4fcf3346.b030cc"]]},{"id":"9bc04bf1.643fb8","type":"function","name":"setConfig","func":"msg.config = {\n    bing_key: \"AAABBBCCC\",\n    topic_prefix: \"node-red.0.traffic.\"\n};\nreturn msg;","outputs":1,"noerr":0,"x":320.11106872558594,"y":2091.5555572509766,"z":"58484835.a7b7b8","wires":[["38e4e608.c71b1a","1310a9a2.ecef56"]]},{"id":"b095a02e.4f6a6","type":"function","name":"loopRoutes","func":"context.routes = context.routes || msg.routes;\n\n// iterate through all the routes\nif (context.routes.length > 0) {\n    msg.payload = context.routes.shift();\n    return [null, msg];\n}\n\n// Reset routes-context, otherwise we immediately stop in the next run\ncontext.routes = false;\n// we are done with the loop\nreturn [msg, null];","outputs":"2","noerr":0,"x":184.6666259765625,"y":2285.22216796875,"z":"58484835.a7b7b8","wires":[[],["bf34f55f.40cb08"]]},{"id":"1310a9a2.ecef56","type":"debug","name":"","active":false,"console":"false","complete":"true","x":704.6666259765625,"y":2211.22216796875,"z":"58484835.a7b7b8","wires":[]},{"id":"c25038ad.3dafc8","type":"ioBroker out","name":"toIoBroker","topic":"","ack":"true","autoCreate":"true","x":639.6666259765625,"y":2546.22216796875,"z":"58484835.a7b7b8","wires":[]},{"id":"639eeea6.9c611","type":"debug","name":"Variablen","active":true,"console":"false","complete":"payload","x":699.6666259765625,"y":2485.22216796875,"z":"58484835.a7b7b8","wires":[]},{"id":"3759620e.c8a69e","type":"catch","name":"","x":692.6666259765625,"y":2093.2222290039062,"z":"58484835.a7b7b8","wires":[["1310a9a2.ecef56"]]},{"id":"39a69e5d.c65962","type":"comment","name":"Define your config and routes here.           ","info":"Define your config and routes here.","x":398.6666259765625,"y":2054.2222290039062,"z":"58484835.a7b7b8","wires":[]},{"id":"4fcf3346.b030cc","type":"debug","name":"WEB","active":false,"console":"false","complete":"url","x":687,"y":2259,"z":"58484835.a7b7b8","wires":[]},{"id":"4b2858cc.b4d7a8","type":"debug","name":"Answer","active":false,"console":"false","complete":"true","x":697,"y":2313,"z":"58484835.a7b7b8","wires":[]},{"id":"4cb75b47.b348a4","type":"debug","name":"Legs","active":false,"console":"false","complete":"true","x":630,"y":2610.9999389648438,"z":"58484835.a7b7b8","wires":[]},{"id":"154f9236.eab06e","type":"delay","name":"Pause","pauseType":"delay","timeout":"3","timeoutUnits":"seconds","rate":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":349,"y":2519,"z":"58484835.a7b7b8","wires":[["b095a02e.4f6a6"]]},{"id":"d70d8ba3.28f278","type":"switch","name":"Error?","property":"payload.statusCode","rules":[{"t":"neq","v":"200"},{"t":"else"}],"checkall":"true","outputs":2,"x":157,"y":2517,"z":"58484835.a7b7b8","wires":[["154f9236.eab06e"],["990145d0.66feb8"]]},{"id":"fb724855.048db8","type":"debug","name":"StatusCode","active":false,"console":"false","complete":"payload.statusCode","x":676,"y":2357,"z":"58484835.a7b7b8","wires":[]},{"id":"7225c9a2.8dda38","type":"catch","name":"","x":136,"y":2731,"z":"58484835.a7b7b8","wires":[["990145d0.66feb8"]]},{"id":"6f13fc3f.90ec04","type":"debug","name":"Route","active":true,"console":"false","complete":"true","x":697,"y":2439,"z":"58484835.a7b7b8","wires":[]}]
                                

                                extractData:

                                /*
                                returns:
                                1\. travelDurationTraffic in min
                                2\. travelDuration in min
                                3\. traveDelay in min
                                4\. trafficJam boolean
                                5\. trafficCongestion string
                                6\. travelDistance in km
                                7\. msg object (for debugging and return to the loop)
                                */
                                var travelDurationTraffic = Math.ceil(msg.payload.resourceSets[0].resources[0].travelDurationTraffic / 60);
                                var travelDuration = Math.ceil(msg.payload.resourceSets[0].resources[0].travelDuration / 60);
                                
                                var shortname = msg.name+":"+msg.payload.resourceSets[0].resources[0].routeLegs[0].description+"/"+msg.payload.resourceSets[0].resources[0].travelDistance+" km";
                                
                                var msgTraffic = [
                                    {
                                        topic: msg.topic_prefix + ".name",
                                        payload: msg.name
                                    },
                                    {
                                        topic: msg.topic_prefix + ".travelDurationTraffic",
                                        payload: travelDurationTraffic
                                    },
                                    {    
                                        topic: msg.topic_prefix + ".travelDuration",
                                        payload: travelDuration
                                    },
                                    {    
                                        topic: msg.topic_prefix + ".travelDelay",
                                        payload: travelDurationTraffic - travelDuration
                                    },
                                    {    
                                        topic: msg.topic_prefix + ".trafficJam",
                                        payload: (travelDurationTraffic - travelDuration >= msg.threshold)
                                    },
                                    {    
                                        topic: msg.topic_prefix + ".trafficCongestion",
                                        payload: msg.payload.resourceSets[0].resources[0].trafficCongestion
                                    },
                                    {    
                                        topic: msg.topic_prefix + ".travelDistance",
                                        payload: msg.payload.resourceSets[0].resources[0].travelDistance
                                    },
                                    {    
                                        topic: msg.topic_prefix + ".travelDescription",
                                        payload: msg.payload.resourceSets[0].resources[0].routeLegs[0].description
                                    }
                                ];
                                
                                return [shortname,msgTraffic,msg.payload.resourceSets[0].resources[0].routeLegs,msg];
                                

                                prepareIteration:

                                // msg.method = "GET";
                                msg.url = encodeURI("http://dev.virtualearth.net/REST/v1/Routes?" + msg.payload.way + "&optimize=timeWithTraffic&key=" + msg.config.bing_key);
                                msg.topic_prefix = msg.config.topic_prefix + msg.payload.name;
                                msg.name = msg.payload.name; 
                                msg.threshold = msg.payload.threshold;
                                return msg;
                                ```` ` 
                                1 Reply Last reply Reply Quote 0
                                • S
                                  Sven2013 last edited by

                                  Im Momant kommt zu dem Fred oben noch folgender Log Fehler.

                                  Vielleicht kann damit jemand etwas anfangen.

                                  Gruß Sven
                                  576_log.png

                                  1 Reply Last reply Reply Quote 0
                                  • F
                                    Fitti last edited by

                                    @Sven2013:

                                    Aber was muss ich mit den Beiden Anderen Code Schnipseln machen?

                                    Bitte um Kurzen Schubs in die richtige Richtung.

                                    Gruß Sven `

                                    Hallo Sven,

                                    Du hast ja drei Code-"Boxen" zitiert.

                                    Wenn ich mich recht erinnere, benötigst Du erst einmal nur die oberste Code-Box. Diesen Code kopierst Du Dir in die Zwischenablage. In Node-Red kannst Du dann diesen kompletten Code importieren, aber du benötigst einen neuen flow. Sonst wird auf den alten flow die neuen Sachen rauf kopiert.

                                    Dann solltest Du erst einmal schauen, ob alles läuft. Diese Fehlermeldung zeigt an, dass anscheinend noch etwas nicht richtig läuft, z. B. eine Variable noch nicht existiert o. ä.

                                    Du musst ja bei jeder Änderung oben rechts auf den "Deploy" Button klicken. Dieser sollte dann von rot zu grau wechseln.

                                    Den Bing-Key hast Du?

                                    Passe bitte mit Sonderzeichen und Umlaute auf - vermeide diese.

                                    Im Node defineRoutes legst Du ja Deinen Weg fest. z. B. so:

                                    msg.routes = [
                                        {
                                            way: "wayPoint.1='Hauptstr.1,12345 Berlin'&" +
                                                 "viaWayPoint.2='Neben Str.,23456 AndererOrt'&" +
                                                 "wayPoint.3='Endstr.2,34567 Endstadt'",
                                            threshold: 5,
                                            name: 'Arbeitsweg_Landstr'
                                    

                                    In iobroker müsste dann, wenn alles läuft, im Reiter OBJEKTE unter Node-red.0 /traffic/Arbeitsweg_Landstr auftauchen. der name: in den Routen landet also auch als Objekt in den Objekten auf.

                                    Bei mir hat es immer mind. 30 Minuten gedauert, bis endlich mal Bing funktionierte. Sonst hatte ich einen Error 4002 oder 503 oder was weiß ich. Hier einfach mal warten. Aber das Objekt mit dem Namen wurde angelegt - wenn auch stark verzögert. ein paar Minuten bis 15 Minuten.

                                    Ich nehme an, das Deine Fehlermeldung auf einen schlecht gewählten Namen zurückgeht.

                                    Teste erst mal das.

                                    Viel Glück,

                                    Fitti

                                    1 Reply Last reply Reply Quote 0
                                    • T
                                      thiel last edited by

                                      Hey,

                                      läuft echt super die Lösung. 🙂 Gibt es auch die Möglichkeit die Voraussichtliche Ankunftszeit mit einzubinden?

                                      Danke euch

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

                                        Hallo, ich bin noch ziemlich neu in dem ganzen iobroker Thema (und allem was dazugehört)

                                        Bei der Stauabfrage bekomme ich folgende Fehlermeldung

                                        [function:extractData] TypeError: Cannot assign to read only property '_msgid' of Home2Office:A59, Münchener Straße/14.065 km
                                        

                                        Ein Reboot vom Pi hat nichts gebracht

                                        Kann mir da jemand helfen?

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

                                          @siedi:

                                          In "defineRoutes" definiert Ihr dann beliebig viele Routen. `

                                          Hallo,

                                          habe gemäß Anleitung dieses Widget installiert und erflgreich am laufen. Klappt super einfach herrlich!

                                          Nun meine Frage(n):

                                          1. Muss ich bei From / To die Adresse OHNE Leerzeichen hinschreiben oder mit %20 auffüllen ?

                                          2. Wenn ich in BING meine Route eingebe bekomme ich drei mögliche Alternativen. Ich möchte nun alle drei mir anzeigen lassen (von mir aus in drei Widgets) damit ich weiss welche Route ich zur Arbeit nehmen werde. Geht das ? (ich habe ja nur Start und Zielpunkt eingegeben!)

                                          Update –> werde mal mein "altes" node-red geschnipsel löschen und das "neue" node-red mit 'via' einbinden

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

                                            So hat jetzt geklappt mit 'via' –> klappt alles wunderbar

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

                                            Support us

                                            ioBroker
                                            Community Adapters
                                            Donate

                                            468
                                            Online

                                            31.9k
                                            Users

                                            80.1k
                                            Topics

                                            1.3m
                                            Posts

                                            22
                                            57
                                            16813
                                            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