How can i end the {cayenne.loop()} if there is no connection?

you could use the ping esp library to restore. example ping to Google if it returns true it restores Cayenne loop