makeWebRequest() returns 402 while getting rest response

Former Member
Former Member
Hi,
I am getting 402 error code from below code. 402 is NETWORK_RESPONSE_TOO_LARGE ?
If yes.. is there any other way to read this response ? It has 2MB of size. Garmin has 100MB of ram yes ? Is it because I have no space left on my device and could clear some unnecessary data ? Or is it prohibited by the API ? Or maybe the background ServiceDelegate invoking the requests is limited by memory ? Maybe I could stream the content somehow ? I would love to have lineIterator like in Java. I don't need the whole file, just to find correct lines and store in memory. I didn't know how to do that, so I am downloading whole file for further processing. On the other hand 2MB is not big size... why there is a problem.. What is the maximum size of response? Can I rewrite the code somehow to accept bigger size ?

(:background)
class WebRequestDelegate extends Toybox.System.ServiceDelegate

function makeRequest() {
Sys.println("makeRequest :)");
// notify.invoke("Executing\nRequest");
try {
Comm.makeWebRequest(
"someaddresswith2mbarray",
null,

{
"Content-Type" => Comm.REQUEST_CONTENT_TYPE_JSON
},
method(:onReceive)
);
} catch (e instanceof Lang.Exception) {
Sys.println(e.getErrorMessage());
}
}
function onReceive(responseCode, data) {

Sys.println("onReceive :)"+responseCode);
}
  • Your app has far less memory than your response. For JSON data, you might get by with something like 8-16k. While the device itself has lots of memory, your app is limited. See the bottom line in the sim for your specific target and app type.

    The fact you want to do this in a background process is even more limited memory wise. In Devices.xml in the SDK, you'll see the max memory for the background based on device, and I don't think I've seen any above 32k for code and data. And I believe, Background.exit() is limited to 8k,
  • 2MB is a *ton* of data to be pulling down to a device that only gives applications enough memory for 128KB of code and data. Not to mention, but downloading 2MB over the bluetooth link is going to be *really* slow.

    There may be other ways, but it seems to me the best way to do this is to implement an intermediary web service that would fetch the full file and do data filtering and pagination.
  • Former Member
    Former Member over 6 years ago
    Hi, I've thought about the intermediary web service but I don't see any free of charge server where I could deploy such service. I would love to consider the other ways. The download would be once per ride, it could be slow, since after it download the data, all calculactions would be done in memory.
    If the API would provide http streaming or I could access a folder on the device with this file and iterate file lines, then life would be simplier and this amount of memory would be enough.

    Or maybe u know some chargable solutions, do amazon or google could provide a place to deploy my rest application ? Then people would have to pay for my application or pay for their accounts on amazon / google and their requests per month. Where could I deploy custom web application ?
  • Comm will be an issue - trying to fit 2mb of data in a 128k "bag" too. And if you're doing it in the background (you have the background annotation), time is also critical as the background can run at most for 30 seconds, and then at most, only every 5 minutes. So even if you send 10k at a time, doing 2mb total could run longer than the 30 seconds allowed, so you might have to use multiple runs of the background.(get it a few "chucks" at a time)

    Let's take comm out of it and say you copy the 2mb to the watch using USB. While that file may be on the device, there is no way to access the file system with CIQ to read it.
  • Former Member
    Former Member over 6 years ago
    Has the webRequest be invoked from the background ? If yes, is it possible to send the 16k of data to the application from the background, assuming that the Background.exit is limited to 8k ? If not, does it mean that I am restricted to 8k using webRequest that always has to be invoked from the background ?

    Apart from temporalEvent, what other even types can be used to send webRequest more often than once per 5 minutes? These request can be send only if there is a movement, so is it possible to have background process that would send such request for example on change speed event ? Is there such event like change in speed or speed sensor event ?
  • Or maybe u know some chargable solutions, do amazon or google could provide a place to deploy my rest application ?

    Google App Engine has a free tier where you don't pay anything until your usage goes beyond specified quotas (https://cloud.google.com/appengine/quotas). IMO the rates are reasonable, but I've never actually had to pay a penny for the service that I'm running there.

    Amazon and Heroku both appear to have free tiers as well. I just don't have any experience with either of them.

  • Former Member
    Former Member over 6 years ago
    Thanks.. I am testing google cloud. I am wondering.. When I would like to create new screens for garmin watches and put it it connectIQ store but charge people for my work (the screen will work for 10 days of trial and then paypal donation would be required) then would it be OK for connectIQ store or I should follow some requirements? I am self employed guy so I could do it legally so in this are there are no problems.

    Moreover if I would use google cloud for processing data and return it to Garmin device where the device asks for it, the Google would charge me for commercial use of their API ? Or I could still use free configuration limited to the quotas u have linked ?
  • I noticed there are many devices in devices.xml that support CIQ 2.4 or later, but have no value specified for the background memory limit. (Approach S60, most Edge devices, many Forerunner devices, some Vivoactive devices.) Is there any way to find out what the limit is for these devices? They seem to run okay in the simulator - at least the Approach does. As long as it's not less than 32k, I can just test with 32k devices. But if any have a background limit of, say 16KB, it would be good to know. Thanks!


    Your app has far less memory than your response. For JSON data, you might get by with something like 8-16k. While the device itself has lots of memory, your app is limited. See the bottom line in the sim for your specific target and app type.

    The fact you want to do this in a background process is even more limited memory wise. In Devices.xml in the SDK, you'll see the max memory for the background based on device, and I don't think I've seen any above 32k for code and data. And I believe, Background.exit() is limited to 8k,


  • Brian corrected me yesterday and the minimum available memory for a background process is 32k.
  • Former Member
    Former Member over 6 years ago
    Hi guys, thank u for all the answers. The last think I don't know - the class where I invoke the webRequest is a process in the background.
    (:background) class WebRequestDelegate extends Toybox.System.ServiceDelegate So when I get the response, and even if it could be like 32k or 16k, I have to pass the response from backgroud to the application. You've said Background.exit is limited to 8k.. Earlier I've read somewhere that webRequest has to be done always in the background. And in the backgroud I can't draw anything in the data field.

    So last question is, can I do anything to overcome 8k limit, or I did everything good and I can't squeeze out anything more from my device.