Requesting data from the microcontroller
We might want to know if the light is currently turned on or off inside the living room, without having to walk all the way into the room. So, it would be great if the Wasm app could request the status of the light and display it.
Now, let's imagine we have one or multiple microcontrollers in different rooms, listening to messages. For this example, we do not want the microcontroller to continuously report the state of the light as this would cause unnecessary network traffic. So, we go on and send a message to request the data. The microcontrollers are subscribed to the status topic and get the message delivered. After receiving the status request, they answer it by each sending a status message.
This process is represented in the following diagram:
In order to implement that behavior, one microcontroller is sufficient. So, let's go on and update our code accordingly...