Okay, you have one of the old free accounts with no monthly message limits.
There are a number of issues with this code, but it’s also far too complex to be used for connection debugging so I’d suggest that you go back to this topic…
and stop posting incomplete or edited code.
Your long ping times are an issue, and could be the cause of your problem. Adding an externa antenna to boost your GPRS signal strength may help, or relocating the device may help. I think some of the TinyGSM examples allow you to show GPRS signal strength, which may be helpful.
The way in which you’re powering your SIM800 module may also be an issue. The module requires a LOT of current when in Tx mode.
Pete.