Custom project to give a display to show when my next train is
Uses RealTime Trains API - for further details: https://api.rtt.io/ - this is where the credentials are obtained from for you to store in a local file called info.json
RTT is what this app is based on, and due to it's use policy you will need to get your own set of personal credentials for this to work.
- Go to the RTT Registration Page
- Fill in your details
- Activate your account using the link you should receive by email
- If you haven't already, go to the RTT Login Page and login (N.B. your username is not your email - this catches me out occasionally!)
- Your auth credentials should be displayed here on the right handside here at https://api.rtt.io/
- In terminal/cmd line navigate to where you want to place the project
- (If using https) Run
git clone https://github.com/jcts3/whenismytrain.git
cd whenismytrain
- enter project foldernpm install
- install the required npm packages- Once install completed, it's time to create
- Take the template info.json file that can be found here and rename it to info.json
- Insert your RTT username and password into the credentials object found above or at your RTT Homepage after logging in
- Using the links found below in useful links, fill in your own favourite stations with their name, CRS and TIPLOC codes. You can either use these to pull in directly from the info.json file
- Save the file as
info.json
- Instructions about fill in favourite services etc.
- Once file has been created
node app.js
- A console message should pop up saying you are now running on port 8081
- In a browser go to http://localhost:8081/EDB/GLQ/departureinfo to test out - this should give the next train from Edinburgh Waverley to Glasgow Queen Street.
- The page listed as the link here should be a base point, which has the API docs? Swagger??
If you set up bookmarks, (or once the app is further developed), it can be useful to have a home server running the app. I use a raspberry pi for this. The following steps should allow this:
- Ensure your pi has npm and node.js - you can check this by getting verion numbers from running
node -v
andnpm -v
- Follow the instructions outlined above in How to
- Find out your Pi's IP address on your Wi-fi - this should be doable using
sudo ifconfig
and looking at the IP value forwlan0
- more details can be found at this Adafruit guide. - On your phone/laptop/other device with browser on the same wifi (let's be honest there's probably a fridge that can do it), navigate to
http://<WLAN_IP_ADDRESS_FOUND_IN_3>:8081/EDB/GLQ/departureinfo
- To find any station code, either CRS, or TIPLOC, use Railway Codes
- If you only need CRS codes, use the National Rail CRS List where you can also get a csv file of these.
- Tidy up README for howto
- Demo images
- Describe API -> Swagger?
- Look at separating out api as separate npm library + build front end to utilise it
- Batch file to autocreate info.json file?
- Re-order file structure to tidy up
- A UI! Don't just display it as basic JSON - React???
- A setup procedure - either a script that runs when first initialised, or an API point of /setup, where you can enter your favourite stations, particular trains, etc.
- A lookup service - potensh just for stations to start with - either expose it as just a page, or store in a database.