shell script to LUA - Printable Version +- Logic Machine Forum (https://forum.logicmachine.net) +-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1) +--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8) +--- Thread: shell script to LUA (/showthread.php?tid=2450) |
shell script to LUA - edos - 03.02.2020 Hello, Can anyone tell me if this sample script can be "transplanted" to LM? Code: #!/bin/bash RE: shell script to LUA - admin - 04.02.2020 See this thread for a similar example: https://forum.logicmachine.net/showthread.php?tid=1921 First request is POST so you need to pass data like this: Code: data = "{'username':'user', 'password':'1234'}" If running an older FW you might also need to change socket.http to ssl.https in order to use https. Newer FW will detect https automatically. RE: shell script to LUA - edos - 04.02.2020 Thanks I looked an example! Here is the result: Code: require('socket.http') But it still gives an error. Code: * string: {"meta":{"rc":"error","msg":"api.err.LoginRequired"},"data":[]} I am not good at scripts, may you help me ? Thanks a lot! RE: shell script to LUA - admin - 05.02.2020 Log what you get during login request. I've also changed data variable to contain valid JSON: Code: require('json') RE: shell script to LUA - edos - 05.02.2020 Yes, now authorization is ok. After changing the data variable to store valid JSON Here is the log: Code: * arg: 1 But I do not see the answer on url2. Thanks RE: shell script to LUA - admin - 05.02.2020 Some extra parsing of cookie header is required. Try this for the second request: Code: cookies = hdrs['set-cookie'] RE: shell script to LUA - edos - 05.02.2020 Yes, I get everything perfectly. Thank you very much. I will try to parse the resulting JSON. P.S. If I can! For information on the forum, I report that it was an API UNIFI Controller. Getting information about clients: connected or not, online time, and a lot of similar information. I did not find such an implementation on this forum. RE: shell script to LUA - admin - 05.02.2020 Let me know if you have any problems with parsing JSON data. RE: shell script to LUA - benanderson_475 - 23.03.2020 I have the following error, what could it be?, i have also tried ssl.https instead of socket.http, it returns the same error...? arg: 1 * nil * arg: 2 * string: error:1408F10B:lib(20):func(143):reason(267) * arg: 3 * nil Code: http = require("socket.http") RE: shell script to LUA - admin - 23.03.2020 See this: https://forum.logicmachine.net/showthread.php?tid=427&pid=15575#pid15575 |