Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X
Hello,
I´m trying to connect a Raspberry Pi 3 with thingwork. I have been following the instructions of this guide, http://developer.thingworx.com/guides/thingworx-raspberry-pi-quickstart?page=1
The problem is that when I try to run the LSR, it send me this error:
Thanks for the help!!!
José, can you copy and attach the entire log file to this thread (both EMS and LSR)? Have you bound this identifier, PiThing to a Remote Thing on the platform? Please do add your config.json and config.lua as well.
I didn´t bound the PiThing to a Remote Thing...
And this are my files
the EMS:
{
"ws_servers": [{
"host": "34.200.94.171",
"port": 80
}],
"resource": "Thingworx/WS",
"http_server": {
"host": "127.0.0.1",
"port": 8080
},
"appkey": "c5bef579-93a5-40ea-a50a-712edf8c2dac",
"logger": {
"level": "TRACE | INFO "
},
"auto_bind": [{
"name": "PiThing",
}],
"certificates": {
"validate": false,
"allow_self_signed": true
},
"ws_connection": {
"encryption": "none",
"verbose": true,
"msg_timeout": 1000
}
}
The LSR:
scripts.log_level = "INFO"
scripts.PiThing = {
file = "thing.lua",
template = "PiTemplate" ,
identifier = "PiThing",
scanrate = 1000,
taskrate = 30000
}
scripts.rap_host = "127.0.0.1"
scripts.rap_port = 8080
and finally the template:
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 = {baseTypes = "NUMBER", pushType="ALWAYS",value=0}
serviceDefinitions.GetSystemProperties(
output { baseType = "BOOLEAN", description = ""},
description { "updates properties" }
)
-- service input parameters
-- me: table that refers to the Thing
-- headers: table of HTTP headers
-- query: query parameters from the HTTP request
-- data: lua table containing the parameters to the service call.
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()
-- use the vcgencmd shell command to get raspberry pi system values and assign to variables
-- measure_temp returns value in Celsius
-- measure_clock arm returns value in Hertz
-- measure_volts returns balue in Volts
local tempCmd = io.popen("vcgencmd measure_temp")
local freqCmd = io.popen("vcgencmd measure_clock arm")
local voltCmd = io.popen("vcgencmd measure_volts core")
-- set property temperature
local s = tempCmd:read("*a")
s = string.match(s,"temp=(%d+\.%d+)");
log.debug("[PiTemplate]",string.format("temp %.1f",s))
properties.cpu_temperature.value = s
-- set property frequency
s = freqCmd:read("*a")
log.debug("[PiTemplate]",string.format("raw freq %s",s))
s = string.match(s,"frequency%(45%)=(%d+)");
s = s/1000000
log.debug("[PiTemplate]",string.format("scaled freq %d",s))
properties.cpu_freq.value = s
-- set property volts
s = voltCmd:read("*a")
log.debug("[PiTemplate]",string.format("raw volts %s", s))
s = string.match(s,"volt=(%d+\.%d+)");
log.debug("[PiTemplate]",string.format("scaled volts %.1f", s))
properties.cpu_volt.value = s
end
tasks.refreshProperties = function(me)
log.trace("[PiTemplate]","~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In tasks.refreshProperties~~~~~~~~~~~~~ ")
queryHardware()
end
I didn´t bound the PiThing and the Remote Thing....
the are the codes:
EMS:
{
"ws_servers": [{
"host": "34.200.94.171",
"port": 80
}],
"resource": "Thingworx/WS",
"http_server": {
"host": "127.0.0.1",
"port": 8080
},
"appkey": "c5bef579-93a5-40ea-a50a-712edf8c2dac",
"logger": {
"level": "TRACE | INFO "
},
"auto_bind": [{
"name": "PiThing",
}],
"certificates": {
"validate": false,
"allow_self_signed": true
},
"ws_connection": {
"encryption": "none",
"verbose": true,
"msg_timeout": 1000
}
}
LSR:
scripts.log_level = "INFO"
scripts.PiThing = {
file = "thing.lua",
template = "PiTemplate" ,
identifier = "PiThing",
scanrate = 1000,
taskrate = 30000
}
scripts.rap_host = "127.0.0.1"
scripts.rap_port = 808
Template:
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 = {baseTypes = "NUMBER", pushType="ALWAYS",value=0}
serviceDefinitions.GetSystemProperties(
output { baseType = "BOOLEAN", description = ""},
description { "updates properties" }
)
-- service input parameters
-- me: table that refers to the Thing
-- headers: table of HTTP headers
-- query: query parameters from the HTTP request
-- data: lua table containing the parameters to the service call.
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()
-- use the vcgencmd shell command to get raspberry pi system values and assign to variables
-- measure_temp returns value in Celsius
-- measure_clock arm returns value in Hertz
-- measure_volts returns balue in Volts
local tempCmd = io.popen("vcgencmd measure_temp")
local freqCmd = io.popen("vcgencmd measure_clock arm")
local voltCmd = io.popen("vcgencmd measure_volts core")
-- set property temperature
local s = tempCmd:read("*a")
s = string.match(s,"temp=(%d+\.%d+)");
log.debug("[PiTemplate]",string.format("temp %.1f",s))
properties.cpu_temperature.value = s
-- set property frequency
s = freqCmd:read("*a")
log.debug("[PiTemplate]",string.format("raw freq %s",s))
s = string.match(s,"frequency%(45%)=(%d+)");
s = s/1000000
log.debug("[PiTemplate]",string.format("scaled freq %d",s))
properties.cpu_freq.value = s
-- set property volts
s = voltCmd:read("*a")
log.debug("[PiTemplate]",string.format("raw volts %s", s))
s = string.match(s,"volt=(%d+\.%d+)");
log.debug("[PiTemplate]",string.format("scaled volts %.1f", s))
properties.cpu_volt.value = s
end
tasks.refreshProperties = function(me)
log.trace("[PiTemplate]","~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In tasks.refreshProperties~~~~~~~~~~~~~ ")
queryHardware()
end
If you go to the Unbound tab in Monitoring -> Remote Things, do you see 'PiThing' there when the LuaScriptResource is also running? If so, please navigate back to your Remote Thing, click on browser in the Identifier section (in General Information), select PiThing and save your Remote Thing.
I recently tried to connect my Raspberry Pi using this method. I got it to work but it was a long and painful process. I recommend using Node Red to connect to ThingWorx in the future. It's a lot more user friendly and you can program using JavaScript instead of LuaScript.
Here's a great guide on how to do this: Drag and Drop Edge Device Development with ThingWorx, Node.js and Node Red
Error 500 is an internal server error and it is temporary,,please clear your browser history and cookies ,,restart browser and restart ./wsems and ./luaScriptResource by changing mode i.e sudo chmod 775