I’ve got my Dot3k installed & working. The sample scripts are executing OK. Now I’m trying to modify a copy of the menu.py script to include power-off and reboot options. Anyone tried this?
I’ve Googled & found references to including the following in a python script. import os import subprocess from subprocess import call
…and I’m trying the following; menu.add_item(‘Power off’, ‘call(“sudo halt, Shell=True”)’)
…but that doesn’t appear to work. The Pi doesn’t power down. I’ve tried executing that menu script under sudo but with no difference; it still doesn’t power down. What am I doing wrong?
Excellent - thank you. Yes, that works. I can now execute sudo halt and sudo reboot using that structure. Just need to run the script at reboot now so the menu is available whenever the system is up.
Tell me… do you know whether it’s possible to run compound operations in that lambda function? I’d like the display to show ‘Powering down’ or some equivalent message when the script calls the halt, or displays ‘Rebooting…’ when it calls a reboot. I speculative appended "& lcd.write(“blah”) in the lambda argument and it didn’t work - but that was just a syntactical guess!
I’ll have a play with that once I’ve got the script running automatically. I’m having trouble getting it to start either @reboot or on a ‘every x mins’ basis. It’s weird; the script can be executed from the /advanced folder where it’s stored with …/advanced $ ./menu.py but when I add the reference to crontab (using full path) - either with or without /usr/bin/python before the path (not sure if it’s needed?) - the script still doesn’t appear to be triggered. Well, the dot3k display remains blank anyway.
Can you try triggering the menu.py advanced example in crontab @reboot on one of your Pi’s; does it work for you?
My usual setup for triggering a script is to create a startup file that changes into the correct directory and then launches the Python script with sudo. It would look something like this: