Reputation: 145
I'm attempting to create an iOS app similar in structure to the initial ios-sample app, the difference being that I draw on the ECG data that is said to be stored in Meas/ECG in the API. I was able to create this handler class by mirroring the code in other observation functions in the sample app (that all work completely fine on their own) and by looking at the iOS MQTT app that seems to have implemented something similar:
class EcgHandler : BaseSubscriptionHandler {
private var values = Array<Int16>()
private var newValue : (Double) -> () = { (value) in }
init(viewController: SubscriptionDetailViewController, toggle: UISwitch,
serial: String, newValueReceiver: @escaping (Double) -> ()) {
super.init(viewController: viewController, toggle: toggle, serial: serial, title: "ECG", filePrefix: "ecg", path: "/Meas/ECG", infoPath: "/Meas/ECG/Info")
self.newValue = newValueReceiver
}
public func subscribe() {
self.toggle.isOn = true
self.dataFile = SubDataFile(self.filePrefix, serial: self.serial)
self.viewController.movesense?.subscribe(self.serial, path: self.path,
parameters: [:],
onNotify: { response in
self.handleData(response)
},
onError: { (_, path, message) in
self.showError("\(path) \(message)")
self.toggle.isOn = false
self.dataFile?.write("Error \(message)")
})
}
private func handleData(_ response: MovesenseResponse) {
let json = JSON(parseJSON: response.content)
if json["Samples"][0].number != nil {
print("{\"Ecg\":\(json["Samples"])}")
}
}
}
but when I run the ecgHandler.subcribe() function, I get the error:
Meas/ECG NOT_FOUND
What is going wrong here? I've looked through the Movesense developer docs and found no mention of a similar issue, and I've looked through the ios-mqtt code and not found any other big differences. It doesn't seem like "ecg" is even mentioned anywhere in the project's code outside of the subscription controller file.
edit: after running mqtt with my device, it seems like that app ran into the same error.
edit 2: figured out the problem, answer is below.
Upvotes: 0
Views: 215
Reputation: 145
Apparently ECG, like Magn and Acc but unlike HR, needs to have the sample rate included in the path in order to return data. I fixed the issue by changing the API path from Meas/ECG to Meas/ECG/125, 125 being the default sample rate that the android app uses.
Upvotes: 1