01-04-2022 01:29
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-04-2022 01:29
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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.

- Labels:
-
JavaScript
Accepted Solutions
01-04-2022 13:20
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-04-2022 13:20
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


01-04-2022 11:48
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
You seem to be sending two separate messages, rather than one message that includes both values.
Gondwana Software

01-04-2022 12:06
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-04-2022 12:06
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


01-04-2022 12:58
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I'd probably use an object, but an array would also work.
Gondwana Software

01-04-2022 12:59
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-04-2022 12:59
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-04-2022 13:00
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-04-2022 13:20
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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);
}

