Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing strings in AppMessage array on the pebble

I'm building a internet connected BitCoin app. To watch the ticker info from different bitcoin markets. Everything works. Now I want to send a list of available markets down to the watch to be displayed as a menu. JSON to be sent:

{"markets": ["MtGox", "BitStamp","BTCChina"]}

"markets" is properly keyed in "appinfo.json" so this is not a problem.

How do I access an element (single string) in this array on the Pebble? I've seen examples of accessing ints and strings directly and these work great, are there any good examples of this? I have not found any.

like image 457
GusOst Avatar asked Dec 01 '13 17:12

GusOst


1 Answers

I am assuming you are using the PebbleKit JS API. The appropriate doc is at: https://developer.getpebble.com/2/guides/javascript-guide.html

The doc says you can only send dictionaries with values as ints, strings, or byte arrays.

To send a list of strings, you have different options.

  1. Send several key/value pairs, starting at a known index

    { 100: "MtGox", 101: "BitStamp", 102: "BTCChina" }
    
  2. Send one string with a known separator and split it on the watch

    { "markets": "MtGox|BitStamp|BTCChina" }
    
  3. Send an array of bytes with a list of keys that contain a market name

    { "markets": [100, 101, 102],
      100: "MtGox", 101: "BitStamp", 102: "BTCChina" 
    }
    
like image 143
sarfata Avatar answered Nov 05 '22 19:11

sarfata