Can you explain more precisely or post a video how this red flashing looks?
Till then, just a few hints that won’t change a lot, but should be kept in mind.
Remove the double includes for libraries.
I’d get rid of
String variables and substitute them with
char - especially in frequently called functions.
TOKEN is a rather common term and
are not really good with scopes, I'd at least change that to something unique or even better replace your#define`s with
const char myToken = "....";
This way you’d get an error and not just a (unseen) warning in case of collisions.
Slow down your
loop() a bit to give the MQTT broker some slack
For formatting posts, these tripple grave accent need to be all alone (with the optional coding scheme) on their lines to do the formatting right
// no blanks or other text before or after
I have corrected that in your post already.