Using domoticz.openURL()

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
Olgmo
Posts: 23
Joined: Tuesday 28 June 2016 12:24
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: Norway
Contact:

Using domoticz.openURL()

Post by Olgmo »

Hi
I am trying to figure out how to use the openurl() command. How is this suppose to work?

I want to fetch a status for a wifi device by this command (http://10.0.0.99/json?cmd=status) This is not the Domoticz server.
When doing this in a browser i get:
"{"successful": true, "name": "430x", "status": {"status": 2, "stopped": false, "duration": 592, "mode": 0, "battery": 55, "hours": 773}, "timer": {"status": 1}, "wlan": {"signal": -70}}"

To debug i´ve tried this:

Code: Select all

        
        local url = 'http://10.0.0.99/json?cmd=status'
        local urlReply = domoticz.openURL(url)
        domoticz.log("Status URL" .. urlReply)
But I get this errors.
"attempt to concatenate local 'urlReply' (a nil value)"
"Error opening url: http://10.0.0.99/xml?cmd=status"

Am I trying the impossible here?
(running on Raspi3 and latest beta)
mivo
Posts: 80
Joined: Friday 21 April 2017 8:58
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Czechia
Contact:

Re: Using domoticz.openURL()

Post by mivo »

Hi,

dzVents is probably using OpenURL via LUA commandArray, so it returns no data. Found this on Wiki:
Using 'OpenURL' it is possible to trigger a url/api based on an event. The url will not retrieve/parse any data, use it for one way communication.
https://www.domoticz.com/wiki/Events
My toys:
Raspberry Pi 3 + UPS PIco HV3.0 A Stack
Minibian (Raspbian Jessie) + Domoticz beta
RFLink 433 Gateway, 1wire DS18B20 temp sensors (GPIO)
RaZberry module + 2x Comet Z-Wave + Z-wave socket
---
Plugins: WeMo Switch, UPS PIco HV3.0A on GitHub
randytsuch
Posts: 90
Joined: Sunday 20 March 2016 18:56
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: LA, Ca USA
Contact:

Re: Using domoticz.openURL()

Post by randytsuch »

When I used openURL, seems like it queues it up, and the command is executed after exiting from the dzvents script.
So no way it could work.

Wonder if you tried something like this?
os.execute('curl "http:..." ')

I think this is executed in the script, but I haven't tried to get the results back from the http call. I've just used it to send commands.
Olgmo
Posts: 23
Joined: Tuesday 28 June 2016 12:24
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: Norway
Contact:

Re: Using domoticz.openURL()

Post by Olgmo »

Okay,
I have s normal LUA scripts that work with curl, but wanted to to try out this new script
zicht
Posts: 272
Joined: Sunday 11 May 2014 11:09
Target OS: Windows
Domoticz version: 2023.1+
Location: NL
Contact:

Re: Using domoticz.openURL()

Post by zicht »

You can do this .... but different with curl and io.popen ( i am not yet on dzevents)

first create a function :

Code: Select all

function os.capture(cmd, raw)				-- os.command uitvoeren en resultaat daarvan lezen in string
  local f = assert(io.popen(cmd, 'r'))
  local s = assert(f:read('*a'))
  f:close()
  if raw then return s end
  s = string.gsub(s, '^%s+', '')
  s = string.gsub(s, '%s+$', '')
  s = string.gsub(s, '[\n\r]+', ' ')
  --
	if s~='{"ok":true,"result":[]}' and string.find(s,'"first_name":"msledgem_bot"')==nil then 
		--WriteToFile(cmd,"capture") 
		--WriteToFile("Resp: "..s,"capture") 
    end
  return s
end
then you can call this like (=just an example i use in my script)

Code: Select all

url = 'http://gadgets.buienradar.nl/data/raintext/ -F lat='..lat..' -F lon='..lon  
content = os.capture("Curl "..url)
"content" will hold the result you are seeking for.
Rpi & Win x64. Using : cam's,RFXCom, LaCrosse, RFY, HuE, google, standard Lua, Tasker, Waze traveltime, NLAlert&grip2+,curtains, vacuum, audioreceiver, smart-heating&cooling + many more (= automate all repetitive simple tasks)
BakSeeDaa
Posts: 485
Joined: Thursday 17 September 2015 10:13
Target OS: Raspberry Pi / ODroid
Domoticz version:

Re: Using domoticz.openURL()

Post by BakSeeDaa »

Just be careful so you don't stall the Domoticz eventsystem while waiting for that http response... There might be all kind of delays on the Internet and a few seconds waiting is a long time for the event system.

domoticz.openURL(url) won't wait for a response and I believe that's the preferred way to do it. But there is obviously no response code.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest