2

I'm building an API based application. I use the Pebble.SendAppMessage function to send data from the API to the watch. Each time I try to send data containing accentued characters and log them, the console print this following empty message:

[xx:xx:xx] javascript>

and no more interaction between the phone and the watch will work.

I first tried to encode each API data to UTF8 encoding but the crash still appears.

Can we send strings containing accents using the Pebble.SendAppMessage function? What exactly did I miss?

C code :

#include <pebble.h>

static Window *window;
static TextLayer *text_layer;

static void message_provider(DictionaryIterator* iterator, void* context) {
    Tuple* tuple = dict_find(iterator, 0);
    text_layer_set_text(text_layer, tuple->value->cstring);
}

static void window_load(Window *window) {
    Layer *window_layer = window_get_root_layer(window);
    GRect bounds = layer_get_bounds(window_layer);

    text_layer = text_layer_create((GRect) { .origin = { 0, 72 }, .size = { bounds.size.w, 20 } });
    text_layer_set_text(text_layer, "Loading...");
    text_layer_set_text_alignment(text_layer, GTextAlignmentCenter);
    layer_add_child(window_layer, text_layer_get_layer(text_layer));
}

static void window_unload(Window *window) {
  text_layer_destroy(text_layer);
}

static void init(void) {
    window = window_create();
    window_set_window_handlers(window, (WindowHandlers) {
            .load = window_load,
            .unload = window_unload,
    });
    const bool animated = true;
    window_stack_push(window, animated);
    app_message_register_inbox_received(message_provider);
    app_message_open(app_message_inbox_size_maximum(), app_message_outbox_size_maximum());

}

static void deinit(void) {
  window_destroy(window);
}

int main(void) {
  init();
  app_event_loop();
  deinit();
}

JS code :

Pebble.addEventListener("ready", function() {
    Pebble.sendAppMessage({"dummy" : "Gérard example is always the best."}, function() {
        console.log("message sent successfully !");
    }, function() {
        console.log("Cannot send message with accent.");
    });
});
Alexis Le Provost
  • 1,803
  • 2
  • 11
  • 9

0 Answers0