Adding more control options to the web app
Our application has let us take control of driving the robot, but we can let it do more. We can extend it to start and stop behaviors, and even turn off the robot. Let’s see how we can use what we’ve learned with Python, MQTT, HTML, and JavaScript to build this launcher.
Adding a launcher
The launcher will make use of the common mqtt_behavior code. Add the file robot/launcher_service.py starting with the following code:
import subprocess
from common.mqtt_behavior import connect, publish_json
def print_message(client, userdata, msg):
print(f"{msg.topic} {msg.payload}")
def start_systemd_unit(client, userdata, msg):
unit_name = msg.payload.decode()
subprocess.run(["systemctl", "start", unit_name])
print(unit_name, "started")
def stop_systemd_unit(client, userdata, msg):
unit_name = msg.payload.decode()
subprocess.run(["systemctl", "stop", unit_name...