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

JQuery document ready function

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

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