Skip to content

PhilipFaure/aisstreamR

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

aisstreamR ⚓️

DOI

How to

Description ⚓️

aisstreamR is an R package that provides a simple and reliable way to connect to the AISStream WebSocket API. It allows users to stream real-time maritime data, including vessel positions, ship names, and other critical information, directly into their R environment. This data can be used for research, data analysis, or real-time monitoring of maritime traffic within a specified geographic area.

The package handles WebSocket connections, subscribes to data streams based on user-defined bounding boxes, and decodes the incoming AIS messages into a user-friendly format. It also includes an option to automatically save the received data to a CSV file.

NOTE: AISStream.io does not have great coverage for South African waters, therefore I stopped developing this package. Works great for North American, European and Mediteranean areas though. Sorry nê.


How to use ⚓️

1. Obtain and API key from https://aisstream.io/apikeys
2. Connect to the Stream

Use the connect_ais_stream() function to start receiving real-time data. You'll need to provide your API key and the coordinates for the bounding box you want to monitor. The connect_ais_stream() function will open a persistent WebSocket connection. As long as your R session is running, messages will be received and processed automatically. Each message will be printed to your console in a clean format and, if you've specified a directory, saved to a CSV file.

3. Disconnect

To close the connection and stop receiving data, you can use the close_ais_stream() function.


Key Functions ⚓️

connect_ais_stream(): Establishes a WebSocket connection and begins streaming data.

close_ais_stream(): Closes the active WebSocket connection.

decode_ais_hex(): Decodes raw hexadecimal AIS messages into a structured R object (used internally by connect_ais_stream).


Example ⚓️

# installation
devtools::install_github("PhilipFaure/aisstreamR")

# load package
library(aisstreamR)

# add API key
api_key <- "YOUR_API_KEY"

# provide bounding box coordinates
bbox <- list(
  list(
    list(-33.90081, 18.39103), 
    list(-33.82374, 18.47033)
  )
)

# open connection and stream AIS messages
ws <- connect_ais_stream(api_key, bbox)

# close connection
close_ais_stream()

https://doi.org/10.5281/zenodo.17404354

About

R package: Real-time vessel AIS messages via AISStream.io

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors