Help with os.execute in lua script

Moderator: leecollings

Post Reply
Kjakan
Posts: 14
Joined: Wednesday 11 March 2015 14:03
Target OS: Linux
Domoticz version: 2024.2
Location: Norway
Contact:

Help with os.execute in lua script

Post 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
User avatar
habahabahaba
Posts: 190
Joined: Saturday 18 March 2023 14:44
Target OS: Windows
Domoticz version: 2024.4
Contact:

Re: Help with os.execute in lua script

Post 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')
Kjakan
Posts: 14
Joined: Wednesday 11 March 2015 14:03
Target OS: Linux
Domoticz version: 2024.2
Location: Norway
Contact:

Re: Help with os.execute in lua script

Post 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.
Kedi
Posts: 536
Joined: Monday 20 March 2023 14:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Somewhere in NL
Contact:

Re: Help with os.execute in lua script

Post 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')
Logic will get you from A to B. Imagination will take you everywhere.
User avatar
habahabahaba
Posts: 190
Joined: Saturday 18 March 2023 14:44
Target OS: Windows
Domoticz version: 2024.4
Contact:

Re: Help with os.execute in lua script

Post by habahabahaba »

what OS you are using?
Kjakan
Posts: 14
Joined: Wednesday 11 March 2015 14:03
Target OS: Linux
Domoticz version: 2024.2
Location: Norway
Contact:

Re: Help with os.execute in lua script

Post 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,
Kjakan
Posts: 14
Joined: Wednesday 11 March 2015 14:03
Target OS: Linux
Domoticz version: 2024.2
Location: Norway
Contact:

Re: Help with os.execute in lua script

Post 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?
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Help with os.execute in lua script

Post 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')
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Kjakan
Posts: 14
Joined: Wednesday 11 March 2015 14:03
Target OS: Linux
Domoticz version: 2024.2
Location: Norway
Contact:

Re: Help with os.execute in lua script

Post 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}'
Kjakan
Posts: 14
Joined: Wednesday 11 March 2015 14:03
Target OS: Linux
Domoticz version: 2024.2
Location: Norway
Contact:

Re: Help with os.execute in lua script

Post 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 :oops:
Thanks for the help.
User avatar
habahabahaba
Posts: 190
Joined: Saturday 18 March 2023 14:44
Target OS: Windows
Domoticz version: 2024.4
Contact:

Re: Help with os.execute in lua script

Post by habahabahaba »

And may be it is better to use domoticz.executeShellCommand ?
Wiki
akamming
Posts: 337
Joined: Friday 17 August 2018 14:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Help with os.execute in lua script

Post by akamming »

Or domoticz.openURL?
Kjakan
Posts: 14
Joined: Wednesday 11 March 2015 14:03
Target OS: Linux
Domoticz version: 2024.2
Location: Norway
Contact:

Re: Help with os.execute in lua script

Post by Kjakan »

I take a look at this. Thanks.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests