Processing the received messages in JavaScript
The onMessageArrived
function receives a Paho.MQTT.Message
instance in the message
argument. The code prints a message to the console log indicating that a message has arrived with the destination topic and the payload string included in the message.destinationName
and message.payloadString
attributes.
Then, the code checks whether message.destionationName
starts with APP.HomeAutomation.Manager.ledResultBaseTopic
to make sure that the message's destination topic is the one defined for the results of the commands related to LEDs.
Note
In this case, the code only subscribes to the topic filters that we defined for publishing messages with the results of the commands related to LEDs. However, we include this code to understand how we should check the message.destinationName
value when we subscribe to multiple topics that have different goals.
Then, the code retrieves the LED ID from the message's topic and saves it in the ledNumber
variable. The code...