Page 1 of 1

No JSON from script, only from browser

Posted: Thursday 30 March 2017 10:40
by remcog
Hi, I'm pretty new to Domoticz and scripting there so I hope someone can shine a light on this.

In LUA I tried;

1. commandArray['OpenURL']='http://127.0.0.1:8080/json.htm?type=com ... ge=MESSAGE'

2. os.execute('curl -s "http://username:[email protected] ... ge=MESSAGE" &')

I found them as examples but both don't work. Not when created in the event system in the GUI nor placed in the scripts/lua directory.

when I try;

curl -s "http://username:[email protected] ... ge=MESSAGE"

on the command line again no success, without username and password I get a reply unauthorized, so the command is doing something.


only executing

http://192.168.100.150:8080/json.htm?ty ... ge=MESSAGE

in a browser works

does anyone have an idea?

Re: No JSON from script, only from browser

Posted: Thursday 30 March 2017 13:56
by lonebaggie
I Use Json call in my scripts without issue . See the enigma script

https://www.domoticz.com/forum/viewtopi ... 38&t=16866

Cannot see anything wrong do you use username and password in Domoticz settings ?

Re: No JSON from script, only from browser

Posted: Thursday 30 March 2017 19:45
by lonebaggie
Just went through my notes again . I also had issues with Json commands. Are you suffering from this

https://www.domoticz.com/forum/viewtopic.php?t=13906

LUa seems to produce an illegal character when sending some Json calls . I had to reorder the call in order to make it work

check your output for a command¶m

Re: No JSON from script, only from browser

Posted: Thursday 30 March 2017 20:05
by Westcott
It's the browser replacing &para with a paragraph character.

Re: No JSON from script, only from browser

Posted: Thursday 30 March 2017 21:18
by remcog
lonebaggie wrote:Just went through my notes again . I also had issues with Json commands. Are you suffering from this<br abp="338"><br abp="339">https://www.domoticz.com/forum/viewtopic.php?t=13906<br abp="340"><br abp="341">LUa seems to produce an illegal character when sending some Json calls . I had to reorder the call in order to make it work<br abp="342"><br abp="343">check your output for a command¶m
Smart trick with the print(cmd) didn't think about that. it's indeed this problem. Do you know the trick to work around this or do I need to wait for a bugfix?

Re: No JSON from script, only from browser

Posted: Thursday 30 March 2017 23:20
by lonebaggie
Looking at the forum the bug been there a while .

I'm sure I found the fix in the forum but I cannot find it. What you need to do is reorder the Json command in my case I wanted to update a user variable.

The documented command is this :-

json.htm?type=command&param=updateuservariable&vname=USERVARIABLENAME&vtype=USERVARIABLETYPE&vvalue=USERVARIABLEVALUE

The command&param causes the bug , no idea why , but if you reorder the Json command to this :-

json.htm?param=updateuservariable&type=command&vname=USERVARIABLENAME&vtype=USERVARIABLETYPE&vvalue=USERVARIABLEVALUE

It works barmy :D

Re: No JSON from script, only from browser

Posted: Saturday 01 April 2017 0:01
by remcog
reordering indeed fixed that part of the problem, funny thing is that still the json command is not executed but when I copy the string from the log and enter it in a browser it works like a charm. any other ideas?

Re: No JSON from script, only from browser

Posted: Saturday 01 April 2017 1:04
by lonebaggie
I had some timeout errors until I added &" at the end of the curl command.

Try something simple to prove the OS is working OK. Cut and paste everyone else code until something sticks ! No idea, if the output works in a browser
must be something in the interaction with the command line ?

Re: No JSON from script, only from browser

Posted: Sunday 02 April 2017 16:52
by remcog
@lonebaggie, you were totally right, I kept trying and funny enough for me the solution was removing the &.
Don't have a clue why this is not working with the commandArray['OpenURL'] but I'm happy this works with curl now.

thanks for your support