This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

RFID access controller Z-5R WEB Json (ironlogic.ru)
#1
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:

Code:
123456789
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:
123456
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:
1234567891011121314151617181920212223242526
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

Attached Files
.pdf   advanced.pdf (Size: 661.85 KB / Downloads: 14)
.zip   web-json-en.zip (Size: 381.6 KB / Downloads: 3)
.pdf   EN_Z-5R_WEB_v-1-01.pdf (Size: 1.78 MB / Downloads: 15)
.pdf   web-json ENG.pdf (Size: 502.2 KB / Downloads: 13)
.pdf   Z397 Guard - IronLogic Wiki.pdf (Size: 329.98 KB / Downloads: 6)
.pdf   Z397 IP - IronLogic Wiki.pdf (Size: 986.79 KB / Downloads: 3)
.pdf   Z397 IP Advanced Mode - IronLogic Wiki.pdf (Size: 293.47 KB / Downloads: 4)
Reply
#2
You don't need a script to create a web server, you can use LM web server's .lp scripts for this task.
1. Disable password access to User directory in User access settings.
2. Upload the example as rfid.lp using FTP apps login into user directory. You can check if the file can be accessed by opening http://LM_IP/user/rfid.lp, you should see a blank page but not a 404 error.
3. In your RFID reader set HTTP notification port to 80 and path to /user/rfid.lp

This example is only a starting point, you need to modify it to check the requested function type and provide a correct response depending on the request. If request is a valid JSON it will be visible in Logs tab in LM.
Code:
123456789101112131415161718192021222324
<? require('apps') post = ngx.req.get_body_data() header('content-type', 'application/json') if post then   data = json.pdecode(post)   if data then     log(data)     print(json.encode({       date = "2020-07-05 07:35:54",       interval = 10,       messages = {         {           id = 123456789,           operation = "set_active",           active = 1,           online = 1         }       }     }))   end end

Apps documentation: https://forum.logicmachine.net/showthread.php?tid=85
Reply
#3
(07.07.2020, 07:13)admin Wrote: You don't need a script to create a web server, you can use LM web server's .lp scripts for this task.
1. Disable password access to User directory in User access settings.
2. Upload the example as rfid.lp using FTP apps login into user directory. You can check if the file can be accessed by opening http://LM_IP/user/rfid.lp, you should see a blank page but not a 404 error.
3. In your RFID reader set HTTP notification port to 80 and path to /user/rfid.lp

This example is only a starting point, you need to modify it to check the requested function type and provide a correct response depending on the request. If request is a valid JSON it will be visible in Logs tab in LM.
Code:
123456789101112131415161718192021222324
<? require('apps') post = ngx.req.get_body_data() header('content-type', 'application/json') if post then   data = json.pdecode(post)   if data then     log(data)     print(json.encode({       date = "2020-07-05 07:35:54",       interval = 10,       messages = {         {           id = 123456789,           operation = "set_active",           active = 1,           online = 1         }       }     }))   end end

Apps documentation: https://forum.logicmachine.net/showthread.php?tid=85

Thank you very much, it was very helpful.
The solution using the application is much easier.
Reply


Forum Jump: