Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X
Hi All,
I am following modbus example from Modbus PLC Simulator, ThingWorx and You
This is my ws_servers & auto_bind section of config.json
"ws_servers": [ {
"host": "192.168.0.94",
"port": 8443
} ],
"appKey": "9311c13b-69a1-49fa-9e22-00bd9fe8c333",
"auto_bind": [ {
"name": "ModbusGateway",
"gateway": true
} ],
and config.lua
scripts.MyPLC = {
file = "thing.lua",
template = "modbusExample",
identifier = "plc",
updateRate = 2000
}
scripts.Thingworx = {
file = "thingworx.lua"
}
scripts.modbus_handler = {
file = "modbus_handler.lua",
name = "modbus_handler",
host = "192.168.0.94",
port = "502"
}
The problem is that I can bind remote properties to a created thing but could not able to read modbus registries.
I am getting following error.
pi@raspberrypi:~/microserver/install_services $ sudo journalctl --unit=tw_luaScriptResourced | tail -20
Oct 21 15:36:01 raspberrypi thingworx[5648]: ScriptResource::executeScriptRequest:Path /scripts/modbus_handler/holding_register/1/40001/ not found
Oct 21 15:36:01 raspberrypi thingworx[5648]: luaInterscriptBinding::l_executeCallback:Error executing callback 'modbus_handler//scripts/modbus_handler/holding_register/1/40001'
Returned: 404 /scripts/modbus_handler/holding_register/1/40001/ not found
Oct 21 15:36:01 raspberrypi thingworx[5648]: MyPLC:Could not read current value of Int16HoldRegExample. Setting quality to UNKNOWN. Resp:
Oct 21 15:36:01 raspberrypi thingworx[5648]: MyPLC:Error while getting property Int16HoldRegExample. msg: /scripts/modbus_handler/holding_register/1/40001/ not found
Oct 21 15:36:04 raspberrypi thingworx[5648]: ScriptResource::executeScriptRequest:Path /scripts/modbus_handler/holding_register/1/40001/ not found
Oct 21 15:36:04 raspberrypi thingworx[5648]: luaInterscriptBinding::l_executeCallback:Error executing callback 'modbus_handler//scripts/modbus_handler/holding_register/1/40001'
Returned: 404 /scripts/modbus_handler/holding_register/1/40001/ not found
Oct 21 15:36:04 raspberrypi thingworx[5648]: MyPLC:Could not read current value of ScaledInt16RegExample. Setting quality to UNKNOWN. Resp:
Oct 21 15:36:04 raspberrypi thingworx[5648]: MyPLC:Error while getting property ScaledInt16RegExample. msg: /scripts/modbus_handler/holding_register/1/40001/ not found
Oct 21 15:36:04 raspberrypi thingworx[5648]: ScriptResource::executeScriptRequest:Path /scripts/modbus_handler/holding_register/1/40002/ not found
Oct 21 15:36:04 raspberrypi thingworx[5648]: luaInterscriptBinding::l_executeCallback:Error executing callback 'modbus_handler//scripts/modbus_handler/holding_register/1/40002'
Returned: 404 /scripts/modbus_handler/holding_register/1/40002/ not found
Oct 21 15:36:04 raspberrypi thingworx[5648]: MyPLC:Could not read current value of Uint16RegExample. Setting quality to UNKNOWN. Resp:
Oct 21 15:36:04 raspberrypi thingworx[5648]: MyPLC:Error while getting property Uint16RegExample. msg: /scripts/modbus_handler/holding_register/1/40002/ not found
Oct 21 15:36:04 raspberrypi thingworx[5648]: ScriptResource::executeScriptRequest:Path /scripts/modbus_handler/holding_register/1/40001/ not found
Oct 21 15:36:04 raspberrypi thingworx[5648]: luaInterscriptBinding::l_executeCallback:Error executing callback 'modbus_handler//scripts/modbus_handler/holding_register/1/40001'
Returned: 404 /scripts/modbus_handler/holding_register/1/40001/ not found
Oct 21 15:36:04 raspberrypi thingworx[5648]: MyPLC:Could not read current value of Int16HoldRegExample. Setting quality to UNKNOWN. Resp:
Oct 21 15:36:04 raspberrypi thingworx[5648]: MyPLC:Error while getting property Int16HoldRegExample. msg: /scripts/modbus_handler/holding_register/1/40001/ not found
am I missing something?
2nd query is how to log the messages from luaScriptResource when its running as service? config.lua does not have logger section.
Solved! Go to Solution.
Hello Mithun,
I recently found some industrial units based on the Raspberry Pi and were quite excited about the possibilities.
Unfortunately I encountered the same issues with both my standard Raspberry Pi and these new ones.
I identified two problems on my side:
1. The modbusExample.lua tries to load file transfer functionality.
2. There is something wrong with the supplied core.so file (maybe it was not compiled for ARM architecture) - you get No such file or directory
[ERROR] when running the luaResource.
To fix the 1st issue is easy... just remove the require "thingworx.shapes.filetransfer" line from modbusExample.lua.
To fix the second issue you need to find a core.so file which is compatible with the ARM Architecture of your Raspberry Pi. In theory, the core.os file supplied as part of the TWEMS MODBUS Package_Linux_ARM.zip file located at microserver/etc/community/clibs/socket/core.so should work, but it does not.
Download the lua-socket resource:
$ sudo apt-get install lua-socket
Copy the newly downloaded core.so to your microserver installation:
$ cp /usr/lib/arm-linux-gnueabihf/lua/5.1/socket/core.so /home/pi/microserver/etc/community/clibs/socket/
Now if your config files are configured correctly, then everything should work.
Good luck!
Mithun, can you output the luaScriptResource onto a log file by running the following?
luaScriptResource > logfile.log
When you run both the EMS and lua, does the Modbus sim show a successful connection?
Ravi,
When i type the command
luaScriptResource > logfile.log
i get following error.
luaScriptResource: command not found
Sorry I am new to Linux.
Yes When I run EMS & Lua services, in Thingworx I can see Identifier for remote thing also I can browse remote properties, only thing is values are not getting updated.
When I type the command
sudo journalctl --unit=Thingworx_Lua | tail -50 (here Thingworx_Lua is my service name from lua script)
get following result
pi@raspberrypi:~/microserver/install_services $ sudo journalctl --unit=Thingworx_Lua | tail -50
Returned: 404 /scripts/modbus_handler/holding_register/1/40001/ not found
Oct 21 19:34:44 raspberrypi thingworx[3844]: luaInterscriptBinding::l_executeCallback:Error executing callback 'modbus_handler//scripts/modbus_handler/holding_register/1/40001'
Returned: 404 /scripts/modbus_handler/holding_register/1/40001/ not found
Oct 21 19:34:44 raspberrypi thingworx[3844]: luaInterscriptBinding::l_executeCallback:Error executing callback 'modbus_handler//scripts/modbus_handler/holding_register/1/40002'
Returned: 404 /scripts/modbus_handler/holding_register/1/40002/ not found
Oct 21 19:34:44 raspberrypi thingworx[3844]: luaInterscriptBinding::l_executeCallback:Error executing callback 'modbus_handler//scripts/modbus_handler/holding_register/1/40001'
Returned: 404 /scripts/modbus_handler/holding_register/1/40001/ not found
Oct 21 19:34:47 raspberrypi thingworx[3844]: luaInterscriptBinding::l_executeCallback:Error executing callback 'modbus_handler//scripts/modbus_handler/holding_register/1/40001'
Returned: 404 /scripts/modbus_handler/holding_register/1/40001/ not found
Oct 21 19:34:47 raspberrypi thingworx[3844]: luaInterscriptBinding::l_executeCallback:Error executing callback 'modbus_handler//scripts/modbus_handler/holding_register/1/40002'
Returned: 404 /scripts/modbus_handler/holding_register/1/40002/ not found
Oct 21 19:34:47 raspberrypi thingworx[3844]: luaInterscriptBinding::l_executeCallback:Error executing callback 'modbus_handler//scripts/modbus_handler/holding_register/1/40001'
Returned: 404 /scripts/modbus_handler/holding_register/1/40001/ not found
Oct 21 19:34:50 raspberrypi thingworx[3844]: luaInterscriptBinding::l_executeCallback:Error executing callback 'modbus_handler//scripts/modbus_handler/holding_register/1/40001'
Returned: 404 /scripts/modbus_handler/holding_register/1/40001/ not found
Oct 21 19:34:50 raspberrypi thingworx[3844]: luaInterscriptBinding::l_executeCallback:Error executing callback 'modbus_handler//scripts/modbus_handler/holding_register/1/40002'
Returned: 404 /scripts/modbus_handler/holding_register/1/40002/ not found
Oct 21 19:34:50 raspberrypi thingworx[3844]: luaInterscriptBinding::l_executeCallback:Error executing callback 'modbus_handler//scripts/modbus_handler/holding_register/1/40001'
Returned: 404 /scripts/modbus_handler/holding_register/1/40001/ not found
Oct 21 19:35:05 raspberrypi systemd[1]: Stopping LSB: ThingWorx Lua Script Resource...
Oct 21 19:35:05 raspberrypi logger[3904]: Stopping ThingWorx Lua Script Resource luaScriptResource
Oct 21 19:35:05 raspberrypi Thingworx_Lua[3899]: start-stop-daemon: warning: this system is not able to track process names
Oct 21 19:35:05 raspberrypi Thingworx_Lua[3899]: longer than 15 characters, please use --exec instead of --name.
Oct 21 19:35:21 raspberrypi thingworx[3844]: HttpClient::processReq:Timeout while waiting for response from localhost.
Oct 21 19:35:21 raspberrypi thingworx[3844]: luaBindings::httpPost:Error POSTing to HTTP Server at localhost/Thingworx/Things/LocalEms/Services/HasEdgeThing
Oct 21 19:35:35 raspberrypi systemd[1]: Stopped LSB: ThingWorx Lua Script Resource.
Oct 21 19:35:48 raspberrypi systemd[1]: Starting LSB: ThingWorx Lua Script Resource...
Oct 21 19:35:48 raspberrypi logger[3944]: Starting ThingWorx Lua Script Resource luaScriptResource
Oct 21 19:35:48 raspberrypi thingworx[3948]: daemonize:Child process running
Oct 21 19:35:48 raspberrypi thingworx[3948]: psrap::daemonize:Child creating session id...
Oct 21 19:35:48 raspberrypi thingworx[3948]: psrap::daemonize:Child continuing...
Oct 21 19:35:48 raspberrypi thingworx[3948]: psrap::daemonize:Child closing out stdin,stdout,stderr...
Oct 21 19:35:48 raspberrypi thingworx[3948]: /home/pi/microserver/install_services/..//luaScriptResource:Using config file: /home/pi/microserver/install_services/..//etc/config.lua
Oct 21 19:35:48 raspberrypi thingworx[3948]: /home/pi/microserver/install_services/..//luaScriptResource:Starting up ....
Oct 21 19:35:48 raspberrypi logger[3949]: 0
Oct 21 19:35:48 raspberrypi systemd[1]: Started LSB: ThingWorx Lua Script Resource.
Oct 21 19:35:48 raspberrypi thingworx[3948]: luaScriptProxy::execute:[1972368464] Error executing script modbus_handler, Error = Error: error loading module 'socket.core' from file '/home/pi/microserver/install_services/..//etc/community/clibs/socket/core.so':
/home/pi/microserver/install_services/..//etc/community/clibs/socket/core.so: cannot open shared object file: No such file or directory
Oct 21 19:35:48 raspberrypi thingworx[3948]: luaScriptProxy::app_unlock:[1972368464] Attempt to unlock app_mutex while not holding it.L= 0x759144e8
Oct 21 19:35:48 raspberrypi thingworx[3948]: httpServer:starting http server port=502
Oct 21 19:35:48 raspberrypi thingworx[3948]: httpserver:Server socket error: Address not available [192.168.0.94:502]
Oct 21 19:35:48 raspberrypi thingworx[3948]: httpServer:unable to bind http server to any port from 502 to 502.
Oct 21 19:35:51 raspberrypi thingworx[3948]: luaInterscriptBinding::l_executeCallback:Error executing callback 'modbus_handler//scripts/modbus_handler/holding_register/1/40001'
Returned: 404 /scripts/modbus_handler/holding_register/1/40001/ not found
Oct 21 19:35:51 raspberrypi thingworx[3948]: luaInterscriptBinding::l_executeCallback:Error executing callback 'modbus_handler//scripts/modbus_handler/holding_register/1/40002'
Returned: 404 /scripts/modbus_handler/holding_register/1/40002/ not found
Oct 21 19:35:51 raspberrypi thingworx[3948]: luaInterscriptBinding::l_executeCallback:Error executing callback 'modbus_handler//scripts/modbus_handler/holding_register/1/40003'
Returned: 404 /scripts/modbus_handler/holding_register/1/40003/ not found
Oct 21 19:35:51 raspberrypi thingworx[3948]: luaInterscriptBinding::l_executeCallback:Error executing callback 'modbus_handler//scripts/modbus_handler/holding_register/1/40001'
Returned: 404 /scripts/modbus_handler/holding_register/1/40001/ not found
In this this result I feel these are the lines which are hinting something
Oct 21 19:35:48 raspberrypi systemd[1]: Started LSB: ThingWorx Lua Script Resource.
Oct 21 19:35:48 raspberrypi thingworx[3948]: luaScriptProxy::execute:[1972368464] Error executing script modbus_handler, Error = Error: error loading module 'socket.core' from file '/home/pi/microserver/install_services/..//etc/community/clibs/socket/core.so':
/home/pi/microserver/install_services/..//etc/community/clibs/socket/core.so: cannot open shared object file: No such file or directory
Oct 21 19:35:48 raspberrypi thingworx[3948]: luaScriptProxy::app_unlock:[1972368464] Attempt to unlock app_mutex while not holding it.L= 0x759144e8
Oct 21 19:35:48 raspberrypi thingworx[3948]: httpServer:starting http server port=502
Oct 21 19:35:48 raspberrypi thingworx[3948]: httpserver:Server socket error: Address not available [192.168.0.94:502]
Oct 21 19:35:48 raspberrypi thingworx[3948]: httpServer:unable to bind http server to any port from 502 to 502.
I am using following EMS and modbus package
MED-61060-CD-053_SP2_Microserver-5-3-2-Linux-ARM-HWFPU.zip
TWEMS MODBUS Package_Linux_ARM.zip
You would need to stop the lua service, navigate to /home/pi/microserver (assuming that's where the luaScriptResource file is) and then run ./luaScriptResource > log.log
That should pipe the output onto the log file. Going by this message -
Oct 21 19:35:48 raspberrypi thingworx[3948]: httpserver:Server socket error: Address not available [192.168.0.94:502]
Is the sim actually running/ connected? If you have the EMS and lua running, and along with the sim, the sim should say something on the lines of Connected (1/10) to show successful connection via port 502 (default port).
Thanks Ravi, Please find the attached lua.log file.
Yes the simulator is running on the machine 192.168.0.94 but its showing
Connected(0/10)
One more query, do I need to configure
host="some.host.com"
port=5222
jid="Something@thingworx.com"
password="somthing"
agent.log_level = "WARN"
scripts.script_resource_host="0.0.0.0"
scripts.log_level="WARN"
scripts.keepAliveRate = 6000
this section in config.lua
The errors are most likely due to the fact that the sim is actually not connected to the platform, as it can't find the holding registers. Here's my config.lua that's using the default modbusExample Template-
scripts.log_level = "TRACE"
scripts.script_resource_port = 12001
scripts.keepAliveRate = 6000
scripts.Thingworx = {
file = "thingworx.lua"
}
scripts.ModbusThing = {
file = "thing.lua",
template = "modbusExample",
updateRate = 2000
}
scripts.modbus_handler = {
file = "modbus_handler.lua",
name = "modbus_handler",
host = "my_ip",
read_timeout = 5
}
By turning off the windows firewall, and configuring following section in config.lua
scripts.script_resource_host="198.168.0.94"
scripts.script_resource_port="512"
scripts.log_level="WARN"
scripts.keepAliveRate = 6000
I got Modbus simulator connected,
but still its not transferring the data
Please find attached log file.
It says address '192.168.0.87:502' not available along with that port in your new set of logs. Do retry with the config.lua I've posted above (with the firewall off for now).
With these changes also its not working.
What is the difference between
scripts.script_resource_host, scripts.script_resource_port and
host and port available in scripts.modbus_handler section?
if i give
scripts.script_resource_host = ip on which modbus simulator running
scripts.script_resource_port = 502
Then my modbus simulator shows as connected but with no data transfer.
But if I comment out scripts.script_resource_host or change the value, even simulator not shows as connected.
Do I need to do any changes on Raspberry side?
Instead of Modbus simulator we tried to connect actual Modbus sensor (which work if we run EMS & Lua on windows machine.)
Instead of raspberry this time we try to run EMS & Lua on ubuntuMate on raspberry but Lua script still giving same issues.
Please find attached log file.
Which ever the the port we give for scripts.script_resource_port, we get following error
httpserver: Server socket error: Address already in use [127.0.0.1:port_no]
I am not sure but I feel these line are the culprit.
[ERROR] 2016-12-12 15:26:09,882 luaScriptProxy::execute: [1982854224] Error executing script modbus_handler, Error = Error: error loading module 'socket.core' from file '/home/wft/microserver/etc/community/clibs/socket/core.so':
/home/wft/microserver/etc/community/clibs/socket/core.so: cannot open shared object file: No such file or directory
[ERROR] 2016-12-12 15:26:09,882 luaScriptProxy::app_unlock: [1982854224] Attempt to unlock app_mutex while not holding it.L= 0xfc3ea0
Hello Mithun,
I recently found some industrial units based on the Raspberry Pi and were quite excited about the possibilities.
Unfortunately I encountered the same issues with both my standard Raspberry Pi and these new ones.
I identified two problems on my side:
1. The modbusExample.lua tries to load file transfer functionality.
2. There is something wrong with the supplied core.so file (maybe it was not compiled for ARM architecture) - you get No such file or directory
[ERROR] when running the luaResource.
To fix the 1st issue is easy... just remove the require "thingworx.shapes.filetransfer" line from modbusExample.lua.
To fix the second issue you need to find a core.so file which is compatible with the ARM Architecture of your Raspberry Pi. In theory, the core.os file supplied as part of the TWEMS MODBUS Package_Linux_ARM.zip file located at microserver/etc/community/clibs/socket/core.so should work, but it does not.
Download the lua-socket resource:
$ sudo apt-get install lua-socket
Copy the newly downloaded core.so to your microserver installation:
$ cp /usr/lib/arm-linux-gnueabihf/lua/5.1/socket/core.so /home/pi/microserver/etc/community/clibs/socket/
Now if your config files are configured correctly, then everything should work.
Good luck!
Thanks Duan Gauche,
I did the same thing and its works for me too
There is issue in core.so file provided by PTC for Modbus package -ARM processor.
My pleasure!