When trying to use Datalogger and Logbook I only get the latest reading when querying the device Logbook when I expect to get an array of the readings saved.
I'm trying to build a 1-Wire reading app to test the platform, I have defined a subscription API very similar to /Meas/Temp
:
paths:
/OneWireTemp/Subscription:
post:
description: |
Subscribe to periodic temperature readings.
responses:
200:
description: Operation completed successfully
x-std-errors:
description: See common error codes http://developer.suunto.com/api/std-errors#subscribe
x-notification:
schema:
$ref: "#/definitions/TempMeasurement"
delete:
description: |
Unsubscribe to periodic temperature readings.
responses:
200:
description: Operation completed successfully
x-std-errors:
description: See common error codes http://developer.suunto.com/api/std-errors#unsubscribe
definitions:
TempMeasurement:
required:
- Timestamp
- Measurement
properties:
Timestamp:
description: Relative time of temperature reading
type: integer
format: uint32
x-unit: millisecond
Measurement:
description: Temperature reading
type: integer
format: int16
x-unit: celsius
I start the logging on device side with:
bool OneWireTempService::startDataLogger() {
WB_RES::DataEntry entry;
// Must match the subscription API path (without the /Subscription)
entry.path = "/OneWireTemp";
WB_RES::DataLoggerConfig dataLoggerConfig;
WB_RES::DataEntry entries[] = {entry};
dataLoggerConfig.dataEntries.dataEntry =
wb::MakeArray<WB_RES::DataEntry>(entries, 1);
wb::Result configureResult =
asyncPut(WB_RES::LOCAL::MEM_DATALOGGER_CONFIG(),
AsyncRequestOptions::Empty, dataLoggerConfig);
if (!wb::RETURN_OK(configureResult)) {
DebugLogger::error("Datalogger configuring failed: %u", configureResult);
return false;
}
wb::Result stateResult = asyncPut(
WB_RES::LOCAL::MEM_DATALOGGER_STATE(), AsyncRequestOptions::Empty,
WB_RES::DataLoggerStateValues::Type::DATALOGGER_LOGGING);
if (!wb::RETURN_OK(stateResult)) {
DebugLogger::error("Datalogger enabling failed: %u", stateResult);
return false;
}
return true;
}
and I update the subscription like this:
WB_RES::TempMeasurement tempMeasurement;
tempMeasurement.measurement = mTempReading;
tempMeasurement.timestamp = currentTime;
updateResource(WB_RES::LOCAL::ONEWIRETEMP(), ResponseOptions::Empty,
tempMeasurement);
Now on Android side I connect to the device using MDS library and MDS/Logbook/{Serial}/Entries
returns a log after a while: {"elements": [{"Id": 2, "ModificationTimestamp": 1613406975, "Size": null}]}
.
When querying MDS/Logbook/{Serial}/ById/2/Data
now I only get the latest measurement: {"OneWireTemp":{"Measurement":2536,"Timestamp":2794239193}}
. The reading is not even in an array.
This was fixed by wrapping the result in an array, then the Datalogger seemed to understand that there can be multiple entries in the log:
paths:
/OneWireTemp/Subscription:
post:
description: |
Subscribe to periodic temperature readings.
responses:
200:
description: Operation completed successfully
x-std-errors:
description: See common error codes http://developer.suunto.com/api/std-errors#subscribe
x-notification:
schema:
$ref: "#/definitions/OneWireTempMeasurements"
delete:
description: |
Unsubscribe to periodic temperature readings.
responses:
200:
description: Operation completed successfully
x-std-errors:
description: See common error codes http://developer.suunto.com/api/std-errors#unsubscribe
definitions:
OneWireTempMeasurements:
required:
- Measurements
properties:
Measurements:
description: Wrapper array
type: array
items:
$ref: '#/definitions/OneWireTempMeasurement'
OneWireTempMeasurement:
required:
- Timestamp
- Measurement
properties:
Timestamp:
description: Relative time of temperature reading
type: integer
format: uint32
x-unit: millisecond
Measurement:
description: Temperature reading in celsius
type: integer
format: int16
x-unit: celsius