Reader small image

You're reading from  Practical Python Programming for IoT

Product typeBook
Published inNov 2020
Reading LevelIntermediate
PublisherPackt
ISBN-139781838982461
Edition1st Edition
Languages
Right arrow

The Paho JavaScript MQTT client

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...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Practical Python Programming for IoT
Published in: Nov 2020Publisher: PacktISBN-13: 9781838982461