Getting "Ignoring invalid key: KEY_TEMPERATURE" error on pebble watch

401 Views Asked by At

I have followed the tutorial for the pebble watch face but changed somethings but get the error in the logs:

Ignoring invalid key: KEY_TEMPERATURE Ignoring invalid key: KEY_CONDITIONS

which leads to no weather being displayed I thought that it maybe the js code but I have used it on the tutorial main.c and it works fine.

Link to Github repo

1

There are 1 best solutions below

0
On BEST ANSWER

You aren't specifying any appKeys in appinfo.json.

Pebble messages are keyed with an integer, not a string. But there are facilities in place so you can 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
}

Note that the keys defined here should match keys in your C code, likely through #define statements in your C source or a header file.

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' });

Make sure to update your code so that you specify these values in C (which you appear to have done via #define) and also in JavaScript by means of the appinfo.json file:

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