Code Monkey home page Code Monkey logo

mmm-nstreinen's Introduction

NS Trains - MagicMirror² module

Build Status

This is a module for MagicMirror². Shows informantion on trains departuring a configurable Dutch trainstation.

(old images, will be replaced for V2) Example Visualization Example Visualization with destination

Installing the module

To install the module, just clone this repository to your modules folder:

  • git clone https://github.com/qistoph/MMM-nstreinen.git nstreinen
  • cd nstreinen
  • npm install to install the dependencies

Updating the module

Two simple steps, in the module dir:

  • git pull
  • npm install to update the dependencies

Using the module

You will need an apikey for the NS-API. This can be requested at http://www.ns.nl/reisinformatie/ns-api.

To use this module, add it to the modules array in the config/config.js file:

modules: [
  {
    module: 'nstreinen',
    position: 'top_right',
    header: 'Treinen vanaf Schiphol Airport',
    config: {
      apiKey:'<NS-API-Key>',
      fromStation: 'SHL'
    }
  }
]

Configuration options

The following properties can be configured:

Option Description
apiKey Your API key.
Request your credentials at NS API
Required
fromStation The station code to show trains for.
Required
toStation The destination (station code) to show trains for. If this is configured the trains and required transfers from station to this destination will be shown.
Optional
maxEntries Maximum number of trains to show per station.
Default value: 5
reloadInterval Number of milliseconds between refresh.
Keep in mind there is a maximum of 50.000 requests per day for the API.
Default value: 5 * 60 * 1000 (5 minutes)
departureOffset Trip planning only, requires destination: Number of seconds to 'delay' the trip plan with.
Especially usefull when you need time to travel to the train station.
Default value: 0 (0 seconds)
displaySymbol Defines wether or not to show a symbol for each line.
Possible values: true or false.
Default value: true
symbolMapping Maps the train types to the symbol to show.
If the train type is not found, the symbol for default is used.
Possible symbols: See Font Awesome website.
Default value: See Default symbolMapping.
fade Fade the trains listed to black. (Gradient)
Possible values: true or false
Default value: true
fadePoint Where to start fade?
Possible values: 0 (top of the list) - 1 (bottom of list)
Default value: 0.25

Station codes

NS API uses station codes to identify stations. You cannot (unlike version 1) use station names. After configuring the nstreinen module with an apiKey in your config.js you can use stations.js:

$ node modules/nstreinen/stations.js | grep -i 'schip'
SHL - Schiphol Airport

Default symbolMapping

symbolMapping: {
  'IC': 'train',
  'SPR': 'stop-circle',
  'Intercity': 'train',
  'Intercity direct': 'forward',
  'Sprinter': 'stop-circle',
  'Stopbus i.p.v. trein': 'bus',
  'Snelbus i.p.v. trein': 'bus',
  'default': 'train'
}

mmm-nstreinen's People

Contributors

dependabot[bot] avatar maximoei avatar qistoph avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

mmm-nstreinen's Issues

symbolMapping goes wrong

Did a new install, and now i got question marks instead of symbolMapping i guess.
So first the symbol of a train is shown, followed by space, then the question marks ??, and then the travel time between (), or Intercity + (traveltime).

Any Clue ?

Error fetching station

Related to #10

Error fetching station when the device temporarily loses internet connection. Module does not recover on its own. Error persists until the module is rebooted.

Error:
Error fetching station: Error: getaddrinfo EAI_AGAIN webservices.ns.nl webservices.ns.nl:80

Reproduce:
Temporarily disable the wifi network that the device is connected to. (Cannot confirm this is also an issue with cable internet, but I assume it is.)

Module stuck after a while

This has basically been an issue for the past year or so. Not sure why I didnt report it earlier.

After a certain amount of days the module will just get stuck and will no longer update the trips. There doesn't seem to be a pattern as to when it gets stuck. Sometimes it's a few days, sometimes more like weeks.

There also is no connection between the times at which it gets stuck. 6:12AM or 7:11PM, it appears to be completely random.

There is a simple workaround and that is just rebooting the magic mirror. While this fixes the issue temporarily this obviously is not the intended behaviour.

"received data emppty or invalid"

Gisteren de module geïnstalleerd en toegang aangevraagd tot de NS travel informatie API, wanneer ik met mijn inloggegevens de API daar test krijg ik de stationsinformatie correct binnen, echter op mijn MagicMirror krijg ik de melding "Received data empty or invalid"

image

Module doesn't start. Update in install required?

