Crash running on the watch but not in the simulator :-(

I get the following error on my watch (Venu 2)

Error: Symbol Not Found Error
Details: "Could not find symbol 'find'"
Time: 2023-04-11T20:56:53Z
Part-Number: 006-B3703-00
Firmware-Version: '12.13'
Language-Code: fre
ConnectIQ-Version: 4.2.1
Filename: TeslaLink
Appname: Tesla Link
Stack:
- pc: 0x10000227
File: 'C:\Users\Sylvain\git\Tesla-Link\source\ServiceDelegate.mc'
Line: 178
Function: onReceiveVehicleData

And the code at that line is

var pos = responseData.find("battery_level");

Same line runs fine in the simulator. anybody know how to fix this? I must specify that that responseData variable contains a string of about 6000 characters, if it matters.

Thanks.

  • Are you sure responseData is always a String?  Is there a case where it could be a Number or null?

  • When the responseCode is 200 (ie, successful), it should always be a string. Otherwise it's null. Sorry, I just have specified that the line just above is

    if (responseCode == 200 && responseData != null) {

    I've never seen anything but a (very big) string there.

    I'll type check though, just in case. Odd it's only on the physical device though,

  • Ok, so the plot thickens. I request my makeWebRequest data as Communications.HTTP_RESPONSE_CONTENT_TYPE_TEXT_PLAIN because it takes too much space as a JSON dictionary, and yet,

    else if (responseData instanceof Toybox.Lang.Dictionary) {
    logMessage("I'm a dictionary?");

    Is hit while running on the watch! And again, NOT in the simulator where it's a string.

    I don't understand why. I can't dump it in a log file since it's too big (even passing it to functions crashes with a out of memory error) but is there a way to at least dump the keys?

    Edit: Duh, keys().

  • So it does read it as a dictionary

    17:59:10 : I'm a dictionary? These are my keys:[response]

    This is what the string starts with while running in the simulator

    {"response":{"id":123456789,"user_id":123456789,"vehicle_id":123456789,"vin":"123456789","

    So it looks like the watch ignores the HTTP_RESPONSE_CONTENT_TYPE_TEXT_PLAIN request when it reads what looks like JSON to it. This is wrong IMHO. I'm asking for a plain text, I should get a plain text. not a dictionary.

  • And of course, the reason in the first place for going with HTTP_RESPONSE_CONTENT_TYPE_TEXT_PLAIN was because watches with just 32KB of background memory had trouble ingesting a 6KB JSON. :-< Now adding code to be able to parse a 6KB plain text AND fetch keys in a dictionary based on what is returned only makes the app bigger for that tiny space.