01-04-2022 01:29
01-04-2022 01:29
Why is this illegal:
app/index.js
messaging.peerSocket.onmessage = evt => {
myWater.text = `${Math.ceil(evt.data.water/29.574)} oz`;
myCalories.text = `${evt.data.calories}`;
};
companion/index.js
if (messaging.peerSocket.readyState === messaging.peerSocket.OPEN) {
messaging.peerSocket.send(myWaterData);
messaging.peerSocket.send(myCalorieData);
}
Calories show up fine but Water shows up as NaN. There has to be a way to batch-send/receive several values from the Web API to the device.
Answered! Go to the Best Answer.
01-04-2022 13:20
01-04-2022 13:20
I figured that that specific function had a "data" element so I tried seeing if the message would accept all of the declared data within the function and it worked!
.then(function(data) {
let calorieGoalData = {"goals":data.goals};
let summary = {"summary":data.summary};
if (messaging.peerSocket.readyState === messaging.peerSocket.OPEN) {
messaging.peerSocket.send(data);
}
01-04-2022 11:48
01-04-2022 11:48
You seem to be sending two separate messages, rather than one message that includes both values.
01-04-2022 12:06
01-04-2022 12:06
What should the format be to send both values in one message? Using commas? Turning them into an array? And would the format in app.index.js still be valid?
Thanks! this is literally the last step before my watch app is completed!
01-04-2022 12:58
01-04-2022 12:58
I'd probably use an object, but an array would also work.
01-04-2022 12:59
01-04-2022 12:59
I realized that the food summary included both water and calorie data so that worked nicely! But what if I were to send separate data points like "calories" and "calorie goal" data in one message, how would I do that? Or sending separate databases like sleep and nutrition in one message even.
01-04-2022 13:00
01-04-2022 13:00
What would that look like? What's the syntax?
@Gondwana wrote:I'd probably use an object, but an array would also work.
01-04-2022 13:20
01-04-2022 13:20
I figured that that specific function had a "data" element so I tried seeing if the message would accept all of the declared data within the function and it worked!
.then(function(data) {
let calorieGoalData = {"goals":data.goals};
let summary = {"summary":data.summary};
if (messaging.peerSocket.readyState === messaging.peerSocket.OPEN) {
messaging.peerSocket.send(data);
}