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?
##
#
# 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())
Ok, gotcha!
These sensors are stationary, so I think I'll get that added in there.
Weird they wouldn't have that in the JSON!
Thanks!
It's not really weird, if the sensor is stationary why use up the bits.
I suppose!
You can actually grab all their sensors data by not including the sensor ID in the WebSocket - but there's not any indication of location information in the data so not very useful for spatial analysis.
@JeffSilberberg Turns out I was using the sensor ID for the wrong component in the. urn:dev:ops:16961-AQT530-V0810232 is the correct one and the schema is detected right away.
Nevermind... I was confused. Alright... moving along now.
--- Great. Be careful of that LONG key value in the Derived Schema.
Good Luck -
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?