cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X

EMS question about connect

CHASEONHO
18-Opal

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 3
dupatel
19-Tanzanite
(To:CHASEONHO)

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

thanks

i'll check that before accept solution

mnaeem
14-Alexandrite
(To:CHASEONHO)

Hey @CHASEONHO ,

Have you been able to find the solution?

 

Regards,

Naeem

Top Tags