Troubleshooting
You may run into a few problems here.
- If the robot doesn’t move, first check that you’ve run the simple motor test above, and the troubleshooting steps there.
- If it still doesn’t work, look at the log of the motors service.
- If you see
json.decoder.JSONDecodeError, check that you have sent the correct message with mosquitto pub.
The deployment and Inventor HAT service code should look similar to https://github.com/PacktPublishing/Learn-Robotics-Programming-3rd-edition/tree/chapter-6/making-an-mqtt-service.We’ve built and troubleshooted a motor-handling service, which we can start to connect to. Let’s make a simple line behavior with it.
Driving forward with MQTT
Our behaviors will all need to connect to MQTT and start a message loop. We can capture that in some common code in robot/common/mqtt_behavior.py:
import paho.mqtt.client as mqtt
import time
import json
def default_on_connect(client, userdata, flags, rc):
print(f"Connected...