UP3 (jawbone) how to retrieve sleep value in REALTIME - jawbone

I am trying to retrieve my sleep data in REAL TIME.
I cannot find how to achieve it from docs:
UP Platform Android SDK
P.S. : I am willing to conduct sleep experiment that requires getting an event when I reach e.g. paradoxal sleep phase. Thanks!

Using the UP APIs, the closest you can get to real time updates is to have your application register for PubSub event notifications for sleep events:
There are two limitations that will keep these event notifications from occurring exactly in real-time:
PubSub events are only triggered when the band syncs data to the phone.
PubSub sleep events are only triggered for a complete sleep and not for individual phases.
Regarding #1, the band (UP24 and newer) must have an active bluetooth connection with the phone and then syncs will usually occur within 15 minutes.
For #2, calculation of the different sleep phases currently requires reviewing the band data for the entire sleep event, so the API cannot send individual event notifications for phase changes.

Related

Strava - How to detect pause in run/activity

Is there a way to detect a user pausing a run/activity within the strava API?
With Get Activity Streams (getActivityStreams) you can obtain differents StreamSet from your activity: in order to detect pause I think you can analyze CadenceStream or MovingStream.
Pauses are not available in the Strava API and can not be extracted consistently through algorithmic processing of the available fields. Moreover, the data contained in the API's streams collection can not be processed in a way which will arrive at the summary distance or time of the run.
The MovingStream contains a bit field which does not flag pauses, but instead (presumably) flags points where the athlete stopped moving. Although, that said, this field can not be used to arrive at the Moving Time by summing up the time values where this flag is true.

What's the Sonos Cloud Queue GET /version periodic polling interval?

We've recently started adding programmed radio to our existing SMAPI implementation. I've followed the Sonos Developer documentation and (eventually) got it working as expected. I'm just seeking for some clarification around the 'auto updating' based on the 'queueVersion' value.
Our schedules which are feeding the programmed radio can change from time to time. These changes should be reflected on the Sonos Players as soon as possible. For what I understand this should be possible by modifying the queueVersion property in both GET /context, GET /itemWindow and GET /version.
Looking at the GET /version documentation I see that Players "[...] are responsible for periodically polling this [QueueVersion] value to detect changes in the cloud queue track list, [...]".
I've monitored our API logs for about 15 minutes in which I would expect at least a GET /version request, but none showed up. The only calls I'm seeing are POST /timePlayed.
Can anyone (from the Sonos team perhaps?) clarify what this interval is set to, or how it can be controlled?
Given that you aren't seeing GET /version requests, there may be an error in your configuration.
The player sends a GET /version request every 5 minutes when paused and every 10 minutes when playing. This is by design, not depending on any setting that you can control. However, players fetch new tracks as needed using GET /itemWindow. The player requires a version in your response, so it doesn't send a GET /version request in this case. After the player gets a new item window, it resets the polling interval to another 10 minutes.
See the Play audio (cloud queue) page for details.

Simple time-based chest push notification setup

