STEP 12: DATA EXCHANGE WITH MQTT
To be able to operate the rover in a convenient way we will use a software to send commands to the rover and to display
information we get back from it (like images, it’s current position and information about obstacles surrounding the vehicle).
This software is called ROVER BASESTATION. The entire software is written in Java. The source code as well as a built version
is available at Gibhub in the repository
An introduction how to use this command software will be given in the next step (STEP 13). Before we can test the software we need to setup our MQTT communication infrastructure.
My communication infrastructure uses the MQTT messaging protocol. MQTT is a lightweight messaging protocol for small sensors and mobile devices, optimized for high-latency or unreliable network - exactly what we need on Mars. MQTT is an open OASIS and ISO standard (ISO/IEC 20922). The MQTT protocol defines two types of network entities: a message broker and a number of clients. An MQTT broker is a server that receives all messages from the clients and then routes the messages to the appropriate destination clients. An MQTT client is any device (from a micro controller up to a full-fledged server) that runs an MQTT library and connects to an MQTT broker over a network. In our case both the rover and the command software are MQTT clients.
Information is organized in a hierarchy of topics. When a publisher has a new item of data to distribute, it sends a control message with the data to the connected broker. The broker then distributes the information to any clients that have subscribed to that topic. The publisher does not need to have any data on the number or locations of subscribers, and subscribers, in turn, do not have to be configured with any data about the publishers.
Which parts do I need?
For this step no new parts are required. Use the software for the ROVER BASESTATION and for STEP 12 from Github
Which software do I need?
SOFTWARE FOR REMOTE BASESTATION
SOFTWARE FOR STEP 12
What needs to be done?
If your rover has connection to the internet, you may use any open MQTT broker, e.g. "broker.hivemq.com". Otherwise you need to run a mqtt broker software on the computer with the command software installed, or on the rover. Since the rover has a static ip (my rover has 10.11.12.1), I'd recommend to run it on the Raspberry Pi.
MQTT Broker Installation on Raspberry Pi
sudo apt install mosquitto mosquitto-clients
You don’t need the mosquitto-clients package for running the broker, but installing it allows you to run the MQTT client code locally for testing. It also means you can use the Raspberry Pi as a client as well as a broker. Enable the broker and allow it to auto-start after reboot using the following command:
sudo systemctl enable mosquitto
The broker should now be running. You can confirm by checking the systemd service status:
sudo systemctl status mosquitto
Download the software for the ROVER BASESTATION (rover_basestation.jar") and store it on your computer or laptop. Make sure that the computer you use has a WIFI module. Also download the file "connectionparameter.xml". The command software loads data about the mqtt broker (IP: 10.11.12.1) and the port (Port: 1883) to be used from this file, just adapt these values to your environment.
Rover SoftwareThen you need the software for the rover. To be able to use MQTT with python, you need first to install the "paho - mqtt" package:
pip install paho-mqtt
Get the Python sources for STEP 12 and run the programm "roverMain.py" on your raspberry.