Skip to main content
Jan 12, 2018 12:15 AM UTC
Question

EMS question about connect

A script written via Lua does not change the value

How do I get it updated at regular intervals?

After luaScriptResourse is executed in cmd, update the value only once at the first time.

module ("templates.PiTemplate", thingworx.template.extend)

    properties.cpu_temperature  =     { baseType="NUMBER",  pushType="ALWAYS", value=0 }

    properties.cpu_freq  =     { baseType="NUMBER",  pushType="ALWAYS", value=0 }

    properties.cpu_volt  =     { baseType="NUMBER",  pushType="ALWAYS", value=0 }

serviceDefinitions.GetSystemProperties(

output { baseType="BOOLEAN", description="" },

description { "updates properties" }

)

services.GetSystemProperties = function(me, headers, query, data)

log.trace("[PiTemplate]","########### in GetSystemProperties#############")

    queryHardware()

--  if properties are successfully updated, return HTTP 200 code with a true service return value

    return 200, true

end

function queryHardware()

local a = math.random(0,10)

local b = math.random(10,20)

local c = math.random(30,40)

     properties.cpu_volt.value = a

properties.cpu_freq.value = b

properties.cpu_temperature.value = c

end

tasks.refreshProperties = function(me)

queryHardware()

end

I want to update the value regularly with a random function.

Help plz

thanks

3 replies

Jan 17, 2018 2:01 PM UTC

seonho Cha​: I believe you can create Tasks in Lua which are functions that executes periodically by the ThingWorx Lua framework. They can be used to execute background tasks, monitor resources, and fire events. You can review the example.lua available ( microserver\etc\custom\templates) with the EMS setup package for more detail with an example usage.

-Durgesh

CHASEONHOAuthor
Jan 17, 2018 11:57 PM UTC

thanks

i'll check that before accept solution

Nov 19, 2019 12:54 PM UTC

Hey @CHASEONHO ,

Have you been able to find the solution?

 

Regards,

Naeem