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"
},
...
]
},
...
}
}
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.
Add the MessageQueue library to your project. This library is great for sending lots of data at a time or many different pieces quickly.
Create a
sendArrayfunction which simply loops through each of the objects in the array and sends them to Pebble withMessageQueue.sendAppMessage()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
temperaturekey 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
DictionaryIteratorinto some sort ofstructwhich you have created to represent the array item.3.2. After processing all of that data, insert that updated
structinto 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.