how does one set the system time & date in a TS?
Is there a module to do it? I dont see any ability to set the system time win lua, only read it - no time.Set_current_time() function.
Thanks
Bruce
how does one set the system time & date in a TS?
Is there a module to do it? I dont see any ability to set the system time win lua, only read it - no time.Set_current_time() function.
Thanks
Bruce
This is possible using a couple of lua scripts, the HTTP Request module, and taking advantage of the ability to set Date and Time with HTTP API.
The HTTP Request host name would the be the IP Address of the Controller you want to change the time/date to. Path is /api/config.
For the rest of this example, I'm going to explain how to set the time, but setting the date is a similar process.
-Create a Startup trigger that executes a Lua script setting 3 global variables.
hour = "0" min = "0" sec = "0"
-Create a Soft trigger that executes a HTTP Make Request. Leave all settings to use instance default, except Data. Set Data to Variable 1 (enable trigger variables in your project file if not already)
-Create 3 Touch Slider Move triggers, each triggering a new Lua script with the following:
Hour
local slider = get_trigger_variable(1) hour = math.floor(slider/11.0869565217) set_control_caption("Hour", "Hour: "..hour)
This will get the value of the slider, convert it to 0-23 from 255, and change the label of the slider (in my case my slider's key was called "Hour") to display the new converted hour number for the user.
Minute
local slider = get_trigger_variable(1) min = math.floor(slider/4.32203389831) set_control_caption("Min", "Min: "..min)
This will get the value of the slider, convert it to 0-59 from 255, and change the label of the slider (in my case my slider's key was called "Min") to display the new converted minute number for the user.
Second
local slider = get_trigger_variable(1)
sec = math.floor(slider/4.32203389831)
set_control_caption("Sec", "Sec: "..sec)
This will get the value of the slider, convert it to 0-59 from 255, and change the label of the slider (in my case my slider's key was called "Sec") to display the new converted second number for the user.
-Create Touch Button Event trigger that triggers a new Lua script with the following:
local json = "{\"hour\":\""..hour.."\", \"minute\":\""..min.."\",\"second\":\""..sec.."\"}"
enqueue_trigger(2,json)
This will be a button to set the new time. It will grab the new global variable numbers for hour, minute, and second and put them into JSON format for the data of the HTTP Request. The script will then trigger the Soft Trigger (in my case trigger 2) that you created in Step 2 and passes the JSON data as a variable into the trigger and sending the HTTP Request to the controller.
Lastly, create an Interface with 3 sliders and 1 button with the appropiate keys for the above scripts and triggers to reference.
...or feature request this to be added to the LUA API.
Tested? I have not used the HTTP API with the new security "stuff" enabled, does it work if it is enabled? This is essentially what I was trying to guess at last night, but I was too lazy(tired?) to look through the API to see if it was documented.. so I captured the commit button on the default GUI instead and determined it was probably possible before responding with a nearly incoherent answer.
It was tested on a MTPC, but with 2.8.4 before all the security features were implemented. There would probably be an additional step or two to retrieve and pass a token if you have that security turned on.
www.etcconnect.com