Are you using the correct PubSubClient.h library for the project as things change sometimes braking the old way of doing things.
Are you awear of Tasmota you can use it to acheave what you are looking to do. You set it up through webpage and it will be easy to install.
I use this tool to flash my devices. tasmotizer
Just run the program
Select serial port
Select image Release
Erase before flashing
Tasmotize
Then in Send config put in all the details.
Goto get ip
Navigate to ip in browser