API - Getting data for events

Материал из WebHMI Wiki
Перейти к: навигация, поиск
Эта страница — перевод страницы API - Получение данных для события. Перевод выполнен на 100%.

Другие языки:
English • ‎русский

To get data from event log, it is necessary to run following GET-query for URL http://192.168.1.1/api/event-data/2. Here 2 - is the ID of the graph of interest.

In the request headers, you must pass the API key and the boundaries of the time interval of interest. X-WH-START and X-WH-END are transmitted in UnixTime format. For example:

X-WH-APIKEY: F3C74230818DA487BB2017CE5D0290F4DABCAFD7
X-WH-START: 1422797440
X-WH-END: 1422997405

Also, in the headers, you must specify the desired data exchange format. Currently, only the JSON format is supported.

Accept: application/json
Content-Type: application/json

Consider an example of two events. Event number 1 is the parent event. It starts on the 5th second of every minute and ends on the 40th second of every minute. The log records data once for the entire event. The time of the beginning of the event and the last value of the interval register I60 are recorded in the log. Screenshots illustrate the setting of this event.
Event-data-1.png

Event-data-2.png

The second event is the child event for the first event. Therefore, it can only be executed when the first event is executed. In addition, the condition is limited so that it starts at the 25th second of every minute and ends at the 35th. Data for it is written to the log every 2 seconds. The current value of the I60 register is written to the log. Screenshots illustrate the setting of this event.
Event-data-5.png

Event-data-4.png

Example of getting date about event #1:

URL: http://192.168.1.1/api/event-data/1
Method: GET

Headers:

Accept: application/json
Content-Type: application/json
Accept-Encoding: gzip, deflate, sdch
X-WH-APIKEY: F3C74230818DA487BB2017CE5D0290F4DABCAFD7
X-WH-START: 1422797440
X-WH-END: 1422997405

Example of response:

[
  {
    "rowid": "3050",
    "event_id": "1",
    "start_time": "1422797405",
    "end_time": "1422797440",
    "xtra_regs": [
      {
        "E1.0": 1422797405
      },
      {
        "E1.1": 39
      }
    ]
  },
  {
    "rowid": "3052",
    "event_id": "1",
    "start_time": "1422797465",
    "end_time": "1422797500",
    "xtra_regs": [
      {
        "E1.0": 1422797465
      },
      {
        "E1.1": 39
      }
    ]
  },
  {
    "rowid": "3054",
    "event_id": "1",
    "start_time": "1422797525",
    "end_time": "1422797560",
    "xtra_regs": [
      {
        "E1.0": 1422797525
      },
      {
        "E1.1": 39
      }
    ]
  },
  {
    "rowid": "3056",
    "event_id": "1",
    "start_time": "1422797585",
    "end_time": "1422797680",
    "xtra_regs": [
      {
        "E1.0": 1422797585
      },
      {
        "E1.1": 39
      }
    ]
  },
  {
    "rowid": "3058",
    "event_id": "1",
    "start_time": "1422797705",
    "end_time": "1422797740",
    "xtra_regs": [
      {
        "E1.0": 1422797705
      },
      {
        "E1.1": 39
      }
    ]
  },
  {
    "rowid": "3060",
    "event_id": "1",
    "start_time": "1422797765",
    "end_time": "1422797800",
    "xtra_regs": [
      {
        "E1.0": 1422797765
      },
      {
        "E1.1": 39
      }
    ]
  },
  {
    "rowid": "3062",
    "event_id": "1",
    "start_time": "1422797825",
    "end_time": "0",
    "xtra_regs": [
      {
        "E1.0": 1422797825
      },
      {
        "E1.1": 39
      }
    ]
  }
]

Event's attrubutes:

rowidintUnique event identifier in database
event_idintEvent ID
start_timeintEvent start time
end_timeintEvent end time. If the event still in progress, then end time = 0
xtra_regsobjectObject with data on additional registers which are saved in event log. Key - Value.

Additional register name format:
"E" + event ID + "." + register's serial number in the event starting from 0



Example of query for data on event #2:

URL: http://192.168.1.1/api/event-data/2
Method: GET

Headers:

Accept: application/json
Content-Type: application/json
Accept-Encoding: gzip, deflate, sdch
X-WH-APIKEY: F3C74230818DA487BB2017CE5D0290F4DABCAFD7
X-WH-START: 1422804505
X-WH-END: 1422800200

Response example:

[
  {
    "rowid": "3201",
    "event_id": "2",
    "start_time": "1422804505",
    "end_time": "1422804515",
    "xtra_regs": [
      {
        "E2.0": 25
      }
    ]
  },
  {
    "rowid": "3201",
    "event_id": "2",
    "start_time": "1422804505",
    "end_time": "1422804515",
    "xtra_regs": [
      {
        "E2.0": 27
      }
    ]
  },
  {
    "rowid": "3201",
    "event_id": "2",
    "start_time": "1422804505",
    "end_time": "1422804515",
    "xtra_regs": [
      {
        "E2.0": 29
      }
    ]
  },
  {
    "rowid": "3201",
    "event_id": "2",
    "start_time": "1422804505",
    "end_time": "1422804515",
    "xtra_regs": [
      {
        "E2.0": 31
      }
    ]
  },
  {
    "rowid": "3201",
    "event_id": "2",
    "start_time": "1422804505",
    "end_time": "1422804515",
    "xtra_regs": [
      {
        "E2.0": 33
      }
    ]
  }
]