Unable to use ssl.https on raspberry pi
Posted: Saturday 27 January 2018 19:51
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:
The Error I get is:
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.
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
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)
Second question: how do I get path the reported Error?
Thanks.