I've worked on UNIX based systems since 1989, and I've always had a healthy respect for accessing the system as super user.
I've seen many times where mistakes made as superuser can have devastating consequences.
So when we added LEDs to the robot, I was a little concerned to find that the neopixel library required root access in order to run.
This also means that the root user environment had to be configured for all the packages the robot required. (i.e. using sudo pip3 to install all the packages I need).
In addition, we also need to configure the audio input device as root for the voice control task - otherwise the robot wouldn't be able to access it.
I decided I really didn't want this, so thought it would be best to have a simple service running as root that controlled the LEDs and the robot, running as a non root user, could send the service messages to change the colour etc. I'm sure there are many other implementations out there I could have used, but I decided what I wanted was so simple I could write my own.
For communications I chose to use a UDP socket. This means the service can just listen on a port, and clients can fire messages at the port without worrying about creating or maintaining a connection.
Both the server and client code would be written in Python so, to encode messages to send between the two, I decided to use the standard python 'pickle' module to encode python objects to and from byte arrays.
Here is the server code:
source at bitbucket.org |
This is installed as a systemd service, and enabled to run at startup.
source at bitbucket.org |
No comments:
Post a Comment