golemparts / rppal

A Rust library that provides access to the Raspberry Pi's GPIO, I2C, PWM, SPI and UART peripherals.
MIT License
1.24k stars 98 forks source link

Failure to configure GPIO if run via systemd although no error propagated #167

Open zacharytomlinson opened 1 day ago

zacharytomlinson commented 1 day ago

I have had hits and misses with this thus far. I have gotten the GPIO configuration to work a few times if I manually start the application after all services have loaded. If run as a systemd service or via rc.local, no error is thrown but subsequent checking of the GPIO voltages indicates that either 1) they were never configured or 2) the configuration was set temporarily and then dropped after all services loaded. I had set the set_reload_on_drop(false) as well. It should be noted doing the same exact operations via python works every time when run via rc.local, I have not tried that one as a systemd service.

golemparts commented 1 day ago

Hey @zacharytomlinson. I don't have experience interacting with the GPIO with an application that's managed by systemd, however my guess would be you'll have to configure After= to wait long enough for the relevant services to finish loading, as it sounds like something is overwriting the pin status. Something else to check in both cases is to make sure the user the process is running as has the correct permissions to access the GPIO devices. If it's run as root that shouldn't be an issue.

If your application works fine when run directly from the command line, it does sound like either a configuration or permissions error. If the above-mentioned doesn't help, you'll probably find better Linux support on the official Raspberry Pi forums to help figure this out.