Hello,
I'm trying to use Domoticz on windows 7. I have to send an http request to a remote server and retrieve a temperature. I try to do this with a LUA script.
The command below doesn't send anything on ethernet (verified with wireshark):
temperature=os.execute('http://169.254.1.1/ forms.htm')
When i try this :
temperature=os.execute('start iexplore.exe "http://169.254.1.1/status.xml"')
the explorer open and I see the html page of the remote server so it's working but I want to retrieve the temperature without opening an explorer.
I've also tried to send "http://169.254.1.1/status.xml" on a switch action and I see with wireshark that the command is sent! but I cannot get the temperature from this action that's why I want to use a script.
I also try (and many other variant....):
os.execute('curl "http://169.254.1.1/status.xml"&')
but it doesn't work.
I've tried a lot of things but it does not work.
Please I somebody have a simple solution.
Thanks a lot
Regards.
os.execute('http...') not working
Moderators: leecollings, remb0
- Egregius
- Posts: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: os.execute('http...') not working
Did you install curl?
Re: os.execute('http...') not working
Hello Egregius,
Thank you very much for your reply.
No I haven't install curl.
So I've install curl on my PC following some forum on web site. I've put curl.exe and ca-bundle.crt in window path folder: C\windows\system32.
I test directly by putting curl "http://169.254.1.1/status.xml" directly in command prompt and that's working: I see the GET command with wireshark.
But, when I try the same command in domoticz script : os.execute('curl..http://169.254.1.1/status.xml') it doesn't work.
I've also tried with a LUA editor and I've the same problem : I don't see any GET on Wireshark.
Where am I wrong?
Thanks you very much for your help.
Regards.
Thank you very much for your reply.
No I haven't install curl.
So I've install curl on my PC following some forum on web site. I've put curl.exe and ca-bundle.crt in window path folder: C\windows\system32.
I test directly by putting curl "http://169.254.1.1/status.xml" directly in command prompt and that's working: I see the GET command with wireshark.
But, when I try the same command in domoticz script : os.execute('curl..http://169.254.1.1/status.xml') it doesn't work.
I've also tried with a LUA editor and I've the same problem : I don't see any GET on Wireshark.
Where am I wrong?
Thanks you very much for your help.
Regards.
- Egregius
- Posts: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: os.execute('http...') not working
Don't know why it works in command prompt and not in lua. Maybe add complete paths?
Re: os.execute('http...') not working
Egregius,
it's working now! thank you. The problem was lua doesn't find curl.exe as I didn't put the directory in the windows environment variables...
So thanks for your help.
May I ask you other question?
Because Domoticz send a get, I see it with Wireshark and the remote server answer with the temperature, but I could not find a mean to retrieve the value sent by the remote server: I try:
- temperature=os.execute('curl "http://169.254.1.1/status.xml"')-> no sucess
I see on the web the there exist the os.capture command that could help me so I try
local cmd='curl.."http://169.254.1.1/status.xml"'
os.capture(cmd, true)
but it doesn't work, lua editor answer:
tack traceback:
[string "script_device_temperature.lua*"]:50: in main chunk
Is there a way (simple way) to get the temperature from os.execute('curl "http://169.254.1.1/status.xml"') ?
and I also try to update virtual sensor on domoticz with the command:
thank you very much.
Regards.
it's working now! thank you. The problem was lua doesn't find curl.exe as I didn't put the directory in the windows environment variables...
So thanks for your help.
May I ask you other question?
Because Domoticz send a get, I see it with Wireshark and the remote server answer with the temperature, but I could not find a mean to retrieve the value sent by the remote server: I try:
- temperature=os.execute('curl "http://169.254.1.1/status.xml"')-> no sucess
I see on the web the there exist the os.capture command that could help me so I try
local cmd='curl.."http://169.254.1.1/status.xml"'
os.capture(cmd, true)
but it doesn't work, lua editor answer:
tack traceback:
[string "script_device_temperature.lua*"]:50: in main chunk
Is there a way (simple way) to get the temperature from os.execute('curl "http://169.254.1.1/status.xml"') ?
and I also try to update virtual sensor on domoticz with the command:
thank you very much.
Regards.
- Egregius
- Posts: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: os.execute('http...') not working
With php: yes, of course.
With lua: I have no clue at all.
With lua: I have no clue at all.
Re: os.execute('http...') not working
Hello,
Finally thanks to forums I found a solution that I summarise below:
The function capture must be created in the script because it's not native in lua (copy from one forum):
function os.capture(cmd, raw)
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]+', ' ')
return s
end
Then when we put :
temperature=os.capture(cmd, true)
Temperature get the result with the tags, so it is necessary to remove the tags from the result, this is done via the following lua code from another forum (Hobbe & zzdomi):
local function extractElement1(tag, xml, default)
local pattern = "<"..tag..">(.-)</"..tag..">"
local result = (xml:match(pattern) or default)
return result
end
This function extract only the value between the tags.
And then it is necessary to update the virtual sensor with the following code:
commandArray[2]={['UpdateDevice']=idx..'|0|'..tostring(temperature)}
This is a bit complicated but domoticz get the result and display the temperature,
hope this summary be useful for others....
Thanks to Egregius, Hobbe, Alcor and zzdomi
Regards.
Finally thanks to forums I found a solution that I summarise below:
The function capture must be created in the script because it's not native in lua (copy from one forum):
function os.capture(cmd, raw)
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]+', ' ')
return s
end
Then when we put :
temperature=os.capture(cmd, true)
Temperature get the result with the tags, so it is necessary to remove the tags from the result, this is done via the following lua code from another forum (Hobbe & zzdomi):
local function extractElement1(tag, xml, default)
local pattern = "<"..tag..">(.-)</"..tag..">"
local result = (xml:match(pattern) or default)
return result
end
This function extract only the value between the tags.
And then it is necessary to update the virtual sensor with the following code:
commandArray[2]={['UpdateDevice']=idx..'|0|'..tostring(temperature)}
This is a bit complicated but domoticz get the result and display the temperature,
hope this summary be useful for others....
Thanks to Egregius, Hobbe, Alcor and zzdomi
Regards.
-
- Posts: 17
- Joined: Saturday 18 March 2017 21:24
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.8889
- Location: Newcastle/UK
- Contact:
Re: os.execute('http...') not working
Sorry for a late posting...
Re...
I've placed my curl folder here c:\curl\bin\curl.exe, and added this folder to system variables for both user and system PATH.
I can also see the GET command using Wireshark when using a windows 10 cmd window with...
...but using folowing LUA code doesn't!
Anything else I need to check? Tried rebooting but think it's something to do with security, system variables etc.
Rob
Re...
I have exactly the same problem!But, when I try the same command in domoticz script : os.execute('curl..http://169.254.1.1/status.xml') it doesn't work.
I've placed my curl folder here c:\curl\bin\curl.exe, and added this folder to system variables for both user and system PATH.
I can also see the GET command using Wireshark when using a windows 10 cmd window with...
and it does work with the ESPEasy E12 device as I can see the PWM change on my scope on pin 4 (GPI04/D2)
...but using folowing LUA code doesn't!
Code: Select all
runcommand = "curl 'http://" .. IP .. "/control?cmd=PWM," ..PIN.. "," .. CalcValue .. "'";
-- runcommand = "http://" .. IP .. "/control?cmd=PWM," ..PIN.. "," .. CalcValue .. "";
os.execute(runcommand);
Rob
- Attachments
-
- wireshark20180329.JPG (134.21 KiB) Viewed 1644 times
Who is online
Users browsing this forum: No registered users and 1 guest