User:Ciprian.bacioiu

From MiOS
Revision as of 12:43, 21 November 2016 by Ciprian.bacioiu (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Useful scripts and tools

Luvit server used to receive POST Recordings from HTTP POST enabled sercomm cameras

Usage
  • Run the source from the cmd using luvit. If the file is name server.lua do a

luvit server.lua

  • Go into the camera administrator page (usually /adm/config_trig.htm)
  • Settup a Trigger for HTTP Post
  • Go into the HTTP Post configuration page and place your IP address and port that the server is running on
  • Generate a trigger event by accessing the camera_ip/adm/http_trigger.cgi.
  • The server will tell you a POST event was received. Wait till FILE saved ------------------ is outputed.


local http = require("http")
local https = require("https")
local pathJoin = require('luvi').path.join
local fs = require('fs')
 
local function onRequest(req, res)
	local buffer = {}
	print(req.socket.options and "https" or "http", req.method, req.url)
	if req.method == "POST" then
		req:on('data', function(chunk)
			table.insert(buffer, chunk)
			if type(chunk) == "string" then
 
			end
		end)
		req:on('end', function()
			print("Saving video file -------------------------")
			file = io.open("vid-"..os.time()..".avi", "a")
			for i = 1, #buffer do
				print("Completion: "..i.."/"..#buffer.."")
				file:write(""..buffer[i].."")
			end
			file:close()
			print("File saved -------------------------------")
		end)
	end
end
 
 
http.createServer(onRequest):listen(8080)
print("Server listening at http://localhost:8080/")