Update README.md
This commit is contained in:
1 parent
91fbcb1c8f
commit
65cd974ec9
1 file changed
+7
-6
@@ -1,7 +1,7 @@
|
||||
# CTA for ESP32
|
||||
## Notes
|
||||
### CTA API interface
|
||||
The CTA API can be fairly trivially queries to get a JSON response with the required metadata.
|
||||
The CTA API can be fairly trivially queried to get a JSON response with the required metadata.
|
||||
- Docs are available here: https://www.transitchicago.com/developers/ttdocs/
|
||||
- API consists of two main queries
|
||||
- 'Arrivals' - which lets you query all arrivals for a station available at https://lapi.transitchicago.com/api/1.0/ttarrivals.aspx
|
||||
@@ -48,7 +48,7 @@ The CTA API can be fairly trivially queries to get a JSON response with the requ
|
||||
|
||||

|
||||
|
||||
- The Locations API install returns all trains along a route.
|
||||
- The Locations API instead returns all trains along a route.
|
||||
- In the above example, we have an array of all trains, starting at the top of the tree, we can pick each like you would in a folder. Some pseudocode:
|
||||
- Say return json is output.json which = https://lapi.transitchicago.com/api/1.0/ttpositions.aspx?key=<KEYID>&rt=Blue&outputType=JSON
|
||||
- `output->tmst` gives us the time we made this query, this is handy to find the current time.
|
||||
@@ -64,11 +64,11 @@ The CTA API can be fairly trivially queries to get a JSON response with the requ
|
||||
|
||||
So example pseudocode:
|
||||
```
|
||||
# Create a simple 2D array of all stations (imagine table with two columns) and when the next train arrives. Let's set arrival time to 999 for now (i.e. not any time soon).
|
||||
# Create a simple 2D array of all stations (imagine table with two columns) and when the next train arrives. Let's set arrival time to 2199-01-01 for now (i.e. not any time soon).
|
||||
# We can use the station number instead of the name to keep code simpler (don't have to deal with spaces or symbols)
|
||||
stations_eta = <array>
|
||||
stations_eta[40380] = 999
|
||||
stations_eta[40390] = 999
|
||||
stations_eta[40380] = 2199-01-01
|
||||
stations_eta[40390] = 2199-01-01
|
||||
.... etc ....
|
||||
|
||||
# Get route data in JSON format
|
||||
@@ -84,7 +84,8 @@ time_now = output->tmst
|
||||
for train in output->ctatt->route->0->train:
|
||||
# 'train' will now refer to the first train in the folder, aka 0.
|
||||
# So we can save the next stop of the train
|
||||
next_stop = train->nextStaId
|
||||
statiom_eta[next_stop] = train->nextStaId
|
||||
|
||||
# The time of the next stop
|
||||
time_to_stop = train->arrT
|
||||
# Get the time difference.
|
||||
|
||||
Reference in new issue
Block a user