efento / NB-IoT-sensors-integration

This quick tutorial will show you how to set up a simple CoAP server, which receives the data from Efento NB-IoT sensors and saves it to a PostgreSQL database.
Apache License 2.0
7 stars 2 forks source link

Start points for major acc channels #12

Open JohnnyPicnic opened 11 months ago

JohnnyPicnic commented 11 months ago

It seems the default start points for acc channels 3 and 5 are "2" and "4". Is this accounted for when summing up major value and minor values?

piotr-szydlowski commented 11 months ago

Yes. Decoding / summing up example below:

Example of data decoding:

Channel 1:

{"timestamp":1627294260,"startPoint":34,"sampleOffsets":[0,0,0]}

Channel 2:

{"timestamp":1627294260,"startPoint":564,"sampleOffsets":[-18,-18,18]}

Channel 1 values (startPoint + sampleOffsets):

34+0 = 34, 34+0 = 34, 34+0 = 34

Channel 2 values (startPoint + sampleOffsets):

564-18 = 546, 564-18 = 546, 564 + 18 = 582

Decoded values:

Channel 1:

34 = 4*8 +2 -> value = 8, metadata = 2 (to get these values: value = floor(34/4) = 8 (metadata factor for this type of sensor = 4); metadata = 34 mod 4 = 2)

Major value = 8 hectolitre, metadata = 2 -> sensor has been reset, value may be understated

Channel 2:

546 = 91*6 + 0 -> value = 91, metadata = 0 (to get these values: value = floor(546/6) = 91 (metadata factor for this type of sensor = 6); metadata = 546 mod 6 = 0)

Minor value = 91 litres, the channel is a minor water meter for major water meter on channel 1

Total value = 800 + 91 = 891 litres

JohnnyPicnic commented 11 months ago

This is what I'm working with.

[{"type":"MEASUREMENT_TYPE_PULSE_CNT_ACC_MAJOR","timestamp":1689707040,"sample_offsets":[0,0,0,0]},{"type":"MEASUREMENT_TYPE_PULSE_CNT_ACC_MINOR","timestamp":1689707040,"start_point":1200,"sample_offsets":[600,-1200,1200,-1200]},{"type":"MEASUREMENT_TYPE_PULSE_CNT_ACC_MAJOR","timestamp":1689707040,"sample_offsets":[0,0,0,0]},{"type":"MEASUREMENT_TYPE_PULSE_CNT_ACC_MINOR","timestamp":1689707040,"start_point":2,"sample_offsets":[0,0,0,0]},{"type":"MEASUREMENT_TYPE_PULSE_CNT_ACC_MAJOR","timestamp":1689707040,"sample_offsets":[0,0,0,0]},{"type":"MEASUREMENT_TYPE_PULSE_CNT_ACC_MINOR","timestamp":1689707040,"start_point":4,"sample_offsets":[0,0,0,0]}]

When calculating the value for the minor channels the start setpoints "2" and "4" throw off the values.

{"PULSE_CNT_ACC_1":[{"type":"PULSE_CNT_ACC_1","value":300},{"type":"PULSE_CNT_ACC_1","value":0},{"type":"PULSE_CNT_ACC_1","value":400},{"type":"PULSE_CNT_ACC_1","value":0}],"PULSE_CNT_ACC_2":[{"type":"PULSE_CNT_ACC_2","value":0.3333333333333333},{"type":"PULSE_CNT_ACC_2","value":0.3333333333333333},{"type":"PULSE_CNT_ACC_2","value":0.3333333333333333},{"type":"PULSE_CNT_ACC_2","value":0.3333333333333333}],"PULSE_CNT_ACC_3":[{"type":"PULSE_CNT_ACC_3","value":0.6666666666666666},{"type":"PULSE_CNT_ACC_3","value":0.6666666666666666},{"type":"PULSE_CNT_ACC_3","value":0.6666666666666666},{"type":"PULSE_CNT_ACC_3","value":0.6666666666666666}]}

Another example with values for channels 2 and 3.

{"serial_num":"KCwCQZrg","battery_status":true,"measurement_period_base":60,"channels":[{"type":"MEASUREMENT_TYPE_PULSE_CNT_ACC_MAJOR","timestamp":1689864420,"sample_offsets":[0,0,0]},{"type":"MEASUREMENT_TYPE_PULSE_CNT_ACC_MINOR","timestamp":1689864420,"start_point":1200,"sample_offsets":[-1200,-1200,1200]},{"type":"MEASUREMENT_TYPE_PULSE_CNT_ACC_MAJOR","timestamp":1689864420,"sample_offsets":[0,0,0]},{"type":"MEASUREMENT_TYPE_PULSE_CNT_ACC_MINOR","timestamp":1689864420,"start_point":902,"sample_offsets":[-900,900,-900]},{"type":"MEASUREMENT_TYPE_PULSE_CNT_ACC_MAJOR","timestamp":1689864420,"sample_offsets":[0,0,0]},{"type":"MEASUREMENT_TYPE_PULSE_CNT_ACC_MINOR","timestamp":1689864420,"start_point":1204,"sample_offsets":[-1200,1200,-1200]}],"next_transmission_at":1690469754,"transfer_reason":4,"signal":23,"measurement_period_factor":1,"hash":38,"cloud_token":""}

Result:

{"PULSE_CNT_ACC_1":[{"type":"PULSE_CNT_ACC_1","value":0},{"type":"PULSE_CNT_ACC_1","value":0},{"type":"PULSE_CNT_ACC_1","value":400}], "PULSE_CNT_ACC_2":[{"type":"PULSE_CNT_ACC_2","value":0.3333333333333333},{"type":"PULSE_CNT_ACC_2","value":300.3333333333333},{"type":"PULSE_CNT_ACC_2","value":0.3333333333333333}], "PULSE_CNT_ACC_3":[{"type":"PULSE_CNT_ACC_3","value":0.6666666666666666},{"type":"PULSE_CNT_ACC_3","value":400.6666666666667},{"type":"PULSE_CNT_ACC_3","value":0.6666666666666666}]}