Question

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.

Was it helpful?

Solution

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" 
    }
    
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top