27.12.2018, 13:46
Try this, change camera URL and text message as needed. Uncomment last line with logging if request does not work.
Code:
url = 'http://USER:PASS@IP/Video/inputs/channels/1/overlays/text/1'
text = 'Test message'
function http_put_xml(url, xml)
local http = require('socket.http')
local ltn12 = require('ltn12')
local resp = {}
local res, code = http.request({
url = url,
method = 'PUT',
headers = {
['content-type'] = 'text/xml',
['content-length'] = #xml,
},
source = ltn12.source.string(xml),
sink = ltn12.sink.table(resp),
})
if res then
return table.concat(resp), code
else
return nil, code
end
end
function xml_escape(text)
return text
:gsub('&', '&')
:gsub('<', '<')
:gsub('>', '>')
:gsub('"', '"')
:gsub("'", ''')
end
xml = [[<?xml version="1.0" encoding="UTF-8"?>
<TextOverlay xmlns="http://www.hikvision.com/ver10/XMLSchema" version="1.0">
<id>1</id>
<enabled>true</enabled>
<posX>16</posX>
<posY>16</posY>
<message>]] .. xml_escape(text) .. [[</message>
</TextOverlay>]]
res, err = http_put_xml(url, xml)
-- log(res, err)