Air Quality Sensor (Vaisala - XWeather) Websocket Connection Help

215
6
3 weeks ago
Teresa_Blader
Occasional Contributor III

Trying to connect websocket in ArcGIS Velocity for Vaisala Air Quality sensors, hosted with XWeather. I'm getting an error in ArcGIS Velocity for the first step - just adding in the URI. I do need to incorporate the api key, so I'm wondering if I'm getting the error because there is not a place to add in an api-key header parameters on the first step?

The company confirmed websocket is external and has given me Python to try to make sure my API key is good, but I've never used Python so not really sure how to use that.  Ultimately, I really just want to connect to the sensor in ArcGIS Velocity and not worry about python!

Websocket: wss://ws-api.eu.platform.xweather.com

URI to call a specific sensor (I think?):
wss://ws-api.eu.platform.xweather.com/measurement-stream?sensor-id=urn:dev:ops:16961AQT530-V0810232

But gives error in ArcGIS Velocity. Would this be because the api-key is not in the URL? Is there a way to add this into the URL? Or should I be able to connect to the base uri without the parameters?

Teresa_Blader_0-1714421025488.png

Teresa_Blader_1-1714421096106.png

##
#
# Copyright (c) Vaisala Oyj. All rights reserved.
#
##

import asyncio
import pathlib
import ssl
import websockets
base_uri = "wss://ws-api.eu.platform.xweather.com"
endpoint = "/measurement-stream"
api_key = "" # Place api-key here
sensor_id = "urn:dev:ops:16961-AQT530-V0810232"

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

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())

 

Teresa Blader
Olmsted County GIS Specialist
0 Kudos
6 Replies
JeffSilberberg
Occasional Contributor III

Teresa, 

 

     Just a guess here after taking a look at the Documention on Weather -- 

        https://docs.vaisala.com/r/M212980EN-B/en-US/GUID-64E9D6A5-0D6E-4A8A-B4E1-040E157A568D

 wss://ws-api.eu.platform.xweather.com/measurement-stream?sensor-id=urn:dev:ops:16961AQT530-V0810232&x-api_key="your_api_kery_here'    

  Note the & after the sensor-id to separate the Key-Value Pairs.  

 

 

 

Teresa_Blader
Occasional Contributor III

Shoot... I did try your suggestion and it still errors... I tried ? and &... Thanks for providing the link! Sounds like Peter and the team will explore header parameter options with my api key... so I'll see how that goes.

In the meantime I'm going to see if Xweather can first get my sensors re-registered to the US api and not the europe api.🙄

Teresa Blader
Olmsted County GIS Specialist
0 Kudos
JeffSilberberg
Occasional Contributor III

 

Good Morning -- I talked with Viasla about this and got two interesting pieces of data. 

First, "So, the key-value pair is x-api-key={'My-Api-Key'}."  

Second, the documentation page I referenced is in review as it "needs updating".

Try this in Velocity -- 

wss://ws-api.eu.platform.xweather.com/measurement-stream?x-api-key='My-Api-Key'&sensor-id=urn:dev:ops:16961AQT530-V0810232

 

0 Kudos
Teresa_Blader
Occasional Contributor III

Still a no go - Vaisala support is telling me api key HAS to be passed as a header parameter and can't be passed in the URL😢 Thanks for investigating!


Regarding the measurement stream api, the api key has to be passed in the headers. The link you shared won't work as the key is passed as a query parameter.

So, if it will be something like this in the system you are using:
URI field: wss://ws-api.eu.platform.xweather.com/measurement-stream?sensor-id=urn:dev:ops:16961AQT530-V0810232
headers field: "x-api_key": ”my-api-key-here”

 

Teresa Blader
Olmsted County GIS Specialist
0 Kudos
PeterNasuti
Esri Contributor

@Teresa_Blader We are targeting a Velocity 5.2 release of this functionality which should go live around mid-June and enable you to ingest this data. If there are any unforeseen delays to a later release I will update this thread.

PeterNasuti
Esri Contributor

Hi Teresa,

We have this written up on our end to implement as an enhancement to add support for custom headers in WebSocket connection from the Velocity backend. Please test the workaround provided by @JeffSilberberg and let me know if that works for you or not?