saml-dev / mmm-traffic Goto Github PK
View Code? Open in Web Editor NEWThis a module for the MagicMirror. It displays travel time between two locations, using the Mapbox directions API to factor in current traffic conditions.
This a module for the MagicMirror. It displays travel time between two locations, using the Mapbox directions API to factor in current traffic conditions.
Hello,
I'm very new to JS and MagicMirror so please forgive my candid question... just in case :)
I'm on a rpi 2 plateform with jessie. I installed the module yesterday, configured it via config.js file and everything was fine. A few hours later, i get back to my desk and see that the commute time wasn't displayed anymore.
Nothing change in the config file, I try to reload MagicMirror application, reboot the pi, look at the log (pm2 log mm) at startup... everything seems to be fine.
My api key was created yesterday too. I can see activity on the google api dashboard and I can see when the activity stoped. I created a second one, same result.
The output on the screen is :
Current commute is --
Travail via --
Here is my config file :
{
module: 'MMM-Traffic',
position: 'bottom_left',
classes: 'dimmed medium',
config: {
api_key: 'ABCDEFGH123',
mode: 'driving',
origin: '1 Boulevard Malesherbes, 75008 Paris',
destination: '1 Rue de Rivoli, 75004 Paris',
route_name: 'Travail',
changeColor: true,
showGreen: false,
limitYellow: 5,
limitRed: 20,
traffic_model: 'pessimistic',
interval: 60000,
showWeekend: false,
allTime: false
}
},
Here are the logs of pm2 :
0|mm | > [email protected] start /home/pi/MagicMirror
0|mm | > electron js/electron.js
0|mm | Starting MagicMirror: v2.1.0
0|mm | Loading config ...
0|mm | Loading module helpers ...
0|mm | No helper found for module: alert.
0|mm | Initializing new module helper ...
0|mm | No helper found for module: clock.
0|mm | Initializing new module helper ...
0|mm | No helper found for module: compliments.
0|mm | Initializing new module helper ...
0|mm | No helper found for module: currentweather.
0|mm | No helper found for module: weatherforecast.
0|mm | Initializing new module helper ...
0|mm | All module helpers loaded.
0|mm | Starting server op port 8080 ...
0|mm | Server started ...
0|mm | Connecting socket for: updatenotification
0|mm | Connecting socket for: calendar
0|mm | Starting node helper for: calendar
0|mm | Connecting socket for: MMM-Traffic
0|mm | MMM-Traffic helper started ...
0|mm | Connecting socket for: newsfeed
0|mm | Starting module: newsfeed
0|mm | Sockets connected & modules started ...
0|mm | Launching application.
0|mm | Create new calendar fetcher for url: https://calendar.google.com/calendar/ical/abcdefg/basic.ics - Interval: 300000
0|mm | Create new calendar fetcher for url: https://calendar.google.com/calendar/ical/abcdefg/basic.ics - Interval: 300000
0|mm | Create new calendar fetcher for url: https://calendar.google.com/calendar/abcdefg/basic.ics - Interval: 300000
0|mm | Create new news fetcher for url: http://www.bfmtv.com/rss/info/flux-rss/flux-toutes-les-actualites/ - Interval: 300000
Do you know anything about this "issu" ?
Is there a way to get logs from the module directly or something like debug mode to help understand what's go wrong ?
I can give further information if you ask.
Hi,
would it be possible to set "Destination" as a dynamic value? I´m storing the parking position of my car in my smarthome system and I would like to use this position as a destination. As the coordinates change daily the destination Value in MagicMirror Config file must be dynamically. Any Idea how I could achieve this?
PS: The access to my Smart Home System (FHEM) will probably be over HTTP
as a MM user, I'd like to understand the traffic times for dropping the kids off at school (dad) and going to work (mom) when it's monday through friday.
After following the directions the module worked perfectly.
But after a few config changes I am getting "Loading Commute..." but it never loads.
Upon exiting the MagicMirror I see this in the terminal window. Node_helper has Legs in it but the Request.js does not contain Legs variable.
Please advise.
Whoops! There was an uncaught exception...
TypeError: Cannot read property 'legs' of undefined
at Request._callback (/home/pi/MagicMirror/modules/MMM-Traffic/node_helper.js:31:45)
at Request.self.callback (/home/pi/MagicMirror/modules/MMM-Traffic/node_modules/request/request.js:187:22)
at emitTwo (events.js:106:13)
at Request.emit (events.js:191:7)
at Request. (/home/pi/MagicMirror/modules/MMM-Traffic/node_modules/request/request.js:1126:10)
at emitOne (events.js:96:13)
at Request.emit (events.js:188:7)
at IncomingMessage. (/home/pi/MagicMirror/modules/MMM-Traffic/node_modules/request/request.js:1046:12)
at Object.onceWrapper (events.js:290:19)
at emitNone (events.js:91:20)
It would be great if the threshold triggers for amber and red were config parameters.
limitAmber: 20,
limitRed: 50
and then
//change color if desired and append
if (this.config.changeColor) {
if (this.trafficComparison >= 1 + (this.config.limitRed / 100)) {
commuteInfo.className += ' red';
} else if (this.trafficComparison >= 1 + (this.config.limitAmber / 100)) {
commuteInfo.className += ' yellow';
} else if (this.config.showGreen) {
commuteInfo.className += ' green';
}
}
This should work... but my test commutes aren't tripping the colour change
Hi,
I'm able to get my general destination working, but am unable to implement the specific weekday destinations (mon_destination, tues_destination, etc). When I tried it as in the example code, none of the weekdays showed up, only my main 'destination'. I tried running the module twice in my config.js, as I found elsewhere that's how to get two destinations going--if I only have the mon_destination named in the second instance, that module shows as loading and never changes. If I put in a different destination into the second module's 'destination' field, it works.
How do I get the daily destinations to work? Am I supposed to be able to run them in the same instance of the module as my standard work destination?
Hi Sam,
Firstly, thanks for sharing such an awesome module - It's the first thing I added to my Magic Mirror and I love it!
This is more of a request than an issue - would it be possible to dynamically set the destination based on the day of the week (or even better, a holiday/non-holiday value)? I suspect the latter would be incredibly difficult but perhaps the former might be a possibility?
I appreciate you've got your own life to live - if it's difficult to spare the time, woud you mind me raising the request and referencing the module on the Magic Mirror builders forum, to see if other developers are up for the challenge?
All the best,
Darren
Hey, I only see "Start at: -- Work via -- to arrive at 8:00
module: 'MMM-Traffic', position: 'top_left', classes: 'dimmed medium', //optional, default is 'bright medium', only applies to commute info not route_name config: { api_key: 'my api !?', mode: 'driving', origin: 'start adress', destination: 'end address', arrival_time: '0800', //optional, but needs to be in 24 hour time if used. route_name: 'Work', changeColor: true, showGreen: false, limitYellow: 5, //Greater than 5% of journey time due to traffic limitRed: 20, //Greater than 20% of journey time due to traffic traffic_model: 'pessimistic', interval: 120000, //2 minutes showWeekend: false, allTime: false, loadingText: 'Check..', prependText: 'Work ', leaveByText: 'Start at: ', hideOffHours: false,
I do have two questions:
Since I am in Europe, does it matter HOW the address is inserted? "Street 1, zip code, city" or " Street+1,Zipcode,city" or somehow else??
Can someone please explain how to obtain a api_key. Since I am not sure, fi I have the right one, or if I have done it correctly!?
Thank You !
I'm sure this is a really dumb issue i'm having, but I'm having the issue where it's stuck loading. I tried out the link mentioned in #10 , which worked. When I look at the API dashboard it is not showing any requests from the MagicMirror. Is there any text I need to include prior to the API key in the quotes?
Hey!
For some reason the module is stuck on "Loading commute..." and when I check the maps api requests section it says it hasn't received any requests. Anyone have any idea what might be causing this and how to fix it? Thanks!
First, I just wanted to say I love the module.
From a different thread I saw, you can have different routes display so I copied my first one and pasted the copy below it. I edited the location to go to my girlfriend's work and changed her arrival_time (1230).
Now it keeps flipping both modules back and forth between my departure time (6:39am) and her departure time (12:06pm).
Is there anything I can do so they don't both update to the same departure times?
Since the calendar module broadcasts location and title, would it be possible to have the traffic model use a dynamic location and time based on if the next appointment in my calendar has a location?
I am very new to using modules. I followed the instructions to install the module. I requested and received an API from Google, and I inserted the API into the script as instructed by the readme. Even when using the example provided by the readme, the screen only says, "loading commute..."
Is there a way to debug this script to find where I am having an issue?
Is there a way to add a line break to the prependText? I have two modules to two different destinations, so I have the prependText set up to say "Current commute time to Destination A is" and "Current commute time to destination B is". Unfortunately, it's extending halfway across the screen and overlapping with the center text.
I tried setting it up as:
prependText: 'Travel time to\nDestination A is',
But it still shows up as a single line. Any ideas?
Hello,
First of all, thank you for providing such a great module.
I have a problem running the magic mirror with this module. After the set up is completed (installing MMM-traffic, get google API key) while trying to run the magic mirror, the interface opens with a blank screen. The application launches well but nothing is displayed on the interface.
Please let me know if you need more information.
Please help. Appreciate your time and effort
Thank you,
bikerboy
Language cannot be set.
THX
I get the response
{
"error_message" : "Invalid request. Missing the 'departure_time' parameter.",
"routes" : [],
"status" : "INVALID_REQUEST"
}
Manually adding &departure_time=now
in the browser URL fixed it for me. Should that key just be included in the getParams
function at https://github.com/SamLewis0602/MMM-Traffic/blob/master/MMM-Traffic.js#L129?
While setting up MMM-Traffic told me that my way to work will be around 1 hour 52 min and the summary says via 2 highways, quite far away from normal track.
I used the example URL from Google with my locations to check the results. There the track and the estimated time are matching real life.
When I use this in the config file, it says that I have an error in my config.
Edit : My mistake, I had a special char in the string!
Thanks!!
LJ
Hey, Nice module but I can't manage to make it work...
It keeps showing 'Commuting...' and nothing happens.
I just pasted your config settings and change API ID.
On the console, it says 'MMM-Traffic received a system notification: DOM_OBJECTS_CREATED'
Nothing seems to work. Did I do something wrong ?
Hi, this is an awesome module, but I am having an issue with using the hideHoursOff argument:
`{
module: 'MMM-Traffic',
position: 'top_left',
classes: 'bright medium', //optional, default is 'bright medium', only applies t$
config: {
api_key: '',
mode: 'driving',
origin: '',
destination: '***************',
arrival_time: '0930',
route_name: 'Home to Work',
changeColor: true,
showGreen: false,
limitYellow: 5, //Greater than 5% of journey time due to traffic
limitRed: 20, //Greater than 20% of journey time due to traffic
traffic_model: 'pessimistic',
interval: 120000, //2 minutes
showWeekend: false,
allTime: false,
startHr: 6,
endHr: 12,
hideOffHours: true
}
},
{
module: 'MMM-Traffic',
position: 'top_left',
classes: 'bright medium', //optional, default is 'bright medium', only applies t$
config: {
api_key: '',
mode: 'driving',
origin: '',
destination: '*****',
arrival_time: '1845', //optional, but needs to be in 24 hour time if used.
route_name: 'Work to Home',
changeColor: true,
showGreen: false,
limitYellow: 5, //Greater than 5% of journey time due to traffic
limitRed: 20, //Greater than 20% of journey time due to traffic
traffic_model: 'pessimistic',
interval: 120000, //2 minutes
showWeekend: false,
allTime: false,
startHr: 15,
endHr: 20,
hideOffHours: true
}
},
`
I believe I am using it correctly, I am expecting it to show the first travel time in the morning and the second in the afternoon, and for it not to be there during the other times outside startHr, and endHr, but it is just not showing at all.
As soon as I put hieOffHours: false, it shows both all the time, am I putting the start and end arguments incorrectly?
Many thanks!!!
Will
It would be awesome if you could work together with @MichMich so that the calendar may send a notification for all events that have a location and your module takes that notification and could then optionally display how long you need to get there and when you should start driving.
Traffic loads times on initialization but fails to update while Magic Mirror runs.
Hello SamLewis,
I am trying to get this module working and I am running into trouble. The magic mirror works and is displaying everything except the traffic module. I believe I installed everything right and I believe I am using the correct API key but the module will no display. any help would be appreciated. Thank you in advance.
Hi,
In your example config.js you are using an attribute called "classes"
module: 'MMM-Traffic',
position: 'top_left',
**classes: 'dimmed medium',** //optional, default is 'bright medium', only applies to commute info not route_name
config: {
The same attribute name is use in MMM-Facial Recognition Module to call the user name that logs in.
If you try to use this module along with MMM-Traffic module there is a conflict that makes this module not work.
module: 'MMM-Traffic',
position: 'top_left',
**classes: 'default for_all',**
**classes: 'dimmed medium',** //optional, default is 'bright medium', only applies to commute info not route_name
config: {
This attribute should be named differently to avoid this conflict
Is there any particular reason why my commute times wouldn't be loading? It just stopped one day and now it just says "Current commute is--". Thank you!
Thanks for this great module, did something similar for the old version of MagicMirror.
But it doesn't work with special characters (german umlauts) in the origin/destination address,
What doesn't work:
origin: 'Werastraße 123, 70190 Stuttgart',
destination: 'Hans-Klemm-Straße 5, 71034 Böblingen',
The request in node_helper.js -> getCommute returns a 400 bad request.
Quick fix: URL Encode both addresses
origin: 'Werastra%C3%9Fe%20123%2C%2070190%20Stuttgart',
destination: 'Hans-Klemm-Stra%C3%9Fe%205%2C%2071034%20B%C3%B6blingen',
If I can figure this git stuff out i will implement a fix to the code and do a pull request :)
Is there any particular reason why you use a table in the wrapper? If this is converted to basic DIV's it can be used in the center elements as well.
Having an issue that the module never fully loads, I have the both the address input correctly in the config file. The Google API key is also there. It shows that the module is loading when the Mirror is launched, but never pulls up. I just continuously get Loading....
Please advise
Thanks
I have absolutely zero coding or java script or JSON knowledge and the fact that Ive gotten to where I am with this project in the time is amazing, But your module (which is amazing for my girlfriend who leaves late every day) takes the toll road which pretty much renders any accurate traffic patterns useless. On the google maps website (where you obtain the API key) it says to add avoid=tolls but with my knowledge, I simply dont know how or where to do so.
If you could possible take a look at that I would forever be grateful.
Thank you
Jose
Hi there,
unfortunately I got an error using this module and it hangs with Loading commute...
The API-Key and stuff are correct, I get data using my config in a webbrowser.
I can see the "legs" section in the webbrowser, but I don't know why the module doesn't handle it.
Thanks in advance,
eazee187
Please make the entry's like arrival, via, to arrive by an maybe others translatable.
I do this every time by my self but when i do update your Module my translation in your MMM-Traffic.js are gone. :-(
Please update this.
Hi Sam,
Great module, very useful every morning!
I would have a feature request to make it even better :) : Is there a possibility to display the arrival hour instead of the time of commute? The way I would see that work is to take the current time and add it the commute time. Not sure how complex or possible that would be?
All the best,
Vincent
I've noticed the "Leave by hh:mm" text will always stay the default color regardless of red/yellow limits. By removing the arrival_time parameter, the colors returned.
Whoops! There was an uncaught exception...
TypeError: Cannot read property 'legs' of undefined
at Request._callback (/home/pi/MagicMirror/modules/MMM-Traffic/node_helper.js:47:55)
at Request.self.callback (/home/pi/MagicMirror/modules/MMM-Traffic/node_modules/request/request.js:187:22)
at emitTwo (events.js:106:13)
at Request.emit (events.js:191:7)
at Request. (/home/pi/MagicMirror/modules/MMM-Traffic/node_modules/request/request.js:1048:10)
at emitOne (events.js:96:13)
at Request.emit (events.js:188:7)
at IncomingMessage. (/home/pi/MagicMirror/modules/MMM-Traffic/node_modules/request/request.js:969:12)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:185:7)
Hi Sam,
First, I would like to congratulate you for the job you have done done!!!
I was wondering if it is possible to have more than one mode in the same module to get to the same adress ?
I managed to have driving mode and transit mode but in two different modules and not in only one.
Thanks for you help
Yann
Hello, first thanks for the module, its very well explained, has lots of customization options, and they are very well listed.
I have an issue with the module though, and I dont know where the problem is. I installed the module and got no error, then I copied the module in the config file, edited it with the API that got from google, added the adresses I wanted and I ran MM. The module seems to work as it appears on the screen, but only displays "Leave by --" or "Current Commute --" depending on wether i chose to put an arrival time or not. Then I tried it with the default adresses and the same happens.
This is a screenshot of what it displays.
I then tried with another API key, and none key, and the same happens, so I imagine it has something to do with that.
Is there any info I can provide so you can tell me if its the API or something else? or is there something in particular I have to do when requesting the key?
Thank you very much! looking forward to solve this issue and enjoy your module!
Hi, i really can't find my mistake. If i set the hideOffHours: true the commute time is never displayed. Any chance someone could point me into the right direction?
settings from config.js
{ module: 'MMM-Traffic',
position: 'top_left',
classes: 'dimmed medium', //optional, default is 'bright medium', only applies to commute info not route_name
config: {
api_key: '*****************************',
mode: 'driving',
avoid: 'highways',
origin: 'Marktplatz 1, 70173, Stuttgart',
destination: 'Kaesbruennlestraße, 71063, Sindelfingen',
arrival_time: '1630', //optional, but needs to be in 24 hour time if used.
route_name: 'Stuggi->SiFi',
changeColor: true,
showGreen: false,
limitYellow: 5, //Greater than 5% of journey time due to traffic
limitRed: 20, //Greater than 20% of journey time due to traffic
traffic_model: 'pessimistic',
interval: 120000, //2 minutes
showWeekend: false,
allTime: false,
hideOffHours: false
}
},
i also checked the values in the MMM-Traffic.js file, they're untouched
startHr: 7,
endHr: 22,
now it's 14:42 in my timezone, this should be within the range of 7 to 22 arrival is set to 1630 but if i change hideOffHours from false to true the module disappears.
Hello,
I think it would be a good option to be able to have multiple destinations, eg. Work, Uni, School, etc.
Do you think this is something possible to add?
Thanks
Luke
is there anyway for it to show summary when mode is transit?
Hi SamLewis0602
First of all thank you for your work!!
I am a novice with all these stuff and i wanted to know witch kind of Google API key have you used??
Server, browser??
I am stuck and the message loading commute... and the request seems good on the google console.
Thanks!
is it possible to have different arrival times for different destinations either for same or different day?
eg.
Destination B, arrival time 1500
Destination C, arrival 1700
I've tried adding arrival_time after each destination, but it calculates everything based on the last arrival time provided
I believe my issue is with the api code, I have one but i dont think it is working. I tried posting it into that weblink you mentioned in another thread, but it told me that my api key was invalid. Any suggestion? Ive double and triple checked the actual module files and everything appears to match yours as far as i can tell. When i run the program, it never loads, only says "Loading commute"
The terminal window outputs this when it tries to load the module,
"Whoops! There was an uncaught exception...
TypeError: Cannot read property 'legs' of undefined
at Request._callback (/home/pi/MagicMirror/modules/MMM-Traffic/node_helper.js:21:39)
at Request.self.callback (/home/pi/MagicMirror/modules/MMM- Traffic/node_modules/request/request.js:187:22)
at emitTwo (events.js:106:13)
at Request.emit (events.js:191:7)
at Request. (/home/pi/MagicMirror/modules/MMM- Traffic/node_modules/request/request.js:1048:10)
at emitOne (events.js:96:13)
at Request.emit (events.js:188:7)
at IncomingMessage. (/home/pi/MagicMirror/modules/MMM-Traffic/node_modules/request/request.js:969:12)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:185:7)
MagicMirror will not quit, but it might be a good idea to check why this happened. Maybe no internet connection?
If you think this really is an issue, please open an issue on GitHub: https://github.com/MichMich/MagicMirror/issues
"
Hello !
First I would like to thank you for this amazing module ! We use it every day with my wife and it is super handy.
I would like to know if it would be possible to display the address set for the current day. To be clearer, I have set a different address for each day of the week and I would like it to appear under "Home to work".
Is it possible/easy to do that ?
Cheers !
It would be awesome if we could get multiple stops added to the commute. I will take a swing at it later but I have never touched node/js
To get this new commit Update, can I just pull the code and type it into my .js file or do I have to flash an update install?
Hi Sam,
Thx for creating this module! I have tought one question, im still stuck in loading face. The api key works fine when tested (lots of links, also the ones mentioned earlyer #25) When put in browser it show up the request in mu developer console.
Have tried with different requests and with place id:s. Also have pulled the latest update.
Tryed to figure this out but now im headbanging the wall :D
Hi Sam,
It's me again.. I've noticed a bug with arrival time.
If the arrival_time has a value and mode is transit or bicycling, then commute keeps loading and nothing is displayed on the mirror ("TRAFFIC_TIMING" is not received in logs).
Any idea on how to correct that?
Thanks a lot,
Vincent
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.