Good day,
I'm trying to integrate "Z-5R WEB" using JSON communication but I'm having trouble.
The LUA script must support multiple connection and must be a server, "Z-5R WEB" will open connection to the LM periodically sends the following:
The server on LogicMachine must respond this:
I don't know how to send an answer.
My test script:
Please Help,
Borek
I'm trying to integrate "Z-5R WEB" using JSON communication but I'm having trouble.
The LUA script must support multiple connection and must be a server, "Z-5R WEB" will open connection to the LM periodically sends the following:
Code:
POST / HTTP / 1.1
Host: 192.168.0.11:8082
Accept: * / *
User-Agent: Z5R WEB
Connection: close
Content-type: application / json
Content-Length: 193
{"type": "Z5RWEB", "sn": 46653, "messages": [{"id": 660260756, "operation": "power_on", "fw": "3.35", "conn_fw": "1.0. 146 "," active ": 0," mode ": 0," controller_ip ":" 192.168.0.248 "," reader_protocol ":" wiegand "}]}
The server on LogicMachine must respond this:
Code:
HTTP/1.0 200 OK
Server: BaseHTTP/0.3 Python/2.7.17
Date: Tue, 07 Jul 2020 04:06:53 GMT
Content-type: application/json
{"date":"2020-07-05 07:35:54","interval":10,"messages":[{"id":123456789,"operation":"set_active","active":1,"online":0}]}
I don't know how to send an answer.
My test script:
Code:
data=[[HTTP/1.0 200 OK
Server: BaseHTTP/0.3 Python/2.7.17
Date: Tue, 07 Jul 2020 04:06:53 GMT
Content-type: application/json
{"date":"2020-07-05 07:35:54","interval":10,"messages":[{"id":123456789,"operation":"set_active","active":1,"online":1}]}
]]
log("DATA: ",data)
local socket = require("socket")
local server = assert(socket.bind("*", 8082))
local tcp = assert(socket.tcp())
while 1 do
local client = server:accept()
line = client:receive("*a")
if line then
log(line)
if string.find(line,"power_on") then
log(client:send(data))
end
end
end
Please Help,
Borek