1

Time Out Error on API Calls from .Net

(23/08/2018 01:44:28 отредактировано grodriguez)

Тема: Time Out Error on API Calls from .Net

Hello all.

We have developed a web API (Midleware) to monitor and calculate some wialon data in the moment (Temperature Sensor)

basically we get those values for each unit.
    {
        "Name": "53170R",
        "UnitId": "15701017",
        "Imei": "4662317653",
        "Location": "Nw 138Th St, Miami, FL 33178, USA",
        "Temperature": "93.3125",
        "LastUpdate": "8/22/2018 9:58:53 PM",
        "Log": "00:00:01.2497030"
    },

but the issue is frequently we got an error: 504 Gateway Time-out 
let say per 5 times we call methods got 3 fails with the 504 error.

What am doing is the following:

First we retrieve all units:
"svc", "core/search_items" with parameters:
"{\"spec\":{\"itemsType\":\"avl_unit\",\"propName\":\"sys_name\",\"propValueMask\":\"*\",\"sortType\":\"sys_name\"},\"force\":1,\"flags\": 4611686018427387903,\"from\":0,\"to\":0}"

And then for each unit we get more detail:
We get the location:
WialonGeoRefUrl = @"https://geocode-maps.wialon.com/hst-api.wialon.com/gis_geocode";
var coord = "[{\"lon\":" + lon.ToString() + ",\"lat\":" + lat.ToString() + "}]";
            queriesStrings.Add("coords", coord);
            queriesStrings.Add("flags", "1255211008");
            queriesStrings.Add("uid", WialonId);

And last we get the value for temperature sensor:
"svc", "unit/calc_last_message" with parameters:
string command = "{\"unitId\":" + unitId + ",\"flags\":1,\"sensors\":[" + temperatureSensorId + "]}";


1 We retrieve all units In this case we have 180 units so we call:
2.For each unit we need to get location method and Calculate temperature sensor.
Approx.: 361 calls in less than 2 minutes.

We are calling the API from an ASP WEB API in C#
Hosted and tested in: AppHarbor and Microsoft Azure.

Do you has done something like this or know if  is there better way to do it?

Thanks in advance.

Let me know if this help or if you need something else.

2

Time Out Error on API Calls from .Net

Re: Time Out Error on API Calls from .Net

grodriguez пишет:

Hello all.

We have developed a web API (Midleware) to monitor and calculate some wialon data in the moment (Temperature Sensor)

basically we get those values for each unit.
    {
        "Name": "53170R",
        "UnitId": "15701017",
        "Imei": "4662317653",
        "Location": "Nw 138Th St, Miami, FL 33178, USA",
        "Temperature": "93.3125",
        "LastUpdate": "8/22/2018 9:58:53 PM",
        "Log": "00:00:01.2497030"
    },

but the issue is frequently we got an error: 504 Gateway Time-out 
let say per 5 times we call methods got 3 fails with the 504 error.

What am doing is the following:

First we retrieve all units:
"svc", "core/search_items" with parameters:
"{\"spec\":{\"itemsType\":\"avl_unit\",\"propName\":\"sys_name\",\"propValueMask\":\"*\",\"sortType\":\"sys_name\"},\"force\":1,\"flags\": 4611686018427387903,\"from\":0,\"to\":0}"

And then for each unit we get more detail:
We get the location:
WialonGeoRefUrl = @"https://geocode-maps.wialon.com/hst-api.wialon.com/gis_geocode";
var coord = "[{\"lon\":" + lon.ToString() + ",\"lat\":" + lat.ToString() + "}]";
            queriesStrings.Add("coords", coord);
            queriesStrings.Add("flags", "1255211008");
            queriesStrings.Add("uid", WialonId);

And last we get the value for temperature sensor:
"svc", "unit/calc_last_message" with parameters:
string command = "{\"unitId\":" + unitId + ",\"flags\":1,\"sensors\":[" + temperatureSensorId + "]}";


