Closed ezio-melotti closed 2 years ago
Currently the sensor sends batches to the server, and the server immediately broadcasts them to the clients. This means that all the clients get the same batch (roughly) at the same time. With multiple sensors we can't immediately broadcast, but we need to store the data somewhere when we receive them from the sensor and then combine them in a bundle before sending them to the client.
Now, there are two options:
An hybrid approach could also be possible: the server could creates bundles every second (or maybe half second) and store them in a global batch. Each client loop can then create a custom batch by extracting bundles from the global batch. For example, if the global batch has the last 100 bundles with a 1s interval, a client with 1s delay and a batch size of 10 bundles could get the last 10 bundles from the global batch, put them together in a custom batch with a custom step number, and repeat the process every 10s. A client with a 5s delay and a batch size of 3 bundles could get the bundles -1
, -6
, -11
, and repeat the process every 15s (3 * 5s). This provides some flexibility while avoiding being memory-intensive, even though the frequency and batch size must be compatible with the global bundle.
Different sensors read data at different times and with different intervals. It would be convenient for the frontend to receive all values at once, with the same step number and timestamp. In order to do that we need to bundle or interpolate the data. I can see three solutions:
To give you an example, assume we have a reading every 1.5s, and we are sending data to the frontend every 1s. At 10s, the frontend has to send a value, but the last reading was at 9s (0s, 1.5s, 3s, 4.5s, 6s, 7.5s, 9s) and the next will be at 10.5s.
The final object emitted by the socketio server could look like:
The list of available sensors should be sent by the server when the frontend connects. We might want to add an id or label to the sensor name in order to distinguish multiple sensors of the same type (e.g.
SCD30-0
orSCD30-greenhouse
).