Publishing messages to target remote devices in JavaScript
Now, we will create a new JavaScript file named home_automation.js
that will provide an APP.HomeAutomation.Manager
object with many strings, objects, and functions that we will use to make it easy to establish a connection with MQTT over WebSockets. The functions will work with the Paho JavaScript client.
We will split the code for the home_automation.js
file in many code snippets to make it easier for us to understand each code section. The following lines start the declaration of the APP.HomeAutomation.Manager
object. The code file for the sample is included in the mqtt_essentials_gaston_hillar_05
folder, in the home_automation.js
file:
var APP = APP || {}; var APP = APP || {}; APP.HomeAutomation = APP.HomeAutomation || {}; APP.HomeAutomation.Manager = { ledCommandBaseTopic: "home/leds/", ledResultBaseTopic: "home/results/leds/", // Replace with the host name for the MQTT Server host: "localhost", // Replace...