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

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.

Related

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...)

UP3 (jawbone) how to retrieve sleep value in REALTIME

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.

Network activity indicator and asynchronous sockets

I have an app which continuously reads status updates from a server connection.
All is working well with a stream delegate to handle all the reading and writing asynchronously.
There's no part of the app that is "waiting" for a specific response from the server, it is just continuously handling status updates as they sporadically arrive from the socket. There are no requests on the client side that are waiting for responses.
I'm wondering what the best practice would be for the network activity indicator in this case.
I could turn it on in the stream event handler, and off before we leave the handler, but that would be a very short time (just enough for an non-blocking read or write to occur). Trying this, I only see the faintest flicker of the indicator; it needs to be on longer than just during the event handler.
What about turning it on in the stream delegate, and setting a timer to turn it off a short time later? (This would ensure it's on long enough to be seen, rather than the short time spent in the stream delegate.)
Note: I've tried this last idea: turning on the network activity indicator whenever there's stream activity, and note the NSDate; then in a timer (that I have fired every 1 second), if the time passsed is >.5 second, I turn off the indicator. This seems to give a reasonable indication of network activity.
Any better recommendations?
If the network activity is continuous then it sounds like it might be somewhat annoying to the user, especially if it's turning on and off all the time.
Perhaps better would be to test for lack-of-response up to a certain timeout value and then display an alert view to the user if you aren't getting any response from the server. Even that could be optional if you can provide feedback (like "Last update: 5 mins ago") to the user instead.

monitor process uptime on Windows

We want to monitor some processes on windows machine. If process is down for 30 minutes, an alarm will be raised. Is it possible/or necessary to monitor a process downtime precisely, say, a process is down EXACTLY for 30 minutes, then an alarm will be raised? Normally, we can check it every 1 minute, but technically, most of the time, you could miss somes seconds.
If you're looking for something much lighter and simpler then Nagios, see AlertGrid. It is very esay to use, the only downside is that it requires a bit of integration: AlertGrid only LISTENS for heartbeat signals, so you have to provide them manually (the API is extremely simple).
The other cool thing is that if the process you want to monitor runs YOUR code - you can send heartbeat events directly "from inside", and these events can carry your own custom parameters. Then, in the AlertGrid - you can easily manage custom rules around these parameters. So if the executable you monitor is, for instance, an order processing application you can send parameter called 'number_of_orders_processed' and create rule "if number_of_orders_processed > 100, send SMS message / make phone call to... " and it will work immediately.
I am in the AlertGrid dev team, if you have any questions - feel free to ask.
Look into Nagios and NSClient++ if you can monitor your Windows host from a Linux host. If this would be an option there is room to do this and many many other things in regards to monitoring your processes and more.

How to wake from sleep programmatically if lid closed?

I want to wake system from sleep programmatically, is there any way to do this?
I have read following link:
http://developer.apple.com/mac/library/qa/qa2004/qa1340.html
this only talk about getting notification , but not sure is there any way to wake system from sleep?
I appreciate some thread to the information...
Update:
As per the suggestion I tried with IOPMSchedulePowerEvent
Code I have used:
NSCalendarDate *timeIntervalSinceNow = [NSCalendarDate dateWithTimeIntervalSinceNow:40];
IOReturn result = IOPMSchedulePowerEvent ((CFDateRef)timeIntervalSinceNow, NULL, CFSTR(kIOPMAutoWake));
Result:
It fails in MacBook if lid closed
Am I doing some thing wrong or Any solution?
You can schedule wake up events with IOPMSchedulePowerEvent through the power manager. You may be able to schedule an immediate wake up. pmset is a command line wrapper for the power manager. You can also prevent sleep with IOCancelPowerChange in certain cases.
You may be able to prevent sleep or wake up by generating a mouse or key event. One way to generate events is with CGPostKeyboardEvent.
Edit:
Normal sleep is different from clamshell closed sleep. To affect the latter you must write a kernel extension like Insomnia.