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,
Till now I've seen that the services and properties have been defined in Rasperry Pi and then bounded to the remote thing in thingworx.
My question is that is the opposite is possible i.e to call the service of Thingworx Remote Thing in Raspberry Pi?
For example-
Firstly Thingworx: MyThing with remoteThing is having a service AddSignal
Secondly RPi: How can I call that already exist service (AddSignal) in RPi using LUA script.
Thank You!
Best Regards,
Naeem
Through Calling the REST api command would work.
https://www.ptc.com/en/support/article?n=CS287763&posno=1&q=rest%20api%20ems&source=search
https://www.ptc.com/en/support/article?n=CS278679&posno=2&q=rest%20api%20ems&source=search
Sorry @zyuan1 for late response.
I tried to understand the articles that you have mentioned in your previous post.
As I'm newbie, it's difficult.
Can you please give a basic example of how to get the value of a property in using Rest API in lua.
Thank you!
Naeem
Hi @zyuan1 @slangley
My question is same as the following.
https://community.ptc.com/t5/ThingWorx-Developers/Sending-Data-from-thingworx-to-ems/td-p/517930
But not able to find any answer.
Thank You!
Naeem
You may want to try this: https://developer.thingworx.com/resources/guides/thingworx-raspberry-pi-quickstart
The lua script customization is out of support, you may need to learn that through public webpage.
Thank you @zyuan1
I've already followed this tutorial, could you please help me to understand me intasks.refreshProperties = function(me)
, it is refering to what in this example, if I'd like to use it? I'd be really thankful for explanation.
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