Select to view content in your preferred language

Air Quality Sensor (Vaisala - XWeather) Websocket Connection Help

1107
16
04-29-2024 02:08 PM
Teresa_Blader
Frequent Contributor

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
16 Replies
JeffSilberberg
Frequent Contributor

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
Frequent Contributor

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
Frequent Contributor

 

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
Frequent Contributor

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.

Teresa_Blader
Frequent Contributor

Hi @PeterNasuti or @JeffSilberberg ! Glad to see the Velocity update! I'm trying out connecting to my two websocket sensors, got past adding the header parameter with the API key, yay! But am having a bit of trouble with deriving the schema. Vaisala's documentation says it's using JSON but it's got two or three pieces that are nested and Velocity isn't detecting it automatically. Think you could take a look and give me advice on how to set up the schema? This would be my first time really working with JSON where the schema wasn't auto-detected. How would I use the Flatten options? Which is the root node? I did see this documentation: https://doc.arcgis.com/en/iot/ingest/configure-input-data.htm#ESRI_SECTION1_65F4CA586A08486CA1675BD2... 

Thanks!!

 

This is an example payload they provided in their API documentation (there would be probably 4 or 5 measurementType but below is just one for AIR_PRESSURE):

[
  {
    "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"
    }
  }
]

 

Teresa_Blader_0-1719516586250.png

 

Teresa Blader
Olmsted County GIS Specialist
0 Kudos
JeffSilberberg
Frequent Contributor

@Teresa_Blader 

    The issue you have here is that Velocity did not get any data/sample data back from its test poll.  So there is no information to Derive the Schema from.   I was able to force a set of data and then edit the "sample Daa" from my poll and replace it with yours.  When I had both Flatten and Flatten Arrays checked, then clicked Derive Schema it did so, although the names it built in one case had more than the allowed number of characters so you will need to edit that.  

Handling Aarry's might still be an issue as I have not seen any news on that front in the Release notes for 5.2 so far.  Use this tool to validate the JSON further if you need.  https://jsoncrack.com/editor

 

0 Kudos
Teresa_Blader
Frequent Contributor

Thanks Jeff! I will reach out to them to get an example of the full JSON payload!

Not sure why Velocity wouldn't be getting data, as the sensors are live an collecting. Guess I'll see what happens next!

I don't see any lat/long fields in the JSON - is that an issue?

Teresa Blader
Olmsted County GIS Specialist
0 Kudos
JeffSilberberg
Frequent Contributor

@Teresa_Blader 

No data means that some part of the Header / Query is not correct yet.

Not having a Lat/Lon/Alt is not a show-stopper, but if you are going to do GIS-type things with the process you will need it.  Maybe do a Survey 123 to collect the location and then a Join in your Anaytic to enrich your data. 

  

 

0 Kudos