Implementation of ASTM TCP Server (Listener) has to be done as external Lua script. This external script can be executed using standalone Lua installation.
Suggested example was written using Lua 5.1 and expected to work with Lua 5.2 as well.
This example is using two Lua modules which may not be included with standard Lua binaries distribution. If your copy of Lua doesn’t have these two modules, then they can be obtained from Internet. These modules licensed with same license as Lua is.
Lua binaries can be downloaded from sourceforge.net.
Module JSON for Lua can be obtained from github.com.
LuaSocket reference can be found here.
Copy listed below scripts into single folder on other (not Iguana’s) machine.
What this sctript does?
- launches ASTM listener;
- accepts ASTM message from Iguana ASTM TCP Client;
- collects all good frames in Lua table (good means checksum is confirmed. find more comments in code.);
- converts Lua table into JSON object;
- does HTTP POST of JSON object to Iguana Web Server;
What this script requires?
- Lua binaries standalone installation.
- socket.lua module has to be installed (see Lua documentation for details)
- json.lua has to be installed (see Lua documentation for details)
- astmutil.lua (included)
- astmlistener.lua module (included)
Command line arguments for main.lua script:
- tcp port to listen on, default is 6557
- timeout to prevent blocking operation by TCP server, default is 10 msec
- webserver IP to send to. deafult is ‘localhost’
- webserver port, default is 6544
- webserver user, default is admin
- webserver password, default is password
- webserver path, default is astm
Example how to execute this script (in Windows notation):
- <project_folder>:\><path_to_Lua>\lua main.lua 6559 15 192.168.5.3 6545 admin password astm
Module astmlistener.lua has extensive debug logging.
To change logs level, comment/uncomment debug variable value assignment statements in code.
- Logs level 4 includes levels 3, 2, and 1;
- Logs level 3 includes 2 and 1; and so on …
- Level 3 is errors only
- Level 4 is complete log
Note: Windows Command Prompt window cannot display this script runtime log messages properly. Rather read this output from logs file or use a debugger. Having said that, this output will show all right in OS X terminal or in any *nix shell. Location of logs file have to be adjusted in astmutil.lua module in function astmutil.logs().
Module astmutil.lua contains functions to calculate checksum digits, write debug logs, and to send HTTP POST request to Iguana Web Server.
Note: The function calculating checksum digits may have to be adjusted to match specific interface design. In this example Checksum calculation is defined for ‘\r’ not ‘\n’ delimiters. Checksum is also defined to exclude <STX>, but to include either <ETX>, or <ETB>. In another environment it potentially can be different. Then algorithm in function astmutil.checksum() in module astmutil has to be adjusted.