I'm used your template as a base, but used some termux scripts instead of Wirebug.I haven't been following the replies on this thread, so I have no idea what's going on anymore. I switched to using root on all my devices for the past few years and didn't really need the adb tcpip 5555 method anymore.
However, I recently bought a device that I can't root because it'll break a few things, such as Widevine L1 for Netflix, among other things. So I've decided to revisit the adb tcpip 5555 method once more.
I ended up creating another solution that is pretty consistent and easy to use. It's currently working on my Redmi K60 running MIUI 14, Android 13. You need Termux and Termux Tasker plugin for this to work.
Basically, I just need to open the Wireless Debugging page under Developer Settings. Then, read the screen contents and grab the values under "IP address and Port". Note that at this step, I don't need to pair my device and enter the pairing code. It's not required.
Once I have the IP address and port (e.g. 192.168.0.140:34551), I then pass this into Termux via the Termux Tasker plugin. It will do a adb connect 192.168.0.140:34551 and then once connected, it will do adb tcpip 5555 and voila, it's working now.
I've uploaded my macro to the template store. Macro id is 21169 and the name is "Switch ADB Mode".
My macro includes the things I've discussed above but also does other things as well. You can ignore those extra stuff if you don't need them. The macro basically uses a MacroDroid quick tile and I can toggle it to turn on ADB USB mode or ADB TCPIP 5555 mode. When ADB TCPIP 5555 mode is toggled, it'll execute the actions described above.
UPDATE:
Found an even better method. You'll need the Wirebug app from F-Droid store. You can then use another macro that I've created (id = 21171) to get it running. You just need the IP to use adb connect, you don't even need the port. It's very easy to get the IP (it'll show on the Wirebug app and you can do a Read Screen Contents and then extract it), or use the builtin Macrodroid magic text {ip} to get the current IP.
Note that during my testing, turning on Wireless Debugging and using adb connect IP_address is not enough. I needed to use Wirebug to enable wireless debugging from the app, then I can use adb connect IP_address and after that I can run adb tcpip 5555. I'm not sure what Wirebug is doing in the background after you enable debugging in the app, but hey it works.
But I have one problem (that I don't know if it's solvable)... is ADB pver TCPIP only supposed to work if you are connected to an wifi network and have wireless debugging turned on?
I currently need to re-run the macro for activating adb over tcpip 5555 not only after I reboot the hpine, but even after I disconnect the wi-fi and later connect again.
It would be fine if only the first activation after reboot needed wifi. Or am I doing something wrong?
btw I'm not rooted, and I'm using termux-adb instead of regular adb from android-tools package