Archiving and synchronization of data along with time stamp with MQTT broker after failure of internet connection in IOT gateway

A good first step is always to search this forum to see if the question has come up before.

Which while not giving an answer, will give you lots of things to think about...