cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X

Calling the service defined in Thingworx in Raspberry Pi?

mnaeem
14-Alexandrite

Calling the service defined in Thingworx in Raspberry Pi?

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

6 REPLIES 6
slangley
23-Emerald II
(To:zyuan1)

Hi @mnaeem.

 

If the response provided by @zyuan1 answered your question, please mark it as the Accepted Solution for the benefit of others with the same question.

 

Regards.

 

--Sharon

mnaeem
14-Alexandrite
(To:zyuan1)

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

mnaeem
14-Alexandrite
(To:mnaeem)

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.

mnaeem
14-Alexandrite
(To:zyuan1)

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

 

Top Tags