Интеграция в другие системы/en — различия между версиями

Материал из WebHMI Wiki
Перейти к: навигация, поиск
(Новая страница: «This function is available since version 2.6.4520.»)
 
(не показаны 4 промежуточные версии этого же участника)
Строка 5: Строка 5:
 
This function is available since version 2.6.4520.
 
This function is available since version 2.6.4520.
  
Пример программы, выполняющей HTTPS-запрос для отправки данных виде файла на URL https://demo.com/upload:
+
An example of a program executing an HTTPS request to send data as a file at URL https://demo.com/upload:
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
 
function main (userId)
 
function main (userId)
Строка 29: Строка 29:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Обратите внимание, что для корректной работы SSL-сертификатов необходимо иметь точное локально время. При значительном отклонении локальных часов, https-запросы могут не работать. Рекомендуем использовать синхронизацию времени по NTP-серверу.
+
Note that for SSL certificates correctly function, you need to have an exact local time. If there is a significant deviation of the local clock, https requests may not work. We recommend using time synchronization via NTP server.
  
  
Пример запроса числа по GET-запросу с URL http://demo.example.com/read-data?param=32 и записи его в регистр с id=4356:
+
Example of requesting a number in the GET request at URL http://demo.example.com/read-data?param=32 and writing it to the register with id=4356:
  
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">

Текущая версия на 13:49, 21 ноября 2017

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

WebHMI allows you to interact with other systems by running HTTP requests. For this, WebHMI has a library Lua-cURLv3. Using it you can easily send data to third-party systems and also request the necessary data from these systems.

This function is available since version 2.6.4520.

An example of a program executing an HTTPS request to send data as a file at URL https://demo.com/upload:

function main (userId)
    
  INFO("Doing CURL");

  c = cURL.easy_init()
  c:setopt_url("https://demo.com/upload")
    
  postdata = {
      name = {
          file="dummy.html",
          data="<html><bold>bold</bold></html>",
          type="text/html"
      } 
  }
  c:post(postdata)
  c:perform()
  c:close()

  INFO("CURL done");
end

Note that for SSL certificates correctly function, you need to have an exact local time. If there is a significant deviation of the local clock, https requests may not work. We recommend using time synchronization via NTP server.


Example of requesting a number in the GET request at URL http://demo.example.com/read-data?param=32 and writing it to the register with id=4356:

function main (userId)
  c = cURL.easy_init()
  c:setopt_url("http://demo.example.com/read-data?param=32")
  local res = "";
  c:perform({
        writefunction = function(str)
            res = res .. str;
        end})
  c:close()
  WriteReg(4356, res);
end