Hello,
I have been curious about using Websockets for different IoT projects and finding info in the API seems promising in figuring out how it works with Webthings.
From my understanding, this web socket interaction is divided into four parts:
-
A subscription object for configuring the type of connection to be established. I want to load a numerical live feed from sensors so I’m attempting to work with the setProperty example here: [https://iot.mozilla.org/wot/#setproperty-message](http://Web Things API Example)
-
A new web socket is created with a link along the lines of (‘wss://me.mozilla-iot.org/things/sensor/properties?jwt=’, ‘webthing’)
-
An onopen function with a method along the lines of websocket.send(JSON.stringify(subscription object))
4: An onopen function that parses data from a response.
The thing that confuses me after browsing the forums, checking the docs, and reading the gateway controllers, is the subscription object. There were a few forum posts that I thought might help, but I couldn’t quite get my head around. I thought that using a key-value pair in the format of the api would do it, but I’m clearly not getting it. Would any of you be kind enough to tell me where I went wrong or send a successful example?
But a picture is worth a thousand words! Here is the websocket portion of my componentDidMount: