# Help with a project to display real time bus/train time tables

**URL:** <https://discourse.nodered.org/t/help-with-a-project-to-display-real-time-bus-train-time-tables/98107>\
**Category:** General\
**Created:** [13 July 2025 07:19 UTC](https://discourse.nodered.org/t/help-with-a-project-to-display-real-time-bus-train-time-tables/98107 "2025-07-13T07:19:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [13 July 2025 07:19 UTC](https://discourse.nodered.org/t/help-with-a-project-to-display-real-time-bus-train-time-tables/98107/1 "2025-07-13T07:19:47Z")

</div>

I'm bored and am playing with having a dynamic display of bus arrival times from _Point 1_ to _Point 2_.

I live in Sydney and there is a page which I can use to get the times but it has me curious.

[This link to get times (example)](https://transportnsw.info/routes/details/sydney-buses-network/491/74491)

 ![Screenshot from 2025-07-13 17-09-52](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/0/d09e1989d14d4572ae0b66a69cd76bf9ac3faa67.jpeg)

(Follow the red line. give or take.)

This is the flow:  
But it doesn't _work_ as expected.

```auto
[{"id":"1f40efb6859bd765","type":"http request","z":"c69fc09ca37a90cf","name":"Call Transport NSW API","method":"GET","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","x":530,"y":570,"wires":[["a23c4fd08cde3d5c"]]},{"id":"fb748427cbbd5591","type":"function","z":"c69fc09ca37a90cf","name":"Build URL & Headers","func":"// Your API key goes here\nconst apiKey = \"my_key_here\";\n\nconst originStop = \"2131101\";\nconst destinationStop = \"2046143\";\n\n// Get current date/time\nconst now = new Date();\n\n// Format date as YYYYMMDD\nconst year = now.getFullYear();\nconst month = String(now.getMonth() + 1).padStart(2, '0');\nconst day = String(now.getDate()).padStart(2, '0');\nconst dateStr = `${year}${month}${day}`;\n\n// Format time as HHMM\nconst hours = String(now.getHours()).padStart(2, '0');\nconst minutes = String(now.getMinutes()).padStart(2, '0');\nconst timeStr = `${hours}${minutes}`;\n\n// Build URL\nconst url = `https://api.transport.nsw.gov.au/v1/tp/trip?outputFormat=rapidJSON&coordOutputFormat=WGS84%5BDD.DDDDD%5D&depArrMacro=dep&type_origin=any&name_origin=${originStop}&type_destination=any&name_destination=${destinationStop}&date=${dateStr}&time=${timeStr}&calcNumberOfTrips=3`;\n\n// Set message properties\nmsg.url = url;\nmsg.headers = {\"Authorization\": `apikey ${apiKey}`};\n\nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":300,"y":570,"wires":[["1f40efb6859bd765"]]},{"id":"a23c4fd08cde3d5c","type":"json","z":"c69fc09ca37a90cf","name":"Parse JSON","property":"payload","action":"obj","pretty":false,"x":730,"y":570,"wires":[["998cfb197a08f554"]]},{"id":"1805d454664526f0","type":"inject","z":"c69fc09ca37a90cf","name":"Start","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":570,"wires":[["fb748427cbbd5591"]]},{"id":"998cfb197a08f554","type":"function","z":"c69fc09ca37a90cf","name":"Process Journeys","func":"// Extract journeys\nlet journeys = msg.payload.journeys || [];\n\nif (journeys.length === 0) {\n node.warn(\"No journeys found.\");\n} else {\n journeys.forEach((journey, i) => {\n journey.legs.forEach((leg, j) => {\n let stops = leg.stopSequence ? leg.stopSequence.map(stop => stop.name) : [];\n node.warn(`Journey ${i+1} Leg ${j+1} stops: ${stops.join(\", \")}`);\n });\n });\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":910,"y":570,"wires":[["ce5db5ecd35b3166"]]},{"id":"ce5db5ecd35b3166","type":"debug","z":"c69fc09ca37a90cf","name":"Debug Output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1100,"y":570,"wires":[]}]

```

This is what I get as output:  
`Journey 1 Leg 1 stops: Frederick St at Banks St, Ashfield, Frederick St at Albert Pde, Ashfield`

`Journey 1 Leg 2 stops: Frederick St at Albert Pde, Ashfield, Frederick St before Elizabeth St, Ashfield, Elizabeth St before Alt St, Ashfield, Elizabeth St at Bland St, Ashfield, Ashfield Station, Brown St, Stand C, Ashfield`

`Journey 1 Leg 3 stops: Ashfield Station, Platform 5, Ashfield, Croydon Station, Platform 5, Croydon, Burwood Station, Platform 6, Burwood`

`Journey 1 Leg 4 stops: Burwood Station, Burwood Rd, Stand E, Burwood, Westfield Burwood, Victoria St, Burwood, Victoria St at Shaftesbury Rd, Burwood, Victoria St at Lucas Rd, Burwood, Burwood Girls High School, Queen St, Croydon, Queen St opp Webb St, Croydon, Blair Park, Queen St, Croydon, Lang St after Queen St, Croydon, Church St opp Centenary Park, Croydon, Church St at Croydon Rd, Croydon, Croydon Rd at Dalmar St, Croydon, Great North Rd opp Harrabrook Ave, Five Dock, Great North Rd at Longview St, Five Dock, Great North Rd opp Club Five Dock RSL, Five Dock`

And then it goes on to `Journey 2`, so I won't include it for now.

But I don't get what's happening.

It _seems_ to me that it thinks I walk from one side of the road to the other and catch the bus going in the opposite direction and all this other stuff which complicates what I'm wanting to get/do.

The API\_KEY is removed. Sorry. But I'm sure you understand.

Anyone near by mind having a look and help me understand how to get it working?

I have a few bus routes / train time tables I want to see dynamically see their times on a GUI.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [13 July 2025 10:43 UTC](https://discourse.nodered.org/t/help-with-a-project-to-display-real-time-bus-train-time-tables/98107/2 "2025-07-13T10:43:43Z")

</div>

> [@Trying\_to\_learn](#):
>
> I have a few bus routes / train time tables I want to see dynamically see their times on a GUI.

Interesting that I've been thinking about timetables myself recently. But I started with something simpler

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/d/fd7932145b3f48926624d700cf955782355fc37f.png)

This uses a simplified web site that already processes the main UK timetables and makes it easier to deal with. I've not tried to do any realtime info as yet.

I really do need to get on top of bus timetables as well but that is certainly a bit harder.

Sorry I can't help you with Sidney though. Wrong side of the world. 😃

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [13 July 2025 10:49 UTC](https://discourse.nodered.org/t/help-with-a-project-to-display-real-time-bus-train-time-tables/98107/3 "2025-07-13T10:49:09Z")

</div>

No problems.

I've got talking to _Mr ChatGPT_ and as handy as _he_ is......

I was given _scripts_ (not exactly) to do and get the information.  
And they worked so then we went to the `function` node and codes.

But they don't.

So there seems to be something wrong.

I mentioned the failings and they were promptly addressed, but it seems there is something else going on not helping.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [13 July 2025 11:01 UTC](https://discourse.nodered.org/t/help-with-a-project-to-display-real-time-bus-train-time-tables/98107/4 "2025-07-13T11:01:30Z")

</div>

Well, interesting! Turns out that there is a UK-wide realtime bus API! Who knew 😃

> **[NextBuses API - data.gov.uk](https://www.data.gov.uk/dataset/15be9dba-392c-4375-a931-425e35b956f7/nextbuses-api)**

Did you check for something like that in Oz?

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [13 July 2025 11:14 UTC](https://discourse.nodered.org/t/help-with-a-project-to-display-real-time-bus-train-time-tables/98107/5 "2025-07-13T11:14:04Z")

</div>

As far as I know, yes.

I can use the site provided or I can get a _KEY_ and make my own _front end_ to display stuff.

It is just knowing how the data is structured to get what I want.

(Strange _Mr Chatgpt_ couldn't work that out)

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [13 July 2025 11:33 UTC](https://discourse.nodered.org/t/help-with-a-project-to-display-real-time-bus-train-time-tables/98107/6 "2025-07-13T11:33:31Z")

</div>

> [@Trying\_to\_learn](#):
>
> (Strange _Mr Chatgpt_ couldn't work that out)

Maybe he gets confused by being upside-down (being in Oz and all!) 🤣

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [11 October 2025 11:33 UTC](https://discourse.nodered.org/t/help-with-a-project-to-display-real-time-bus-train-time-tables/98107/7 "2025-10-11T11:33:37Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
