1

API PHP - how to get event - unit status?

Topic: API PHP - how to get event - unit status?

Hi,
I want to get Unit's all events (most important to get "Unit status") via PHP. I am getting all other information about unit, but with events - it not works. Can anyone help in this case?

2

API PHP - how to get event - unit status?

Re: API PHP - how to get event - unit status?

rolandas wrote:

Hi,
I want to get Unit's all events (most important to get "Unit status") via PHP. I am getting all other information about unit, but with events - it not works. Can anyone help in this case?

Hello,

You can use HTTP requets events/get but you need to load events into session before with request events/load

If you mean units/resources events please use avl_evts but you need to subscribe on them with request core/update_data_flags

3

API PHP - how to get event - unit status?

Re: API PHP - how to get event - unit status?

Thank you. Now I get events, but - it shows only one time. Second time when I checking events - there is no event, but I need to get last events of each unit

4

API PHP - how to get event - unit status?

Re: API PHP - how to get event - unit status?

rolandas wrote:

Thank you. Now I get events, but - it shows only one time. Second time when I checking events - there is no event, but I need to get last events of each unit


Hello!
System calculates events in online mode, also depend on incoming messages/parameters, events can be recalculated periodically
the requests events/load and events/get are used to get history events which have been calculated for some period.
If you would like to get online events which calculated recently in real time you can use the following requests: events/update_units and events/check_updates
First you need to add units which would like to get events from - execute request
For example, request with the following parameters  adds 2 units and allows to control all events for these units

https://hst-api.wialon.com/wialon/ajax.html?svc=events/update_units&params={"mode":"add","units":[{"id":160,"detect":{"*":0}},{"id":194,"detect":{"*":0}}]}&sid=your_session_sid

Then you need to execute request events/check_updates to get updated events, you can execute this request every several seconds. If event for some unit(s) has been update the response will be with new information, if no,there will not information

For example,

https://hst-api.wialon.com/wialon/ajax.html?svc=events/check_updates&params={"lang":"en","measure":"si","detalization":7}&sid=your_session_sid

first time - new events for two units "160"(unit_id):[ ....], "194"(unit_id):[ ....]

