Skip to main content
Nov 14, 2019 8:02 PM UTC
Question

Updating property using same header read function

Hello,
After following the IoT Connectivity with Thingworx course, I'd like to understand if is it possible to use on handler for more than one properties.

For Example:

I'd like to update signal1, signal2 and signal3 values 0 or 1, but it doesn't seem to work for me. 
SolarCollector1.lua:
properties.Signal1 = { baseType=“NUMBER”, pushType=“NEVER”, value=1, handler=“signalhandler” }

properties.Signal2 = { baseType=“NUMBER”, pushType=“NEVER”, value=1, handler=“signalhandler” }

properties.Signal3 = { baseType=“NUMBER”, pushType=“NEVER”, value=1, handler=“signalhandler” }

 

signalhandler.lua:
function read(me, pt, headers, query)
log.info(p_data.name, “Entering Signal Read Handler Function”)

– use csvtools to get last line
csvtools = require(“csvtools”)
file = io.open(“c:\EMS\microsever\logs\signal_log.csv”)
local lastline = csvtools.getLastLine(file)

 

local signalName = pt.name   --For example Signal1

local rightColumn = 0

csvtable = csvtools.csvfile2table(file)

for k,v in ipairs(csvtable) do

        for k2,v2 in ipairs(v) do

                 if v == signalName  then

                          rightColumn = k

                  end

       end

end

local timestamp = tonumber(lastline[1])

pt.value = tonumber(lastline[rightcolumn]
pt.time = tostring(os.time())
pt.quality = “GOOD”

pt.next = nil
tw_mutex.unlock()

return 200
end

2 replies

Nov 19, 2019 8:34 PM UTC

Hi @mnaeem.

 

It is possible to send mutliple properties to the platform with one handler.  What error are you seeing?  Can you provide the logs?

 

We also recommend taking a look at the sample scripts that come with the EMS download.  In particular, we recommend reviewing the example.lua template as it has several examples of property pushes using various handler types.

 

Regards.

 

--Sharon

Dec 11, 2019 7:50 PM UTC

Hi @mnaeem.

 

If the previous response helped to answer your question, please mark it as the Accepted Solution for the benefit of others with the same question.  Otherwise, please provide the logs previously requested for further review of the issue.

 

Regards.

 

--Sharon