Try reading
Wi fi is easily susceptible to interference which will cause dropouts
Try the test with an Ethernet cable, a couple of $, it will almost certainly eliminate your problem. Then you can think how to implement a proper solution
I haven’t used WiFi for over 10 yrs for that reason