Trying to run LUA Script got error 'popen' not supported-osx

Moderator: leecollings

karde
Posts: 24
Joined: Monday 04 January 2016 16:57
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.7412
Location: Sweden
Contact:

Trying to run LUA Script got error 'popen' not supported-osx

Post by karde »

Hi,

I'm trying to run a battery check script (http://www.domoticz.com/wiki/Battery_level_check).
I have installed JQ with brew, but when Domoticz try to run the script I get the following error in domoticz log:
"Error: EventSystem: /Users/johan/domoticz/scripts/lua/script_time_battery.lua:37: 'popen' not supported"

Don't know what popen is, but as I understand this has something to do with Lua?
I have also tried to install LUA (and have curl installed as well), is there someway you can check that you have popen installed? Is there any path you have to change in domoticz? :/
In a terminal window in osx I can successfully type:

MacMiniVpn:~ johan$ lua
Lua 5.2.4 Copyright (C) 1994-2015 Lua.org, PUC-Rio
> popen
>>

Thanks for any help!!
karde
Posts: 24
Joined: Monday 04 January 2016 16:57
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.7412
Location: Sweden
Contact:

Re: Trying to run LUA Script got error 'popen' not supported

Post by karde »

Hi,

So the error is on line 37, right? :/ tried to change a bunch os stuff but is there any better way you can test the script and see what the error might be?
Is there any better way to see battery level than the script? Get notifications and so forth..

This is what I have on line 37

local handle = io.popen("/usr/local/bin/jq -r '.\"" .. DeviceName .. "\" | values' " .. DeviceFileName)

Have the server on a MacMini osx with JQ | LUA and Curl installed.

Thanks!
Johan
simonrg
Posts: 329
Joined: Tuesday 16 July 2013 22:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8807
Location: North East England
Contact:

Re: Trying to run LUA Script got error 'popen' not supported

Post by simonrg »

karde wrote:This is what I have on line 37
local handle = io.popen("/usr/local/bin/jq -r '.\"" .. DeviceName .. "\" | values' " .. DeviceFileName)
Have the server on a MacMini osx with JQ | LUA and Curl installed.
The error suggests that popen is not implemented in the version of Lua inside the Mac OSX version of Domoticz. The version you have installed is not the version executed by Domoticz. In test of Lua you haven't actually completed a popen command, so that version may not have popen.

Even if you didn't have the popen issue, the script is set up to run on a Raspberry Pi, everything will be different on Mac OSX.

/usr/local/bin/jq is the path to jq on Linux, so on your Mac OSX where is jq executable - could be something like /Users/yourname/jq/jq. You will also need to make sure that the user Domoticz runs under is allowed to execute jq.

Try in your external version of Lua something like io.popen("jq") and see if that give an error other than popen not implemented, if so then try to correct the battery script with the correct paths for Mac OSX for jq you might not need a path, Mac OSX may just find it, try in Domoticz and see if you get a different error message.

Good luck, Simon
Raspberry Pi 2 B - 2A@5V PSU - Raspbian + Domoticz + RFXtrx(89), LightwaveRF House(dimmers, sockets, wireless/mood switches), Owl CM113, 4 LaCross Temp / Humidity Sensors, 4 Siemens PIR, Smappee, Solaredge, ESP8266
karde
Posts: 24
Joined: Monday 04 January 2016 16:57
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.7412
Location: Sweden
Contact:

Re: Trying to run LUA Script got error 'popen' not supported

Post by karde »

Hmm, ok :/, but the path for jq seems to be /usr/local/bin for me, but, I see that the filename in the script is called "JsonAllDevData", and jq -r says:
-r output raw strings, not JSON texts;

Isn't the user which you installed domoticz the user that's trying to execute.., it should be johan.
lrwxr-xr-x 1 johan admin 24 Jan 12 22:40 jq -> ../Cellar/jq/HEAD/bin/jq
I have version 1.5 of jq though.

"
MacMiniVpn:bin johan$ pwd
/usr/local/bin
MacMiniVpn:bin johan$ jq -r
jq - commandline JSON processor [version ]

Usage:

jq [options] <jq filter> [file...]

jq is a tool for processing JSON inputs, applying the given filter to
its JSON text inputs and producing the filter's results as JSON on
standard output.

The simplest filter is ., which copies jq's input to its output
unmodified (except for formatting, but note that IEEE754 is used
for number representation internally, with all that that implies).

For more advanced filters see the jq(1) manpage ("man jq")
and/or https://stedolan.github.io/jq

Example:

$ echo '{"foo": 0}' | jq .
{
"foo": 0
}

