Page 1 of 1

Unable to use ssl.https on raspberry pi

Posted: Saturday 27 January 2018 19:51
by xraken
I'm trying to make a https GET request from a lua script, the script runs fine if I run the script from the bash shell (with the device stuff stubbed) but when I run it from within the scripts/lua directory there were path issues that I tried to fix but I still get an error.
Here's the code:

Code: Select all

package.path = package.path .. ';/usr/share/lua/5.2/?.lua;/usr/share/lua/5.2/?/?
.lua'
package.cpath = package.cpath .. ';/usr/lib/arm-linux-gnueabihf/lua/5.2/?.so;/us
r/lib/arm-linux-gnueabihf/lua/5.2/?/?.so'

print(_VERSION)
print("LUA MODULES:\n",(package.path:gsub("%;","\n\t")),"\n\nC MODULES:\n",(pack
age.cpath:gsub("%;","\n\t")))

local http = require("ssl.https")
local ltn12 = require("ltn12")

devicename = "One Temperature" --Name of the device
debug = false
commandArray = {}
if (devicechanged[devicename]) then
	
	newtemp = devicechanged[devicename.."_Temperature"]
	response_body = {}
	request_body = ""
	local url = "https://graph.api.smartthings.com/api/smartapps/installatio
ns/88888888-3333-2222-1111-aaaaaaaaaaaa/update/"..newtemp.."/F/"
	local rbody, rcode, rheaders, rstatus = http.request{
	      method = "GET",
	      headers = {
     	      ["Authorization"] = "Bearer 88888888-3333-2222-1111-bbbbbbbbbbbb",
    	      ["Content-Length"] = string.len(request_body)
     	    },
	    url = url,
	    source = ltn12.source.string(request_body),
 	    sink = ltn12.sink.table(response_body)
	}
	print("ST return code: "..rcode)
end
return commandArray
The Error I get is:

Code: Select all

Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_device_temps.lua: /usr/share/lua/5.2/ssl.lua:11: attempt to call global 'module' (a nil value)
First question is: how can I fix the raspberry path issues in a more elegant way?
Second question: how do I get path the reported Error?

Thanks.

Re: Unable to use ssl.https on raspberry pi

Posted: Sunday 28 January 2018 0:16
by simonrg
xraken wrote: Saturday 27 January 2018 19:51First question is: how can I fix the raspberry path issues in a more elegant way?
Second question: how do I get path the reported Error?
Not sure how you have installed the libraries.
I have found that following these instructions on a Raspberry Pi means that the libraries work in Lua:
https://www.domoticz.com/wiki/Remote_Co ... _Libraries
I believe that will fix both of your errors and means you can ignore all the complicated path stuff, as the libraries and their support files will be where Lua expects them.

Re: Unable to use ssl.https on raspberry pi

Posted: Sunday 28 January 2018 3:17
by xraken
Appreciate the response but a manual copy to a system folder is not the right way to do it even though it may temporarily get around the problem. I need to find a way to get domoticz lua scripts to work with the default apt-get installed directory locations so future updates to lua will continue to work. I'm hoping to avoid hacking my way through.

Re: Unable to use ssl.https on raspberry pi

Posted: Sunday 28 January 2018 14:59
by xraken
Figured out the paths. Here it is for anyone else running into the same problem on Raspberry Pi:

Code: Select all

package.path = package.path .. ';/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua;/usr/local/lib/lua/5.1/?.lua;/usr/local/lib/lua/5.1/?/init.lua;/usr/share/lua/5.1/?.lua;/usr/share/lua/5.1/?/init.lua;/usr/share/lua/5.2/?.lua;/usr/share/lua/5.2/?/?.lua'
package.cpath = package.cpath .. ';/usr/local/lib/lua/5.1/?.so;/usr/lib/arm-linux-gnueabihf/lua/5.1/?.so;/usr/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/loadall.so;/usr/lib/arm-linux-gnueabihf/lua/5.2/?.so;/usr/lib/arm-linux-gnueabihf/lua/5.2/?/?.so'
This includes paths for both 5.1 and 5.2 (you may not need both).
If you just copy the lua files to your root directories as suggested in the Wiki you will not be able to upgrade lua cleanly when using apt-get.

Re: Unable to use ssl.https on raspberry pi

Posted: Sunday 28 January 2018 16:18
by simonrg
xraken wrote: Sunday 28 January 2018 3:17 Appreciate the response but a manual copy to a system folder is not the right way to do it even though it may temporarily get around the problem. I need to find a way to get domoticz lua scripts to work with the default apt-get installed directory locations so future updates to lua will continue to work. I'm hoping to avoid hacking my way through.
Totally agree but how did you install the libraries.

If installed via a package then you shouldn't need to set the paths manually in Lua.

Previously the http Lua Libraries weren't packaged, are they now?