MQTT Node MCU - Publish on High Pin


First ever post on here so I'm sorry if I have asked anything I shouldn't.

I'm trying to set up an MQTT topic publish on a NodeMCU when a digital pin goes high.

I have only ever done this the other way round, where I subscribe to an MQTT topic and set a pin to high for a relay.

Any help would be appreciated. I currently have no sketch but I'm hoping someone might be able to point me to an example I'm yet to find.

Or maybe this isn't even possible. Sorry for my noobness.. :o


Where is your problem in calling the publish function when the pin gets changed? If you are already able to connect, that are literally additional 2-4 lines.