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

EMS question about connect

Highlighted
Level 12

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

2 REPLIES 2

Re: EMS question about connect

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

Re: EMS question about connect

thanks

i'll check that before accept solution