问题描述
尝试使用 Datalogger 和 Logbook 时,当我希望获得保存的读数数组时,查询设备 Logbook 时只会获得最新读数。
我正在尝试构建一个 1-Wire 阅读应用程序来测试该平台,我已经定义了一个与 /Meas/Temp
非常相似的订阅 API:
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
我开始在设备端登录:
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(),WB_RES::DataLoggerStateValues::Type::DATALOGGER_LOGGING);
if (!wb::RETURN_OK(stateResult)) {
DebugLogger::error("Datalogger enabling Failed: %u",stateResult);
return false;
}
return true;
}
我像这样更新订阅:
WB_RES::TempMeasurement tempMeasurement;
tempMeasurement.measurement = mTempReading;
tempMeasurement.timestamp = currentTime;
updateResource(WB_RES::LOCAL::ONEWIRETEMP(),ResponSEOptions::Empty,tempMeasurement);
现在在 Android 端,我使用 mds 库连接到设备,mds/Logbook/{Serial}/Entries
一段时间后返回一个日志:{"elements": [{"Id": 2,"ModificationTimestamp": 1613406975,"Size": null}]}
。
现在查询 mds/Logbook/{Serial}/ById/2/Data
时,我只得到最新的测量值:{"OneWireTemp":{"Measurement":2536,"Timestamp":2794239193}}
。读数甚至不在数组中。
解决方法
这是通过将结果包装在一个数组中来解决的,然后数据记录器似乎明白日志中可以有多个条目:
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