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

Thingworx and EMS

Re: Thingworx and EMS


   Just as you say, I have HC-SR04 UItrasonic senor .I want to send the data to thingworx Platform through Edge MicroServer(EMS)&LuaScriptResource(LUA). My EMS version is 5.3.2.


With your best regards!

Re: Thingworx and EMS

Would this GitHub - sza2/node_hcsr04: Distance measurement example for ESP8266/NodeMCU using HC-SR04 ultrasonic... help? I believe with this you can get going with reading data within your existing LSR setup together with EMS


Re: Thingworx and EMS

Hi Sushant, Wang,

The example Sushant shared seems close to connecting directly from Lua to a development board, however the board is not exactly Arduino, it's Node MCU which is based on the board that comes as a WiFi module for Arduino - ESP8266. It's not a big difference but it's not the same as a regular Arduino board. Interfacing Arduino boards (Nano, Uno, Mini etc.) with ESP8266 takes a bit of work to make them talk to each other, but again there's plenty of examples on how to do that. So if you don't mind using the ESP8266 and an Arduino board then what Sushant shared is a good way to start.


Re: Thingworx and EMS

Hi Wang, Aanjan Ravi​,

I am trying Raspberry Pi Quickstart documentation and stuck at Step 10(Run LSR). I am using EMS provided in the guide in beginning steps.

When i am running LSR it starts but it is giving error as

[INFO ] 2017-03-06 17:20:46,870 PiThing: ------------------------------------------------

[INFO ] 2017-03-06 17:20:48,838 PiThing: -- Starting script --------------------------

[INFO ] 2017-03-06 17:20:48,838 PiThing: Registering core callback handler

[INFO ] 2017-03-06 17:20:48,838 PiThing: Starting main loop

[INFO ] 2017-03-06 17:20:48,838 PiThing: Calling lifecycle start listeners.

[INFO ] 2017-03-06 17:20:48,838 shapes.propsubscribe: Initialized

[INFO ] 2017-03-06 17:20:48,839 thingworx.handler: Creating a new handler.

[WARN ] 2017-03-06 17:20:48,943 HttpClient::processReq: Authentication requested but no credentials supplied

[INFO ] 2017-03-06 17:20:48,944 PiThing: Error occured while accessing EMS. Checking isConnected.

[WARN ] 2017-03-06 17:20:49, 46 HttpClient::processReq: Authentication requested but no credentials supplied

[INFO ] 2017-03-06 17:20:49, 46 PiThing: MicroServer is now available.

[INFO ] 2017-03-06 17:20:49, 46 PiThing: EMS is available: true, online: false



"ws_servers": [{

"host": "",

"port": 8081


"http_server":  {

    "host": "",

    "port": 8081


"appKey": "213abab3-a234-4357-a1f7-49e59d6ac8db",

"logger":   {

    "level":    "DEBUG"


"auto_bind":    [{

        "name": "PiThing",

        "gateway":  false


"certificates": {

    "validate": false,

    "allow_self_signed":    true


"ws_connection":    {

    "encryption":   "none",

    "verbose":  true,

    "msg_timeout":  1000




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 = { baseType="NUMBER", pushType="ALWAYS", value=0 }


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#############")


--  if properties are successfully updated, return HTTP 200 code with a true service return value

return 200, true


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


tasks.refreshProperties = function(me)

log.trace("[PiTemplate]","~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In tasks.refreshProperties~~~~~~~~~~~~~ ")



Config.lua file

scripts.log_level = "INFO"

scripts.PiThing = {

    file = "thing.lua",

    template = "PiTemplate",

    scanrate = 1000,

    taskrate = 3000


scripts.rap_host = ""

scripts.rap_port = 8081

Since it worked for you can you please help what is the issue.

Is my below code ok?  When i tried using is was not even connecting to EMS.

scripts.rap_host = ""

scripts.rap_port = 8081

What is difference between WS or Http? I am new to Thingworx so excuse me for this basic question.

Re: Thingworx and EMS

Its working now. I was giving wrong http details. Thanks!!

Re: Thingworx and EMS

Hi Ravindra singh,

I am getting the same error as above.

Can you guide me how to give those details correctly?


Naveen Kumar

Re: Thingworx and EMS

Were you able to solve your problem?

Re: Thingworx and EMS


Thanks for this example it was exactly what I was looking for.
Next step would be to send data back to the Sense hat. If I get it right I will add to this.


Re: Thingworx and EMS

Hi BryanK,


If Gowresh_R response answered your question? kindly mark the reply as the Accepted Solution, this will benefit others in the Community. 


Thank you,