Websocket API for realtime vehicle positions and stop sequences based on scheduled times and realtime updates.
The websocket API works by receiving commands from and sending messages to the client application. The possible commands and messages are described in detail in the Operations section of this AsyncAPI documentation.
Note that for basic browser applications, it might not be necessary to talk directly to the realtime API. Consider using our client library instead. If your use-case is not covered by that, feel free to read on.
You have to establish a websocket connection as described in the Servers section using your favorite client library. A valid API key is needed. See terms of service for more information on API keys.
If your client library does not support websocket native ping/pong frames (for example
if your application runs in a web browser), you have to periodically send application
layer PingCommand
s to keep the connection alive. The payload of
a PingCommand
is simply PING
. If the connection is still
alive, you should receive a PongMessage
shortly after. If you
don't get a PongMessage
within a reasonable amount of time,
consider reconnecting.
A typical use case is to draw vehicles (trains, trams, busses, ...) moving on a map. The
coordinate system used by the API is Web Mercator (EPSG:3857) and the zoom level is
given as a mapbox zoom level. In
order to get vehicle positions within a given bounding box, you have to subscribe using
the BBoxCommand
. For example, a payload to get initial vehicle
positions and vehicle position updates close to Olten in Switzerland at zoom level 11
would look like this:
BBOX 837468 5963148 915383 6033720 11
See BBoxCommand
for details and additional filters.
You will then start receiving
PartialTrajectoryMessage
s. Each message is
basically a section of the trajectory of a train (in the sense of a series of vehicles)
together with timing information. This spatial and temporal information can be used to
interpolate the vehicle position in your client application. The longest possible
partial trajectory is between two stops of a train. You will receive new partial
trajectories whenever a train passes the next stop or new timing information is
available. Here is an example of such a partial trajectory in spacetime:
{
"source": "trajectory",
...
"content": {
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[
287268,
6246052
],
[
286486,
6245972
]
]
},
"properties": {
...
"time_intervals": [
[
1699631460000,
0,
0
],
[
1699631460000,
0,
0
],
[
1699631580000,
1,
0
],
[
1699631580000,
1,
0
]
],
...
}
}
}
The spatial part is given as a GeoJSON
LineString
Feature
. The temporal
information is given in the Feature
properties
at the time_intervals
key. The
value is a JSON array. Each item is a JSON array with 3 entries: The timestamp
(milliseconds since the epoch), the fraction along the LineString
from 0
to 1
, and
the rotation of the vehicle in radians (with zero pointing west).
If you want to change the bounding box or zoom level, simply send another
BBoxCommand
. Mind that choosing a bounding box bigger than what
the user actually sees and sending a new command only when the user's view leaves this
bounding box will help to reduce communication load.
You can find suitable background maps here.
GetStopSequenceCommand
and
SubStopSequenceCommand
BufferCommand
DeletedVehicleMessage
GetFullTrajectoryCommand
ResetCommand
We can also offer station information and departure and arrival timetables at stations for selected data sources. If you are interested in such functionalities, please contact us.
Backend to connect to. v1 corresponds to production, dev to development. Note that this asyncapi schema describes only the v1 backend. API version and schema can differ on dev backend.
Your API key. See terms of service for more information.
The exclusive channel that corresponds to the websocket connection.
Commands that can be sent to the application.
Commands are used to request messages from the application, to subsribe to message streams and to keep the connection alive. Unlike messages sent by the application, commands are not JSON objects but plain strings.
Available only on servers:
Accepts one of the following messages:
Application-Layer Ping Command
Application-Layer ping command for clients not supporting websocket ping/pong
frames. Send this (periodically) to avoid connection timeouts or to validate the
connection. If the connection is alive, the application will respond with a
PongMessage
. Not needed if your client supports websocket native ping/pong frames
(browsers usually don't).
The form of the command is
PING
The only possible message.
PING
BBox Command
Subscribe to PartialTrajectoryMessage
s for a given bounding box and zoom level
with optional additional filters. The form of the command is
BBOX <left> <bottom> <right> <top> <zoom> [<tenant>] [<has_realtime>] [<gen>] [<mots>]
The bounding box is in web mercator epsg:3857 units. The zoom level is a mapbox zoom
level. Arguments can also be passed by name (see examples). Subscribing will also
trigger sending the initial content once. If buffering is enabled (see
BufferCommand
), the last message in the buffer array of the initial content will
always be a null
message.
Optional Filter Arguments:
tenant
: filter on a specific data source (tenant)has_realtime
: filter on GTFS tenants with GTFS-RTgen
:preferred generalization level (5
, 10
, 30
, 100
, 150
). So far,
only effective for tenant sbb.mots
: comma separated list of modes of transport (MOT) to filter on. Possible
MOTs:tram
subway
rail
bus
ferry
cablecar
gondola
funicular
coach
A new BBoxCommand
will always abort all previous running or queued BBoxCommand
s.
Subscribe to all trajectories in a bounding box at zoom level 12.
BBOX 797797 5917228.5 856296 5950915 12
Subscribe to all trajectories in a bounding box at zoom level 12 with generalization level 5, certain modes of transport and tenant sbb.
BBOX 797797 5917228.5 856296 5950915 12 mots=rail,subway tenant=sbb gen=5
Subscribe to all trajectories in a bounding box at zoom level 7 and filter on rail trajectories from GTFS tenants having a GTFS-Realtime feed.
BBOX -90679 5865470 2246130 7211150.3 7 mots=rail has_realtime=true
Get Full Trajectory Command
Get the full trajectories for all journeys of a given train. The command has the form
GET full_trajectory_<train_id>[_gen<gen_level>][ client_ref=<client_ref>]
The parameters are as follows:
train_id
: the id of the train as found in a trajectory
messagegen_level
: the preferred generalization level (optional, see also
BBoxCommand
)client_ref
: optional client reference forwarded to the
FullTrejectoryMessage
The result will be a FullTrajectoryMessage
with the source set according to the
request.
Get ungeneralized full trajectories for the journeys of train `sbb_139776730704336`.
GET full_trajectory_sbb_139776730704336
Get full trajectories for the journeys of train `sbb_139776730704336` with preferred generalization level `30`.
GET full_trajectory_sbb_139776730704336_gen30
Get Partial Trajectory Command
Get the partial trajectory for a given train. The command has the form
GET partial_trajectory_<train_id>[_gen<gen_level>][ client_ref=<client_ref>]
The parameters are as follows:
train_id
: the id of the train as found in a trajectory
messagegen_level
: the preferred generalization level (optional, see also
BBoxCommand
)client_ref
: optional client reference forwarded to the
PartialTrejectoryMessage
The result will be a PartialTrajectoryMessage
with the source set according to the
request.
Get ungeneralized partial trajectory for train `sbb_139776730704336`.
GET partial_trajectory_sbb_139776730704336
Get partial trajectory for train `sbb_139776730704336` with preferred generalization level `30`.
GET partial_trajectory_sbb_139776730704336_gen30
Get Stop Sequence Command
Get the stop sequences for all journeys of a given train. The command has the form
GET stopsequence_<train_id>[ client_ref=<client_ref>]
The parameters are as follows:
train_id
: the id of the train as found in a trajectory
messageclient_ref
: optional client reference forwarded to the
StopSequenceMessage
The result will be a StopSequenceMessage
with the source set according to the
request.
Get stop sequence for train `sbb_139776730704336`.
GET stopsequence_sbb_139776730704336
Sub Stop Sequence Command
Subscribe to the stop sequences for all journeys of a given train. The command has the form
SUB stopsequence_<train_id>
The parameters are as follows:
train_id
: the id of the train as found in a trajectory
messageThe result will be StopSequenceMessage
s with the source set according to the
request. This command will only subscribe to updates. Use the according GET
command first to get the current state.
Note that trains without any realtime information will not receive stop sequence
updates for performance reasons. Instead, the client is responsible for calculating
the current call based on time. This is indicated by "state": "TIME_BASED"
in the
stations
field.
Subscribe to stop sequences for train `sbb_139776730704336`.
SUB stopsequence_sbb_139776730704336
Buffer Command
Request that messages tagged as buffer
should be sent in chunks via
BufferMessage
.
The command has the form
BUFFER <timeout> [<size>]
The parameters are as follows:
timeout
: the timeout for flushing the buffer in mssize
: the buffer size (defaults to the max buffer size of 500)Note that buffer settings cannot be changed unless after sending a ResetCommand
.
The channel default is to not use any buffering.
A buffer command setting only the timeout to 2 seconds and leaving the size at the default.
BUFFER 2000
A buffer command setting the timeout to 1.5 seconds and the size to 100.
BUFFER 1500 100
Reset Command
Reset all settings and cancel all subscriptions to get back to a websocket channel state as before sending any commands.
The form of the command is
RESET
The only possible message.
RESET
The exclusive channel that corresponds to the websocket connection.
Messages sent by the application.
Messages sent by the application as a result of having received a command in the past. All messages are JSON objects with the fields source
, timestamp
, client_reference
and content
. The source
field serves as a virtual channel/topic.
Available only on servers:
Accepts one of the following messages:
Status Message
When the channel is ready to receive commands, a status open message is sent.
A status open message indicating that the channel is ready.
{
"source": "websocket",
"timestamp": 1700038249579,
"client_reference": "",
"content": {
"status": "open"
}
}
Application-Layer Pong Message
Response to an application-layer PING
command.
A pong message.
{
"source": "websocket",
"timestamp": 1699528818892,
"client_reference": "",
"content": "PONG"
}
Partial Trajectory Message
Current section of the route the given train is on with a TrackerTrajectory
GeoJSON Feature as the content
. This message is sent in response to either a
BBoxCommand
or to a GetPartialTrajectoryCommand
.
The source
field is either trajectory
for messages originating from a
BBoxCommand
or has the form trajectory_<train_id>[_gen<gen_level>]
when
originating from a GET
command with the same value as an argument.
The content
is null
if this message is a response to a GET
command with a
failed lookup.
client_reference
is an empty string if originating from a BBoxCommand
or the
client reference set in the GET
command if originating from a GET
command.
A partial trajectory.
{
"source": "trajectory",
"timestamp": 1699631462752,
"client_reference": "",
"content": {
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[
287268,
6246052
],
[
286486,
6245972
]
]
},
"properties": {
"train_number": null,
"rake": null,
"raw_time": null,
"variants": [],
"bounds": [
286486,
6245972,
287268,
6246052
],
"gen_level": null,
"gen_range": [
-32767,
32767
],
"tenant": "various-ile-de-france",
"type": "bus",
"time_intervals": [
[
1699631460000,
0,
0
],
[
1699631460000,
0,
0
],
[
1699631580000,
1,
0
],
[
1699631580000,
1,
0
]
],
"train_id": "various-ile-de-france_140638544321456",
"event_timestamp": 1699574453203,
"line": {
"id": 27561127,
"name": "310",
"color": "#d2d200",
"text_color": null,
"stroke": "#d2d200"
},
"timestamp": 1699631462758,
"state": "DRIVING",
"time_since_update": null,
"has_realtime": false,
"has_realtime_journey": false,
"operator_provides_realtime_journey": "unknown",
"has_journey": true,
"route_identifier": "IDFM:C01278",
"delay": null
}
}
}
Full Trajectory Message
All trajectories for the journeys of a train with a FullTrajectoryCollection
GeoJSON FeatureCollection as the content
. This message is sent in response to a
GetFullTrajectoryCommand
.
The source
field has the form full_trajectory_<train_id>[_gen<gen_level>]
which
corresponds to the argument of the GET
command.
The content
is null
if the lookup of the GET
command failed.
A full trajectory.
{
"source": "full_trajectory_various-ile-de-france_140638505354480",
"timestamp": 1699630189434,
"client_reference": "",
"content": {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "GeometryCollection",
"geometries": [
{
"type": "LineString",
"coordinates": [
[
279940,
6249955
],
[
279972,
6249965
],
[
279970,
6249970
],
[
279970,
6249972
],
[
280176,
6250036
],
[
280415,
6250110
],
[
280580,
6250159
],
[
280638,
6250179
],
[
280702,
6250201
],
[
281049,
6250308
],
[
281290,
6250388
],
[
281328,
6250405
],
[
281397,
6250436
],
[
281789,
6250647
],
[
281783,
6250691
],
[
281788,
6250700
],
[
281784,
6250726
],
[
281784,
6250732
],
[
281775,
6250748
],
[
281732,
6251043
],
[
281697,
6251265
],
[
281689,
6251298
],
[
281680,
6251341
],
[
281674,
6251357
],
[
281660,
6251463
],
[
281660,
6251484
],
[
281655,
6251609
],
[
281651,
6251633
],
[
281641,
6251769
],
[
281639,
6251798
],
[
281625,
6251862
],
[
281556,
6252076
],
[
281528,
6252244
],
[
281570,
6252256
],
[
281702,
6252299
],
[
281985,
6252428
],
[
282294,
6252565
],
[
282391,
6252621
],
[
282416,
6252641
],
[
282442,
6252652
],
[
282474,
6252671
],
[
282487,
6252676
],
[
282527,
6252685
],
[
282530,
6252679
],
[
282540,
6252671
],
[
282552,
6252671
],
[
282558,
6252674
],
[
282616,
6252570
],
[
282651,
6252525
],
[
282759,
6252336
],
[
282779,
6252288
]
]
},
{
"type": "MultiPoint",
"coordinates": [
[
279940,
6249955
],
[
279970,
6249970
],
[
280176,
6250036
],
[
280638,
6250179
],
[
281049,
6250308
],
[
281328,
6250405
],
[
281784,
6250726
],
[
281689,
6251298
],
[
281641,
6251769
],
[
281570,
6252256
],
[
281985,
6252428
],
[
282779,
6252288
]
]
}
]
},
"properties": {
"train_id": "various-ile-de-france_140638505354480",
"gen_level": null,
"gen_range": [
-32767,
32767
],
"journey_id": 2358244505,
"line_id": 27560931,
"stroke": "#ff82b4",
"line_name": "203",
"type": "bus",
"event_timestamp": 1699574453203
}
}
],
"properties": {
"train_id": "various-ile-de-france_140638505354480",
"gen_level": null,
"gen_range": [
-32767,
32767
],
"tenant": "various-ile-de-france",
"publisher": null,
"publisherUrl": null,
"operator": "RATP",
"operatorUrl": "http://www.navitia.io/",
"license": "ODbL",
"licenseUrl": "https://opendatacommons.org/licenses/odbl/1-0/",
"licenseNote": "trip shapes were added"
}
}
}
Stop Sequence Message
Information about the stops along the journeys of a train. This message is sent in
response to a GetStopSequenceCommand
or a SubStopSequenceCommand
.
The source
field has the form stopsequence_<train_id>
which corresponds to the
argument of the GET
or SUB
command.
The content
is null
if the lookup of the GET
/ SUB
command failed.
Stop sequences for all journeys of a train.
{
"source": "stopsequence_sbb_139776730704336",
"timestamp": 1699871495089,
"client_reference": "",
"content": [
{
"id": "sbb_139776730704336",
"color": "#ffea00",
"stroke": "#ffea00",
"text_color": "#000000",
"destination": "Buchs SG",
"new_destination": null,
"longName": "S4",
"routeIdentifier": "011448.000082.103:4",
"shortName": "S4",
"type": "rail",
"has_realtime": true,
"has_realtime_journey": true,
"operator_provides_realtime_journey": "yes",
"extra_data": {
"event_timestamp": null,
"event_location_name": null
},
"situations": [],
"vehicle_mode": null,
"train_number": null,
"line": {
"color": "#ffea00",
"id": 30482480,
"name": "S4",
"stroke": "#ffea00",
"text_color": "#000000"
},
"stations": [
{
"state": "LEAVING",
"formation_id": null,
"arrivalDelay": null,
"arrivalTime": 1699870680000,
"aimedArrivalTime": 1699870680000,
"cancelled": false,
"departureDelay": 60000,
"departureTime": 1699870740000,
"aimedDepartureTime": 1699870680000,
"noDropOff": false,
"noPickUp": false,
"stationId": null,
"stationName": "Uznach",
"coordinate": [
999726,
5978760
],
"stopUID": null,
"platform": "4"
},
{
"state": "LEAVING",
"formation_id": null,
"arrivalDelay": 0,
"arrivalTime": 1699871040000,
"aimedArrivalTime": 1699871040000,
"cancelled": false,
"departureDelay": 60000,
"departureTime": 1699871100000,
"aimedDepartureTime": 1699871040000,
"noDropOff": false,
"noPickUp": false,
"stationId": null,
"stationName": "Schänis",
"coordinate": [
1006771,
5967846
],
"stopUID": null,
"platform": "1"
},
{
"state": "LEAVING",
"formation_id": null,
"arrivalDelay": 0,
"arrivalTime": 1699871280000,
"aimedArrivalTime": 1699871280000,
"cancelled": false,
"departureDelay": 60000,
"departureTime": 1699871340000,
"aimedDepartureTime": 1699871280000,
"noDropOff": false,
"noPickUp": false,
"stationId": null,
"stationName": "Ziegelbrücke",
"coordinate": [
1008560,
5964327
],
"stopUID": null,
"platform": "10"
},
{
"state": "PENDING",
"formation_id": null,
"arrivalDelay": 0,
"arrivalTime": 1699871640000,
"aimedArrivalTime": 1699871640000,
"cancelled": false,
"departureDelay": 0,
"departureTime": 1699871640000,
"aimedDepartureTime": 1699871640000,
"noDropOff": false,
"noPickUp": false,
"stationId": null,
"stationName": "Mühlehorn",
"coordinate": [
1021136,
5961330
],
"stopUID": null,
"platform": "1"
},
{
"state": "PENDING",
"formation_id": null,
"arrivalDelay": 0,
"arrivalTime": 1699871820000,
"aimedArrivalTime": 1699871820000,
"cancelled": false,
"departureDelay": 60000,
"departureTime": 1699871880000,
"aimedDepartureTime": 1699871820000,
"noDropOff": false,
"noPickUp": false,
"stationId": null,
"stationName": "Murg",
"coordinate": [
1025814,
5960567
],
"stopUID": null,
"platform": "2"
},
{
"state": "PENDING",
"formation_id": null,
"arrivalDelay": 0,
"arrivalTime": 1699872060000,
"aimedArrivalTime": 1699872060000,
"cancelled": false,
"departureDelay": 60000,
"departureTime": 1699872120000,
"aimedDepartureTime": 1699872060000,
"noDropOff": false,
"noPickUp": false,
"stationId": null,
"stationName": "Unterterzen",
"coordinate": [
1030264,
5960678
],
"stopUID": null,
"platform": "2"
},
{
"state": "PENDING",
"formation_id": null,
"arrivalDelay": -60000,
"arrivalTime": 1699872300000,
"aimedArrivalTime": 1699872360000,
"cancelled": false,
"departureDelay": 0,
"departureTime": 1699872360000,
"aimedDepartureTime": 1699872360000,
"noDropOff": false,
"noPickUp": false,
"stationId": null,
"stationName": "Walenstadt",
"coordinate": [
1036716,
5961663
],
"stopUID": null,
"platform": "3"
},
{
"state": "PENDING",
"formation_id": null,
"arrivalDelay": 0,
"arrivalTime": 1699872540000,
"aimedArrivalTime": 1699872540000,
"cancelled": false,
"departureDelay": 60000,
"departureTime": 1699872600000,
"aimedDepartureTime": 1699872540000,
"noDropOff": false,
"noPickUp": false,
"stationId": null,
"stationName": "Flums",
"coordinate": [
1040607,
5957859
],
"stopUID": null,
"platform": "4"
},
{
"state": "PENDING",
"formation_id": null,
"arrivalDelay": 0,
"arrivalTime": 1699872840000,
"aimedArrivalTime": 1699872840000,
"cancelled": false,
"departureDelay": 0,
"departureTime": 1699872840000,
"aimedDepartureTime": 1699872840000,
"noDropOff": false,
"noPickUp": false,
"stationId": null,
"stationName": "Mels",
"coordinate": [
1048380,
5950851
],
"stopUID": null,
"platform": "4"
},
{
"state": "PENDING",
"formation_id": null,
"arrivalDelay": -60000,
"arrivalTime": 1699873020000,
"aimedArrivalTime": 1699873080000,
"cancelled": false,
"departureDelay": 0,
"departureTime": 1699873200000,
"aimedDepartureTime": 1699873200000,
"noDropOff": false,
"noPickUp": false,
"stationId": null,
"stationName": "Sargans",
"coordinate": [
1051553,
5949394
],
"stopUID": null,
"platform": "5"
},
{
"state": "PENDING",
"formation_id": null,
"arrivalDelay": -60000,
"arrivalTime": 1699873860000,
"aimedArrivalTime": 1699873920000,
"cancelled": false,
"departureDelay": -60000,
"departureTime": 1699873860000,
"aimedDepartureTime": 1699873920000,
"noDropOff": false,
"noPickUp": false,
"stationId": null,
"stationName": "Buchs SG",
"coordinate": [
1055157,
5969607
],
"stopUID": null,
"platform": "2"
}
],
"tenant": "sbb",
"publisher": "SBB",
"publisherUrl": "http://www.sbb.ch",
"operator": "SOB-sob (Schweizerische Südostbahn (sob))",
"operatorUrl": "http://www.sbb.ch",
"license": null,
"licenseUrl": null,
"licenseNote": null
}
]
}
Deleted Vehicle Message
This message is informing about deletion of a train.
The content
is the train id.
A message indicating that the train with id `sbb_140357024577472` has been deleted.
{
"source": "deleted_vehicles",
"timestamp": 1700038249579,
"client_reference": "",
"content": "sbb_140357024577472"
}
Buffer Message
A wrapper combining multiple messages. Buffering is activated by the
BufferCommand
.
The content
is an array of wrapped messages. Only messages tagged as buffer
will
potentially be wrapped up. The initial messge from a buffered BBoxCommand
is
always terminated with a null
message. See also BufferCommand
and BBoxCommand
.
A buffer message .
{
"source": "buffer",
"timestamp": 1700044694366,
"client_reference": "",
"content": [
{
"source": "trajectory",
"timestamp": 1700044694366,
"client_reference": "",
"content": {
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[
1046933,
6003823
],
[
1046909,
6003844
],
[
1046858,
6003873
],
[
1046789,
6003902
],
[
1046761,
6003917
],
[
1046737,
6003934
],
[
1046708,
6003958
],
[
1046617,
6004059
],
[
1046606,
6004071
],
[
1046586,
6004084
],
[
1046561,
6004096
],
[
1046535,
6004104
],
[
1046501,
6004105
],
[
1046436,
6004097
],
[
1046408,
6004098
],
[
1046378,
6004107
],
[
1046353,
6004123
],
[
1046332,
6004144
],
[
1046295,
6004192
],
[
1046274,
6004215
],
[
1046251,
6004235
],
[
1046227,
6004251
],
[
1046201,
6004264
],
[
1046169,
6004276
],
[
1046049,
6004311
],
[
1046020,
6004326
],
[
1046000,
6004342
],
[
1045984,
6004359
],
[
1045974,
6004375
],
[
1045961,
6004401
],
[
1045955,
6004429
],
[
1045954,
6004457
],
[
1045965,
6004626
],
[
1045969,
6004660
],
[
1045980,
6004727
],
[
1045984,
6004774
],
[
1045986,
6004815
],
[
1045984,
6004870
],
[
1045978,
6004917
],
[
1045965,
6004978
],
[
1045940,
6005047
],
[
1045924,
6005079
],
[
1045910,
6005102
],
[
1045889,
6005130
],
[
1045869,
6005151
],
[
1045840,
6005172
],
[
1045757,
6005214
],
[
1045729,
6005231
],
[
1045699,
6005253
],
[
1045679,
6005275
],
[
1045663,
6005296
],
[
1045597,
6005404
],
[
1045584,
6005430
],
[
1045512,
6005614
],
[
1045499,
6005639
],
[
1045447,
6005720
],
[
1045416,
6005783
],
[
1045395,
6005831
],
[
1045383,
6005888
],
[
1045367,
6005930
],
[
1045282,
6006050
]
]
},
"properties": {
"train_number": null,
"rake": null,
"raw_time": null,
"variants": [],
"bounds": [
1045282,
6003823,
1046933,
6006050
],
"gen_level": null,
"gen_range": [
150,
32767
],
"tenant": "sbb",
"type": "rail",
"time_intervals": [
[
1700044440000,
0,
0
],
[
1700044500000,
0,
0
],
[
1700044740000,
1,
0
],
[
1700044800000,
1,
0
]
],
"train_id": "sbb_140356899179680",
"event_timestamp": 1700035444874,
"line": {
"id": 27813146,
"name": "S21",
"color": "#ffea00",
"text_color": "#000000",
"stroke": "#ffea00"
},
"timestamp": 1700044505914,
"state": "DRIVING",
"time_since_update": null,
"has_realtime": false,
"has_realtime_journey": true,
"operator_provides_realtime_journey": "yes",
"has_journey": true,
"route_identifier": "002112.000022.001:21",
"delay": 0
}
}
},
{
"source": "deleted_vehicles",
"timestamp": 1700044694370,
"client_reference": "",
"content": "sbb_140357024577472"
}
]
}
Log Message
A message with technical information or a warning regarding the channel or received commands.
Note that more than one field of the content
can be set (see examples).
A log message warning about a repeated buffer call and informing about the current buffer settings.
{
"source": "websocket",
"timestamp": 1700044915842,
"client_reference": "",
"content": {
"warning": "Ignoring repeated `BUFFER` call.",
"info": "Buffering messages up to 100 regular messages for up to 90ms"
}
}
BBox Command
Subscribe to PartialTrajectoryMessage
s for a given bounding box and zoom level
with optional additional filters. The form of the command is
BBOX <left> <bottom> <right> <top> <zoom> [<tenant>] [<has_realtime>] [<gen>] [<mots>]
The bounding box is in web mercator epsg:3857 units. The zoom level is a mapbox zoom
level. Arguments can also be passed by name (see examples). Subscribing will also
trigger sending the initial content once. If buffering is enabled (see
BufferCommand
), the last message in the buffer array of the initial content will
always be a null
message.
Optional Filter Arguments:
tenant
: filter on a specific data source (tenant)has_realtime
: filter on GTFS tenants with GTFS-RTgen
:preferred generalization level (5
, 10
, 30
, 100
, 150
). So far,
only effective for tenant sbb.mots
: comma separated list of modes of transport (MOT) to filter on. Possible
MOTs:tram
subway
rail
bus
ferry
cablecar
gondola
funicular
coach
A new BBoxCommand
will always abort all previous running or queued BBoxCommand
s.
Buffer Command
Request that messages tagged as buffer
should be sent in chunks via
BufferMessage
.
The command has the form
BUFFER <timeout> [<size>]
The parameters are as follows:
timeout
: the timeout for flushing the buffer in mssize
: the buffer size (defaults to the max buffer size of 500)Note that buffer settings cannot be changed unless after sending a ResetCommand
.
The channel default is to not use any buffering.
Buffer Message
A wrapper combining multiple messages. Buffering is activated by the
BufferCommand
.
The content
is an array of wrapped messages. Only messages tagged as buffer
will
potentially be wrapped up. The initial messge from a buffered BBoxCommand
is
always terminated with a null
message. See also BufferCommand
and BBoxCommand
.
Deleted Vehicle Message
This message is informing about deletion of a train.
The content
is the train id.
The trajectory for one of the journeys of a train as a GeoJSON Feature.
The geometry
is either a (Multi)LineString or a GeometryCollection of a
(Multi)LineString and a MultiPoint. If the MultiPoint is delivered, the points
correspond to stops projected onto the trajectory.
MultiLineStrings can occur when the trajectory is discontinous at at least one of the stops.
All trajectories for the journeys of a train as a GeoJSON FeatureCollection.
Full Trajectory Message
All trajectories for the journeys of a train with a FullTrajectoryCollection
GeoJSON FeatureCollection as the content
. This message is sent in response to a
GetFullTrajectoryCommand
.
The source
field has the form full_trajectory_<train_id>[_gen<gen_level>]
which
corresponds to the argument of the GET
command.
The content
is null
if the lookup of the GET
command failed.
Collection of MultiPoint, LineString and MultiLineString
MultiPoint is a list of points of interest, i.e. stop points in this context. (Multi)LineStrings represent a trajectory.
Get Full Trajectory Command
Get the full trajectories for all journeys of a given train. The command has the form
GET full_trajectory_<train_id>[_gen<gen_level>][ client_ref=<client_ref>]
The parameters are as follows:
train_id
: the id of the train as found in a trajectory
messagegen_level
: the preferred generalization level (optional, see also
BBoxCommand
)client_ref
: optional client reference forwarded to the
FullTrejectoryMessage
The result will be a FullTrajectoryMessage
with the source set according to the
request.
Get Partial Trajectory Command
Get the partial trajectory for a given train. The command has the form
GET partial_trajectory_<train_id>[_gen<gen_level>][ client_ref=<client_ref>]
The parameters are as follows:
train_id
: the id of the train as found in a trajectory
messagegen_level
: the preferred generalization level (optional, see also
BBoxCommand
)client_ref
: optional client reference forwarded to the
PartialTrejectoryMessage
The result will be a PartialTrajectoryMessage
with the source set according to the
request.
Get Stop Sequence Command
Get the stop sequences for all journeys of a given train. The command has the form
GET stopsequence_<train_id>[ client_ref=<client_ref>]
The parameters are as follows:
train_id
: the id of the train as found in a trajectory
messageclient_ref
: optional client reference forwarded to the
StopSequenceMessage
The result will be a StopSequenceMessage
with the source set according to the
request.
Log Message
A message with technical information or a warning regarding the channel or received commands.
Note that more than one field of the content
can be set (see examples).
Partial Trajectory Message
Current section of the route the given train is on with a TrackerTrajectory
GeoJSON Feature as the content
. This message is sent in response to either a
BBoxCommand
or to a GetPartialTrajectoryCommand
.
The source
field is either trajectory
for messages originating from a
BBoxCommand
or has the form trajectory_<train_id>[_gen<gen_level>]
when
originating from a GET
command with the same value as an argument.
The content
is null
if this message is a response to a GET
command with a
failed lookup.
client_reference
is an empty string if originating from a BBoxCommand
or the
client reference set in the GET
command if originating from a GET
command.
Application-Layer Ping Command
Application-Layer ping command for clients not supporting websocket ping/pong
frames. Send this (periodically) to avoid connection timeouts or to validate the
connection. If the connection is alive, the application will respond with a
PongMessage
. Not needed if your client supports websocket native ping/pong frames
(browsers usually don't).
The form of the command is
PING
Application-Layer Pong Message
Response to an application-layer PING
command.
Reset Command
Reset all settings and cancel all subscriptions to get back to a websocket channel state as before sending any commands.
The form of the command is
RESET
Status Message
When the channel is ready to receive commands, a status open message is sent.
Stop Sequence Message
Information about the stops along the journeys of a train. This message is sent in
response to a GetStopSequenceCommand
or a SubStopSequenceCommand
.
The source
field has the form stopsequence_<train_id>
which corresponds to the
argument of the GET
or SUB
command.
The content
is null
if the lookup of the GET
/ SUB
command failed.
Sub Stop Sequence Command
Subscribe to the stop sequences for all journeys of a given train. The command has the form
SUB stopsequence_<train_id>
The parameters are as follows:
train_id
: the id of the train as found in a trajectory
messageThe result will be StopSequenceMessage
s with the source set according to the
request. This command will only subscribe to updates. Use the according GET
command first to get the current state.
Note that trains without any realtime information will not receive stop sequence
updates for performance reasons. Instead, the client is responsible for calculating
the current call based on time. This is indicated by "state": "TIME_BASED"
in the
stations
field.
Current section of the route the given train is on as a GeoJSON Feature.
The geometry
contains the LineString between two stops.
The time_intervals
property contains a list of [timestamp, fraction, direction]
tuples.
Each time_intervals
item contains the fraction of the geometry where
the vehicle is at the given timestamp. If present the direction is the
current rotation of the vehicle relative to the horizontal axis as
radian.
The current location of the vehicle can be calculated by linear interpolation from the fraction of the first item where the timestamp is smaller then the current time to the fraction of the next item.
If the last timestamp is in the past, the trajectory should not be visualized by a client.