Maybe this has been answered several times, but I haven't been able to find an answer that helps me. I'm not very code skilled, more of a DIY enthusiast with good patience. My apologies if double posting or using the wrong forum section.
I have an MCP23017 expansion board hooked up and use MQTT to send commands turning on/off the relays connected to the MCP.
My subscription is created using a wildcard
const char* controllerSubscription = "Controller/+/command";
Everything is working fine - I can receive MQTT commands and turn the relays on/off and publish back a state when successful. A topic I use in my callback may look like this
Where the "0" between "P" and "/command" is identifying the MCP pin to get the status change and the integer I want to get my hands on.
My issue is that I would like to have a more elegant code and avoid duplicating it. Sure, I could write 16 if statements using strcmp() and have the exact same code within each section. But, that will take up a lot of space and be cumbersome to maintain when doing changes.
So, I'm thinking that extracting the int "0" (in the example above) could allow me to skip the if section and work with the extracted int and concatenating when needed.
There are 16 pins on the MCP expander, so the int I need to extract can be 0-15. Any help would be appreciated, thanks.