Time() returning incorrect value after power cycle

The following code:
Agent:

server.log("Agent start");

function printTimestamp() {
    imp.wakeup(1, printTimestamp);
    server.log("agent timestamp is: " + time());
}

printTimestamp();

Device:

server.log("Device start");

function printTimestamp() {
    imp.wakeup(1, printTimestamp);
    server.log("device timestamp is: " + time());
}

printTimestamp();

Produces the following log file:

|2022-10-12T02:58:13.860 +00:00 |[Status] |Downloading new code; 0.07% program storage used|
|---|---|---|
|2022-10-12T02:58:19.418 +00:00 |[Status] |Agent restarted: reload.|
|2022-10-12T02:58:19.429 +00:00 |[Agent] |Agent start|
|2022-10-12T02:58:19.430 +00:00 |[Agent] |agent timestamp is: 1665543499|
|2022-10-12T02:58:20.088 +00:00 |[Status] |Downloading new code; 0.70% program storage used|
|2022-10-12T02:58:20.329 +00:00 |[Device] |Device start|
|2022-10-12T02:58:20.333 +00:00 |[Device] |device timestamp is: 1665543500|
|2022-10-12T02:58:20.430 +00:00 |[Agent] |agent timestamp is: 1665543500|
|2022-10-12T02:58:21.346 +00:00 |[Device] |device timestamp is: 1665543501|
|2022-10-12T02:58:21.421 +00:00 |[Agent] |agent timestamp is: 1665543501|
|2022-10-12T02:58:22.423 +00:00 |[Device] |device timestamp is: 1665543502|
|2022-10-12T02:58:22.425 +00:00 |[Agent] |agent timestamp is: 1665543502|
|2022-10-12T02:58:23.369 +00:00 |[Device] |device timestamp is: 1665543503|
|2022-10-12T02:58:23.423 +00:00 |[Agent] |agent timestamp is: 1665543503|
|2022-10-12T02:58:24.429 +00:00 |[Agent] |agent timestamp is: 1665543504|
|2022-10-12T02:58:24.372 +00:00 |[Device] |device timestamp is: 1665543504|
|2022-10-12T02:58:25.384 +00:00 |[Device] |device timestamp is: 1665543505|
|2022-10-12T02:58:25.428 +00:00 |[Agent] |agent timestamp is: 1665543505|
|2022-10-12T02:58:26.423 +00:00 |[Agent] |agent timestamp is: 1665543506|
|2022-10-12T02:58:27.428 +00:00 |[Agent] |agent timestamp is: 1665543507|
|2022-10-12T02:58:28.423 +00:00 |[Agent] |agent timestamp is: 1665543508|
|2022-10-12T02:58:29.420 +00:00 |[Agent] |agent timestamp is: 1665543509|
|2022-10-12T02:58:30.421 +00:00 |[Agent] |agent timestamp is: 1665543510|
|2022-10-12T02:58:31.429 +00:00 |[Agent] |agent timestamp is: 1665543511|
|2022-10-12T02:58:32.013 +00:00 |[Status] |Device disconnected|
|2022-10-12T02:58:32.024 +00:00 |[Status] |Device connected|
|2022-10-12T02:58:32.422 +00:00 |[Agent] |agent timestamp is: 1665543512|
|2022-10-12T02:58:32.307 +00:00 |[Device] |Device start|
|2022-10-12T02:58:32.366 +00:00 |[Device] |device timestamp is: 946684800|
|2022-10-12T02:58:33.296 +00:00 |[Device] |device timestamp is: 946684801|
|2022-10-12T02:58:33.421 +00:00 |[Agent] |agent timestamp is: 1665543513|
|2022-10-12T02:58:34.306 +00:00 |[Device] |device timestamp is: 946684802|
|2022-10-12T02:58:34.424 +00:00 |[Agent] |agent timestamp is: 1665543514|
|2022-10-12T02:58:35.423 +00:00 |[Agent] |agent timestamp is: 1665543515|
|2022-10-12T02:58:35.307 +00:00 |[Device] |device timestamp is: 946684803|
|2022-10-12T02:58:36.424 +00:00 |[Agent] |agent timestamp is: 1665543516|
|2022-10-12T02:58:36.324 +00:00 |[Device] |device timestamp is: 946684804|
|2022-10-12T02:58:37.337 +00:00 |[Device] |device timestamp is: 946684805|

If the device is restarted using the restart instruction from within impcentral (ie renew code) the timestamp on the device is the same as the timestamp on the agent (starts with 16) however when turning off the power and turning on again, the device starts at 946684800 which is 00:00:00 1Jan2000.

This happens on the imp001 and imp002. Tested on the imp005 & imp006 where it works as expected. These are the only imp’s I have available.

How can I get the same on a power startup as I do when it’s a restart from within impcentral?

If the RTC on the imp is not battery-backed, you would expect it to be reset to its default value after a power cycle. The imp’s RTC time will be synced shortly after connecting. You might find that the imp005/6 are reporting correct time values only because Squirrel is blocked until a connection with the server is made.