Android Question How to run scripts .py and .sh

AlpVir

Well-Known Member
Licensed User
Longtime User
How to run pyton script (*.py) and "shell bash" (*.sh) script that reside on a web server Apache ?
These scripts do not return output but interact with the hardware of the server (that has an address like name.no-ip.com or name.dlinkddns.com or name.ddns.com).
Thank you in advance
 

LucaMs

Expert
Licensed User
Longtime User
upload_2015-12-10_18-7-22.png
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
Test 5 (the real one) should start gphoto2
This is no more related to B4A as I do understand it but more on your Linux system.
If you were able to execute some bash script from your app, you would be able to execute any script on the server. So, perhaps should you take some time to test the script. Again, it could be any error related to permissions or the parameters used (I don't remember which parameters gphoto2 takes exactly). Good luck :)
 
Upvote 0

AlpVir

Well-Known Member
Licensed User
Longtime User
I have the impression that the system used here (job2.Initialize ("Job2" Me); job2.PostString (SiteNoIp & "script.php", "")) is valid only for a subset of the script and not for everyone.
I repeat that /var/www/html/unafoto.sh really snaps the photo and then permission should be OK.
 
Upvote 0

AlpVir

Well-Known Member
Licensed User
Longtime User
SOLVED!
I followed these instructions, you will find the link https://www.raspberrypi.org/forums/viewtopic.php?t=2276
Firstly to get it working at all I needed to edit /etc/sudoers file using visudo. I gave www-data the same permissions as the default user pi by the following to the end of the file:
www-data ALL=(ALL) NOPASSWD: ALL
I also needed to change the permissions on the USB port in use for it all to work. Using the info from earlier in the thread to find the port I created the following script called usbperm
#!/bin/bash
#
dev=`gphoto2 --auto-detect | grep usb | cut -b 36-42 | sed 's/,/\//'`
sudo chmod 777 /dev/bus/usb/${dev}
exit 0
Changing the permissions to 777 maybe overkill but it works!

Then just a couple of weeks to get the web page working as I wanted and looking pretty (please notice the symbols matching the camera ones and rounded corners!)
I found using exec('gphoto2 --list-all-config',$output,$int); to get the camera config settings and then parsing it to find the individual settings was much faster than separate calls to get each one.
Changes then made using --set-config from popup windows for each setting.
Clicking on the look-a-like camera button takes a picture with
exec('gphoto2 --capture-image-and-download --keep --filename capt0000.jpg --force-overwrite --quiet');
For my Canon I also needed to insert every time a --set-config /main/settings/capturetarget=1 to force it to use the card and not the internal memory of the camera which it keeps defaulting to.
Clicking on Preview takes a quick preview (if the camera supports it) using
exec('gphoto2 --capture-image-and-download --filename capture_preview.jpg --force-overwrite --quiet')
Of course after each call to gphoto2 I need to do a usb reset with
exec('usbreset /dev/bus/usb/'.$dev);
usbreset and usbperm were added to /usr/bin/ with full permissions.

I did not use the file unafoto.sh but only unafoto.php call with education B4A
B4X:
job2.PostString (SiteNoIp & "unafoto.php", "")

The picture is taken. I have not applied the further suggestion that there is at the end of the document above ("after each call to gphoto2 I need to do a usb reset")
For now it works :)!
 
Upvote 0
Top