LogicMachine Forum
Reading event notifications from Grandstream GDS3710 - Printable Version

+- LogicMachine 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: Reading event notifications from Grandstream GDS3710 (/showthread.php?tid=4710)



Reading event notifications from Grandstream GDS3710 - tigi - 13.04.2023

I'm trying to setup event notification for the grandstream GDS3710.
I cannot use an lp script since the gds3710 only accepts an ip and port
   

I've searched the forum for a simple resident script which is able to capture the data the gds3710 sends when an event occurs but without any luck.
I've found a script which at least generates some output but not the whole body.
Code:
* string: POST / HTTP/1.1User-Agent: Wget/1.16.1 (linux-gnu)Accept: */*Accept-Encoding: identityHost: 192.x.x.x:7777Connection: Keep-AliveContent-Type: application/x-www-form-urlencodedContent-Length: 29


Can someone point me to the right direction or alter the script below.

Code:
local socket = require("socket") local server = assert(socket.bind("*", 7777)) local header while 1 do   local client = server:accept()   local line = client:receive()   header = line   while (#line > 0) do     line = client:receive()     header = header .. line   end   log(header)  end

Thanks in advance!


RE: Reading event notifications from Grandstream GDS3710 - admin - 13.04.2023

Try this:
Code:
local socket = require("socket") local server = assert(socket.bind("*", 7777)) local crlf = '\r\n' while true do   local client = server:accept()   client:settimeout(5)   local pat, len   while true do     local res, err = client:receive(pat)     if err then       break     end     if type(pat) == 'number' then       client:send(         'HTTP/1.1 200 OK' .. crlf ..         'Connection: close' .. crlf .. crlf       )       log(res) -- contains request body       break     elseif #res == 0 then       pat = len     elseif not len then       len = res:match('Content%-Length: (%d+)')       len = tonumber(len)     end   end   client:close() end



RE: Reading event notifications from Grandstream GDS3710 - tigi - 13.04.2023

(13.04.2023, 08:55)admin Wrote: Try this:
Code:
local socket = require("socket") local server = assert(socket.bind("*", 7777)) local crlf = '\r\n' while true do   local client = server:accept()   client:settimeout(5)   local pat, len   while true do     local res, err = client:receive(pat)     if err then       break     end     if type(pat) == 'number' then       client:send(         'HTTP/1.1 200 OK' .. crlf ..         'Connection: close' .. crlf .. crlf       )       log(res) -- contains request body       break     elseif #res == 0 then       pat = len     elseif not len then       len = res:match('Content%-Length: (%d+)')       len = tonumber(len)     end   end   client:close() end

Works as a charm! 
Thank you very much admin! Cool