在 pebble 手表上出现 "Ignoring invalid key: KEY_TEMPERATURE" 错误
Getting "Ignoring invalid key: KEY_TEMPERATURE" error on pebble watch
我已经按照 pebble 表盘的教程进行操作,但进行了一些更改,但在日志中收到错误消息:
忽略无效密钥:KEY_TEMPERATURE
忽略无效密钥:KEY_CONDITIONS
这导致没有天气显示我认为它可能是 js 代码,但我已经在教程中使用它 main.c 并且它工作正常。
您没有在 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
},
...
我已经按照 pebble 表盘的教程进行操作,但进行了一些更改,但在日志中收到错误消息:
忽略无效密钥:KEY_TEMPERATURE 忽略无效密钥:KEY_CONDITIONS
这导致没有天气显示我认为它可能是 js 代码,但我已经在教程中使用它 main.c 并且它工作正常。
您没有在 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 theappinfo.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
},
...