At line (4), we create our Paho-MQTT Client instance and assign it to the client variable.
The parameters to Paho.MQTT.Client() are the broker's hostname and port. We are serving this web page via Mosquitto, so the broker's host and port will be the same as web pages:
const client = new Paho.Client(location.hostname, // (4)
Number(location.port),
CLIENT_ID);
You may have noticed in the http://localhost:8083Â URLÂ that the port is 8083, while in Python we used port 1883:
- Port 1883 is the MQTT protocol port on the broker. Our Python program connects directly to the broker on this port.
- We previously configured port 8083 as a Web Socket port on the Mosquitto broker. Web pages can speak HTTP and Web Socket protocols, not MQTT.
This raises an important point. While we're using the term MQTT in the context of our JavaScript code, we're really proxying the...