I've made an app that streams heartrate in real time, however I'm running into the -101 and -2 errors as have many in the past.
My App only ever has 1 webRequest outstanding, if the request comes back with anything other than a 200 it starts backing off, however this doesn't help.
I have a vivoactive 3, and sometimes it works for hours, sometimes minutes. I have a friend with a Forerunner 245 Music and it's much more reliable though sometimes does a similar thing.
I'm looked to all the previous forum posts and I think I've done everything recommended, but the issue persists, at least for me.
Any suggestions or is this a limitation of the hardware/ API?
function initialize() {
Sensor.setEnabledSensors([Sensor.SENSOR_HEARTRATE]);
Sensor.enableSensorEvents(method(:onSensor));
View.initialize();
}
function onSensor(sensorInfo) {
if (!pending) {
hr = sensorInfo.heartRate;
if (!backoff) {
var url = "https://real.ssl.site/page";
var params = {
"hr" => hr
};
var opts = {
:method => Communications.HTTP_REQUEST_METHOD_POST,
:headers => {
"Content-Type" => Communications.REQUEST_CONTENT_TYPE_URL_ENCODED},
:responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_JSON
};
Communications.makeWebRequest(url, params, opts, method(:onResponse));
if (hr == null) {
hr = "";
}
} else {
backoff--;
}
WatchUi.requestUpdate();
}
}
function onResponse(responseCode, responseData)
{
if (responseCode == 200) {
backoff = 0;
prev_backoff = 0;
} else {
prev_backoff++;
backoff = prev_backoff;
}
pending = false; //Implement backoff for 101 errors?
}