Now the flow is roughly:
- On Watch
- CMSensorRecorder is activated and is recording records locally regardless of the application state of the Watch
- When the sensor application is in the foreground, a thread attempts to dequeue data form the recorder
- And when this data is received a WCSession:sendMessage is used to send the data to the iPhone in the background
- Iff a valid reply comes back from this message, the CMSensorRecorder fetch position is updated to fetch the next unprocessed sensor data
- On iPhone
- A background thread is always ready to receive messages from the Watch
- Those messages are saved to a local Kinesis queue
- A timer based flush will submit this Kinesis queue to AWS
- AWS credentials from Cognito are now manually refreshed by checking the credentials expire time
- The send and submit kinesis calls are now asynchronous tasks
So this is pretty close to continuous feed on the iPhone side.
Some areas of durability to re-explore next:
- How to build a Watch dequeue that can run when the application isn't in foreground?
- Is there another way for WCSession to send to a background task other than sendMessage?
- How reliable is the sendMessage call?
- When the iPhone is out of range
- When the iPhone is locked
- When it is busy running another application
- I do see some transient 'not paired' exceptions when sending volume
- While this does allow for automatic background processing, is there a simpler way of transferring data that doesn't require the application handling reachability errors?
- How reliable is the Kinesis send-retry when the iPhone can't reach AWS?
I will next be building more quantitative checks of the actual data sent through the system to understand where data get sent more than once, or where it is lost.
Hey Greg, thanks for sharing your adventure with the CMSensorRecorder. It helped me a bit with my own project. Question: What is the outcome of your project in the end?
ReplyDeleteThanks David. I'm right now in the middle of code clean up and processing the other end of Kinesis. I do have a basic Lambda running, but will have it go to some persistent store [probably dynamoDB] - for some basic UI.
ReplyDeleteNext I'll add in motion and heartrate state. Note., this exercise is primarily to exercise the new WatchOS features.
Okay, cool to know. Btw, do you still have the problem with the freakin startDate after starting the Accelerometer? It messed up my sync a bit but i solved it now i guess. I start the Accelerometer in the Init of my class even before i start the actual recording. Since this change i didn't have a problem with it again.
ReplyDeleteBtw. the Accelerometer of the Apple Watch and the one in the Iphone are out of sync or better to say their dates. I didn't get it totally synchronous yet.