Using the Industrial Communication toolbox, we were able to use MATLAB to connect to our MQTT broker as a client by creating a client object and using write function.
Put our MQTT client object into our userdata and replace the task display code in our callTask function with the MQTT write function and now we can control the zigbee electrical outlet with IR remote.
This part is the most problematic of this week’s work. Due to the lack of experience with how a MATLAB app works, we encounter several problems during our attempt to implement IR signal graph plotting. For example, the configureCallback function won’t work like in normal MATLAB. You have to pass an extra “event” argument to it for it to work.
After we were able to display the IR signal graph in our GUI app, we implemented the MQTT publishing function to toggle the zigbee electrical outlet. It worked well in normal condition, but there is rapid repeating toggling when the Zigbee2MQTT lost connection to the MQTT broker unexpectedly then reconnected.