I'm still pretty new to python and node red... I'm experimenting with upython on ESP32 and node red on raspberry pi. I'm more of a hacker than a programmer... I find examples that I can modify to do what I want. Several good examples here...
There is a new feature on github called gists... a way to share bits of code that are not so easy to share via a web page such this blog which is hosted on google blogger. You can copy the code in the window below and then import it into node red.
The code is for the bottom bit below as the top portion is avalable from the link above. The top one was the example I found and the bottom one was after modifications for my use. The original only changed the look and label. I've added the capability to send custom topic and payload to turn on a relay controlled by an ESP32 running upython. It acts as a client and the raspberry pi acts a the broker using the mosquito protocol. Node red is a package running on the raspberry pi which provides a graphical interface to create flows like the ones below to direct information to and from client devices on your local network.