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

Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X

EMS fails to fire remote events

???-31
1-Newbie

EMS fails to fire remote events

Hello,

I've been testing remote events on EMS based on example.lua, but never succeeded..

With scripts below, I can successfully connect to TW platform and bind to a local Thing.

I can add remote services (Add and FireExampleEvent) from "Browse Remote Services" on the platform,

and actually testing "Add" service works perfectly.

However, "FireExampleEvent" service never works, and returns

Unable to Invoke Service FireExampleEvent on LSR_VM_002 : null

I can see no remote events from "Browse Remote Events", but it seems to be natural because we have no definition of events in the lua scripts like services.

So I manually added a remote event "ExampleEvent", and its datashape is ExampleEvent, which has value, label, count and time fields.

But still going wrong...

I used "PCEMS" from DevWorx and version of TW platform is 6.5.

I would really appreciate if you could give me any advice.

Regards,

S.Yamabe

config.json

{

  "ws_servers": [{

  "host": "hostname (not localhost)",

  "port": 80

  }],

  "appKey": "appkey",

  "ws_connection": {

  "encryption": "none",

  "verbose": true

  },

  "logger": {

  "level": "WARN",

  "publish_directory": "D:/EMSDemo/logs/",

  "publish_level": "WARN",

  "max_file_storage": 2000000,

  "auto_flush": true

  }

}

config.lua

scripts.log_level = "TRACE"

scripts.EdgeThing = {

    file = "thing.lua",

    template = "example",

    identifier = "ident"

}

templates/example.lua

module ("templates.example", thingworx.template.extend)

dataShapes.ExampleEvent(

  { name = "value", baseType = "STRING" },

  { name = "label", baseType = "STRING" },

  { name = "count", baseType = "INTEGER" },

  { name = "time",  baseType = "DATETIME" }

)

serviceDefinitions.Add(

  input { name="p1", baseType="NUMBER", description="The first addend of the operation" },

  input { name="p2", baseType="NUMBER", description="The second addend of the operation" },

  output { baseType="NUMBER", description="The sum of the two parameters" },

  description { "Add two numbers" }

)

serviceDefinitions.FireExampleEvent(

  input { name="value", baseType="STRING", description="String Data For the event" },

  output { baseType="NOTHING", description="" },

  description { "Fire the ExampleEvent" }

)

services.Add = function(me, headers, query, data)

  if not data.p1 or not data.p2 then

    return 400, "You must provide the parameters p1 and p2"

  end

  return 200, data.p1 + data.p2

end

services.FireExampleEvent = function(me, headers, query, data)

  if not data.value then

    return 400, "You must provide the 'value' parameter."

  end

  me.example_event_count = (me.example_event_count or 0) + 1

  tw_mutex.lock()

  local ds = DataShape.ExampleEvent:clone()

  tw_mutex.unlock()

  local it = tw_infotable.createInfoTable(ds)

  local success, err = it:addRow({

    value = data.value,

    label = me.name,

    count = me.example_event_count,

    time = os.time() * 1000

  })

  if err then return 400, err end

  return server.fireEvent("ExampleEvent", it:toTable())

end

+ A log file is attached.

1 ACCEPTED SOLUTION

Accepted Solutions
Aanjan
9-Granite
(To:???-31)

Yamabe, I believe this was fixed in the 5.3.1 version of the EMS. We had an issue where firing events through the EMS would result as firing a service in the platform, thereby failing. Please retry using the 5.3.1 EMS.

View solution in original post

2 REPLIES 2
Aanjan
9-Granite
(To:???-31)

Yamabe, I believe this was fixed in the 5.3.1 version of the EMS. We had an issue where firing events through the EMS would result as firing a service in the platform, thereby failing. Please retry using the 5.3.1 EMS.

???-31
1-Newbie
(To:Aanjan)

Aanjan Ravi  worte:

Yamabe, I believe this was fixed in the 5.3.1 version of the EMS. We had an issue where firing events through the EMS would result as firing a service in the platform, thereby failing. Please retry using the 5.3.1 EMS.

Now it works nicely!

Thanks.

Top Tags