Page 1 of 1

lua socket require socket.http and socket.core problem and solution

Posted: Monday 23 October 2017 15:46
by bbqkees
Just in case anyone has the same problem when trying to run lua-socket on Debian on X86 (Intel NUC):
(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
But this will install the files in a different location than where Lua in Domoticz expects.

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")
add;

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
These two lines prepend the default search locations with the actual folders the files are in.
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;
If you can't find where the files are installed you can use f.i.

Code: Select all

find /usr -name "core.so"

Re: lua socket require socket.http and socket.core problem and solution

Posted: Wednesday 14 August 2019 14:39
by Derik
i do have the same error in my system..
Please explane how to use this option..

Thanks

Re: lua socket require socket.http and socket.core problem and solution

Posted: Wednesday 25 March 2020 9:12
by hansonexperience
I have the same problem after updating to buster. How can I use your solution?

Re: lua socket require socket.http and socket.core problem and solution

Posted: Wednesday 25 March 2020 10:04
by cabbie
Hi,

I'm using domoticz for a couple of years now, and never required to register to this forum to solve issues.
however after installing the V2020.1 version my domoticz setup is broken regarding the lua issues.

Above solution partly solved my issue, when I add the code as below:

Code: Select all

----------------------------------------------------------------------------------------------------------
-- Require parameters
----------------------------------------------------------------------------------------------------------
package.cpath ="/usr/lib/arm-linux-gnueabihf/lua/5.2/?.so;" .. package.cpath
package.path = "/usr/share/lua/5.2/?.lua;" .. package.path
local http = require("socket.http")
I get the next error message:

Code: Select all

2020-03-25 09:58:02.267 Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_device_calculate_consumption.lua: error loading module 'socket.core' from file '/usr/lib/arm-linux-gnueabihf/lua/5.2/socket/core.so':
2020-03-25 09:58:02.267 /usr/lib/arm-linux-gnueabihf/lua/5.2/socket/core.so: undefined symbol: lua_gettop
anyone know how to solve this issue?

Re: lua socket require socket.http and socket.core problem and solution

Posted: Thursday 26 March 2020 8:48
by ErikM
cabbie wrote: Wednesday 25 March 2020 10:04 Hi,

I'm using domoticz for a couple of years now, and never required to register to this forum to solve issues.
however after installing the V2020.1 version my domoticz setup is broken regarding the lua issues.

Above solution partly solved my issue, when I add the code as below:

Code: Select all

----------------------------------------------------------------------------------------------------------
-- Require parameters
----------------------------------------------------------------------------------------------------------
package.cpath ="/usr/lib/arm-linux-gnueabihf/lua/5.2/?.so;" .. package.cpath
package.path = "/usr/share/lua/5.2/?.lua;" .. package.path
local http = require("socket.http")
I get the next error message:

Code: Select all

2020-03-25 09:58:02.267 Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_device_calculate_consumption.lua: error loading module 'socket.core' from file '/usr/lib/arm-linux-gnueabihf/lua/5.2/socket/core.so':
2020-03-25 09:58:02.267 /usr/lib/arm-linux-gnueabihf/lua/5.2/socket/core.so: undefined symbol: lua_gettop
anyone know how to solve this issue?
I'm facing the exact same problem since updating to V2020.1... Tried changing folders, lua5.2 to 5.3 etc, but no result.

Edit: I solved the issue by putting -- in front of the lines in the script. Apparently they are not required anymore.

Re: lua socket require socket.http and socket.core problem and solution

Posted: Thursday 26 March 2020 14:01
by cabbie
ErikM wrote: Thursday 26 March 2020 8:48
cabbie wrote: Wednesday 25 March 2020 10:04 .
I'm facing the exact same problem since updating to V2020.1... Tried changing folders, lua5.2 to 5.3 etc, but no result.

Edit: I solved the issue by putting -- in front of the lines in the script. Apparently they are not required anymore.
Specifically for the script I quoted it isn't required anymore, however I still require the socket.http in another LUA script to upload data to pvoutput.

so my problem still persists.

never mind. I converted my script to dzVents zo no more Lua required...

Re: lua socket require socket.http and socket.core problem and solution

Posted: Saturday 28 March 2020 14:01
by DiaDomo
Hi Cabbie,

I have the same problem with the lua script "script_time_upload_to_PVOutput.lua".

Code: Select all

2020-03-28 13:35:00.054 Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_time_upload_to_PVoutput.lua: .../domoticz/scripts/lua/script_time_upload_to_PVoutput.lua:47: attempt to index a nil value (global 'http')
Unfortunately I'm not very familiar with dzVents (yet). Could you please share your solution?

Thx in advance

Re: lua socket require socket.http and socket.core problem and solution

Posted: Saturday 28 March 2020 18:08
by waaren
DiaDomo wrote: Saturday 28 March 2020 14:01 I have the same problem with the lua script "script_time_upload_to_PVOutput.lua".
Unfortunately I'm not very familiar with dzVents (yet). Could you please share your solution?
You can find a dzVents pvoutput script here


When not yet familiar with dzVents please start with reading Get started Before implementing (~ 5 minutes). Special attention please for "In Domoticz go to Setup > Settings > Other and in the section EventSystem make sure the checkbox 'dzVents enabled' is checked. Also make sure that in the Security section in the settings you allow 127.0.0.1 to not need a password. dzVents uses that port to send certain commands to Domoticz. Finally make sure you have set your current location in Setup > Settings > System > Location, otherwise there is no way to determine nighttime/daytime state."