1

In my iOS App i want to send an message to the watch like this:

NSMutableDictionary *message = @{@(1): @(1),
                                 @(2): @"The String"}
[_watch appMessagesPushUpdate:message onSent:^(PBWatch *watch, NSDictionary *update, NSError *error) {
  if (error != nil)
    NSLog(@"Error sending message: %@", error);
}];

If i am sending it like this it works. But if my string is longer or if i add more than 3 or 4 keys to the dictionary the message will not be delivered. Error is "the app did not acknowledge the message in time".

In my pebble App i do the following:

static void message_handler(DictionaryIterator *iter, void *context) {
  APP_LOG(APP_LOG_LEVEL_DEBUG, "Received message.");
  Tuple *msg_type_tuple = dict_find(iter, PebbleMessageKeyType);
  Tuple *msg_value_tuple = dict_find(iter, PebbleMessageKeyValue);
  write_line_on_screen(msg_value_tuple->value->cstring);
}
...
// Set sniff interval.
app_comm_set_sniff_interval(SNIFF_INTERVAL_NORMAL); 

// Register message handlers
app_message_register_inbox_received(message_handler);
app_message_register_inbox_dropped(message_dropped);

// Init buffers
app_message_open(app_message_inbox_size_maximum(), app_message_outbox_size_maximum());
APP_LOG(APP_LOG_LEVEL_DEBUG, "App Message set up.");

My thought is that it has something to do with the message size. But i can´t imagine that messages can only be so small? In the ToDo list example i saw that they used app_message_open with values 64 for inbox and 16 for outbox parameter. What units are meant with this? 64 characters? How do i know on the iOS side how big my message will be when it arrives on the pebble?

sarfata
  • 4,625
  • 4
  • 28
  • 36
r-dent
  • 685
  • 8
  • 22
  • I finally did it by splitting the message and sending the parts through a queue. I wrote down the process in [this blogpost](http://r-dent.github.io/pebble/2014/01/17/Send-large-messages-to-pebble/). – r-dent Jan 17 '14 at 09:29

1 Answers1

1

First thing you should do when debugging this type of problem is adding a message_dropped handler and printing the failure reason:

void init() {
   // ...
   app_message_register_inbox_dropped(appmsg_in_dropped);
   app_message_open(...);
   // ... 
}

static void appmsg_in_dropped(AppMessageResult reason, void *context) {
  APP_LOG(APP_LOG_LEVEL_DEBUG, "In dropped: %i", reason);
}

You will find a list of reason code in the documentation.

The two most common problems are:

  1. APP_MSG_BUFFER_OVERFLOW: The message is too big (see below)
  2. APP_MSG_BUSY: You are sending messages too fast. You cannot send a new message until the previous one has been acknowledged.

The size of the message is equal to the size of the dictionary. The documentation of dict_calc_buffer_size() explains how to calculate it:

1 byte + 7 bytes for each key + the sum of the sizes of the values

Finally, the values passed to app_message_open() are the buffer sizes in bytes.

sarfata
  • 4,625
  • 4
  • 28
  • 36
  • Thanks! I get an error now. But how could i tell wich one it is? I have error code 128. But in [the documentation](https://developer.getpebble.com/2/api-reference/group___app_message.html#ga695a78c926b20edbb14d7faf5a78c29e) i can´t find information on which enum value is mapped on what integer. (i posted a [related question](http://stackoverflow.com/questions/21150193/logging-enums-on-the-pebble-watch) earlier) – r-dent Jan 16 '14 at 16:30
  • I replied to your other question with a function to translate error code in messages. If you look in `pebble.h`, you will see: that `APP_MSG_BUFFER_OVERFLOW` equals `1 << 7` which is 128. Your buffer is too small for your message. – sarfata Jan 16 '14 at 20:32
  • The related question is here. http://stackoverflow.com/questions/21150193/logging-enums-on-the-pebble-watch – tokentoken Nov 16 '14 at 00:37