Subscribing to measurements from specific sensor - Xweather Insight

Vaisala Xweather Observe API Reference

Document code
M212980EN
Revision
B
ft:locale
en-US
Product
Xweather Insight
Document type
Technical description

You can subscribe to the following channel to receive measurements from a specific sensor published by the service.

/measurement-stream?{sensor_id}

Provide your API key as the user and leave the password empty.

Table 1. Parameters
Parameter Mandatory Description Example
sensor_id Sensor uniform resource name (URN) urn:dev:ops:16961-WXT530-S4131016

Message

Example

[
  {
    "observedTime": "2023-05-12T14:49:00Z",
    "value": 1021.1,
    "sourceId": "urn:dev:ops:16961-WXT530-S4131016",
    "quality": {
      "qualityValue": 8500,
      "checkLevel": 1,
      "checkedAt": "2023-05-12T14:49:00Z",
      "qualityReasons": [
        {
          "name": "Level0.Unknown",
          "description": "ACCEPTED by the measurement device."
        }
      ]
    },
    "measurementType": {
      "parameter": "AIR_PRESSURE",
      "unit": "HECTOPASCALS",
      "statistics": "MEAN",
      "period": "PT1M",
      "height": 2,
      "dataLevel": "LEVEL_TWO"
    }
  }
]

Example in Python using API key

##
#
# Copyright (c) Vaisala Oyj. All rights reserved.
#
##
import asyncio
import websockets

base_uri = "wss://ws-api.eu.platform.xweather.com"
endpoint = "/measurement-stream"
api_key = "your-api-key" # Place your api-key here
sensor_id = "123"  # Replace with your actual full sensor_id, e.g. urn:dev:ops:16961-WXT530-F1234567, remove if all data is needed

uri = f"{base_uri}{endpoint}?sensor-id={sensor_id}"

async def connect_websocket():

    # Define the headers, including the x-api-key header
    headers = {
        "x-api-key": api_key,
    }

    async with websockets.connect(uri, extra_headers=headers) as websocket:
        print("WebSocket connection established")

        # Receive data once
        response = await websocket.recv()
        print(f"{response}")

if __name__ == "__main__":
    asyncio.get_event_loop().run_until_complete(connect_websocket())