One Streaming endpoint for all the devices state updates?

Hi there,

We are using streaming endpoints to relay the real-time state updates of the devices to our front-end app which then makes the necessary updates on the platform for the user to see.

However, the problem we are facing as of now is that when we subscribe to 5-6 devices with an SSE, all other subsequent API requests stay in pending state and timeout.

Is it possible to have one streaming end-point that would send device updates for all the devices with their device id on the payload, that way we will only have one open continuous connection with the SSE and be able to make state updates on the front-end?

Please let me know. Thanks

You most certainly can have one endpoint for all your streams! When configuring your SSE Endpoint Reply, you can include multiple devices in the stream by clicking the “+” button alongside the “Device State Topic” dropdown and keep adding as many devices as you’d like.

What you’ll get in the stream won’t include the device ID as a property, but it will include the topic on which the message was originally published, and that topic does include the device ID in the form of “losant/DEVICE_ID/state”. So with a little bit of extra work on the browser end, you can extract the device ID from there quite easily.

@Dylan_Schuster

Thank you for the reply.

That solution won’t work out for us as it’s a manual thing whereas we need to do it dynamically either based on device tag query or just all devices by default if possible.

This is a multi-tenant application and each of the organizations will have its own set of devices so it won’t be possible to go in and modify the workflow every time a new device is added to the system.

Is it possible to create an SSE for all the devices or pick devices by query?

@Suroor_Wijdan it’s not possible at this time to open a device stream by query, but I will open a feature request for that.

What if you do the following …

  • Given Devices A, B and C that are part of Organization XYZ - and this assumes that is designated on the devices themselves through tags i.e. “organization=xyz” …
  • In an application workflow, use a Device: State Trigger to publish the state report to a different MQTT topic (using the MQTT Node) whenever any device tied to an organization reports state, i.e. trigger on the tag “organization=*” …
  • The topic you publish to has the organization ID somewhere in it, such as “orgstate/{{device.tags.organization}}”
  • Separately, in your Endpoint Reply Node that is serving the SSE stream, instead of subscribing to individual device state topics, you instead subscribe to only that custom MQTT topic you are publishing to (“orgstate/{{device.tags.organization}}”)

Bear in mind this will lead to additional payload consumption for your account, but I think it would get you what you are looking for.

Thanks @Dylan_Schuster. The proposed solution works for now and we will stick with it until we get the native functionality to open streaming endpoints by querying devices.

Cheers!