JSON array prefixed with 76\r\n

0

I'm making a JSON array in PHP

$js2 = array("location"=>$js1[0], "status"=>$js1[1],"nc"=>$js1[2],"nt"=>$js1[3],"fc"=>$js1[4],"ft"=>$js1[5]);

the output looks fine in the browser

{"location":"Wellhouse Rock ","status":"falling","hc":"0hr 15min","ht":"18:32 GMT","lc":"3hr 18min","lt":"21:35 GMT"}

but when receiving the returned body via connectIQ (HTTP traffic logs) I get

76\r\n{"location":"Rockall ","status":"rising","hc":"1hr 13min","ht":"19:20 GMT","lc":"7hr 19min","lt":"Sat 19th 01:26 GMT"}\r\n0\r\n\r\n

The widget works in the simulator but not when on a watch. Any ideas how I can strip the 76\r\n etc and Do I need to? 

At first I thought this was an HTTPS thing so have sorted that and now make the call via https 

I do see Content-Type: application/json; charset=utf-8\r\n in the traffic logs so the header is correct 

web call method is using

var options = {
		:method => Comms.HTTP_REQUEST_METHOD_GET,
		:headers => {"Content-Type" => Comms.REQUEST_CONTENT_TYPE_JSON},
		:responseType => Comms.HTTP_RESPONSE_CONTENT_TYPE_JSON
		

I could really do with someone helping me get this across the line. Once I have the app working on the watch and sim I am good to start adding features but right now I only get it in the sim

Happy to provide the codeto someone who is willing to help me out. I;ve learned a lot int he past week (its taken me that long to setup an environment and piece bits together).

This is all based off of modifications to the OpenWeatherMapWidget example code 

Thanks

Lee

  • Have you checked the raw response in Chrome developer tools? If it's got 76 in front of it, you should see that, otherwise it's in your monkey c somewhere.

    I presume you're using json_encode() in your php?

    I might also try curl to call your service to be sure of the raw response

  • Thanks Dresbo, RAw response in dev tools looks OK 

    I am encoding and the debug within monkeyc looks to be the expected result. 

    Sim works a dream but the watch just hangs with no result. 

    $js1 = explode("|", $result);
    $js2 = array("location"=>$js1[0],"status"=>$js1[1],"hc"=>$js1[2],"ht"=>$js1[3],"lc"=>$js1[4],"lt"=>$js1[5]);
    header('Content-Type: application/json; charset=utf-8');
    echo json_encode($js2,true);

  • Mysterious. If when you print it in monkey c it looks OK that 76 might be a red herring.

    You might want to provide more of the code for making the Web request in case we can spot anything.

    What happens on the device. Do you get an error log or a crash log? If you print the request and response on the watch does that tell you anything?

  • One thing I like to do to aid in troubleshooting is in the onReceive() method is add a the following line to print out the data received.

    System.println("webdata: "+data.toString());

    This will output to the console the contents of the data received in the request with a notation in the log to indicate what the line is.  That should give you and idea exactly what the code is receiving from the web request.  I suspect you won't see the 76\r\n.  In which case you can follow the steps capture the log on the actual device and see if you are even getting the data there.  See this link for how to set up capturing the logs on a device.

    forums.garmin.com/.../new-developer-faq

  • It appears the \r\n was not affecting the watch. 
    I had express vpn running on my phone which was also causing issues for other apps/widgets. 
    turning off the von on the phone appears to have resolved the hanging on the watch 

    I’m not sure if this is a known issue with iPhone/vpn/ConnectIQ, will post a separate question on that in the forum