c - pebble watch 上出现 "Ignoring invalid key: KEY_TEMPERATURE"错误

标签 c pebble-watch cloudpebble pebble-js

我已按照 pebble 表盘的教程进行操作,但更改了一些内容,但在日志中收到错误:

忽略无效 key :KEY_TEMPERATURE 忽略无效 key :KEY_CONDITIONS

这导致没有显示天气,我认为这可能是 js 代码,但我已经在教程 main.c 上使用了它,并且工作正常。

Link to Github repo

最佳答案

您没有在 appinfo.json 中指定任何 appKeys

Pebble 消息使用整数作为键控,而不是字符串。但是有适当的设施,所以您可以 use meaningful strings when coding :

Using Named Keys in PebbleKit JS Messages

PebbleKit JavaScript provides a mechanism to use named keys instead of integer keys. This improves the readability of your JavaScript code and allows you to group in one place the definition of your AppMessage keys.

Keys are declared in CloudPebble in the 'PebbleKit JS Message Keys' section of the 'Settings' screen.

In the native SDK, named keys are configured through the appKeys object in the appinfo.json file. This object associates integer values to strings. Those values are used to convert the keys of outgoing and incoming messages.

"appKeys": {
  "firstKey":  0,
  "secondKey": 1
}

请注意,此处定义的键应与 C 代码中的键匹配,可能是通过 C 源代码或头文件中的 #define 语句实现的。

For each key of an incoming message, PebbleKit JS looks for an element in the appKeys object that has the same integer value as the key. If it can find one, it replaces this key by this string in the JavaScript object. If it cannot find one, it creates a new string containing the integer value of the key.

For each key of an outgoing message, PebbleKit JS looks for an element in the appKeys object that is equal to the key. If it finds one, it uses the integer value associated with this element as the integer representation of the key. If it cannot find one, it tries to convert the key into an integer. If this fails, an error is raised.

For example, given the appKeys configuration above, the following statements are equivalent:

Pebble.sendAppMessage({ '0':        'A value' });
Pebble.sendAppMessage({ 'firstKey': 'A value' });

确保更新您的代码,以便在 C 中指定这些值(您似乎是通过 #define 完成的)以及 JavaScript 中通过appinfo.json 文件:

...
"appKeys": {
  "KEY_TEMPERATURE": 0,
  "KEY_CONDITIONS": 1
},
...

关于c - pebble watch 上出现 "Ignoring invalid key: KEY_TEMPERATURE"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28014969/

相关文章:

c - 查找二维数组中的交集

c - fscanf 读访问段错误

c - 在c中连续跳出两个循环

c++ - 什么是数据对齐?在 C 中对指针进行类型转换时,为什么以及何时应该担心?

ios - CLLocationManager startUpdatingLocation() 在后台调用时不起作用

c - 使用 Str(n)cat 的 Pebble 堆损坏

c - 使用 Pebble iOS Kit 获取 Pebble 应用程序元数据的正确方法

Watchface 安装后出现 Cloudpebble 错误

javascript - 使用云卵石 (Pebble.js) 访问 firebase