The Signal K server Weather API provides a common set of operations for retrieving meteorological data via a "provider plugin" to facilitate communication with a weather service provider.
A weather provider plugin is a Signal K server plugin that brokers communication with a weather provider.
For a plugin to be a weather provider it must implement the WeatherProvider
Interface which provides the Signal K server with methods to pass the details contained in API requests.
A weather provider MUST return data as defined by the OpenAPI definition.
Multiple weather providers can be registered with the Signal K server to enable meteorogical data retrieval from multiple sources.
Weather API requests made to the Signal K server will result in the plugin's WeatherProviderMethods
being called.
A weather provider plugin MUST implement ALL of the WeatherProviderMethods
:
The Weather Provider is responsible for implementing the methods and returning data in the required format!
Now that the plugin has implemented the required interface and methods, it can be registered as a weather provider with the SignalK server.
The plugin registers itself as a weather provider by calling the server's registerWeatherProvider
function during startup.
Do this within the plugin start()
method.
Example.
import { WeatherProvider } from '@signalk/server-api'
module.exports = function (app) {
const weatherProvider: WeatherProvider = {
name: 'MyWeatherService',
methods: {
getObservations: (
position: Position,
options?: WeatherReqParams
) => {
// fetch observation data from weather service
return observations
},
getForecasts: (
position: Position,
type: WeatherForecastType,
options?: WeatherReqParams
) => {
// fetch forecasts data from weather service
return forecasts
},
getWarnings: () => {
// Service does not provide weather warnings.
throw new Error('Not supported!')
}
}
}
const plugin = {
id: 'mypluginid',
name: 'My Weather Provider plugin'
start: (settings: any) => {
app.registerWeatherProvider(weatherProvider)
}
}
return plugin