access_via_api
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
access_via_api [2020/04/07 10:05] – [Getting graph data] emozolyak | access_via_api [2022/01/26 10:03] – atolstov | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | <WRAP center round tip 60%> | ||
+ | |||
+ | |||
====== Using API ====== | ====== Using API ====== | ||
Line 25: | Line 28: | ||
Content-Type: | Content-Type: | ||
+ | <WRAP center round important 60%> | ||
+ | Note that, if you are using another WebHMI as client (via [[Lua_API|cURL Lua]]' | ||
+ | Accept-Encoding: | ||
+ | </ | ||
+ | |||
Example of a connection list request: | Example of a connection list request: | ||
Line 518: | Line 526: | ||
} | } | ||
</ | </ | ||
+ | ==== Register' | ||
^ Register' | ^ Register' | ||
|**id**| int | Unique register id | | |**id**| int | Unique register id | | ||
Line 609: | Line 617: | ||
|3|Double Word | | |3|Double Word | | ||
|4|Unix Time | | |4|Unix Time | | ||
+ | |5|String | | ||
+ | |||
^Storage formats identifiers: | ^Storage formats identifiers: | ||
Line 1238: | Line 1248: | ||
|min_val |double |Minimal value of the Y axis| | |min_val |double |Minimal value of the Y axis| | ||
|max_val |double |Maximal value of the Y axis| | |max_val |double |Maximal value of the Y axis| | ||
+ | |||
+ | ===== Alert list ===== | ||
+ | |||
+ | To get a list of all alerts, you must perform a GET request on the URL like this: http:// | ||
+ | |||
+ | To obtain information about a particular alert, you must perform a following GET request on a URL ' | ||
+ | |||
+ | In the headers, it is necessary to pass API key. For example: | ||
+ | |||
+ | X-WH-APIKEY: | ||
+ | | ||
+ | Also, in the headers, you must specify the desired data exchange format. Currently, only the JSON format is supported. | ||
+ | |||
+ | Accept: application/ | ||
+ | Content-Type: | ||
+ | |||
+ | Example of query for the full graph list: | ||
+ | |||
+ | ***URL:** http:// | ||
+ | ***Method: | ||
+ | *Headers: | ||
+ | |||
+ | Accept: application/ | ||
+ | Content-Type: | ||
+ | Accept-Encoding: | ||
+ | X-WH-APIKEY: | ||
+ | |||
+ | Reply example: | ||
+ | < | ||
+ | [ | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | ] | ||
+ | </ | ||
+ | |||
+ | <WRAP center round info 60%> | ||
+ | To get information about currently active alerts, you can use [[current_alerts? | ||
+ | </ | ||
+ | |||
+ | |||
===== Image list ===== | ===== Image list ===== | ||
Line 1296: | Line 1370: | ||
|title |string |Image name| | |title |string |Image name| | ||
- | ===== Getting | + | ===== Getting |
- | There is an option | + | To get data from graph log, it is necessary |
- | To obtain entries from the meters, you must perform follwing GET request on a URL | + | Also, instead of specifying |
- | http://192.168.1.1/ | + | |
- | In the request headers, | + | X-WH-REGISTERS: |
+ | |||
+ | In the request headers, | ||
X-WH-APIKEY: | X-WH-APIKEY: | ||
- | X-WH-START: | + | X-WH-START: |
- | X-WH-END: | + | X-WH-END: |
- | X-WH-REGISTERS: 8,10 ?? check this | + | X-WH-SLICES: 300 |
- | + | ||
- | Also, in the headers, you must specify the desired data exchange format. Currently, only the JSONformat | + | X-WH-SLICES is the number of values. The time interval X-WH-START-X-WH-END will be divided into X-WH-SLICES of equal intervals and the system will take the most detailed values for each of them. |
+ | X-WH-SLICES should be chosen based on the necessary detail of the graph. So, if you need to build a graph 800 pixels wide, then it makes no sense to choose more than 800 values from the log. And sometimes there will be enough 200-400 values depending on the width of the line on the graph. | ||
+ | |||
+ | To speed up the operation, the system can store the averaged values of the registers for different intervals (1 minute, 2 minutes, 5 minutes, 15 minutes, 1 hour). In the configuration of each register, you can specify the required detail of the stored data. Depending on the selected time interval and the number of values, the system will attempt to take data from the most appropriate table of averaged values. or from the register register (if it is included for the specified register) | ||
+ | |||
+ | Also, in the headers, you must specify the desired data exchange format. Currently, only the JSON format | ||
Accept: application/ | Accept: application/ | ||
Content-Type: | Content-Type: | ||
+ | | ||
+ | Example of getting data for graph #1: | ||
- | Example of querying records from the register log: | + | |
- | + | ***Method:** GET | |
- | | + | *Headers: |
- | ***Method**: GET | + | |
- | *Header: | + | |
Accept: application/ | Accept: application/ | ||
Line 1325: | Line 1405: | ||
Accept-Encoding: | Accept-Encoding: | ||
X-WH-APIKEY: | X-WH-APIKEY: | ||
- | X-WH-START: | + | X-WH-START: |
- | X-WH-END: | + | X-WH-END: |
- | X-WH-REGISTERS: 8,10 | + | X-WH-SLICES: 20 |
- | + | ||
- | Reply example: | + | |
+ | Response example: | ||
< | < | ||
- | { | + | [ |
- | "1422598266": | + | |
- | | + | |
- | | + | "10": |
- | "v": "6", | + | "16": "NaN;NaN;NaN", |
- | "s": | + | "x": |
- | }, | + | }, |
- | { | + | { |
- | "r": | + | "8": |
- | "v": "", | + | "10": "NaN;NaN;NaN", |
- | "s": "" | + | "16": "NaN;NaN;NaN", |
- | | + | |
- | | + | |
- | | + | |
- | | + | " |
- | | + | "10": "NaN;NaN;NaN", |
- | "v": "11", | + | "16": "NaN;NaN;NaN", |
- | "s": "-1" | + | "x": |
- | }, | + | }, |
- | | + | { |
- | | + | " |
- | "v": "", | + | "10": "NaN;NaN;NaN", |
- | "s": | + | "16": "NaN;NaN;NaN", |
- | } | + | "x": |
- | ], | + | }, |
- | | + | |
- | | + | " |
- | "r": | + | "10": "NaN;NaN;NaN", |
- | "v": "16", | + | "16": "0.000000; |
- | "s": "-1" | + | "x": |
- | }, | + | }, |
- | | + | |
- | | + | "8": "0.000000; |
- | "v": "", | + | "10": "NaN;NaN;NaN", |
- | "s": | + | "16": "0.000000; |
- | } | + | |
- | ], | + | |
- | | + | { |
- | | + | "8": |
- | | + | "10": "NaN;NaN;NaN", |
- | "v": " | + | "16": "0.000000; |
- | "s": "-1" | + | |
- | }, | + | |
- | | + | { |
- | | + | "8": |
- | "v": "", | + | "10": "NaN;NaN;NaN", |
- | "s": | + | "16": "0.000000; |
- | } | + | |
- | | + | |
- | "1422598285": | + | { |
- | { | + | "8": |
- | | + | "10": "NaN;NaN;NaN", |
- | "v": "5", | + | "16": "0.000000; |
- | "s": "-1" | + | |
- | }, | + | |
- | { | + | { |
- | "r": | + | "8": |
- | "v": "", | + | "10": "NaN;NaN;NaN", |
- | "s": "" | + | "16": "0.000000; |
- | | + | |
- | | + | |
- | | + | { |
- | | + | "8": |
- | "r": | + | "10": "NaN;NaN;NaN", |
- | "v": "10", | + | "16": "0.000000; |
- | "s": "-1" | + | |
- | }, | + | |
- | { | + | |
- | "r": | + | " |
- | "v": "", | + | "10": "NaN;NaN;NaN", |
- | "s": "" | + | "16": "0.000000; |
- | | + | "x": |
- | | + | |
- | | + | { |
- | | + | "8": |
- | "r": | + | "10": "NaN;NaN;NaN", |
- | "v": "15", | + | "16": "0.000000; |
- | "s": "-1" | + | |
- | }, | + | |
- | { | + | { |
- | "r": | + | "8": |
- | "v": "", | + | "10": "NaN;NaN;NaN", |
- | "s": "" | + | "16": "0.000000; |
- | | + | |
- | | + | |
- | | + | { |
- | | + | "8": |
- | "r": 8, | + | "10": "NaN;NaN;NaN", |
- | "v": " | + | "16": "0.000000; |
- | "s": "-1" | + | |
- | }, | + | |
- | | + | { |
- | | + | "8": |
- | "v": "", | + | "10": "NaN;NaN;NaN", |
- | "s": | + | "16": "0.000000; |
- | } | + | |
- | | + | |
- | | + | { |
- | | + | "8": |
- | "r": | + | "10": "NaN;NaN;NaN", |
- | "v": "5", | + | "16": "0.000000; |
- | "s": "-1" | + | |
- | }, | + | |
- | { | + | { |
- | "r": | + | "8": |
- | "v": "", | + | "10": "NaN;NaN;NaN", |
- | "s": "" | + | "16": "0.000000; |
- | | + | |
- | | + | |
- | | + | |
- | | + | " |
- | "r": | + | "10": "NaN;NaN;NaN", |
- | "v": "10", | + | "16": "0.000000; |
- | "s": "-1" | + | "x": |
- | }, | + | }, |
- | { | + | |
- | "r": | + | " |
- | "v": "", | + | "10": "NaN;NaN;NaN", |
- | "s": "" | + | "16": "0.000000; |
- | | + | "x": |
- | | + | }, |
- | | + | |
- | | + | " |
- | "r": | + | "10": "NaN;NaN;NaN", |
- | "v": "15", | + | "16": "0.000000; |
- | "s": "-1" | + | "x": |
- | }, | + | }, |
- | { | + | |
- | "r": | + | " |
- | "v": "", | + | "10": "NaN;NaN;NaN", |
- | "s": "" | + | "16": "0.000000; |
- | | + | "x": |
- | | + | }, |
- | | + | |
- | | + | " |
- | | + | "10": "NaN;NaN;NaN", |
- | "v": " | + | "16": "NaN;NaN;NaN", |
- | "s": "-1" | + | "x": |
- | }, | + | }, |
- | | + | |
- | | + | " |
- | "v": "", | + | "10": "NaN;NaN;NaN", |
- | "s": | + | "16": "NaN;NaN;NaN", |
- | } | + | "x": |
- | ], | + | } |
- | | + | |
- | | + | |
- | | + | |
- | "v": "5", | + | |
- | "s": "-1" | + | |
- | }, | + | |
- | | + | |
- | | + | |
- | "v": "", | + | |
- | "s": | + | |
- | } | + | |
- | ], | + | |
- | | + | |
- | | + | |
- | | + | |
- | "v": "10", | + | |
- | "s": "-1" | + | |
- | }, | + | |
- | | + | |
- | | + | |
- | "v": "", | + | |
- | "s": | + | |
- | } | + | |
- | ], | + | |
- | | + | |
- | | + | |
- | | + | |
- | "v": "15", | + | |
- | "s": "-1" | + | |
- | }, | + | |
- | | + | |
- | | + | |
- | "v": "", | + | |
- | "s": | + | |
- | } | + | |
- | ], | + | |
- | | + | |
- | | + | |
- | | + | |
- | "v": "0", | + | |
- | "s": "-1" | + | |
- | }, | + | |
- | | + | |
- | | + | |
- | "v": "", | + | |
- | "s": | + | |
- | } | + | |
- | ], | + | |
- | | + | |
- | | + | |
- | | + | |
- | "v": "5", | + | |
- | "s": "-1" | + | |
- | }, | + | |
- | | + | |
- | | + | |
- | "v": "", | + | |
- | "s": | + | |
- | } | + | |
- | ], | + | |
- | и т.д. | + | |
] | ] | ||
</ | </ | ||
- | Returns | + | The structure of the returned data is as follows. An array of objects |
- | Each object has three properties: r, v, s. | + | Also in this object there are attributes with values for each register. The attribute name is the register ID. The attribute value is a string where the minimum, average and maximum |
- | + | ||
- | ^r|is the register ID. For example, 10 | | + | |
- | ^v|is the value of the register | + | |
- | ^s|is the state of the register | + | |
- | | -1|Unknown | | + | |
- | | 0|Disabled | | + | |
- | | 1|Normal | | + | |
- | | 2|Warning | | + | |
- | | 3|Alert | | + | |
- | | '' | + | |
===== Event list ===== | ===== Event list ===== | ||
Line 1690: | Line 1698: | ||
Content-Type: | Content-Type: | ||
| | ||
- | 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. | ||
- | |||
- | {{:: | ||
- | |||
- | {{:: | ||
- | |||
- | 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. | ||
- | |||
- | {{:: | ||
- | {{:: | + | <WRAP center round info 80%> |
+ | Please refer for [[events]] chapter for more information. | ||
+ | </ | ||
- | {{:: | ||
Example of getting date about event #1: | Example of getting date about event #1: | ||
Line 2273: | Line 2273: | ||
If the request is valid, API will return HTTP-code 200. | If the request is valid, API will return HTTP-code 200. | ||
+ | |||
+ | ===== Getting meters log ===== | ||
+ | |||
+ | There is an option to use a register as a tolalizers for resources like water, has, heat, electricity etc. Then its current value together with hourly consumption will be stored in the database. | ||
+ | |||
+ | To obtain entries from the meters log, you must perform follwing GET request on a URL http:// | ||
+ | |||
+ | In the request headers, it is necessary to pass the API key, the boundaries of the time interval of interest, X-WH-START and X-WH-END are transmitted in UnixTime format. All meter registers will be returned, so X-WH-REGISTER header is omitted. For example: | ||
+ | |||
+ | X-WH-APIKEY: | ||
+ | X-WH-START: 1422595501 | ||
+ | X-WH-END: 1422599101 | ||
+ | | ||
+ | Also, in the headers, you must specify the desired data exchange format. Currently, only the JSON format is supported. | ||
+ | |||
+ | Accept: application/ | ||
+ | Content-Type: | ||
+ | |||
+ | Example of querying records from the register log: | ||
+ | |||
+ | ***URL**: http:// | ||
+ | ***Method**: | ||
+ | ***Headers**: | ||
+ | |||
+ | Accept: application/ | ||
+ | Content-Type: | ||
+ | Accept-Encoding: | ||
+ | X-WH-APIKEY: | ||
+ | X-WH-START: 1422595501 | ||
+ | X-WH-END: 1422599101 | ||
+ | |||
+ | Reply example: | ||
+ | |||
+ | < | ||
+ | [ | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | ] | ||
+ | </ | ||
+ | |||
+ | The %%//%% are comments, they are absent in the real reponse. | ||
+ | |||
+ | ====== API usage examples ====== | ||
+ | |||
+ | * [[example_of_data_access_from_excel_via_api|Data access from Excel]] | ||
+ | * [[example_of_data_access_from_c_c|Data access from C/C++]] | ||
+ | * [[google_sheet_api_example|Data access from the Google Sheets]] | ||
+ | * [[Android demo application]] | ||
+ | * [[Android application via Chrome]] | ||
+ | |||
access_via_api.txt · Last modified: 2023/03/02 10:53 by emozolyak