This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

HTTP Post
#1
Hello,
How can I send POST command "POST /relay/0?turn=on" from lua script?


Thanks
Deso
Reply
#2
One of these requests should work for you, don't forget to change the IP address as required.
Code:
local http = require('socket.http')

-- empty post body
http.request('http://192.168.1.1/relay/0?turn=on', '')

-- post instead of get
http.request('http://192.168.1.1/relay/0', 'turn=on')

-- post and get
http.request('http://192.168.1.1/relay/0?turn=on', 'turn=on')
Reply
#3
Thanks, it work. Is there any manual or examples about http post and get?
Reply
#4
Here's the library reference:
http://w3.impa.br/~diego/software/luasoc...ml#request
Reply
#5
(07.11.2016, 07:17)admin Wrote: Here's the library reference:
http://w3.impa.br/~diego/software/luasoc...ml#request

Hello Admin,
I would like to send by order on a second LM or on another box (Box TV) i use this script but the command is not sent.
I indicate the IP and the password but the request is not sent.
I try directly in the browser and it works.
these scripts are still functional?


local http = require('socket.http')

http.request('http://remote:remote@IP/scada-remote?m=json&r=grp&fn=write&alias=34/1/2&value=1', '')

thanks.
B.R.
Reply
#6
Hi
Are you referring to remote services? Sure they work, fallow this
https://forum.logicmachine.net/showthrea...09#pid3009
BR
Reply
#7
Add log call to see what the web server returned in Logs tab:

Code:
local http = require('socket.http')
res, err = http.request('http://remote:remote@IP/scada-remote?m=json&r=grp&fn=write&alias=34/1/2&value=1')
log(res, err)
Reply
#8
(09.05.2019, 10:09)admin Wrote: Add log call to see what the web server returned in Logs tab:

Code:
local http = require('socket.http')
res, err = http.request('http://remote:remote@IP/scada-remote?m=json&r=grp&fn=write&alias=34/1/2&value=1')
log(res, err)
Can be then admin login request ?

Log : 
* arg: 1
 * nil
* arg: 2
 * string: connection refused
Reply
#9
Connection refused means that URL has incorrect IP or port (optional, default 80). Can you ping that IP from System config > Status > Network utilities?
Reply
#10
(09.05.2019, 11:53)admin Wrote: Connection refused means that URL has incorrect IP or port (optional, default 80). Can you ping that IP from System config > Status > Network utilities?

it works with the local IP but not the public one I do not know why. I continue my tests. With the FREEPLAYER i have : 

* arg: 1
 * string:
* arg: 2
 * number: 403
Reply
#11
Do you mean that you use port forwarding? Are two devices in the same sub-network and you want to access another device via port-forwarded IP?
Reply
#12
(09.05.2019, 12:18)admin Wrote: Do you mean that you use port forwarding? Are two devices in the same sub-network and you want to access another device via port-forwarded IP?

No for example I have an LM in the same network as the player freebox and I would like to drive via the LM this player. 
So I have the following script (For the remote I did my tests for sending URLs because it did not work with the player, to be sure I was not wrong in the scripts).


Code:
   local http = require('socket.http')
        res, err = http.request('http://http://IPLOCAL/pub/remote_control?code=CODETELECOMMAND"&key=play')
    log(res, err)
--[[
"red" // Bouton rouge
"green" // Bouton vert
"blue" // Bouton bleu
"yellow" // Bouton jaune


"power" // Bouton Power
"list" // Affichage de la liste des chaines
"tv" // Bouton tv

"1" // Bouton 1
"2" // Bouton 2
"3" // Bouton 3
"4" // Bouton 4
"5" // Bouton 5
"6" // Bouton 6
"7" // Bouton 7
"8" // Bouton 8
"9" // Bouton 9

"back" // Bouton jaune (retour)
"0" // Bouton 0
"swap" // Bouton swap

"info" // Bouton info
"epg" // Bouton epg (fct+)
"mail" // Bouton mail
"media" // Bouton media (fct+)
"help" // Bouton help
"options" // Bouton options (fct+)
"pip" // Bouton pip

"vol_inc" // Bouton volume +
"vol_dec" // Bouton volume -

"ok" // Bouton ok
"up" // Bouton haut
"right" // Bouton droite
"down" // Bouton bas
"left" // Bouton gauche

"prgm_inc" //Bouton programme +
"prgm_dec" // Bouton programme -

"mute" // Bouton sourdine
"home" // Bouton Free
"rec" // Bouton Rec

"bwd" // Bouton << retour arrière
"prev" // Bouton |<< précédent
"play" // Bouton Lecture / Pause
"fwd" // Bouton >> avance rapide
"next" // Bouton >>| suivant
--]]

When I realize it directly in my browser it works.
Reply
#13
Your URL has http:// twice and there's a double quote character in code argument: code=CODETELECOMMAND"
Reply
#14
(09.05.2019, 13:05)admin Wrote: Your URL has http:// twice and there's a double quote character in code argument: code=CODETELECOMMAND"

Yes i have a single http lack of copy.
it's the " who's causing the problem...
(Sorry for making you waste yout time !!!!)
it works perfectly.

One las question concerning all of thse commands how can i easily reduce the script and not put if 1 then play if 2 then power if 3 .... etc...
can we recover the names of the custom values in order to put in my URL according to the command achieve?

Thanks a lot.
BR.
Reply
#15
There's no easy way of accessing custom values. But you can create a table with number - key mapping:
Code:
keys = {
  [0] = 'stop',
  [1] = 'play',
}

val = event.getvalue()
key = keys[ val ]

if key then
  local http = require('socket.http')
  res, err = http.request('http://IPLOCAL/pub/remote_control?code=CODETELECOMMAND&key=' .. key)
end
Reply
#16
(09.05.2019, 13:28)admin Wrote: There's no easy way of accessing custom values. But you can create a table with number - key mapping:
Code:
keys = {
 [0] = 'stop',
 [1] = 'play',
}

val = event.getvalue()
key = keys[ val ]

if key then
 local http = require('socket.http')
 res, err = http.request('http://IPLOCAL/pub/remote_control?code=CODETELECOMMAND&key=' .. key)
end

Thank you again for your answers.
B.R.
Reply


Forum Jump: