Hi all,
I'm getting my widget ready for upload to the app store and discovered a weird bug which occurs when I first install the widget (both as beta or by manually copying .PRG). My widget is simple, it does a web request to one of my own servers (as explained here in the example: developer.garmin.com/.../Communications.html) and then draws data on the screen. The weird thing is that the first time the widget runs, it times out and gives error code -2. This doesn't happen on the Simulator even if I delete the temp files.
If I turn off and then turn on bluetooth on my phone, it works right away. If I don't do this, it keeps failing and giving -2. Anyone have any idea what's going on here? It seems similar to this thread https://forums.garmin.com/developer/connect-iq/f/discussion/211119/ble-host-timeout but unfortunately this didn't get me any further to solving it.
Below are some relevant code snippets once inside the class. I'm compiling for Fenix 5S in this case (that's the only physical watch I have), using SDK 3.1.6, manifest uses SDK => 1.2.X and Eclipse IDE 2019-06 (4.12.0).
Thanks in advance for anyone who can help!
Niall
App.mc
function initialize() {
AppBase.initialize();
var savedSpot = Storage.getValue("savedSpot");
if (savedSpot == null) {
SpotNr = "22";
} else {
SpotNr = savedSpot;
}
}
...
function onStop(state) {
Storage.setValue("savedSpot", SpotNr);
}
View.mc
function initialize() {
firstRunBool = 1;
View.initialize();
}
...
function onUpdate(dc) {
if (firstRunBool == 1){
makeRequest();
}
View.onUpdate(dc);
...
function makeRequest() {
firstRunBool = 0;
var url = "https://WEBSITE_HIDDEN";
var params = {
"definedParams" => "null",
"spot" => SpotNr
};
var options = {
:method => Comm.HTTP_REQUEST_METHOD_GET,
:responseType => Comm.HTTP_RESPONSE_CONTENT_TYPE_JSON
};
var responseCallback = method(:onReceive);
Comm.makeWebRequest(url, params, options, method(:onReceive));
}
...
function onReceive(responseCode, data) {
if ((responseCode == 200) && (data != null)){
// do a whole bunch of stuff to update view based on data. Code removed.
} else {
timestampDisplay.setText(getResponseMsg(responseCode));
spotDisplay.setText("Error");
}
WatchUi.requestUpdate();
}