Search code examples
cpebble-watchcloudpebblepebble-appmessage

pebblekit js send array to pebble C by appmessage


I am trying to code my first Pebble C app which is based on a pebble.js app I made. I am basically showing the bus schedules.

My question, How can I pass the information from pebblekit js to the pebble C by appmessage so that I can construct a menu? how can I pass an multiple dimension array by appmessage to the watch?

here is an example of the json my pebblekit js has to send to the watch:

{  
    "buses":[
        {  
         "bus_number":"55",
         "stops":[  
            {  
                 "stop_id":"109698",
                 "stop_times":[  
                    {  
                       "arrival_time":"21:22:25",
                       "departure_time":"21:22:25"
                    },
                    {  
                       "arrival_time":"21:52:25",
                       "departure_time":"21:52:25"
                    },
                    ...
                 ]
            },
            ...
       }
   }

Solution

  • Unfortunately there is no way to send an array natively. This is the general framework of how I go about it in my apps. I won't post code because it varies depending on the project.

    1. Add the MessageQueue library to your project. This library is great for sending lots of data at a time or many different pieces quickly.

    2. Create a sendArray function which simply loops through each of the objects in the array and sends them to Pebble with MessageQueue.sendAppMessage()

    3. On the C side, in your inbox handler, check for a certain key which you expect to be sent with the array object. For example, if each array object has a temperature key in it, check for that key and then you'll know the rest of the data should be there too.

      3.1. Insert all of this data you just got on the C side from the DictionaryIterator into some sort of struct which you have created to represent the array item.

      3.2. After processing all of that data, insert that updated struct into an array.

    Keeping a stack count for that array is usually a good idea too.

    Let me know if you need any more help or if I can explain anything better.