(this took me a couple of hours to solve correctly).
If you need to use http in lua, you need to add the module lua-socket.
You can't just grab any compiled lua-socket module from the web, because the .so files are specific to the hardware platform you use.
For Debian, the normal apt-get install will do to get the correct version:
Code: Select all
sudo apt-get install lua-socket
Domoticz expects the files to be in f.i. /usr/local/share/lua.
But in my Debian Jessy X86 system the system independent files (the .lua files) are located in: /usr/share/lua/5.2/
and the system dependent files (the .so files) are located in: /usr/lib/x86_64-linux-gnu/lua/5.2/.
If you then execute a script, you get the error: "module 'socket.core' not found" or "module 'socket.http' not found".
This is because the lua 'require' function cannot find these files in the default locations.
Before you call the following in your script;
Code: Select all
local http = require("socket.http")
Code: Select all
package.cpath ="/usr/lib/x86_64-linux-gnu/lua/5.2/?.so;" .. package.cpath
package.path = "/usr/share/lua/5.2/?.lua;" .. package.path
If the require function is executed, it will look in the correct folders first and the error will be gone.
The best method to solve this is to find the correct file locations first before adding the possible locations to the function above.
It is also possible to add more search locations by adding the following after the last semicolon:
Code: Select all
/folder-to-look-in/?.so;
Code: Select all
find /usr -name "core.so"