oele-isis-vanderbilt / SyncFlow

Harmonize Your Data Streams
https://syncflow.live
Apache License 2.0
2 stars 0 forks source link

IoT Integration #144

Open edavalosanaya opened 1 month ago

edavalosanaya commented 1 month ago

The objective of this integration is to make IoT use seamless with the goal of IoT devices joining automatically when a LiveKit room is created by a super-user (teacher, admin, researcher) who owns these IoT devices within a project. For this first version, we will build the infrastructure to support this feature; however, the management of super-users is a responsibility by the learning environment. Therefore, the goal of this issue is to implement the mechanism of automatic IoT joining that is controlled by the SyncFlow admin within the SyncFlow dashboard. However, we want to make the management of IoT devices easy and allow for an entire group of IoT devices to join with a single button.

Here is an overview figure:

Screenshot from 2024-10-10 09-16-34

We want to support IoT devices within a project and a group. We are using RabbitMQ to support the exchange of messages from the SyncFlow cloud infrastructure and the local IoT devices.

By using a routing key (e.g., f"{project_id}.{group_id}"), we can selectively send JOIN messages to the desired IoT device collections. However, the routing key must be provided to the RabbitMQ consumer before they create a connection. Therefore, it's required before we can communicate with the IoT device via RabbitMQ. To achieve this, we need to perform IoT registration. Below is the workflow for IoT registration.

Screenshot from 2024-10-10 09-18-47

Once the IoT device is registered, the IoT RabbitMQ consumer can connect to the RabbitMQ Cloud Exchange and listen for JOIN messages. For this issue, our goal is to provide a button within the SyncFlow dashboard to allow the request of a IoT group to join the room. When the user request this, the SyncFlow RabbitMQ producer should relay the JOIN message to the fan-out message queue with the project and group IDs. All the desired IoT devices should then receive the message and join the requested LiveKit room.

Screenshot from 2024-10-10 09-22-48

Given this use-case, the following requirements need to be fulfilled:

umesh-timalsina commented 1 month ago

Thanks @edavalosanaya for this thorough issue description. This is an epic feature addition, and has many moving pieces. In this and subsequent comments, we can go back and forth for implemetation details:

The way I have thought about this integration needs to be divided into a series of steps

IOT Device Schema, CRUD and API Routes

"group": "The group ID for the IOT device(should be unique for the project)",
"name": "Name of the Device",
"comments": "Optional Comments"
"registration_timestamp": "Datetime"

Crud implemetations for the IoT devices

RabbitMQ deployment and Authetication Scheme

This will be the crux of our deployment and CI/CD integrations. Here, we will deploy a RMQ instance with http server based authentication scheme. Clients to the queue will sign the tokens and connect to the queue using their group id and token. The RMQ will send a token verification request to the syncflow and project and group id are verified with the token. Upon success, the clients will be able to consume the queue. The routing key for a specific client device will be project.id-group.id, where a Join Message will look like the following:

"session_id": "UUID of the session",
"session_name": "Name of the session",
"session_metadata": "Session metadata",
"session_join_token": "Livekit token to join the session"

Optional: Ping Messages

This can use a broadcast(fanout) queue for periodic healthchecks. May be we can even leverage the RMQ API for this.

I will first start my implementing the schema and even the registration CRUD for the IOT Devices. This will be necessary regardless of how we decide to move forward with this integration.

umesh-timalsina commented 1 month ago

Now that #148 is done, it might be good to move forward with an automated deployment scheme for a Rabbit MQ and add an HTTP authentication backend for it with SyncFlow.

umesh-timalsina commented 1 month ago

I think we have the pieces needed to test this feature out.