How to get the thing name in LUA script file (EMS)
Hi,
I have an EMS running in a docker container. On thingworx side I have a parent device with different child devices (hierachy is build as property relation).
All devices are in auto_bind of config.json
"auto_bind": [
{
"name": "ParentDevice",
"gateway": false,
"host": "127.0.0.1"},
{
"name": "ChildDevice_01",
"gateway": false,
"host": "192.168.0.1"
},{
"name": "ChildDevice_02",
"gateway": false,
"host": "192.168.0.2"
}]
On Lua every device has its script-section
scripts.ParentDevice = {
file = "thing.lua",
template = "edgeBoxTemplate",
scanRate = 3000,
taskRate = 60000,
keepAliveRate = 10000
}
scripts.ChildDevice_01= {
file = "thing.lua",
template = "edgeBoxTemplate",
scanRate = 3000,
taskRate = 2000,
keepAliveRate = 10000
}
scripts.ChildDevice_02= {
file = "thing.lua",
template = "edgeBoxTemplate",
scanRate = 3000,
taskRate = 2000,
keepAliveRate = 10000
}
scripts.EdgeDevice = {
file = "EdgeDevice.lua"
}
Than I have a lua file in custom/tempaltes folder which define remote properties and services
For example:
properties.isAlive={baseType="BOOLEAN", pushType="ALWAYS", handler="script", key="EdgeDevice/property/isAlive" }
and a lua file in custom/scripts folder which define how the remote properties will get there values.
function property_isAlive(method, path, headers, query, data)
local resp = nil
if method == "GET" then
local ip = ReadFilesystemFile("/var/EdgeIoTConfig/ip")
local pingCall = "/var/EdgeIoTConfig/custom/bash/ping.sh " .. ip
local handle = io.popen(pingCall)
local result = handle:read("*a")
result = string.gsub(result, "[\r\n]", "")
handle:close()
if result == "0" then
resp = json.encode({
value = true,
time = os.time() * 1000,
quality = "GOOD"
})
else
resp = json.encode({
value = false,
time = os.time() * 1000,
quality = "GOOD"
})
end
else
return 405, "Only GET is allowed"
end
return 200, resp
end
At this moment I try to get the ip from a text file (filename: ip). But to ping the right physical device I need more ip files like ip_ChildDevice_01 or so. But how can I get the thing name in the lua script file?

