With the end drawing in for Pebble and my old Pebble Time’s battery dying I decided to get a Pebble 2 before they all disappear.

I have to say the Pebble 2 is quite a nice device however its not completely the same as the Pebble 1. I wrote an application that sends and receives data from my Android phone to the Pebble and it worked fine however with the new watch all sorts of weirdness happens.

When I looked at Logcat I could see an error when the app was trying to establish a comms link

sendAckNackToJs: run: can not send ack message to javascript code because uuid is null

I did find someone who had found this problem (I guess this resource will disappear with the rest of the Pebble infrastructure).

The gist of the problem appear to be the way I was initialising the comms link on the Pebble and the fact that I had a new SDK. There was a clue when I build the app I was getting (but ignoring) this error.

[09:18:38] mainWindow.c:150> Showing main Window.
[09:18:38] mainWindow.c:133> Creating main window, 2 items
[09:18:38] mainWindow.c:155> Pushing main Window. 0x2002a7c8
[09:18:38] essage_outbox.c:69> app_message_open() called with app_message_outbox_size_maximum().
[09:18:38] essage_outbox.c:72> This consumes 8200 bytes of heap memory, potentially more in the future!
[09:18:38] message_inbox.c:13> app_message_open() called with app_message_inbox_size_maximum().
[09:18:38] message_inbox.c:16> This consumes 8200 bytes of heap memory, potentially more in the future!

Its the potentially more in the future! bit that contains the clue. It looks as though the older Pebbles did not try and allocate the whole of the watch memory to the comms buffer but the newer ones did.

In the end I fixed it by tweaking the way I setup the buffer like this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#ifdef PBL_PLATFORM_DIORITE
#define OUTBOX_SIZE_BYTES 8000
#define INBOX_SIZE_BYTES 8000
#else 
#define OUTBOX_SIZE_BYTES (int) app_message_outbox_size_maximum()
#define INBOX_SIZE_BYTES (int) app_message_inbox_size_maximum()
#endif

void open_app_sync() {
  APP_LOG(APP_LOG_LEVEL_DEBUG, "inbox max size: %d", OUTBOX_SIZE_BYTES);
  APP_LOG(APP_LOG_LEVEL_DEBUG, "outbox max size: %d", INBOX_SIZE_BYTES);
  int retVal = app_message_open(OUTBOX_SIZE_BYTES, INBOX_SIZE_BYTES);
  APP_LOG(APP_LOG_LEVEL_DEBUG, "app_message_open() retval: %d", retVal);
  if (retVal == APP_MSG_OK) 
    APP_LOG(APP_LOG_LEVEL_DEBUG, "comms_init() - app_message_open() Success");
  else if (retVal == APP_MSG_OUT_OF_MEMORY)
    APP_LOG(APP_LOG_LEVEL_DEBUG, "comms_init() - app_message_open() Out of Memory");
}

I restrict the size of the buffers on DIORITE (Pebble 2) and leave the others alone. I also emit logging messages if there is a problem - something which would have made debugging this easier.

I wonder if this is the last bit of Pebble dev I will do?