Connecting the phone app to MQTT
The phone app runs on HTML and JavaScript. This cannot directly connect to network services like MQTT and requires WebSockets.We will need to configure Mosquitto on the robot to allow WebSockets. We then need to install another JS library, and then connect this to our joystick.
Enabling MQTT WebSockets on the robot
WebSockets will allow Javascript to open and keep a persistent connection to our robot via MQTT, allowing us to publish and subscribe to messages. WebSockets are the only option to communicate directly from our web app to MQTT. This is not enabled by default in Mosquitto, so we will need to enable this.We can configure Mosquitto with a configuration file. Create the file deploy/robot_mosquitto.conf:
password_file /etc/mosquitto/passwd
allow_anonymous false
listener 1883
protocol mqtt
# Websockets
listener 9001
protocol websockets
Mosquitto listens by default on port 1883 using the MQTT protocol. However, when we add a config file, we must...