Hi , I tried implementing this module. The install was pretty straightforward. Getting an API these days works with the API portal by NS. I subscribed to public transport information API (many other APIS on prices / promotion etc are available. I presume that's the appropriate API. When I sign up for the API , I get a primary and secondary API. I tried pasting both in the basic config.js text:

{
module: 'nstreinen',
position: 'top_right',
header: 'Treinen vanaf Schiphol Airport',
config: {
apiKey:'',
fromStation: 'SHL'
}
}

Ive fillin in my API-key.... no module appears.
Could someone give me a few pointers?

npm install results in errors

Hi,
I am quite new to this, so forgive me for saying stupid stuff. I tried to follow the instructions to add the nstreinen module, but I ran into some issues. npm install resulted in several errors. I added a screenshot of these errors. The module is stuck at loading in my magicmirror. Here is the module in my config file:
{ module: 'nstreinen', position: 'top_right', header: 'Treinen vanaf Schiphol Airport', config: { apiKey:'xxx', fromStation: 'SHL' } },
Here are the versions I use:
magicmirror v2
npm version 6.13.4
nodejs version 10.18.0
Raspbian GNU/Linux 10

Additionally, I used the primary key of the "Public-Travel-Information" for the API-key in the config file (xxx). Is that the correct way?
Errors

If I need to provide additional info, please let me know.

Errors running npm install from nstreinen directory

When running npm install I get an error on the deprecated [email protected].
Then the installation quits.

I deleted the nstreinen directory, downloaded the module and the npm install again.
I get another error message that failed to parse package.json data. I am to inform the package author to fix his package.json file JSON.parse.

Error log is attached.
npm-debug.log

Keeps loading

Hi,

This module keeps loading on my mirror.
What am I doing wrong?

Bastiaan

OV Fiets counter

It would be cool to show the amount of available public transport bikes (OV Fietsen) for the selected train station. This data is available in json format at http://fiets.openov.nl/locaties.json, but I have insufficient knowledge about javascript to build this in to your existing version. Is this something you could implement?

Add parameter to display in the future

HI,
Great app, I have 2 instances on my mirror.
I have a future request. Is it possible to add paramater with a kind of delay in minutes. I need 10 minutes to get to the station, so I want to see the departures within 10 minutes. The current trains will already be gone when I arrive at the station.
Thanks!

Herman

Train delay traveladvice gone

For example the train is leaving 12:00 but has +12 minutes delay. The traveladvice (trip) is gone when it's 12:01. Is it possible to calculate the delay? or show the previous trip?

No helper found for module: nstreinen.

So I tried to load up the nstreinen module but it doesn't seem to work. It is showing that it needs a helper. I am new to using a Raspberry Pi so I'm not sure if I'm doing something wrong. I tested a other 3rd party Module and that one is working fine for me.

pi@raspberrypi:~/MagicMirror $ npm start

[email protected] start /home/pi/MagicMirror
sh run-start.sh

Starting MagicMirror: v2.3.1
Loading config ...
Loading module helpers ...
No helper found for module: nstreinen.

does anyone know how to fix this issue?

show one trip only.

Is it possible to only show the train from location A to B instant of every train from location A ?
is het mogelijk alleen 1 traject te laten zien?
For example / voorbeeld:
Utrecht > Heerlen 10.00
Utrecht > Maastricht 10.15
Utrecht > Maastricht 10.30 +3

Error fetching NS info: invalid API key

Hi,

Can you please help me? The screen keeps saying "Error fetching NS info: invalid API key"

I've got an API-key for "Public-Travel-Information" on https://apiportal.ns.nl/. Tried both primaire and secondaire key and also generated new ones. Do I have the wrong API?

The code is the one from the readme file:

` {
module: "nstreinen" ,
position: " top_right" ,
header: " Treinen vanaf Schiphol Airport" ,
config: {
apiKey: "xxxxxxxxxxxxxxxxxxxxxx",
fromStation: "SHL"
}
},

Thank you,
Mike

"Dit reisadvies vervalt" not shown on mirror

The problem i'm having, and probably all other users of the MM-NStreinenn module, is the missing message of "dit reisadvies vervalt" or roughly translated: "This travel advice is not longer valid".

What am i talking about

Mobile version:

Mobile version

MagicMirror version

MagicMirror version

How to test for yourself

What i did to show this problem:

  1. Look at the NS app to see where the problems are this day
  2. Travel from this station to another
  3. If the options are grayed out in the app, try it on your mirror
  4. The mirror will show the trains are driving as normal (Not good)

What should the MagicMirror show

The mirror should show the train is not driving at all (preferably), this can be shown with a crossCross or/and by Strikethrough text.

The "Let op, storing" message can be shown with a explanation mark or similar.

module wont load - naming wonkiness?

I'm having trouble getting this momdule to work. I followed the example provided. I get the following console.log messages:

error on loading script: modules/nstreinen//nstreinen.js

note the double slash and the fact that the dir is refered to as nstreinen and not MMM-nstreinen

I tried renaming the nstreinen.js to MMM-nstreinen.js and renamed the module in config.js, but I still cant get it to load. any suggestions?

cheers,
marc

Error (undefined) fetching NS info

H
hermlam 2 days ago

Hi,
A week or two ago my MMM-nstreinen module suddenly stopped. I didn’t make any changes, the api-key is ok and valid on the ns api portal.
Error is: Error (undefined) fetching NS info

Thanks,
Herman

Module doesn't show

the files are in the moved to the modules folder
installled them
i have setup the config file

but nothing on screens happen?

Error when specifying the arrival station: "Error fetching NS info: invalid API key"

Using only a departure station (without arrival station) works fine. Whenever I specify the arrival station, I get the "Error fetching NS info: invalid API key". Am I doing something wrong? Are other people facing the same issue?

{ module: 'nstreinen', position: 'top_right', header: 'Treinen', config: { apiKey:'<MyKey>', fromStation: 'GN', toStation: 'UT' } },

Error fetching station

After MMM-pir-sensor wake-up the MMM-nstreinen cannot load data.
error: Error fetching station: Error: read ECONNRESET

when refreshing magicmirror manually through MMM-Remotecontrol it works fine again,

cant find the problem :(

nstreinen, "Invalid namespace"

Hi! Getting this weird api response from socket.io:

Config:

{
                      module: 'nstreinen',
                      position: 'top_center',
                      header: 'Treinen vanaf Capelle Schollevaar',
                      config: {
                              apiKey: 'primary_ns_app_api_key',
                              fromStation: 'CPS',
                              toStation: 'LEDN'
                      }
},

Error:
Screenshot 2020-06-01 at 14 51 27

New API

NS just emailed that the API will change in early 2019.

This module should be updated accordingly.

Additional information that was sent:

De NS-API zoals u die kent zal uitgefaseerd worden. Van u als gebruiker verwachten wij, als u gebruik wilt blijven maken van onze services, dat u gaat migreren naar onze nieuwe API.

Hoe u dit aan moet pakken is te lezen in de migratiehandleiding die we met deze mail meesturen.

Kort samengevat gaat het volgende voor u veranderen:
· U heeft voor het gebruik van de nieuwe API een API-key nodig. Deze is aan te vragen via het NS API portaal (https://apiportal.ns.nl/)
· URL’s naar de services veranderen
· Het response is in het JSON formaat
· De veldnamen van de parameters en de responses zijn verandert.

U krijgt 6 maanden de tijd om de migratie uit te voeren. De planning is om per 1 oktober 2019 de oude API uit te schakelen en onze services niet meer beschikbaar te stellen.

Bij vragen kunt u ons bereiken via het volgende e-mailadres: [email protected]

NS REST API migration guide.pdf

randstadrail

Hi,

first of all, thnx for this great module. Looks really nice.
I was wondering if it's possible to add the stations for the "randstadrail".
Although the ns.nl website recognize the randstadrail stations, this module cant find them.

Would be a great update.

Thnx in advance.

Getting new (undefined) error

Hi guys,
sorry for I have not been able to get more details about it. I have updated the module and all dependencies, but I get the following error still:
LIZE - Payload: [object Object]
[2020-06-07 14:01:25.272] [LOG] Error: Error: Resource not found
at /home/pi/MagicMirror/modules/nstreinen/node_modules/ns-api/nsapi.js:69:19
at finalCallback (/home/pi/MagicMirror/modules/nstreinen/node_modules/httpreq/lib/httpreq.js:98:7)
at IncomingMessage. (/home/pi/MagicMirror/modules/nstreinen/node_modules/httpreq/lib/httpreq.js:376:9)
at IncomingMessage.emit (events.js:205:15)
at endReadableNT (_stream_readable.js:1154:12)
at processTicksAndRejections (internal/process/task_queues.js:84:9) {
statusCode: 404
}
Can someone help point me in the right direction? Thank you:)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.