Maslow Home Maslow Community Garden Newsletter

Webcontrol Buttons and LEDs

I’ve been working on webcontrol for a while to customize it for the raspberry pi to use some features only available on the raspberry pi and have tried a number of things and I’m kind of stuck and looking for ideas on how to correctly approach the problem.

As it is set up, the buttons and Led’s don’t work (because of gevent used for flask or socket conflicts with gpiozero), so I tried 2 approaches:

The first approach was to make a button service that then called a pendant service (systemctl in systemd with .service files). This works, but requires root permissions to run and is difficult to manage starting / stopping of the service and has a hardcoded port number, so if user changes it in webcontrol, it doesn’t work anymore, but this worked.

The problem with the first was that the file had to be copied by a sudo command and run by a sudo command from a specific location. the dependencies were light though, so it likely wouldn’t be hard for a user to set up, but this type of operational mode is frowned upon. There are several batch files that accompany it and it lacked the ability to easily change ports. I don’t know where or how this fits in with a webcontrol release though it communicates with webcontrol via the socket IO.
The second approach was to make a button and LED subprocess that ran from webcontrol as an orphan that could be killed and restarted. The truth of the matter is that my code fu is on a white belt level. In theory once the syntax is correct and I get past the weird file not found and maximum recursion depth errors, it should work.

The second is supposed to be managed from webcontrol. Instead of 4 files, it only has 2 and no root privileges are required. It runs fine independently, but when subprocess.Popen() is used to execute a batch file to start the python code from within webcontrol, it throws a recursion depth error and does not run. I made the file house a class that runs from main.

So what is the “right” way to do this? I also have a cool idea for my controller LED I’d like to implement and I think others would appreciate, but I need some help getting the button part to run before I can try it and share it. Any suggestions or references for study would be appreciated.

I really like mosquitto for this kind of loose coupling. See The best python adaptor is probably paho-mqtt.

I’ve used mqtt for microcontroller data packet IOT communication, but that was to a database on a server, not as a control set for active buttons that need to have real-time responses. The data is currently sent from the raspberry pi hardware out over the socket to the same pi via localhost:5000 as if it were a remote web client because webcontrol already has the logic coded to receive that. Setting up an mqtt receiver as well as the sender might be a bit more than I signed up for to have the button start or stop the cut and reboot the raspberry pi. The goal is to have the features user selectable and startable / managed from webcontrol yet run as a sub process that does not diminish the webcontrol functionality.