{"160":[{"ignition":{"1":{"from":{"t":1563374767,"y":53.9073219299,"x":27.5188350677},"to":{"t":1563428311,"y":53.9057502747,"x":27.457069397},"m":1563428311,"f":0,"state":0,"type":1,"hours":207315,"switches":314,"value":0},"2":{"from":{"t":0,"y":0,"x":0},"to":{"t":0,"y":0,"x":0},"m":1563428311,"f":0,"state":-348201.3876,"type":1,"hours":0,"switches":0,"value":-348201.3876}},"sensors":{"10":{"from":{"t":1562583015,"y":0,"x":0},"to":{"t":1562662285,"y":53.9057655334,"x":27.4570426941},"m":1563428311,"f":0,"type":4,"value":56},"11":{"from":{"t":1562583017,"y":53.9057579041,"x":27.45703125},"to":{"t":1562662285,"y":53.9057655334,"x":27.4570426941},"m":1563428311,"f":0,"type":3,"counter":328.234996796,"total_counter":8602.70002317,"value":19.5879993439},"12":{"from":{"t":1562583015,"y":0,"x":0},"to":{"t":1562662285,"y":53.9057655334,"x":27.4570426941},"m":1563428311,"f":0,"state":56,"type":1,"hours":79270,"switches":1,"value":56},"5":{"from":{"t":1562663575,"y":53.9059181213,"x":27.457036972},"to":{"t":1563428311,"y":53.9057502747,"x":27.457069397},"m":1563428311,"f":0,"type":2,"counter":5992,"summary":5992,"total_counter":0,"total_summary":0,"value":1},"6":{"from":{"t":0,"y":0,"x":0},"to":{"t":0,"y":0,"x":0},"m":1563428311,"f":0,"type":3,"counter":0,"total_counter":0,"value":-348201.3876},"7":{"from":{"t":1562583017,"y":53.9057579041,"x":27.45703125},"to":{"t":1563428311,"y":53.9057502747,"x":27.457069397},"m":1563428311,"f":0,"type":4,"value":10},"8":{"from":{"t":1562583015,"y":0,"x":0},"to":{"t":1562662285,"y":53.9057655334,"x":27.4570426941},"m":1563428311,"f":0,"type":2,"counter":58,"summary":2702,"total_counter":0,"total_summary":0,"value":56},"9":{"from":{"t":1562583047,"y":53.9057655334,"x":27.4571208954},"to":{"t":1563374736,"y":53.9072685242,"x":27.5189781189},"m":1563428311,"f":0,"type":4,"value":251.339229953}},"trips":{"from":{"t":1563374767,"y":53.9073219299,"x":27.5188350677},"to":{"t":1563428311,"y":53.9057502747,"x":27.457069397},"m":1563428311,"f":0,"state":0,"max_speed":0,"curr_speed":0,"avg_speed":0,"distance":0,"odometer":11190,"course":0,"altitude":313},"counters":{"from":{"t":1563428533,"y":53.9057502747,"x":27.457069397},"to":{"t":1563428533,"y":53.9057502747,"x":27.457069397},"m":1563428311,"f":0,"engine_hours":367662,"mileage":15003520,"bytes":9694},"lls":{}}],"194":[{"ignition":{"2":{"from":{"t":0,"y":0,"x":0},"to":{"t":0,"y":0,"x":0},"m":1563538378,"f":0,"state":-348201.3876,"type":1,"hours":0,"switches":0,"value":-348201.3876}},"sensors":{"1":{"from":{"t":0,"y":0,"x":0},"to":{"t":0,"y":0,"x":0},"m":1563538378,"f":0,"type":3,"counter":0,"total_counter":0,"value":-348201.3876},"3":{"from":{"t":0,"y":0,"x":0},"to":{"t":0,"y":0,"x":0},"m":1563538378,"f":0,"type":4,"value":-348201.3876}},"trips":{"from":{"t":1563283552,"y":-26.0013198853,"x":28.1317825317},"to":{"t":1563538378,"y":-26.1343841553,"x":28.2284832001},"m":1563538378,"f":0,"state":1,"max_speed":166,"curr_speed":25,"avg_speed":291,"distance":20571008,"odometer":75058377,"course":326,"altitude":274},"counters":{"from":{"t":1563538378,"y":-26.1343841553,"x":28.2284832001},"to":{"t":1563538378,"y":-26.1343841553,"x":28.2284832001},"m":1563538378,"f":0,"engine_hours":1377834,"mileage":125648939,"bytes":0},"lls":{}}]}

Second time - new events only for 1 unit  "194"(unit_id):[ ....]

{"194":[{"ignition":{"2":{"from":{"t":0,"y":0,"x":0},"to":{"t":0,"y":0,"x":0},"m":1563538488,"f":0,"state":-348201.3876,"type":1,"hours":0,"switches":0,"value":-348201.3876}},"sensors":{"1":{"from":{"t":0,"y":0,"x":0},"to":{"t":0,"y":0,"x":0},"m":1563538488,"f":0,"type":3,"counter":0,"total_counter":0,"value":-348201.3876},"3":{"from":{"t":0,"y":0,"x":0},"to":{"t":0,"y":0,"x":0},"m":1563538488,"f":0,"type":4,"value":-348201.3876}},"trips":{"from":{"t":1563283552,"y":-26.0013198853,"x":28.1317825317},"to":{"t":1563538488,"y":-26.0177440643,"x":28.1239242554},"m":1563538488,"f":0,"state":1,"max_speed":166,"curr_speed":20,"avg_speed":291,"distance":20591683,"odometer":75058377,"course":48,"altitude":274},"counters":{"from":{"t":1563538488,"y":-26.0177440643,"x":28.1239242554},"to":{"t":1563538488,"y":-26.0177440643,"x":28.1239242554},"m":1563538488,"f":0,"engine_hours":1377834,"mileage":125648939,"bytes":0}}]}
Diana Cheley
Wialon Hosting Expert
Gurtam