0

I have the following code that I send messages to my pebble watchapp, from the js in the phone. this is with sdk2.

Pebble.sendAppMessage({note_id:json[count].note_id,
title:json[count].title,
text:json[count].text,
total_count: count
});

I can console.log() the total_count property in the JS when I run the app, and it rightly gets the count , like 2.

Yet, in my pebble app, when I try to extract it in the in_received_handler function, the APP LOG in the code below prints out 536999434.

Tuple *total_count_tuple = dict_find(iter, TOTAL_COUNT_KEY);

if (total_count_tuple) {
    current_count = (int)total_count_tuple->value->cstring;
    APP_LOG(APP_LOG_LEVEL_DEBUG, "In in_received_handler, total count     %u",current_count);

}

It is getting a count, so I know the dictionary is being filled out and sent over to the watch, but I can't figure out how to get the value that I store in the js to be the same on the pebble side.

Any experienced pebble programmers have a thought?

virindh
  • 3,775
  • 3
  • 24
  • 49
med116
  • 1,526
  • 17
  • 16

1 Answers1

1

You are sending an integer so to read it you need to use:

current_count = total_count_tuple->value->int32;

instead of:

current_count = (int)total_count_tuple->value->cstring;
sarfata
  • 4,625
  • 4
  • 28
  • 36
  • Thank you very much, this is exactly the issue, I was trying to convert a c string to an int, but I didn't realize int32 existed, thanks, you saved me a lot of trouble – med116 Feb 28 '14 at 18:01