overthesun / simoc-sam

Live backend for SAM at Biosphere 2
2 stars 1 forks source link

Remove batching and add bundling #21

Closed ezio-melotti closed 2 years ago

ezio-melotti commented 2 years ago

This PR does two things:

  1. it removes batching from the sensors
  2. it adds a main loop that emit bundles

With this changes, the server asks the sensors to send a reading every second, the sensors use the send-reading event to emit readings, the server receives them and stores them in the SENSOR_READINGS object. The server also keeps track of SUBSCRIBERS and SENSORS and adds a main loop that is launched when the server starts. The main loop checks if there are subscribers and sensors, and if there are, it takes from SENSOR_READINGS the latest readings from all the sensors and creates a bundle that includes a number, a timestamp, and an object that maps each sensor with its reading. This bundle is then broadcasted to all the subscribers. The server also keeps track of sensor and subscriber (dis)connections.

See also #12.

ezio-melotti commented 2 years ago

The last 2 commits:

  1. Allow for multiple hab-info and sensor-info events to be sent. These assume that full info are sent every time, and they override the previous info.
  2. Remove the send-step-data event. Now the client only needs to send a register-client and the server will, in order, send hab-info, sensor-info, and step-batch in a loop.

See also #22 for a description of the events.