overthesun / simoc-sam

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

Define socketio protocol #22

Open ezio-melotti opened 2 years ago

ezio-melotti commented 2 years ago

The socketio protocol currently uses these events:

sensor <-> server:

If/when the server disconnects from the sensor, the loop detects that, stops sending readings, and sits idle. If/when the server reconnects, the steps above are repeated again.

sensor <-> client:

If/when the server disconnects from the client, the client stops receiving batches and sits idle. If/when the server reconnects, the steps above are repeated again.


Once the protocol is fully defined, it should be added to the documentation. For each event, it should specify when it's emitted, the kind of object sent with the event (if any), if it can be sent multiple times.

@hiyaryan suggests to add a sensor-status. This could either be a separate event that is only sent when the status of sensor changes, or it could be added in the each bundle, to make it easier to track the status for each individual bundle.


For reference, this is an example of sensor-info:

{
    'byHCpwOFe95xtO3eAAAB': {
        'sensor_type': 'Mock',
        'sensor_name': 'MockSensor',
        'reading_info': {
            'co2': {'label': 'CO2', 'unit': 'ppm'},
            'temp': {'label': 'Temperature', 'unit': '°C'},
            'rel_hum': {'label': 'Relative Humidity', 'unit': '%'}
        }
    },
    '4lCz9k02vhu9VVyyAAAF': {
        'sensor_type': 'SCD-30',
        'sensor_name': 'SCD-30',
        'reading_info': {
            'co2': {'label': 'CO2', 'unit': 'ppm'},
            'temp': {'label': 'Temperature', 'unit': '°C'},
            'rel_hum': {'label': 'Relative Humidity', 'unit': '%'}
        }
    }
}

and this is an example of reading:

{
    'n': 3662,
    'timestamp': '2022-03-04 02:58:02.793324',
    'readings': {
        'byHCpwOFe95xtO3eAAAB': {
            'co2': 1222.0,
            'temp': 21.78860661931555,
            'rel_hum': 46.0,
            'timestamp': '2022-03-04 03:58:02.771409',
            'n': 3686
        },
        '4lCz9k02vhu9VVyyAAAF': {
            'co2': 181.9676055908203,
            'temp': 29.59296417236328,
            'rel_hum': 20.79315185546875, 
            'timestamp': '2022-03-04 03:58:01.669364',
            'n': 4361
        }
    }
}
GregRRoss commented 2 years ago

I think this is already done, right?