Some of the options include:
-c compact instead of pretty-printed output;
-n use `null` as the single input value;
-e set the exit status code based on the output;
-s read (slurp) all inputs into an array; apply filter to it;
-r output raw strings, not JSON texts;
-R read raw strings, not JSON texts;
-C colorize JSON;
-M monochrome (don't colorize JSON);
-S sort keys of objects on output;
--tab use tabs for indentation;
--arg a v set variable $a to value <v>;
--argjson a v set variable $a to JSON value <v>;
--slurpfile a f set variable $a to an array of JSON texts read from <f>;

See the manpage for more options."


Sorry, but what do you mean by:
"Try in your external version of Lua something like io.popen("jq")"

Thank you for your help!!
simonrg
Posts: 329
Joined: Tuesday 16 July 2013 22:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8807
Location: North East England
Contact:

Re: Trying to run LUA Script got error 'popen' not supported

Post by simonrg »

karde wrote:Try in your external version of Lua something like io.popen("jq")
Start Lua by typing Lua, then enter:

Code: Select all

io.popen("/usr/local/bin/jq")
Press return and see what is returned.

However, it would appear that if jq was in the same place as Linux, then no reason why popen shouldn't have worked in the script, so it would appear that for whatever reason the popen is not implemented in the Mac OSX Domoticz Lua.
Raspberry Pi 2 B - 2A@5V PSU - Raspbian + Domoticz + RFXtrx(89), LightwaveRF House(dimmers, sockets, wireless/mood switches), Owl CM113, 4 LaCross Temp / Humidity Sensors, 4 Siemens PIR, Smappee, Solaredge, ESP8266
karde
Posts: 24
Joined: Monday 04 January 2016 16:57
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.7412
Location: Sweden
Contact:

Re: Trying to run LUA Script got error 'popen' not supported

Post by karde »

Thanks!
Getting this:

MacMiniVpn:bin johan$ lua
Lua 5.2.4 Copyright (C) 1994-2015 Lua.org, PUC-Rio
> io.popen("/usr/local/bin/jq")
>
>
>
no return... but no failure.
Should it work then? Do you think this mean that no LUA script will work on OS X distribution of Domoticz :/, that's a bummer then..
simonrg
Posts: 329
Joined: Tuesday 16 July 2013 22:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8807
Location: North East England
Contact:

Re: Trying to run LUA Script got error 'popen' not supported

Post by simonrg »

karde wrote:Should it work then? Do you think this mean that no LUA script will work on OS X distribution of Domoticz :/, that's a bummer then..
Ok, so we now know that there is a version of Lua on Mac OSX in which popen is implemented.

Lua is working in Domoticz for you, as you are getting the error about popen, so it is just a matter of getting a different version of Lua included within Domoticz.

Have you installed Domoticz from a binary or compiled it?

Best bet now is to find somebody who is building Domoticz on Mac OSX and seek their advice.
Raspberry Pi 2 B - 2A@5V PSU - Raspbian + Domoticz + RFXtrx(89), LightwaveRF House(dimmers, sockets, wireless/mood switches), Owl CM113, 4 LaCross Temp / Humidity Sensors, 4 Siemens PIR, Smappee, Solaredge, ESP8266
karde
Posts: 24
Joined: Monday 04 January 2016 16:57
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.7412
Location: Sweden
Contact:

Re: Trying to run LUA Script got error 'popen' not supported

Post by karde »

:/ Ok, thanks for your help!
compiled from the below source, with this guide "https://www.domoticz.com/wiki/Mac_OS_X"

git clone https://github.com/domoticz/domoticz.git domoticz
DrMacabre
Posts: 74
Joined: Monday 26 December 2016 16:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.11590
Location: France
Contact:

Re: Trying to run LUA Script got error 'popen' not supported-osx

Post by DrMacabre »

Hello,

I'm running into a similar issue with a different script.

Just to make sure, i tried lua command with no success but i had lua52 installed.

Code: Select all

root@domoticz:/ # lua                                                           
lua: Command not found.                                                         
root@domoticz:/ # lua52                                                         
Lua 5.2.4  Copyright (C) 1994-2015 Lua.org, PUC-Rio                             
> io.popen("/usr/local/bin/jq")                                                 
> /usr/local/bin/jq: not found                                                  
                              
any idea why its not working from within domoticz ?

Thanks
User avatar
Siewert308SW
Posts: 290
Joined: Monday 29 December 2014 15:47
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: The Netherlands
Contact:

Re: Trying to run LUA Script got error 'popen' not supported-osx

Post by Siewert308SW »

DrMacabre wrote:Hello,

I'm running into a similar issue with a different script.

Just to make sure, i tried lua command with no success but i had lua52 installed.

Code: Select all

root@domoticz:/ # lua                                                           
lua: Command not found.                                                         
root@domoticz:/ # lua52                                                         
Lua 5.2.4  Copyright (C) 1994-2015 Lua.org, PUC-Rio                             
> io.popen("/usr/local/bin/jq")                                                 
> /usr/local/bin/jq: not found                                                  
                              
any idea why its not working from within domoticz ?

Thanks
As it aint a Domoticz issue but Raspberry issue.
If im correct then i did the following when i ran into the same problem.

Code: Select all

sudo apt-get update

sudo apt-get install build-essential

sudo apt-get install jq
If all goes well then i amended the battery script.
And changed "/usr/local/bin/jq" to "/usr/bin/jq"
Setup:
- RPi4 - Domo Stable / Aeotec Z-stick7 / PiHole Unbound Gemini
- RPi4 - PiHole / PiVPN Unbound Gemini
- Synology DS923+ / DS218j
- P1 Gas/Power, SmartGateway watermeter
- Fibaro switches, contacts, plugs, smoke/Co2 ect
- rootfs @ USB HDD
trixwood

Re: Trying to run LUA Script got error 'popen' not supported-osx

Post by trixwood »

On mac if you have homebrew installed:

Code: Select all

brew install jq
DrMacabre
Posts: 74
Joined: Monday 26 December 2016 16:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.11590
Location: France
Contact:

Re: Trying to run LUA Script got error 'popen' not supported-osx

Post by DrMacabre »

Sorry, i forgot to mention i'm on freenas trying to run the Lux Sensor script which has nothing to do with JQ.

Still, i have this popen not supported error and no one seems to have a clue why. :/
trixwood

Re: Trying to run LUA Script got error 'popen' not supported-osx

Post by trixwood »

if popen is not supported try using

os.execute

and save the output to a file in the tmp file, read that...
DrMacabre
Posts: 74
Joined: Monday 26 December 2016 16:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.11590
Location: France
Contact:

Re: Trying to run LUA Script got error 'popen' not supported-osx

Post by DrMacabre »

trixwood wrote:if popen is not supported try using

os.execute

and save the output to a file in the tmp file, read that...
Good, at least it's going to the next line :D
  • 2016-12-27 11:10:00.600 Error: EventSystem: in Lux Sensor: [string "--[[ Virtual Lux sensor and other real-t..."]:66: attempt to index local 'config' (a boolean value)
Here is the part of the script causing problem. May be i should open a different topic for this.
trixwood

Re: Trying to run LUA Script got error 'popen' not supported-osx

Post by trixwood »

What i mean was as workaround:

http://lua-users.org/wiki/OsLibraryTutorial

non tested code:

Code: Select all

-- tmpfile = /tmp/whatever.tmp
-- or let lua generate one
tmpfile = os.tmpname()
-- pipes to file 'curl http://api.wunderground.com/api/....json/ > /tmp/whatever.tmp'
command = 'curl http://api.wunderground.com/api/'..wuAPIkey..'/conditions/q/'..countryCode..'/'..city..'.json') .. ' > ' .. tmpfile
-- 'popen' has output direct, but with 'execute' its in the file...
os.execute(command)
local config = io.open(tmpfile, "r")
local location = config:read("*all")
config:close()
DrMacabre
Posts: 74
Joined: Monday 26 December 2016 16:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.11590
Location: France
Contact:

