No JSON from script, only from browser

Moderator: leecollings

Post Reply
remcog
Posts: 5
Joined: Thursday 30 March 2017 0:35
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

No JSON from script, only from browser

Post 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?
User avatar
lonebaggie
Posts: 86
Joined: Tuesday 31 January 2017 13:21
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: England
Contact:

Re: No JSON from script, only from browser

Post 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 ?
User avatar
lonebaggie
Posts: 86
Joined: Tuesday 31 January 2017 13:21
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: England
Contact:

Re: No JSON from script, only from browser

Post 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
User avatar
Westcott
Posts: 423
Joined: Tuesday 09 December 2014 17:04
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: UK - Glos
Contact:

Re: No JSON from script, only from browser

Post by Westcott »

It's the browser replacing &para with a paragraph character.
Zwave - Sigma Z+ stick, Fibaro, Horstmann, Neo Coolcam, EUROtronic
RFlink - IR detectors and temperatures
Wifi - YeeLights, ESP32s, Anoop sockets
Zigbee - lots with zigbee2mqtt and ZbBridge
remcog
Posts: 5
Joined: Thursday 30 March 2017 0:35
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: No JSON from script, only from browser

Post 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?
User avatar
lonebaggie
Posts: 86
Joined: Tuesday 31 January 2017 13:21
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: England
Contact:

Re: No JSON from script, only from browser

Post 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
remcog
Posts: 5
Joined: Thursday 30 March 2017 0:35
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: No JSON from script, only from browser

Post 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?
User avatar
lonebaggie
Posts: 86
Joined: Tuesday 31 January 2017 13:21
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: England
Contact:

Re: No JSON from script, only from browser

Post 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 ?
remcog
Posts: 5
Joined: Thursday 30 March 2017 0:35
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: No JSON from script, only from browser

Post 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
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest