Stops sending data to MQTT

I have this solar project where I upload data to I have to esp32s with the same code. I have this hypotosis, that they disrupt each others signal, because when i put then close it seems that one of them stop transmitting data. So I put them 5-10 meters apart and the use diffrent wifis. Randomly one of them stops transmitting, but when I press the reset button on them, I starts again. Anybody who has an idea of whats going on? Thanks. It's really annoying since I'm trying to run test during a week, when one stops transmitting, It disrupts the data, and the test. Link to code: Thanks for any help

i'm curious how you code works. there's no loop() body and it looks the code sleeps at the end of setup(). Does it just execute loop() when it wakes up? is all the monitoring and messaging handled in callback functions?

presumably the code needs to reconnect when coming out of sleep. connect() makes an attempt and disconnect()s when failed. is there some guarnatee that a connect will always succeed? why not try again?

@gcjr esp32 deep sleep on wake up is a reset that causes setup() to be ran.

so it starts fresh each time -- it has no history from what happened previously. It should behave as if it were powered up after waking up from sleep?

but it doesn't

I doubt that the two devices are interfering with each other, in the RF sense. WiFi is just too good at correcting for collisions.

I have never used the Adafruit library, but I have a similar issue using the PubSub library.
In the PubSub library, the client constructor has to be unique on the network because this is how the broker identifies the node.

Try this. On one node (no change)

// Create an ESP8266 WiFiClient class to connect to the MQTT server.
WiFiClient client;

And in the second copy, change the constructor name:

// Create an ESP8266 WiFiClient class to connect to the MQTT server.
WiFiClient client2;

And, please let me know the results.

Thanks I will try it and see if it helps. One thing that I tried was using two diffrent accounts on, but that didn’t seem to help. It’s really weird I suspect that someting else is off with the code. For example I have two solar panels, one that’s mounted on a servo and one thats static. When the dynamic solar panel stops sending the servo also stops moving. It’s only when I press reset on the esp32 that the servo starts moving and the esp32 starts sending data. It’s like something stops/ pauses the code, it’s like it runs out of “memory” and you have to reset it for it to start again. Do you have any idea of what might be causing this? Where I should look in the code?

Thanks for the help