aerosense-ai / data-gateway

Data influx for Aerosense.
https://www.aerosense.ai/
Other
3 stars 1 forks source link

Recompute sensor_time_offset after handles update. #42

Closed time-trader closed 2 years ago

time-trader commented 2 years ago

Feature request

Use Case

Sensor node internal clock can reset itself, if the sensor node crashes and resets. If such event occurs, sensor_time_offset should be recomputed.

Current state

Currently sensor_time_offset is computed only once per gateway session. IF the internal sensor node clock is reset during the gateway operation, and the connection is reestablished, then previously computed offset is no longer correct.

Proposed solution

When connection is reestablished, the handles are updated, so it is possible to reinitialize sensor_time_offset to None, in this method. This will force time-stamping method to recompute it.

time-trader commented 2 years ago

@WeikangKong, @tommasopolonelli since you introduce cross-node synchronization, do you have something like a "master clock"? If so, what is t=0 for that clock?

WeikangKong commented 2 years ago

@WeikangKong, @tommasopolonelli since you introduce cross-node synchronization, do you have something like a "master clock"? If so, what is t=0 for that clock?

t=0 would be around the moment when the base station is turned on.

cortadocodes commented 2 years ago

Closed by #25

time-trader commented 2 years ago

@WeikangKong, @tommasopolonelli since you introduce cross-node synchronization, do you have something like a "master clock"? If so, what is t=0 for that clock?

t=0 would be around the moment when the base station is turned on.

@WeikangKong you mean when the bt receiver is plugged in, or the gateway script started?

WeikangKong commented 2 years ago

@WeikangKong, @tommasopolonelli since you introduce cross-node synchronization, do you have something like a "master clock"? If so, what is t=0 for that clock?

t=0 would be around the moment when the base station is turned on.

@WeikangKong you mean when the bt receiver is plugged in, or the gateway script started?

when the bt receiver is plugged in (power on)

time-trader commented 2 years ago

oki thanks.

time-trader commented 2 years ago

Sensor_time_offset was not recomputed after Handles updated for recent tests.

From log:

[2022-03-22 17:49:08,880 | INFO | multiprocessing | Parser] Window 39 uploaded to cloud.
[2022-03-22 17:50:12,655 | INFO | multiprocessing | Reader] Successfully updated handles.
[2022-03-22 17:51:03,249 | INFO | multiprocessing | Parser] Window 40 uploaded to cloud.

window-39.json and window-40.json can be found here: aerosense-ingress-eu/data_gateway/790791 sensor_time_offset remained same.

The line that should reinitialize offset is https://github.com/aerosense-ai/data-gateway/blob/cf3fcf4bd1581efd6e7adbfb50c668ed0f51759b/data_gateway/packet_reader.py#L238

The offset is computed with https://github.com/aerosense-ai/data-gateway/blob/cf3fcf4bd1581efd6e7adbfb50c668ed0f51759b/data_gateway/packet_reader.py#L525

I am still to find out why that was the case.

cortadocodes commented 2 years ago

I think this is because the offset is reset in the Reader process - this attribute value change won't be communicated to the Parser process. I'll need to make the attribute process-safe or only update the handles in the Parser process.