Whiles I review your code, your ESP8266 does not have the same capability of using the pointers in the same way I do.
Just below the Arduino IDE icon located to the right side, kinda under the x, to open the Monitor and under that is another icon. Click that icon, select new tab, name the tab certs.h, OK,go to the new tab and enter your secret info there.
Example.
const char* SSID = "SomeSSID";
const char* PASSWORD = "somepassword";
Save.
On the main tab, add #include "certs.h"
Now you can use SSID for your ssid and PASSWORD for the password, select your code, and paste it elsewhere, without having to deal with making sure your code is clean before posting it.
And, could you state the issue you are having and the possible location in code you think the issue stems from?
You are running a MQTT keepalive, client.loop(). Perhaps adding client.setKeepAlive( 90 ); could help?