1 We retrieve all units In this case we have 180 units so we call:
2.For each unit we need to get location method and Calculate temperature sensor.
Approx.: 361 calls in less than 2 minutes.

We are calling the API from an ASP WEB API in C#
Hosted and tested in: AppHarbor and Microsoft Azure.

Do you has done something like this or know if  is there better way to do it?

Thanks in advance.

Let me know if this help or if you need something else.


Hello if you need get for example the sensor temp each 1 minute you can use the flag to get the lats message and basic informration, I can see in your code a very long flags, In my case i work with 600-700 unist and I do not have any problem, Or besides you can use a batch request to get this information in a single request. Remember if you use a job and in this job you make login with a token close this session.

Another observation is check your network and ISP if that have a issue is a bit complicated get the information in a correct form, also if you rutines run in parallel to some reason it's necessayi you manage concurrency .

3

Time Out Error on API Calls from .Net

Re: Time Out Error on API Calls from .Net

Hello , cerpas  Thansk for your  reply.

this is how we are calculanting the sensor value:

"svc", "unit/calc_last_message" with parameters:
string command = "{\"unitId\":" + unitId + ",\"flags\":1,\"sensors\":[" + temperatureSensorId + "]}";

as you can see this method needs a sensor Id, I found it first retreiving all the units and second for each unit looking in the sensors property and looking for the sensor tagged "temperature" to get the id.

So at this point I don't know how to  retrieve all this data with less calls.

can you put some  reference or example of code how I can do this.

Thanks.

4

Time Out Error on API Calls from .Net

(24/08/2018 20:17:02 отредактировано cerpas)

Re: Time Out Error on API Calls from .Net

Hello.

Perfectly you can get all units with al sensor for each unit this is posible throughthe correct flags in core_search_items in a same request you got the unit id and all sensors, besides yo can created a object  to a batch request. You can learn more about batch request in the next link https://sdk.wialon.com/wiki/en/sidebar/ … ore/batch., and you can learn about data flags in the netx link
https://sdk.wialon.com/wiki/en/sidebar/ … mat/format

Also  batch request is percfect for your task , basically in a batch you have svc= "service name"  and params = "json objcet params"  for your case should be.

svc=core/batch&params={
            "params": [
                                 {
                "svc":"unit/calc_last_message" ,
                "params":{"unitId":" + "id unit 1"+ ","flags":1,"sensors":[" + id sensor unit 1 + "]}
                                 }.{
                 "svc":"unit/calc_last_message" ,
                "params":{"unitId":" + "id unit 2"+ ","flags":1,"sensors":[" + id sensor unit 2 + "]}
                                 },...{
                 "svc":"unit/calc_last_message" ,
                "params":{"unitId":" + "id unit n"+ ","flags":1,"sensors":[" + id sensor unit n + "]}
                                }
                         ],"flags":1
                }

I hope this help you.

5

Time Out Error on API Calls from .Net

(30/08/2018 21:35:05 отредактировано grodriguez)

Re: Time Out Error on API Calls from .Net

Hello cerpas.  Thansk for your  reply.
That solution works like a charm to get the temperature, thanks.

I want to apply the same Batch Request tecnique to get the addresses ,but I can't get it to work.

https://geocode-maps.wialon.com/hst-api … s_geocode?
    coords=[{
        "lon":27.516643322771575,
        "lat":53.91069937030936
    }]
    &flags=1255211008
    &uid=50935

Thanks for your help.

6

Time Out Error on API Calls from .Net

(07/09/2018 19:08:40 отредактировано cerpas)

Re: Time Out Error on API Calls from .Net

Dear grodriguez

This request is not generated by sdk not is posible use a batch request but  you can send an array of cordinates for example.

https://geocode-maps.wialon.com/hst-api.wialon.com/gis_geocode?'coords=[{"lat":'lat 1',"lon":'lat 2'},...{"lat":'lat n',"lon":'long n'}]&flags='yourflags'&uid='youruid'