【问题标题】:How to send the last sync time through the Fitbit Companion Messaging API to a clock face?如何通过 Fitbit Companion Messaging API 将上次同步时间发送到钟面?
【发布时间】:2021-08-10 18:30:23
【问题描述】:

目标是在 Fitbit Sense 表盘 (SDK 6.0.0) 中将 device.lastSyncTime 从伴侣 index.js 获取到 app/index.js

我的简单想法是tellSync() 函数会发送一条包含device.lastSyncTime 的消息

function sendVal(data) {
  if (messaging.peerSocket.readyState === messaging.peerSocket.OPEN)
    messaging.peerSocket.send(data);
}

function tellSync() {
  let date = device.lastSyncTime;
  let data = {
    key: 'lastSync',
    newValue: date
  };
  sendVal(data);
}

但是,在 app/index.js 中,收到的消息不包含device.lastSyncTime

messaging.peerSocket.onmessage = evt => {
  console.log(JSON.stringify(evt))
};

输出是App: {"data":{"key":"lastSync","newValue":{}}}。没有错误,它已连接到当前版本的 Fitbit Sense 设备 (2021-08-10) 和手机。

现在,如果我将 device.lastSyncTime 放入 console.log(),它会将时间戳交给我(例如 Tue Aug 10 2021 19:59:40 GMT+0200 (Central European Summer Time) ),所以我一定做错了什么,但我不太确定是什么。

【问题讨论】:

    标签: javascript sdk fitbit


    【解决方案1】:

    这是数据类型的问题。对 tellSync() 函数的修改修复了它:

    newValue: device.lastSyncTime.toString()
    

    现在的输出如你所愿:

    App: {"data":{
        "key":"lastSync",
        "newValue":"Tue Aug 10 2021 20:51:27 GMT+0200 (Central European Summer Time)"}}`
    

    【讨论】:

      猜你喜欢
      • 2017-04-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-11
      • 2015-08-17
      • 1970-01-01
      • 2020-02-23
      • 2021-10-14
      相关资源
      最近更新 更多