MRX-Work-Traffic - Shows the time you need to get to work



  • Description:

    Hey ho,
    I wrote my first module wich is showing the current time to my workplace.
    You can add more than one.
    I think, its not the best code at all… but it works :)
    Uses google REST API to get the details…

    Screenshot

    0_1489741327810_Screen.PNG

    Download:



  • @domsen123 Interesting how you get in 11mins from Berlin to Hofbräuhaus in Munich :rofl:



  • haha this screen is with an other config :D

    Its from the Main Trainstation in Munich :)



  • @domsen123 bummer thought you are probably related to captain kirk with access to warp speed



  • @strawberry-3.141 thats the next module I will write (MMM-MagicBeam) with Alexa support…
    Mirror, beam me up to Oktoberfest…


  • Module Developer

    For the life of me, I can’t get this to work… I don’t even get the header label. Here’s what I did:

    1. Cloned the repo into my modules directory with
      git clone https://github.com/domsen123/mrx-work-traffic.git

    2. In the new directory first I tried to run npm install but I got the error that package.json didn’t exist. So I tried to install request directly by running npm install requestbut I got the same error.

    3. I tried creating package.json by running npm init. then I was able to install Request by running npm install request.

    4. I requested a Google API key from here:
      https://developers.google.com/maps/documentation/javascript/get-api-key

    5. My config looks like this:

        {
          module: 'mrx-work-traffic',
          position: 'top_left',
          header: 'Traffic',
          config: {
            apikey: '*** My API Key ***',
            origin: '135 Bellefair Ave, Toronto ON M4L 3V1',
            startTime: '00:00',
            endTime: '23:59',
            destinations: [
              {
                destination: '37 Holland Dr Bolton, ON L7E 5S4',
                label: 'Mars'
              }
            ]
          }
        },    
    
    

    I don’t see any errors in the console. All I get on my screen is the header’s underline, but not even the label text.

    I suspect that the problem is either that Request is not installed properly, or that this won’t work with Canadian addresses. Any thoughts?

    Thanks!
    -Jeff



  • Hey j.e.f.f…

    1. clone in modules directory (remove the npm files you created through npm install)
    2. go back to root…
    3. type “npm install”, if “request” not installed yet (should be installed by default)
    4. request api key (you have already, looks good)

    your config looks good too…

    just to be sure, plz use :

    origin: 'Platz der Republik 1, 11011 Berlin',
    destinations: [
    			{
    				destination: 'Platzl 9, 80331 München',
    				label: 'Hofbräuhaus'
    			}
    		]
    

    But it shouldn’t be a problem, using Canadian addresses…


  • Module Developer

    @domsen123 I followed your instructions and I still can’t get it to work for me.

    I did a little digging into your code, and it seems like this line is evaluating to false every time:

    mrx-work-traffic.js: Line 43

    if( now >= this.config.startTime && now < = this.config.endTime )
    

    (space between < and = added by me. Otherwise it broke markdown…)

    I added a console.log at line 57:

    else{
          console.log("====================== hiding...");
          this.hide(0);
    }
    

    and I see that in my console. It looks like now is not interpreted to be between config.startTime and config.endTime.

    My config has them set as follows:

            startTime: '00:00',
            endTime: '23:59',
    

  • Module Developer

    @domsen123 A bit more hacking on this and I got it to work. I changed how the date comparison is done:

        var now = moment();
        var startTimeSplit = this.config.startTime.split(":");
        var endTimeSplit = this.config.endTime.split(":");
    
        var startTime = moment().hour(startTimeSplit[0]).minute(startTimeSplit[1]);
        var endTime = moment().hour(endTimeSplit[0]).minute(endTimeSplit[1]);
    
        if( now.isSameOrAfter(startTime) && now.isSameOrBefore(endTime) ){
    
    

    I had to do this in three places:

    1. in the start() function
    2. in the getDom() function
    3. in the getHeader() function

    I’m no seasoned programmer, so I’m sure there is a better way to do this, but this at least works for me, and I can verify that Canadian addresses seem to work fine.

    Any chance you can add a configuration to each destination for the travel mode? i.e.: Driving, Transit, Biking, Walking. I have two destinations currently configured, my wife’s commute, which she drives, and mine, for which I take transit. I’d like mine to show transit time, not driving time.


Log in to reply
 

Looks like your connection to MagicMirror Forum was lost, please wait while we try to reconnect.