Re: Trying to run LUA Script got error 'popen' not supported

Post by DrMacabre »

Thank you very much, I'll give it a try.
DrMacabre
Posts: 74
Joined: Monday 26 December 2016 16:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.11590
Location: France
Contact:

Re: Trying to run LUA Script got error 'popen' not supported-osx

Post by DrMacabre »

hi, missing a ( before 'curl http://
local location = config:read('*all') instead of ("*all") may be ?

still getting an error.
2016-12-29 05:05:00.018 Error: EventSystem: in Lux Sensor 2: [string "--[[ Virtual Lux sensor and other real-t..."]:76: attempt to index local 'config' (a nil value)
trixwood

Re: Trying to run LUA Script got error 'popen' not supported-osx

Post by trixwood »

well looking at the code:

Code: Select all

command = 'curl http://api.wunderground.com/api/'..wuAPIkey..'/conditions/q/'..countryCode..'/'..city..'.json') .. ' > ' .. tmpfile
there is a typo i think... there should be no )

Code: Select all

command = 'curl http://api.wunderground.com/api/'..wuAPIkey..'/conditions/q/'..countryCode..'/'..city..'.json' .. ' > ' .. tmpfile
but it was pseudo code...but i have no running domoticz at the moment to test anything...
DrMacabre
Posts: 74
Joined: Monday 26 December 2016 16:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.11590
Location: France
Contact:

Re: Trying to run LUA Script got error 'popen' not supported-osx

Post by DrMacabre »

ok. i removed the ) error is still here (a nil value)

thats weird, i've read the whole topic about this script, seems to be working pretty fine for everyone with a lot of debugging since the origin of the code.

thanks for your help.
DrMacabre
Posts: 74
Joined: Monday 26 December 2016 16:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.11590
Location: France
Contact:

Re: Trying to run LUA Script got error 'popen' not supported-osx

Post by DrMacabre »

I've tested the api, it returns all the proper data btw.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest