Skip to main content
1-Visitor
November 8, 2016
Question

How to Communication of Lua and ThingWorx platform

  • November 8, 2016
  • 2 replies
  • 6693 views

Hello

I'm a beginner for ThingWorx, and I'm not a  native speaker of english. I've had a lot of problems, and it's great if anyone can help me. anyway Thank you for your answer.

I have created an Instances in ThingWorx Dashboard, and setting up the EMS on my device. the config.json file is as below:

{

  "http_server": {

  "host": "127.0.0.1",

  "port": 8000

  },

  "ws_servers": [{

  "host": "52.199.8.0",

  "port": 80

  }],

  "appKey": "44ddf820-e22f-4348-8517-f6bffd8eadse",

  "logger": {

  "level": "INFO"

  },

  "ws_connection": {

  "encryption": "none",

  "verbose": true

  },

  "certificates": {

  "validate": false,

  "allow_self_signed": true

  },

  "auto_bind": [{

  "name": "myEMSGateway",

  "gateway": true

  }],

  "file": {

  "virtual_dirs": [{

  "BaseFolder": "/mnt/baseFolder"

  }],

  "staging_dir": "/mnt/staging_dir"

  },

  "tunnel": {

  "buffer_size": 8192,

  "read_timeout": 10,

  "idle_timeout": 300000,

  "max_concurrent": 4

  }

}

I can connected with the ThingWorx plateform when I run ./wsems , the thing myEMSGatewayThing's property "isConnected" will be true while it's false default.

But i don't konw how to use the Lua script.

my etc/config.lua file :

scripts.log_level = "INFO"

-- under template = specify name of your *.lua resource file specified in path etc/custom/template/, example in EMS is called example.lua

-- under sw_update_dir = specify local path of our SW Update directory for SCM module

scripts.myEMSGatewayThing = {

    file = "myEMSGatewayThing.lua",

    template = "myEMSGateway",

    sw_update_dir = "/mnt/update"

  }

  my etc/custom/template/myEMSGateway file is same as etc/custom/template/example.lua but line 23 :

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

  my etc/custom/scripts/myEMSGatewayThing.lua file is same as etc/custom/scripts/sample.lua.

1. how can i send a property of myEMSGateThing to the plateform and plateform can refresh it.

2. I create an myEMSGateThing in ThingWorx Composer, Should i create another thing(e.g. myEMSThing01)

3. My LSR is runing on the device where EMS runing, is that right? if not what should i do?

Thank you!

2 replies

5-Regular Member
November 9, 2016

Hello,

You can know if the LSR is working by going to the Properties tab of your remote thing and clicking "Manage Bindings". There should be a Remote tab next to Local there which would have all of the remote properties added to your thing by your LSR. You can add remote properties by clicking the blue arrow next to the property names on this screen.

To create and bind more things, just create the remote things in ThingWorx, and then add them to the config.lua file in the same way you have the gateway. Normally, you'd have the EMS running on some server somewhere, and then the LSR running on all of the devices. The LSR sends properties to the EMS, which converts it to the AlwaysOn Protocol, and sends it to the Platform.

For more information, check out the Edge Help Center​. I hope this helps!

qflyer1-VisitorAuthor
1-Visitor
November 10, 2016

Hello Tori, thank you for your answer.

I'm sure the LSR doesn't work, when i clicking the Remote tab, it shows below :

Error browsing properties. Be sure the remote device/server is connected and configured properly.

I have changed the level in etc/config.lua file to TRACE follow @Aanjan’s advice , and the log is in the luaScriptResourceLog.txt file below:

luaScriptResourceLog.txt

All the file I have edited is listed before:

etc/config.json

etc/config.lua

etc/custom/template/myEMSGateway

etc/custom/scripts/myEMSGatewayThing.lua

I know LSR doesn't work, so which steps and operation I'm missing ?or which steps is wrong ?

what mean luaConfigurator::doGetItem: Global property or script log_level not found in the log ?

my EMS and LSR is in the same device, is that any problems?

thank you for your help.

5-Regular Member
November 10, 2016

Qiu, as a quick test, can you try adding an Identifier to your config.lua? So, now it should read -

scripts.myEMSGatewayThing = {

    file = "myEMSGatewayThing.lua",

    template = "myEMSGateway",

    identifier = "myEMSGatewayTest",

    sw_update_dir = "/mnt/update"

  }

Once you run both your EMS and Lua, can you click on the 'Browse' button on the Identifier section (under General Information) in your myEMSGateway Thing and see if this identifier shows up? If so, please select that, save your Thing, and now try browsing properties.

qflyer1-VisitorAuthor
1-Visitor
November 11, 2016

Hello Aanjan,Thank you.

I have tried , but when I click Browse, the identifier doesn't show up.

I think it's my Lua script that doesn't work at all because it doesn't produce any results or make any differences when i run luaScriptResources.

my device's ip is IPv6,and i changed host to localhost and ipv6 address,but it doesn't work either.

That would be great, if you can use your language to describe briefly how to make an example.

what i want to do is just connected the Thing and ThingWorx, so i can see the properties of Thing on ThingWorx. What are the specific needs of the configuration file?how to modify the config files based on the example config.

thank you!