Page 1 of 1
Help with os.execute in lua script
Posted: Sunday 28 January 2024 16:16
by Kjakan
This command work for me in command line:
Code: Select all
curl -X POST -H "Content-Type: application/json" -d '{"text": "Test Message"}' http://192.168.2.34/api/notify
How can I get this command to run in lua?
This does not work.
Code: Select all
os.execute ('curl -X POST -H "Content-Type: application/json" -d '{"text": "Test Message"}' http://192.168.2.34/api/notify')
Code: Select all
/lua/script_variable_Timelapse.lua:15: ')' expected near '{'
I'm guessing I need to escape some characters, but not sure how.
Domoticz 2024.2 and Debian bookworm
Re: Help with os.execute in lua script
Posted: Sunday 28 January 2024 18:36
by habahabahaba
Try
Code: Select all
os.execute('curl -X POST -H "Content-Type: application/json" -d \'{\"text\": \"Test Message\"}\' http://192.168.2.34/api/notify')
Re: Help with os.execute in lua script
Posted: Sunday 28 January 2024 20:02
by Kjakan
Thanks for the response. No error in domoticz, but command did not execute.
I've tried different ways, but I may be missing something.
Re: Help with os.execute in lua script
Posted: Sunday 28 January 2024 20:25
by Kedi
try:
Code: Select all
os.execute('curl -X POST -H "Content-Type: application/json" -d \"{\"text\": \"Test Message\"}\" http://192.168.2.34/api/notify')
or
Code: Select all
os.execute('curl -X POST -H "Content-Type: application/json" -d "{\"text\": \"Test Message\"}" http://192.168.2.34/api/notify')
Re: Help with os.execute in lua script
Posted: Sunday 28 January 2024 20:31
by habahabahaba
what OS you are using?
Re: Help with os.execute in lua script
Posted: Sunday 28 January 2024 20:35
by Kjakan
Debian bookworm.
Still no luck. No error in domoticz and command not execute.
If I change -d '{\"text\": \"Test Message\"}' to -d "{\"text\": \"Test Message\"}" the command will not work and no error in domoticz,
Re: Help with os.execute in lua script
Posted: Sunday 28 January 2024 21:26
by Kjakan
This works in command line, but not in lua. No error in domotiicz, but command not execute.
Code: Select all
curl -X POST -H "Content-Type: application/json" -d "{\"text\": \"Test Message\"}" http://192.168.2.34/api/notify
Any other easy way to send json to http api in lua?
Re: Help with os.execute in lua script
Posted: Sunday 28 January 2024 21:33
by jvdz
What about this version
Code: Select all
os.execute('curl -X POST -H "Content-Type: application/json" -d \'{"text": "Test Message"}\' http://192.168.2.34/api/notify')
Re: Help with os.execute in lua script
Posted: Sunday 28 January 2024 21:38
by Kjakan
Same result. No error in domoticz, but command not execute.
From command line
curl: (3) unmatched close brace/bracket in URL position 13:
Test Message}'
Re: Help with os.execute in lua script
Posted: Sunday 28 January 2024 22:29
by Kjakan
habahabahaba wrote: ↑Sunday 28 January 2024 18:36
Try
Code: Select all
os.execute('curl -X POST -H "Content-Type: application/json" -d \'{\"text\": \"Test Message\"}\' http://192.168.2.34/api/notify')
This is working. I messed up somwhere
Thanks for the help.
Re: Help with os.execute in lua script
Posted: Monday 29 January 2024 5:24
by habahabahaba
And may be it is better to use domoticz.executeShellCommand ?
Wiki
Re: Help with os.execute in lua script
Posted: Monday 29 January 2024 7:46
by akamming
Or domoticz.openURL?
Re: Help with os.execute in lua script
Posted: Monday 29 January 2024 21:31
by Kjakan
I take a look at this. Thanks.