### ExtendedClassBPositionReport Example Source: https://aisstream.io/documentation Provides detailed vessel position, course, and speed, including rate of turn and heading. Use for enhanced situational awareness and collision avoidance. ```json { "AssignedMode": false, "Cog": 234.5, "Dimension": { "A": 0, "B": 0, "C": 0, "D": 0 }, "Dte": false, "FixType": 1, "Latitude": 22.314829999999997, "Longitude": 114.510795, "MessageID": 19, "Name": "51118-02-75%", "PositionAccuracy": false, "Raim": false, "RepeatIndicator": 0, "Sog": 0, "Spare1": 226, "Spare2": 0, "Spare3": 0, "Timestamp": 0, "TrueHeading": 511, "Type": 0, "UserID": 225111802, "Valid": true } ``` -------------------------------- ### MultiSlotBinaryMessage Example Source: https://aisstream.io/documentation Transmits binary data in multiple time slots, suitable for larger data payloads. Ensure ApplicationID and DestinationID are correctly populated if used. ```json { "ApplicationID": { "DesignatedAreaCode": 366, "FunctionIdentifier": 10, "Valid": true }, "ApplicationIDValid": true, "CommunicationState": 36002, "CommunicationStateIsItdma": true, "DestinationID": 0, "DestinationIDValid": false, "MessageID": 26, "Payload": "", "RepeatIndicator": 0, "Spare1": 0, "Spare2": 0, "UserID": 367635490, "Valid": true } ``` -------------------------------- ### BaseStationReport Example Source: https://aisstream.io/documentation Represents a fixed AIS base station's location and status. Use this to model data from coastal stations or VTS centers. ```json { "CommunicationState": 20180, "FixType": 15, "Latitude": 43.49155666666666, "LongRangeEnable": false, "Longitude": -5.941905, "MessageID": 4, "PositionAccuracy": false, "Raim": true, "RepeatIndicator": 0, "Spare": 0, "UserID": 2241118, "UtcDay": 9, "UtcHour": 7, "UtcMinute": 53, "UtcMonth": 9, "UtcSecond": 30, "UtcYear": 2022, "Valid": true } ``` -------------------------------- ### AidsToNavigationReport JSON Example Source: https://aisstream.io/documentation This JSON object represents a sample AidsToNavigationReport AIS message. It includes details about the navigational aid's type, position, and status. ```json { "AssignedMode": false, "AtoN": 0, "Dimension": { "A": 0, "B": 0, "C": 0, "D": 0 }, "Fixtype": 7, "Latitude": 30.099798333333336, "Longitude": -90.91296166666666, "MessageID": 21, "Name": "B ", "NameExtension": "", "OffPosition": false, "PositionAccuracy": false, "Raim": false, "RepeatIndicator": 0, "Spare": false, "Timestamp": 61, "Type": 26, "UserID": 993682816, "Valid": true, "VirtualAtoN": true } ``` -------------------------------- ### SafetyBroadcastMessage Example Source: https://aisstream.io/documentation Alerts other vessels to potential safety hazards. The 'Text' field contains critical information about the hazard and location. ```json { "MessageID": 14, "RepeatIndicator": 3, "Spare": 0, "Text": "CRASH:413900364 POS:22^18.279N,114^9.451E", "UserID": 22, "Valid": true } ``` -------------------------------- ### StaticDataReport JSON Example Source: https://aisstream.io/documentation This JSON represents a StaticDataReport AIS message. It contains non-dynamic vessel information such as name, dimensions, ship type, and call sign. Transmit this message periodically or upon request. ```json { "MessageID": 24, "PartNumber": true, "RepeatIndicator": 0, "ReportA": { "Name": "", "Valid": false }, "ReportB": { "CallSign": "LESW", "Dimension": { "A": 12, "B": 3, "C": 3, "D": 2 }, "FixType": 0, "ShipType": 37, "Spare": 0, "Valid": true, "VenderIDModel": 1, "VenderIDSerial": 292978, "VendorIDName": "SRT" }, "Reserved": 0, "UserID": 257702970, "Valid": true } ``` -------------------------------- ### StandardSearchAndRescueAircraftReport JSON Example Source: https://aisstream.io/documentation This JSON represents a StandardSearchAndRescueAircraftReport AIS message. It includes details about an aircraft's position, status, and ongoing search and rescue activities. Use this message to track SAR aircraft. ```json { "AltFromBaro": false, "Altitude": 19, "AssignedMode": false, "Cog": 311.5, "CommunicationState": 49152, "CommunicationStateIsItdma": false, "Dte": true, "Latitude": 38.47499666666667, "Longitude": -8.871578333333334, "MessageID": 9, "PositionAccuracy": true, "Raim": true, "RepeatIndicator": 0, "Sog": 0, "Spare1": 0, "Spare2": 0, "Timestamp": 7, "UserID": 266125000, "Valid": true } ``` -------------------------------- ### SingleSlotBinaryMessage JSON Example Source: https://aisstream.io/documentation This JSON represents a SingleSlotBinaryMessage AIS message. It is used to convey binary data, typically including vessel position, course, and speed, in a single transmission slot. This message is limited to 280 bits. ```json { "ApplicationID": { "DesignatedAreaCode": 247, "FunctionIdentifier": 59, "Valid": true }, "ApplicationIDValid": true, "DestinationID": 0, "DestinationIDValid": false, "MessageID": 25, "Payload": "", "RepeatIndicator": 0, "Spare": 0, "UserID": 247155300, "Valid": true } ``` -------------------------------- ### Connect and Subscribe to AIS Stream (Python) Source: https://aisstream.io/documentation Connect to the AISStream websocket, subscribe to position reports, and print ship details. Requires asyncio and websockets libraries. ```python import asyncio import websockets import json from datetime import datetime, timezone async def connect_ais_stream(): async with websockets.connect("wss://stream.aisstream.io/v0/stream") as websocket: subscribe_message = {"APIKey": "", # Required ! "BoundingBoxes": [[[-90, -180], [90, 180]]], # Required! "FiltersShipMMSI": ["368207620", "367719770", "211476060"], # Optional! "FilterMessageTypes": ["PositionReport"]} subscribe_message_json = json.dumps(subscribe_message) await websocket.send(subscribe_message_json) async for message_json in websocket: message = json.loads(message_json) message_type = message["MessageType"] if message_type == "PositionReport": ais_message = message['Message']['PositionReport'] print(f"[{datetime.now(timezone.utc)}] ShipId: {ais_message['UserID']} Latitude: {ais_message['Latitude']} Latitude: {ais_message['Longitude']}") if __name__ == "__main__": asyncio.run(asyncio.run(connect_ais_stream())) ``` -------------------------------- ### Connect and Subscribe to AIS Stream (Javascript) Source: https://aisstream.io/documentation Connect to the AISStream websocket and send a subscription message. Handles incoming messages by parsing and logging them. ```javascript const WebSocket = require('ws'); const socket = new WebSocket("wss://stream.aisstream.io/v0/stream") socket.onopen = function (_) { let subscriptionMessage = { Apikey: "", BoundingBoxes: [[[-90, -180], [90, 180]]], FiltersShipMMSI: ["368207620", "367719770", "211476060"], // Optional! FilterMessageTypes: ["PositionReport"] // Optional! } socket.send(JSON.stringify(subscriptionMessage)); }; socket.onmessage = function (event) { let aisMessage = JSON.parse(event.data) console.log(aisMessage) }; ``` -------------------------------- ### Authentication Source: https://aisstream.io/documentation Explains how to authenticate with the AIS Stream websocket API using API keys generated through the user's account. ```APIDOC ## Authentication ### Description AIS-Stream websockets uses API keys for authentication. API keys can be created for authenticated users via the API Keys page. When an API key is revoked, it will still appear in the console but will be marked invalid. ### Method WSS ### Endpoint / ### Parameters #### Query Parameters - **apiKey** (string) - Required - The API key for authentication. ``` -------------------------------- ### ChannelManagement Structure Source: https://aisstream.io/documentation Manages communication channel parameters. Includes channel assignments, transmission/reception modes, power settings, area definitions, and unicast configurations. ```json { "Area": { "Latitude1": 23.31, "Latitude2": 21.93166666666667, "Longitude1": 120.88166666666666, "Longitude2": 119.42166666666667 }, "BwA": false, "BwB": false, "ChannelA": 2087, "ChannelB": 2088, "IsAddressed": false, "LowPower": false, "MessageID": 22, "RepeatIndicator": 0, "Spare1": 0, "Spare4": 0, "TransitionalZoneSize": 4, "TxRxMode": 0, "Unicast": { "AddressStation1": 0, "AddressStation2": 0, "Spare2": 0, "Spare3": 0 }, "UserID": 4163400, "Valid": true } ``` -------------------------------- ### Create Subscription Message Structure Source: https://aisstream.io/documentation Use this JSON object to define your subscription to ais events. It includes your API key and the geographical bounding box for message filtering. Optional fields allow filtering by ship MMSI and message types. ```json { "APIKey": , # list of arrays containing the lat and long of the two corners of the bounding box "BoundingBoxes": [[[-90, -180], [90, 180]]], "FiltersShipMMSI": ["368207620", "367719770", "211476060"], # Optional field. "FilterMessageTypes": ["PositionReport"] # Optional Field. } ``` -------------------------------- ### Create Subscription Message Source: https://aisstream.io/documentation This object is used upon connection to create your subscription to AIS events. It includes your API key and the bounding box of the area you wish to subscribe to messages for. FiltersShipMMSI and FilterMessageTypes are optional fields. ```APIDOC ## Create Subscription Message ### Description Used to establish a subscription to AIS events, specifying an API key and geographical bounding box. Optional filters for Ship MMSI and Message Types can be included. ### Attributes * **APIKey** (String) - Your unique API key. * **BoundingBoxes** (List) - A list of arrays, where each inner array contains two coordinate pairs representing the corners of a bounding box. Example: `[[[-90, -180], [90, 180]]]`. * **FiltersShipMMSI** (List) - Optional. A list of ship MMSI (Maritime Mobile Service Identity) numbers (strings) to filter messages by. Maximum of 50 MMSI values supported. * **FilterMessageTypes** (List) - Optional. A list of AIS message type names (strings) to filter messages by. Supported types include: PositionReport, UnknownMessage, AddressedSafetyMessage, AddressedBinaryMessage, AidsToNavigationReport, AssignedModeCommand, BaseStationReport BinaryAcknowledge, BinaryBroadcastMessage, ChannelManagement, CoordinatedUTCInquiry, DataLinkManagementMessage, DataLinkManagementMessageData, ExtendedClassBPositionReport GroupAssignmentCommand, GnssBroadcastBinaryMessage, Interrogation, LongRangeAisBroadcastMessage, MultiSlotBinaryMessage, SafetyBroadcastMessage, ShipStaticData SingleSlotBinaryMessage, StandardClassBPositionReport, StandardSearchAndRescueAircraftReport, StaticDataReport. ### Request Example ```json { "APIKey": "", "BoundingBoxes": [[[-90, -180], [90, 180]]], "FiltersShipMMSI": ["368207620", "367719770", "211476060"], "FilterMessageTypes": ["PositionReport"] } ``` ``` -------------------------------- ### AssignedModeCommand Structure Source: https://aisstream.io/documentation Issues commands to assigned modes, specifying destination IDs and associated increments/offsets. Used for controlling device behavior or settings. ```json { "Commands": { "0": { "DestinationID": 249362000, "Increment": 0, "Offset": 20, "Valid": true }, "1": { "DestinationID": 249362000, "Increment": 0, "Offset": 20, "Valid": true } }, "MessageID": 16, "RepeatIndicator": 0, "Spare": 0, "UserID": 2320844, "Valid": true } ``` -------------------------------- ### DataLinkManagementMessage Structure Source: https://aisstream.io/documentation Represents a message for managing data links. It includes message identification, user information, validity status, and a data payload with increment, offset, timeout, and slot information. ```json { "Data": { "0": { "Increment": 750, "Offset": 623, "TimeOut": 7, "Valid": false, "integerOfSlots": 1 }, "1": { "Increment": 1125, "Offset": 1125, "TimeOut": 7, "Valid": false, "integerOfSlots": 1 }, "2": { "Increment": 0, "Offset": 0, "TimeOut": 0, "Valid": false, "integerOfSlots": 0 }, "3": { "Increment": 0, "Offset": 0, "TimeOut": 0, "Valid": false, "integerOfSlots": 0 } }, "MessageID": 20, "RepeatIndicator": 0, "Spare": 0, "UserID": 2655069, "Valid": true } ``` -------------------------------- ### AddressedBinaryMessage Structure Source: https://aisstream.io/documentation Used for sending binary data to a specific destination. Includes application identification, binary data payload, destination details, and retransmission flags. ```json { "ApplicationID": { "DesignatedAreaCode": 1, "FunctionIdentifier": 40, "Valid": true }, "BinaryData": "", "DestinationID": 2442131, "MessageID": 6, "RepeatIndicator": 0, "Retransmission": true, "Sequenceinteger": 1, "Spare": false, "UserID": 538006462, "Valid": true } ``` -------------------------------- ### BinaryAcknowledge Structure Source: https://aisstream.io/documentation Confirms receipt of binary messages. It specifies the message ID, user ID, validity, and a list of destinations with their sequence integers and validity status. ```json { "Destinations": { "0": { "DestinationID": 992351360, "Sequenceinteger": 0, "Valid": true }, "1": { "DestinationID": 0, "Sequenceinteger": 0, "Valid": false }, "2": { "DestinationID": 0, "Sequenceinteger": 0, "Valid": false }, "3": { "DestinationID": 0, "Sequenceinteger": 0, "Valid": false } }, "MessageID": 7, "RepeatIndicator": 0, "Spare": 0, "UserID": 2320075, "Valid": true } ``` -------------------------------- ### Error Message Structure Source: https://aisstream.io/documentation This JSON object is returned when an error occurs while interacting with the service. It includes a string field 'error' that describes the issue, such as an invalid API key or throttling. ```json { "error": "Api Key Is Not Valid" } ``` -------------------------------- ### Error Message Structure Source: https://aisstream.io/documentation Message returned in the event of an error interacting with the service, such as throttling or an invalid API key. ```APIDOC ## Error Message ### Description Message returned in the event of an error interacting with the service. It could be due to throttling (you can send a maximum of 1 subscription update a second), or any other error such as an invalid API key. ### Attributes * **error** (String) - A description of the error that occurred. ### Example ```json { "error": "Api Key Is Not Valid" } ``` ``` -------------------------------- ### AIStream WebSocket Subscription Message Source: https://aisstream.io/documentation This JSON message is used to subscribe to AIS data. It must be sent within 3 seconds of establishing the WebSocket connection. Include your API key and desired geographic bounding boxes. Optional filters for specific ship MMSI numbers or AIS message types can also be provided. ```json { "APIKey": , "BoundingBoxes": [[[25.835302, -80.207729], [25.602700, -79.879297]], [[33.772292, -118.356139], [33.673490, -118.095731]] ], "FiltersShipMMSI": ["368207620", "367719770", "211476060"], "FilterMessageTypes": ["PositionReport"] } ``` -------------------------------- ### StandardClassBPositionReport AIS Message Structure Source: https://aisstream.io/documentation Reports position and related information for Class B AIS devices, including vessel dimensions and communication status. This message enhances tracking capabilities for smaller vessels. ```json { "AssignedMode": false, "ClassBBand": true, "ClassBDisplay": false, "ClassBDsc": true, "ClassBMsg22": true, "ClassBUnit": true, "Cog": 210.5, "CommunicationState": 393222, "CommunicationStateIsItdma": true, "Latitude": 39.562353333333334, "Longitude": 2.6283216666666664, "MessageID": 18, "PositionAccuracy": true, "Raim": true, "RepeatIndicator": 0, "Sog": 0, "Spare1": 0, "Spare2": 0, "Timestamp": 49, "TrueHeading": 511, "UserID": 367000980, "Valid": true } ``` -------------------------------- ### AISMessage Structure Source: https://aisstream.io/documentation Represents a single AIS event message received. It includes metadata, the message type, and the specific message payload. ```APIDOC ## AISMessage ### Description The message type passed for each AIS event. It contains metadata about the message such as the position and ship name, the message type and the message field. The message field contains a JSON object with the AIS message contained inside with the key being the AIS message type or in other words the value of the `MessageType` key. ### Attributes * **MetaData** (Object) - Contains metadata about the AIS message, including MMSI, ShipName, latitude, longitude, and time_utc. * **MessageType** (AisMessageTypes) - The type of the AIS message (e.g., "PositionReport"). * **Message** (AisStreamMessage_Message) - A JSON object containing the specific AIS message payload, keyed by the `MessageType`. ### Example ```json { "Message":{ "PositionReport":{ "Cog":308, "CommunicationState":81982, "Latitude":66.02695, "Longitude":12.253821666666665, "MessageID":1, "NavigationalStatus":15, "PositionAccuracy":true, "Raim":false, "RateOfTurn":4, "RepeatIndicator":0, "Sog":0, "Spare":0, "SpecialManoeuvreIndicator":0, "Timestamp":31, "TrueHeading":235, "UserID":259000420, "Valid":true } }, "MessageType":"PositionReport", "MetaData":{ "MMSI":259000420, "ShipName":"AUGUSTSON", "latitude":66.02695, "longitude":12.253821666666665, "time_utc":"2022-12-29 18:22:32.318353 +0000 UTC" } } ``` ``` -------------------------------- ### GnssBroadcastBinaryMessage Structure Source: https://aisstream.io/documentation Represents a GnssBroadcastBinaryMessage AIS message containing binary data from GNSS broadcasters to improve positioning accuracy. Includes ephemeris, almanac, and correction data. ```json { "MessageID": 0, "RepeatIndicator": 0, "UserID": 0, "Valid": false, "Spare1": 0, "Longitude": 0.0, "Latitude": 0.0, "Spare2": 0, "Data": "" } ``` -------------------------------- ### AIS Message Format Source: https://aisstream.io/documentation The standard format for AIS messages received over the websocket, including message type, metadata, and the AIS message body. ```json { "MessageType": "", "Metadata": { "Latitude": -54.0, "Longitude": -87.0, ... }, "Message": { "": { ....} } } ``` -------------------------------- ### PositionReport AIS Message Structure Source: https://aisstream.io/documentation Represents a vessel's current position, heading, speed, and navigation status. This message is crucial for real-time tracking and collision avoidance. ```json { "Cog":0, "CommunicationState":59916, "Latitude":51.44458833333333, "Longitude":3.590816666666667, "MessageID":1, "NavigationalStatus":7, "PositionAccuracy":true, "Raim":true, "RateOfTurn":0, "RepeatIndicator":0, "Sog":0, "Spare":0, "SpecialManoeuvreIndicator":0, "Timestamp":12, "TrueHeading":17, "UserID":245473000, "Valid":true } ``` -------------------------------- ### AIS Message Structure Source: https://aisstream.io/documentation This JSON object represents an incoming AIS event. It contains metadata about the message, the message type, and the specific AIS message payload nested under the 'Message' key. ```json { "Message":{ "PositionReport":{ "Cog":308, "CommunicationState":81982, "Latitude":66.02695, "Longitude":12.253821666666665, "MessageID":1, "NavigationalStatus":15, "PositionAccuracy":true, "Raim":false, "RateOfTurn":4, "RepeatIndicator":0, "Sog":0, "Spare":0, "SpecialManoeuvreIndicator":0, "Timestamp":31, "TrueHeading":235, "UserID":259000420, "Valid":true } }, "MessageType":"PositionReport", "MetaData":{ "MMSI":259000420, "ShipName":"AUGUSTSON", "latitude":66.02695, "longitude":12.253821666666665, "time_utc":"2022-12-29 18:22:32.318353 +0000 UTC" } } ``` -------------------------------- ### ShipStaticData AIS Message Structure Source: https://aisstream.io/documentation Contains static information about a vessel, including its name, call sign, dimensions, and destination. This data is transmitted periodically to aid in vessel identification. ```json { "AisVersion": 2, "CallSign": "LBHF", "Destination": "COASTGUARD@@@@@@@@H", "Dimension": { "A": 20, "B": 27, "C": 7, "D": 7 }, "Dte": false, "Eta": { "Day": 0, "Hour": 0, "Minute": 0, "Month": 0 }, "FixType": 1, "ImoNumber": 9353333, "MaximumStaticDraught": 4.5, "MessageID": 5, "Name": "KV FARM", "RepeatIndicator": 0, "Spare": false, "Type": 55, "UserID": 257069200, "Valid": true } ``` -------------------------------- ### LongRangeAisBroadcastMessage Structure Source: https://aisstream.io/documentation Defines a LongRangeAisBroadcastMessage AIS message for long-range communication up to 20 nautical miles. Includes location, course, speed, and other details for maritime safety. ```json { "Latitude1": 55.74, "Latitude2": 55.64333333333333, "Longitude1": 21.168333333333333, "Longitude2": 20.975, "MessageID": 23, "QuietTime": 0, "RepeatIndicator": 0, "ReportingInterval": 11, "ShipType": 0, "Spare1": 0, "Spare2": 0, "Spare3": 0, "StationType": 0, "TxRxMode": 0, "UserID": 2770030, "Valid": true } ``` -------------------------------- ### Interrogation AIS Message Structure Source: https://aisstream.io/documentation Represents an Interrogation AIS message used to request information from nearby vessels. Includes vessel identification, position, course, and other relevant data. ```json { "MessageID": 15, "RepeatIndicator": 0, "Spare": 0, "Station1Msg1": { "MessageID": 431006614, "SlotOffset": 0, "StationID": 431006614, "Valid": true }, "Station1Msg2": { "MessageID": 3, "SlotOffset": 0, "Spare": 0, "Valid": false }, "Station2": { "MessageID": 0, "SlotOffset": 0, "Spare1": 0, "Spare2": 0, "StationID": 0, "Valid": false }, "UserID": 4310211, "Valid": true } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.