Finally, we encounter the document ready function at line (1o) where we initialize our web page content and register the event listener for the slider:
$(document).ready(function() { // (10)
$("#clientId").html(CLIENT_ID);
// Event listener for Slider value changes.
$("input[type=range].brightnessLevel").on('input', function() {
level = $(this).val();
payload = {
"level": level
};
// Publish LED brightness.
var message = new Paho.Message( // (11)
JSON.stringify(payload)
);
message.destinationName = TOPIC; // (12)
message.qos = 2;
message.retained = true; // (13)
client.send(message);
});
});
Within the sliders event handler at line (11), we see how to create an MQTT message. Notice the use of JSON.stringify...