Setting system time on a TS.... with lua?

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

  • Hi Bruce; 

    You can set the time at upload or via the webui. 

  • so no way to do it at a touch screen, without using an external laptop?

  • Smartphone or tablet with ethernet dongle? Grimacing
    This is something I have never actually needed but I used to want the ability to do..

    I am really tired so i don't know if I am about to type will make any sense.. You submit a form with 6 variables when you hit the commit button on the default GUI after changing date/time. It shouldn't be an impossible feature. I have never taken the time to try "spoofing" actions from the default GUI but you might be able to duplicate that form submission 

  • Depending on what you are trying to achieve it would be possible to write a script which you enter a offset to real time.

    So having a timed event which runs every 5 minutes and gets the real time then checks what your offset should be and then if it matches one of your programmed times which will need to be stored in lua table then you can do an action.

    Its a load of lua and if timed events want to be changes it will require edits to the lua to be done.

    What is the application for this, the only time i have know to need to edit times on the fly would be a curse ship which moves between time zones??

  • What about dealing with a drifing clock?  I guess I haven't played with Mosaic enough to know for sure, but I know that Paradigm clocks often will drift off by a few mins a year.  This is an independent processor with no time server access.

  • Mosaic has the ability to connect to an external NTP server to sync time if time drift is a concern. 

  • SO a few things here.

    • The drift here is minimal compared to Paradigm
    • You can set it up to have time server access, We do this shipboard A LOT :-)
    • You can change it at the webui which essentially is the customer interface

    I completely understand your concerns, but the number of customer reports of incorrect time or drift has been minimal.  This doesn't mean that it has not happened, but not often enough that you need a direct customer-facing tool on the touchscreen. 

  • Its an independent system, so time server access.

    I will trust you about the clock's stability...but if the Elfs start singing and dancing out of hours...I know who to blame.

    As always, thank you

    BK

  • 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. 

  • Thank you.  

    Unfortunately. time is not on my side and I had to skip implimenting this.  But this very much makes sense. 

Related