Hello I am trying to create a simple push-notification system similar to this common use case:
1. The user gets a chest and can either watch an ad to skip the wait time or wait one hours for the chest to open. The app sends an upstream request which sets up a downstream push notification that shall be delivered in one hour to let the user know the chest is ready.
2a. The user then waits an hour, gets a push notification (outside of the app) to open their chest and they do!
or
2b. They wait 20 minutes then decide to watch the ad. The app sends an upstream request which cancels the pending push notification which would have otherwise been delivered in 40 minutes.
Okay awesome so that is the problem and I am having a hard time understanding how to do this. I have looked over the documentation for each of these programs but they seem designed for downstream push notifications. It just seems odd there is no built-in support for this use case. It seems like such a common use case.
I so far found 3 solutions that will integrate into my cross-platform Unity setup and provide services for free or super-cheap:
Amazon Simple Notification Service (SNS)
Google Firebase Cloud Messaging (FCM)
OneSignal
Amazon seems to group clients into "Topics" so I guess I would be setting up a one-device-topic and essentially. I can subscribe and unsubscribe from them but it doesn't seem to support a topic with a 60 minute delay.
2a. Create a topic: https://docs.aws.amazon.com/sns/latest/dg/sns-tutorial-create-topic.html (it would just include the current device)
2b. Subscribe to it
2c. Send a message to it https://docs.aws.amazon.com/sns/latest/dg/sns-tutorial-publish-message-with-attributes.html
So basically I can add attributes to my message but it would seem I need to implement the server-side code to read a delay attribute then somehow queue a message for delay. Maybe I am missing something?
For Firebase I pretty much see the same thing as Amazon. There are topics https://firebase.google.com/docs/cloud-messaging/android/topic-messaging and a means to send upstream messages https://firebase.google.com/docs/cloud-messaging/android/send-with-console but with the messages I don't see anyway here to get the time delay https://firebase.google.com/docs/cloud-messaging/unity/topic-messaging I see conditions towards the bottom of that article but I don't know if it is meant for this use case.
OneSignal has the easiest to scroll-through API. I'll refer to some strings that you can CTRL-F by using the format ("Create Notif") because everything is on this one page: https://documentation.onesignal.com/reference
So basically I can ("Send to Specific Devices") which I guess would be the sending device, then I can ("Schedule notification for future delivery.") using the send_after parameter. And finally, if need be, I can ("Cancel notification"). So this appears to be everything I need. I'm currently looking at this option and trying to figure out how to actually get this working.
So there is my progress over the last few hours researching each of these options. I am hoping you can help me better understand how I may be misunderstanding the above options as this seems to me a very common use-case. Perhaps I am just not googling the question correctly. Any help appreciated.
Whenever there's a likelihood that you'll need to cancel a significant percent of the notifications you send, you should use local notifications. That way you can easily schedule and cancel them locally without making any network requests. Also, this solution works for offline devices which is great for games (played on planes, etc...)

How to perform waking up, after 80 seconds of light sleep began

I want to use UP3 for a very specific task, which I should be able to implement using API. I am trying to understand, is it possiblу to write a following application.
Basing on https://jawbone.com/support/articles/000005231/tracking-sleep , the UP3 can catch switching between sleep phases. I need, for example, catch a Light Sleep beginning, wait for 80 seconds and then vibrate for waking up. Can it be done?
After reading documentation I do not understand fundamental applications architecture. I assume, that there should be opened bluetooth channel, and, for example, every 10 seconds I write to the channel sleep status request with 1-2 seconds feedback. Then I write "awake" command which tells the band to vibrate.
Another scenario - somehow I get notification about sleep phase swithcing. Then I start timer, and send this wake-up command.
But these are just my theories. Please explain me, can it be done and how?
The short answer to your question is no, this cannot be done.
Here's why:
Changes in sleep phase are calculated server-side after the entire sleep event has occurred, so there is no way to receive a real-time notification for a sleep phase change. Here's another SO question with additional details about this and on how to receive sleep event notifications.
Jawbone does not allow third party applications to trigger band vibration. Here's another SO question with details on why.
Jawbone does not allow third party applications to connect directly to the band over bluetooth.

Why observer notifications for timer and input sources are delivered before those events actually occur in run loop sequence of events

I am learning how to use NSRunLoop and reading Apple Doc about Run Loops chapter.
I am confused about some description about how the doc states about the the run loop sequence of events
Because observer notifications for timer and input sources are delivered before those events actually occur, there may be a gap between the time of the notifications and the time of the actual events. If the timing between these events is critical, you can use the sleep and awake-from-sleep notifications to help you correlate the timing between the actual events
Here is doc link
It says observer notifications for timer and input sources are delivered before those events actually occur. Since those events being not happened, how does run loop knows those events are about to happen and sends notifications for thoes events in advance?
After many searches, It may help.
The doc says the followings in Custom Input Sources section.
In addition to defining the behavior of the custom source when an event arrives, you must also define the event delivery mechanism. This part of the source runs on a separate thread and is responsible for providing the input source with its data and for signaling it when that data is ready for processing. The event delivery mechanism is up to you but need not be overly complex.
More details link1 and link2
The event may occur, but that event may not be ready for using, cause the actual data produced by that event, processed on a separate thread, may not be enough to trigger the thread, which is listening that notification. So their is a gap between the notification posted by run loop and the finished happen event.
There are also other processes that leads to that gap, such as timer input source etc.
Anyone has better explanation?