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

Moderator: leecollings

Post Reply
User avatar
bbqkees
Posts: 407
Joined: Sunday 17 August 2014 21:01
Target OS: Linux
Domoticz version: 4.1x
Location: The Netherlands
Contact:

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

Post 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"
Bosch / Nefit / Buderus / Junkers / Worcester / Sieger EMS bus Wi-Fi MQTT Gateway and interface boards: https://bbqkees-electronics.nl/
Derik
Posts: 1602
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

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

Post by Derik »

i do have the same error in my system..
Please explane how to use this option..

Thanks
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
User avatar
hansonexperience
Posts: 12
Joined: Thursday 19 October 2017 14:24
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.1
Location: the Netherlands
Contact:

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

Post by hansonexperience »

I have the same problem after updating to buster. How can I use your solution?
Solar: pvoutput, solarman, JFY inverter, enelogic, slimmemeterportal, Greenchoice
Weather: Davis VUE ISS, meteobridge wunderground, Asus WL -330N3G, leuven template
Website: http://www.hansonexperience.com / http://www.mooiweerboxtel.nl
cabbie
Posts: 2
Joined: Wednesday 25 March 2020 10:00
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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?
ErikM
Posts: 8
Joined: Monday 23 March 2020 10:09
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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.
cabbie
Posts: 2
Joined: Wednesday 25 March 2020 10:00
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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...
DiaDomo
Posts: 37
Joined: Saturday 28 March 2020 13:55
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

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

Post 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
Raspberry PI 2 & 3 & 4 | RFlink | MySensors | ESP32 | Homebridge | Tasmota Sonoff | Zigbee2Mqtt | ADS-B
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

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

Post 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."
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest