Skip to content

Instantly share code, notes, and snippets.

@callumbrieske
Last active October 7, 2020 09:43
Show Gist options
  • Save callumbrieske/83591172dabc0adc6d8da58f375e79ea to your computer and use it in GitHub Desktop.
Save callumbrieske/83591172dabc0adc6d8da58f375e79ea to your computer and use it in GitHub Desktop.
json = require("rapidjson") -- Load the rapidjson library to parse the responses.
queryTimer = Timer.New()
-- Setup your server details here:
Server = {
Address = "127.0.0.1", -- The address of the server
--Port = 80, -- Optional, the port to connect on. Defaults to 80.
Timeout = 5, -- Time to wait for a responce before throwing an error.
QueryInterval = 10 -- How often to poll the endpoint. This should probably be longer than the timeout.
}
-- A generic function to generate a query for the server.
function queryServer(Query, Params)
print(("Sending query '%s' to server."):format(Query))
HttpClient.Download{
Url = HttpClient.CreateUrl{
Host = "http://" .. Server.Address, Port = Server.Port, Path = "api/delta/rpc/" .. Query,
Query = Params
},
Timeout = Server.Timeout,
EventHandler = function(t, c, d, e, h)
if c == 200 then
local responce = json.decode(d)
-- We can put some code in here to do useful things with the data. For now we will just print the results:
if responce.msg:find("getShortStatus called OK") then
print(("Got ShortStatus. Time: %s, Mode: %s"):format(responce.data.time, responce.data.mode))
end
else
print(("Error retreiving data: %d, %s"):format(c, e))
end
end
}
end
-- Setup out timer event.
queryTimer.EventHandler = function()
queryServer("getShortStatus", {tl = 1, smpte = "false"})
end
-- Start the timer once we have everything ready.
queryTimer:Start(Server.QueryInterval)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment