Skip to main content
1-Visitor
June 12, 2019
Solved

Thingworx connecting to Raspberry Pi

  • June 12, 2019
  • 4 replies
  • 1914 views

Hello,

 

i am trying to get the data from my PIR motion sensor to the remote PiThing i created in the Quickstart guide.

i added this code in the PiTemplate.lua

 

properties.PIR = { baseType="NUMBER", pushType="ALWAYS", value=0 }
local sensorCmd = io.popen("python etc/custom/templates/11.py")
s = sensorCmd:read("*a") properties.PIR.value = s

 

and i tried with 2 types (with and without a loop) of python code (the code works fine if i am trying it from terminal only in the raspberry Pi, does not work in TW) that i attached.

 

the other sensors as in the guide work just fine, only with this one i am not getting any data, event though the remote thing sees it as a property

 

can anyone please help?

 

Best answer by gabitudor

Managed to solve this. Apparently i was not sending anything to Lua because my Python script was composed of a void function that did not have a return statement. so i made a function that returns true when the movement is made.

4 replies

5-Regular Member
June 12, 2019

What is the value 's' after you read it in? Are you seeing any errors? I would also try using a property with a STRING type since you may be getting a null character, or carriage return, or EOF put into that variable

gabitudor1-VisitorAuthor
1-Visitor
June 13, 2019

thanks for the replay! i set the type as string but did not see any difference. no, i do not see errors and looks like 's' is having 0 as value, it sends 0 to Thingworx

gabitudor1-VisitorAuthor
1-Visitor
June 18, 2019

does anybody know how to make this work please?