User Tools

Site Tools


access_via_api

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
access_via_api [2019/06/07 14:29] akuzmukaccess_via_api [2023/03/02 10:53] (current) – [API usage examples] emozolyak
Line 1: Line 1:
 +<WRAP center round tip 60%>There is Excel VBA scripts codes example [[example_of_data_access_from_excel_via_api|here]]</WRAP>
 +
 +
 ====== Using API ====== ====== Using API ======
  
Line 25: Line 28:
   Content-Type: application/json   Content-Type: application/json
    
 +<WRAP center round important 60%>
 +Note that, if you are using another WebHMI as client (via [[Lua_API|cURL Lua]]'s library), the following line should be removed 
 +  Accept-Encoding: gzip, deflate, sdch
 +</WRAP>
 +
 Example of a connection list request: Example of a connection list request:
  
Line 518: Line 526:
 } }
 </code> </code>
 +==== Register's attributes ====
 ^ Register's attributes: ^^^ ^ Register's attributes: ^^^
 |**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://192.168.1.1/api/alerts.
 +
 +To obtain information about a particular alert, you must perform a following GET request on a URL 'http://192.168.1.1/api/alerts/1' . Here "1" is the ID of the desired alert.
 +
 +In the headers, it is necessary to pass API key. For example:
 +
 +  X-WH-APIKEY: F3C74230818DA487BB2017CE5D0290F4DABCAFD7
 +  
 +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
 +
 +Example of query for the full graph list:
 +
 +  ***URL:** http://192.168.1.1/api/alerts
 +  ***Method:** GET
 +  *Headers:
 +
 +  Accept: application/json
 +  Content-Type: application/json
 +  Accept-Encoding: gzip, deflate, sdch
 +  X-WH-APIKEY: F3C74230818DA487BB2017CE5D0290F4DABCAFD7
 +
 +Reply example:
 +<code>
 +[
 +    {
 +        "id": "1",
 +        "title": "a1",
 +        "description": "<p>my alert</p>",
 +        "image": "",
 +        "level": "0",
 +        "sound": "0",
 +        "canack": "1",
 +        "dict_id": "",
 +        "condition": "[{\"condition\":\"moreThan\",\"regId\":1,\"min\":\"0\",\"max\":\"\",\"bitNum\":\"\",\"state\":\"\",\"value\":\"\"}]",
 +        "category": "",
 +        "group_id": ""
 +    },
 +    {
 +        "id": "2",
 +        "title": "a2",
 +        "description": "<p>my alert</p>",
 +        "image": "",
 +        "level": "0",
 +        "sound": "0",
 +        "canack": "1",
 +        "dict_id": "",
 +        "condition": "[{\"condition\":\"moreThan\",\"regId\":1,\"min\":\"0\",\"max\":\"\",\"bitNum\":\"\",\"state\":\"\",\"value\":\"\"}]",
 +        "category": "",
 +        "group_id": ""
 +    }
 +]
 +</code>
 +
 +<WRAP center round info 60%>
 +To get information about currently active alerts, you can use [[current_alerts?s[]=getcurrentalerts |GetCurrentAlerts]] function and copying its output to some register (and then use GET method for current register's values). 
 +</WRAP>
 +
 +
  
 ===== Image list ===== ===== Image list =====
Line 1624: Line 1698:
   Content-Type: 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.  
  
-{{::api_ev_1_example.png?direct}}+<WRAP center round info 80%> 
 +Please refer for [[events]] chapter for more information 
 +</WRAP>
  
-{{::api_ev_1_example_actions.png?direct}} 
- 
-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.  
- 
-{{::api_ev_child_1.png?direct}} 
- 
-{{::api_ev_child_2.png?direct}} 
- 
-{{::api_ev_child_3.png?direct}} 
  
 Example of getting date about event #1: Example of getting date about event #1:
Line 2207: 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://192.168.1.1/api/meters-log.
 +
 +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: F3C74230818DA487BB2017CE5D0290F4DABCAFD7
 +  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/json
 +  Content-Type: application/json
 +
 +Example of querying records from the register log:
 +
 +  ***URL**: http://192.168.1.1/api/meters-log
 +  ***Method**: GET
 +  ***Headers**:
 +
 +  Accept: application/json
 +  Content-Type: application/json
 +  Accept-Encoding: gzip, deflate, sdch
 +  X-WH-APIKEY: F3C74230818DA487BB2017CE5D0290F4DABCAFD7
 +  X-WH-START: 1422595501
 +  X-WH-END: 1422599101
 +
 +Reply example:
 +
 +<code>
 +[
 +  {
 +    "t": 1586253600, // timestamp 
 +    "r": 65,         // register id 
 +    "s": "0.0",      // hour start value 
 +    "e": "5.0",      // hour end value
 +    "v": "5.0"       // difference
 +  },
 +  {
 +    "t": 1586257200, 
 +    "r": 65,
 +    "s": "5.0",
 +    "e": "20.0",
 +    "v": "15.0"
 +  },
 +  {
 +    "t": 1586257200,
 +    "r": 76,
 +    "s": "100.0",
 +    "e": "200.0",
 +    "v": "100.0"
 +  }
 +]
 +</code>
 +
 +The %%//%% are comments, they are absent in the real reponse. 
 +
 +====== API usage examples ======
 +
 +    * [[access_from_lua_to_webhmi_itself | Data access from WebHMI itself]]
 +    * [[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.1559917785.txt.gz · Last modified: 2019/06/07 14:29 by akuzmuk

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki