I am currently working on an application that reads values from external devices and then writes these values to a database.
The values I deal with include acceleration, gyroscope, magnetometer, and pressure.
For acceleration, gyroscope, and magnetometer, the readings are obtained along with a timestamp as shown below:
(for example, for acceleration)
const buf = Buffer.from(characteristic.value, "base64");
const [time, ...acc] = [0,2,4,6].map(index => buf.readInt16LE(index));
this.setState(state => ({
time,
acc,
array_acc_sx: [
...state.array_acc_sx,
[time , acc ]
]
}));
However, obtaining the timestamp for pressure readings poses a challenge since it doesn't come automatically. To address this issue, I have considered setting a variable 'timeP' equal to the timestamp of the accelerometer, gyroscope, and magnetometer readings.
But doing so results in the timestamp for pressure starting before the actual pressure values are read, leading to inaccurate data representation like the one shown below:
"PL":
"[740,740,740,740,700,700,660,660,580,580,580,
560,500,500,500,500,500,440,400,400,340,340,320,300,
280,260,260,260,200,180,160,160,140,
// timestamps + pressure values commence here.
[140,[0,0,0,0,0]],[160,[0,0,0,0,0]],[160,[0,0,0,0,0]],
[180,[0,0,0,0,0]],[200,[0,0,0,0,0]],[260,[0,0,0,0,0]],
[260,[0,0,0,0,0]],[260,[0,0,0,0,0]],[280,[0,0,0,0,0]],
[300,[0,0,0,0,0]],[320,[0,0,0,0,0]],[340,[0,0,0,0,0]],
[340,[0,0,0,0,0]],[400,[0,0,0,0,0]],[400,[0,0,0,0,0]],
[440,[0,0,0,0,0]],[500,[0,0,0,0,0]],[500,[0,0,0,0,0]],
.....
In order to address this issue, I've included code snippets that handle reading and storing the sensor data in the application. However, I'm seeking advice on how to effectively solve this problem. Any insights would be greatly appreciated. Thank you.