Page 1 of 1
Execute Python script from web via Domoticz internal server
Posted: Monday 30 April 2018 13:27
by EdddieN
Hello,
I'm trying this with Python, to create a setup page for this project:
http://www.domoticz.com/forum/viewtopic ... 40#p178879 and the challenge I'm having is that Domoticz internal webserver does not execute Python scripts outside its own management system.
I guess I could solve this using Apache or Nginx, but seems a bit overkill to install another server when Domoticz has already one. This is the architecture:
1.- I have a web setup page with multiple options for its nearly 50 I/Os, some of them have multiple options per I/O, hence the reason to create its own custom setup page
2.- From this page, it generates a configuration file that is pushed via UART to the guest micro-controllers on the main board.
3.- Similar for reading the status settings of the main board.
I also tried with PHP, same situation. The question, can I call from a web page within the www folder of Domoticz a python script and execute it?
Re: Execute Python script from web via Domoticz internal server
Posted: Monday 30 April 2018 22:54
by zak45
EdddieN wrote: ↑Monday 30 April 2018 13:27
the challenge I'm having is that Domoticz internal webserver does not execute Python scripts outside its own management system.
The question, can I call from a web page within the www folder of Domoticz a python script and execute it?
Hi, have a python plugin for that that I'm calling PSExec ( if you see the reference

. Able to execute any kind of command on system where Domoticz is installed, so if you want to execute a python script, this can be done without problem. I'm using it actually to execute some specific command for my voice system control.
Let me know if you are interested, can provide it to you.
Re: Execute Python script from web via Domoticz internal server
Posted: Tuesday 01 May 2018 8:55
by EdddieN
Yes interested! Are you able to trigger it from a web page?
Re: Execute Python script from web via Domoticz internal server
Posted: Tuesday 01 May 2018 11:48
by EdddieN
Ok, I saw your plugin, really nice! Just to advance for me, I get lost
To give you a more real example of what I'm tying, I have a simple website served by Domoticz webserver, this webpage produces a configuration file or similar with the above:
Code: Select all
4;1;1;0;24;1\n
4;1;1;0;25;99,345\n
4;1;1;0;26;30,38\n
4;2;1;0;24;1\n
4;2;1;0;25;99,345\n
4;2;1;0;26;30,38\n
4;3;1;0;24;1\n
4;3;1;0;25;99,345\n
4;3;1;0;26;30,38\n
4;4;1;0;24;1\n
4;4;1;0;25;99,345\n
4;4;1;0;26;30,38\n
4;5;1;0;24;2\n
4;5;1;0;25;99,345\n
4;5;1;0;26;30,39\n
4;6;1;0;24;2\n
4;6;1;0;25;99,345\n
4;6;1;0;26;30,39\n
4;7;1;0;24;2\n
4;7;1;0;25;99,345\n
4;7;1;0;26;30,39\n
4;8;1;0;24;2\n
4;8;1;0;25;99,345\n
4;8;1;0;26;30,39\n
Which I need to send via serial port. I have a python/bash script that already pushes the data to the motherboard, however I cannot execute the script from the web itself... any ideas how to bypass this without having to install a new server?
Re: Execute Python script from web via Domoticz internal server
Posted: Tuesday 01 May 2018 13:05
by zak45
EdddieN wrote: ↑Tuesday 01 May 2018 11:48
Ok, I saw your plugin, really nice! Just to advance for me, I get lost
Which I need to send via serial port. I have a python/bash script that already pushes the data to the motherboard, however I cannot execute the script from the web itself... any ideas how to bypass this without having to install a new server?
Hummm.. I think I see the one you're speaking.. not mine and I'm also lost

Mine request that you send the command you want by doing a POST on specific port, so this can be made by curl and of course any web page.
curl example :
curl --data "ls -altr >$HOME/ls.lst" 192.168.1.20:9002
Do not be afraid about the code inside, do not have take time to clear it and made something better.. but work as it is.
you just need to change this line and put the command you want to allow:
Code: Select all
#
# Authorized commands, if not into the list, not executed
commandok=['samsungctl','dir','py', 'tt.cmd']
you need to adapt also the psexec.sh, something like that:
nohup sudo /bin/sh $1
Re: Execute Python script from web via Domoticz internal server
Posted: Tuesday 01 May 2018 13:09
by EdddieN
Thanks!
I'll have to play with it a bit, I'll come back with feedback hopefully in a few days

Re: Execute Python script from web via Domoticz internal server
Posted: Wednesday 02 May 2018 15:51
by EdddieN
Just thinking aloud, what about forgetting about the whole web page served by Domoticz but actually building a plugin:
https://www.domoticz.com/wiki/Developin ... hon_plugin
From what I can see here
http://www.domoticz.com/forum/viewtopic ... 65&t=21297 , python can access the UART of the Raspberry Pi (or any UART I guess), so I could create the setup page as a plugin, right?
If anyone has a simple way to explain how it works, I'll take it! as I'm really new to it, it is going to take me a while
