MagicMirror Forum

    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • Donate
    • Discord

    Changing MMM-Traffic into using TomTom API

    Development
    2
    17
    720
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R
      rxlDavid last edited by rxlDavid

      Hi Guys,
      Since the Mapbox API is very inaccurate in my region, I want to use the TomTom API.
      I am completely new to developing modules, so I am trying to change an existing one.
      I tried it with this one: MMM-Traffic

      The first thing I change is the API Link, for the first tests, I removed the vars from the Link and replaced them with a static API request.
      Another thing I changed was the

      self.duration = Math.round(json.routes[0].duration / 60);
      

      into:

      self.duration = Math.round(json.routes[0].travelTimeInSeconds / 60);
      

      I uploaded an extinct of the API Return here

      But after the changes, the Modules just shows its “Loading” Phrase, so I guess I missed something.

      I would appreciate any type of help and I will provide further information if needed 🙂

      S 1 Reply Last reply Reply Quote 0
      • S
        sdetweil @rxlDavid last edited by

        @rxldavid the data is not the same from the two apis…

        so, you either have to change EVERYTHING that touches the data OR, after receiving change the layout to match the old format.

        json is pretty nice to work with …

        use the validator here https://codebeautify.org/jsonvalidator?/jsonvalidate
        click the top left button and it will format the data in a nice readable format

        loading… is the initial message, til the actual data arrives…
        so, the data didn’t arrive

        I assume that the request for the data is done in the node_helper

        u can write messages to the console and see them in the window where u start MM

        during development, use npm start >somefile.txt

        and then u can see all the messages in somefile.txt

        I use ssh connection to pi, so I can edit on my desktop
        when using windows desktop i use bitvise ssh client or winscp
        as they provide a networked disk page like file explorer so I can just doubleclick to edit,

        when using linux, most of the file browsers will allow access to ssh connected systems the same way…

        Sam

        Create a working config
        How to add modules

        R 1 Reply Last reply Reply Quote 0
        • R
          rxlDavid @sdetweil last edited by rxlDavid

          @sdetweil
          hi,
          I changed the API Return, there is an option to get it back in JSON.
          What do you mean with write message to the console? & where/when should I execute “npm start >somefile.txt”

          S 3 Replies Last reply Reply Quote 0
          • S
            sdetweil @rxlDavid last edited by

            @rxldavid

            write message to console
            console,log(“some message”+variable+…)

            Sam

            Create a working config
            How to add modules

            1 Reply Last reply Reply Quote 0
            • S
              sdetweil @rxlDavid last edited by

              @rxldavid u probably use pm2, so

              pm2 stop all
              

              then

              cd ~/MagicMirror
              

              then u can

              npm start >somefile.txt
              

              ctrl-c to end

              repeat til working

              Sam

              Create a working config
              How to add modules

              1 Reply Last reply Reply Quote 0
              • S
                sdetweil @rxlDavid last edited by

                @rxldavid the json data u posted is not valid… something is missing after the trailing comma

                Sam

                Create a working config
                How to add modules

                R 1 Reply Last reply Reply Quote 0
                • R
                  rxlDavid @sdetweil last edited by

                  @sdetweil
                  I know, it was just an extinct, since it used private Data,
                  I updated it to the full return with random Data

                  S 1 Reply Last reply Reply Quote 0
                  • S
                    sdetweil @rxlDavid last edited by

                    @rxldavid if u put it thru the formatter

                    {
                      "formatVersion": "0.0.12",
                      "routes": [
                        {
                          "summary": {
                            "lengthInMeters": 1147,
                            "travelTimeInSeconds": 140,
                            "trafficDelayInSeconds": 0,
                            "trafficLengthInMeters": 0,
                            "departureTime": "2021-09-19T17:16:54+02:00",
                            "arrivalTime": "2021-09-19T17:19:14+02:00"
                          },
                          "legs": [
                            {
                              "summary": {
                                "lengthInMeters": 1147,
                                "travelTimeInSeconds": 140,
                                "trafficDelayInSeconds": 0,
                                "trafficLengthInMeters": 0,
                                "departureTime": "2021-09-19T17:16:54+02:00",
                                "arrivalTime": "2021-09-19T17:19:14+02:00"
                              },
                              "points": [
                                {
                                  "latitude": 52.5093,
                                  "longitude": 13.42937
                                },
                                {
                                  "latitude": 52.50904,
                                  "longitude": 13.42913
                                },
                                {
                                  "latitude": 52.50895,
                                  "longitude": 13.42904
                                },
                                {
                                  "latitude": 52.50868,
                                  "longitude": 13.4288
                                },
                                {
                                  "latitude": 52.5084,
                                  "longitude": 13.42857
                                },
                                {
                                  "latitude": 52.50816,
                                  "longitude": 13.42839
                                },
                                {
                                  "latitude": 52.50791,
                                  "longitude": 13.42825
                                },
                                {
                                  "latitude": 52.50757,
                                  "longitude": 13.42772
                                },
                                {
                                  "latitude": 52.50752,
                                  "longitude": 13.42785
                                },
                                {
                                  "latitude": 52.50742,
                                  "longitude": 13.42809
                                },
                                {
                                  "latitude": 52.50735,
                                  "longitude": 13.42824
                                },
                                {
                                  "latitude": 52.5073,
                                  "longitude": 13.42837
                                },
                                {
                                  "latitude": 52.50696,
                                  "longitude": 13.4291
                                },
                                {
                                  "latitude": 52.50673,
                                  "longitude": 13.42961
                                },
                                {
                                  "latitude": 52.50619,
                                  "longitude": 13.43092
                                },
                                {
                                  "latitude": 52.50608,
                                  "longitude": 13.43116
                                },
                                {
                                  "latitude": 52.50574,
                                  "longitude": 13.43195
                                },
                                {
                                  "latitude": 52.50564,
                                  "longitude": 13.43218
                                },
                                {
                                  "latitude": 52.50528,
                                  "longitude": 13.43299
                                },
                                {
                                  "latitude": 52.50513,
                                  "longitude": 13.43336
                                },
                                {
                                  "latitude": 52.505,
                                  "longitude": 13.43366
                                },
                                {
                                  "latitude": 52.50464,
                                  "longitude": 13.43451
                                },
                                {
                                  "latitude": 52.50451,
                                  "longitude": 13.43482
                                },
                                {
                                  "latitude": 52.50444,
                                  "longitude": 13.43499
                                },
                                {
                                  "latitude": 52.50418,
                                  "longitude": 13.43564
                                },
                                {
                                  "latitude": 52.50364,
                                  "longitude": 13.4369
                                },
                                {
                                  "latitude": 52.50343,
                                  "longitude": 13.43738
                                },
                                {
                                  "latitude": 52.5033,
                                  "longitude": 13.43767
                                },
                                {
                                  "latitude": 52.50275,
                                  "longitude": 13.43873
                                }
                              ]
                            }
                          ],
                          "sections": [
                            {
                              "startPointIndex": 0,
                              "endPointIndex": 28,
                              "sectionType": "TRAVEL_MODE",
                              "travelMode": "car"
                            }
                          ]
                        }
                      ]
                    }
                    

                    Sam

                    Create a working config
                    How to add modules

                    R 1 Reply Last reply Reply Quote 0
                    • R
                      rxlDavid @sdetweil last edited by

                      @sdetweil
                      this is also the view Tomtom provided me.
                      but I don’t get what I need to change.
                      right now I got the following error in the console:
                      [19.09.2021 17:22.10.688] [ERROR] Failed to fetch git data for MMM-Traffic: Erro r: block timeout reached

                      S 1 Reply Last reply Reply Quote 0
                      • S
                        sdetweil @rxlDavid last edited by

                        @rxldavid that is from the updateNotifcation module which has a bug … fixed in next release

                        after u got the data, then what did u do?

                        Sam

                        Create a working config
                        How to add modules

                        R 1 Reply Last reply Reply Quote 0
                        • 1
                        • 2
                        • 1 / 2
                        • First post
                          Last post
                        Enjoying MagicMirror? Please consider a donation!
                        MagicMirror created by Michael Teeuw.
                        Forum managed by Paul-Vincent Roll and Rodrigo Ramírez Norambuena.
                        This forum is using NodeBB as its core | Contributors
                        Contact | Privacy Policy