I was able to get back onto this. I’m committed to finding a solution and sharing it for others.
So I was able to make some stuff happen and get some error logs, I went through them all (things like exporting dbus, etc) but now I have no log at all when I press the button. So no errors but also no shutdown just this:
<Interface <ProxyObject wrapping <dbus._dbus.SystemBus (system) at 0x769f41b0> :1.1 /org/freedesktop/login1 at 0x769ef690> implementing 'org.freedesktop.login1.Manager.PowerOff' at 0x769ef830>
dockercompose
button:
build: ./button
restart: always
network_mode: host
privileged: true
labels:
io.balena.features.dbus: '1'
io.balena.features.firmware: '1'
environment:
- DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket
dockerfile:
#!/usr/bin/env bash
## connect to the host's system bus from the application container
export DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket
python button.py
button.py
import RPi.GPIO as GPIO
import time
import dbus
# Set GPIO mode: GPIO.BCM or GPIO.BOARD
GPIO.setmode(GPIO.BOARD)
# Set pin 5 an an input, and enable the internal pull-up resistor
GPIO.setup(5, GPIO.IN, pull_up_down=GPIO.PUD_UP)
oldButtonState1 = True
while True:
buttonState1 = GPIO.input(5)
if buttonState1 != oldButtonState1 and buttonState1 == False :
bus = dbus.SystemBus()
boolean = dbus.Boolean(True)
remote_object = bus.get_object('org.freedesktop.login1', '/org/freedesktop/login1')
interface = dbus.Interface(remote_object, 'org.freedesktop.login1.Manager.PowerOff')
print interface
oldButtonState1 = buttonState1
time.sleep(1)
Once this is solved it will wake using the same button. I can power the device down from the dashboard/balena cloud and wake it back up whenever by just pressing the button. So when this get’s solved, it’ll be a pretty cool, handy feature.