Hello everyone,
I am very new to the Garmin IQ environment and am working my way through various content to try to put together a widget able to extract weather data from a website and display it on a widget and/or watch face. this website has publicly available data in various formats:
- page source code: www.bom.gov.au/.../IDW60801.95620.shtml
- comma delimited axf file: http://www.bom.gov.au/fwo/IDW60801/IDW60801.95620.axf
- JSON file: http://www.bom.gov.au/fwo/IDW60801/IDW60801.95620.json
After doing some research, it seems like using the JSON capabilities might be the easiest/neatest way to achieve this. I have set the basic architecture based on example I found and trial/errors which got me to Error -1001 , ended up having to disable HTTPS requirements which now gets me to error -402 which seems to indicate an issue with the parameters (which I haven't defined). According to the following page, it could mean that the data requested it too large: https://developer.here.com/blog/build-your-own-sightseeing-app-with-garmin-connect-iq-and-the-here-location-apis
Apologies for the very basic question but I have very limited experience with JSON requests and could find any simple example showing the syntax needed for the calls. I am looking for a basic example which could work and extra anything from the page, at least to show that it can be done (such as the first "wind_spd_kt" of the first "data" set) so I can understand the syntax and I'll take it from there hopefully.
If anyone could point me in the right direction that would be much appreciated! if we can get the JSON request work, I would also be very interested in the syntax to extract the values from the response!
See code extracts below:
using Toybox.WatchUi; using Toybox.Graphics; using Toybox.System; using Toybox.Lang; using Toybox.Communications; // set up the response callback function function onReceive(responseCode, data) { if (responseCode == 200) { System.println("Request Successful"); // print success } else { System.println("Response: " + responseCode.toString()); // print response code } } function makeRequest() { var url = "http://www.bom.gov.au/fwo/IDW60801/IDW60801.95620.json"; // set the url var params = { "sort_order" => 0, "data" => "wind_spd_kt", }; //Not sure what to include here??? var options = { //:methods => Communications.HTTP_REQUEST_METHOD_GET, //:headers => {"Content-Type" => Communications.REQUEST_CONTENT_TYPE_URL_ENCODED}, :responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_JSON }; var callable = new Lang.Method($, :onReceive); // set responseCallback to // onReceive() method // Make the Communications.makeWebRequest() call Communications.makeWebRequest(url, params, options, callable); } class WinWatchWidgetView extends WatchUi.View { function initialize() { View.initialize(); } // Load your resources here function onLayout(dc) { setLayout(Rez.Layouts.MainLayout(dc)); } // Called when this View is brought to the foreground. Restore // the state of this View and prepare it to be shown. This includes // loading resources into memory. function onShow() { } // Update the view function onUpdate(dc) { //removed Settings->Use device HTTPS requirements in Simulator var test = makeRequest(); System.println("Test Response: " + test); // Call the parent onUpdate function to redraw the layout View.onUpdate(dc); } // Called when this View is removed from the screen. Save the // state of this View here. This includes freeing resources from // memory. function onHide() { } }