2 Replies Latest reply on Jan 17, 2018 6:57 PM by scha-2 RSS
    scha-2 Apprentice

    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