API - Getting data for events

Материал из WebHMI Wiki
Версия от 09:13, 18 апреля 2018; Evgeniy.mozoliak (обсуждение | вклад) (Новая страница: «Example of response: <pre> [ { "rowid": "3050", "event_id": "1", "start_time": "1422797405", "end_time": "1422797440", "xtra_regs": […»)

Перейти к: навигация, поиск

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
      }
    ]
  }
]

Атрибуты данных события:

rowidintУникальный идентификатор события в базе данных
event_idintID события
start_timeintВремя начала события
end_timeintВремя окончания события. Если событие еще не окончилось то end_time = 0
xtra_regsobjectОбъект с данными о дополнительных регистрах которые сохраняются в логе событий. Ключ-значение.

Формат имени дополнительных регистров:
"E" + ID события + "." + порядковый номер регистра в событии начиная с нуля



Пример запроса данных для события номер 2:

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

Заголовки:

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

Пример ответа:

[
  {
    "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
      }
    ]
  }
]