I am trying to program my Arduino to be pinged by the server/MQTT broker when it has not sent any data for over a period of x minutes to check if it is alive/dead(by low battery/lost connectivity)? Is there a way I can implement this and also is there an example code for reference?
Generally, the MQTT server does that out of the box. The usual interval for the keep alive ping is 60 seconds and if the Arduino doesn't respond, the connection is dropped. If you run the server in verbose mode you can see the event in the console.