04.11.2016, 20:40
Hello,
How can I send POST command "POST /relay/0?turn=on" from lua script?
Thanks
Deso
How can I send POST command "POST /relay/0?turn=on" from lua script?
Thanks
Deso
HTTP Post
|
04.11.2016, 20:40
Hello,
How can I send POST command "POST /relay/0?turn=on" from lua script? Thanks Deso
05.11.2016, 11:25
One of these requests should work for you, don't forget to change the IP address as required.
Code: 12345678910 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')
05.11.2016, 20:39
Thanks, it work. Is there any manual or examples about http post and get?
07.11.2016, 07:17
Here's the library reference:
http://w3.impa.br/~diego/software/luasoc...ml#request
09.05.2019, 08:46
(07.11.2016, 07:17)admin Wrote: Here's the library reference: 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.
09.05.2019, 09:10
Hi
Are you referring to remote services? Sure they work, fallow this https://forum.logicmachine.net/showthrea...09#pid3009 BR
------------------------------
Ctrl+F5
09.05.2019, 10:09
Add log call to see what the web server returned in Logs tab:
Code: 123 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)
09.05.2019, 11:37
(09.05.2019, 10:09)admin Wrote: Add log call to see what the web server returned in Logs tab:Can be then admin login request ? Log : * arg: 1 * nil * arg: 2 * string: connection refused
09.05.2019, 11:53
Connection refused means that URL has incorrect IP or port (optional, default 80). Can you ping that IP from System config > Status > Network utilities?
09.05.2019, 12: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
09.05.2019, 12:18
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?
09.05.2019, 12:55
(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: 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 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.
09.05.2019, 13:05
Your URL has http:// twice and there's a double quote character in code argument: code=CODETELECOMMAND"
09.05.2019, 13:18
(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.
09.05.2019, 13:28
There's no easy way of accessing custom values. But you can create a table with number - key mapping:
Code: 123456789101112 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
09.05.2019, 14:20
(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: Thank you again for your answers. B.R.
Hi !!!
Please, whear can I put the script for Http POST ??? In Resident ??? I have seen this: https://forum.logicmachine.net/showthread.php?tid=453 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') Thanks in advance for your answer Regards
11.09.2023, 11:06
It depend of the application but it can be simple event script.
------------------------------
Ctrl+F5
13.09.2023, 14:11
|
« Next Oldest | Next Newest »
|