Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Send message on Companion wake?

I can't seem to get a message to send when the Companion wakes up. 

 

The following code in my Companion always results in: 'messaging not open'

How can I open the messaging on wokenUp?

 

if (me.launchReasons.wokenUp) {
    console.log("Started due to wake interval!");
    sendWakeMessage();
}

 

function sendWakeMessage() {
    if (messaging.peerSocket.readyState === messaging.peerSocket.OPEN) {
        var data = {
            message: "wake"
        }
        messaging.peerSocket.send(data);
        console.log("Message sent from companion");
    } else {
        console.log("messaging not open");
    }
}

 

 

I also tried putting 

 

messaging.peerSocket.onopen = function() {
sendWakeMessage();
}

 

inside the wokenUp handler, with no luck

Best Answer
0 Votes
2 REPLIES 2

bump.

 

does anyone have a solution to this?

is it even possible to communicate or start the app from companion wake?

Best Answer
0 Votes

Apps do not work in background, so if your app is off, then you can't communicate with it.

 

There is a feature suggestion combining background processing with app-originated notifications:

 

https://community.fitbit.com/t5/Feature-Suggestions/Background-notifications-for-Ionic-apps/idi-p/21...

 

Feel free to vote on it.

Best Answer
0 Votes