set device time on connect

This commit is contained in:
liamcottle 2025-03-09 13:31:30 +13:00
parent 5c6b2e1e04
commit 4925d7fa4f

View file

@ -10,6 +10,9 @@ connection.on("connected", async () => {
// we are now connected
console.log(`Connected to: [${connection.host}:${connection.port}]`);
// set device time
await setDeviceTime();
// send flood advert when connected
await connection.sendFloodAdvert();
@ -31,6 +34,15 @@ connection.on(Constants.PushCodes.MsgWaiting, async () => {
}
});
async function setDeviceTime() {
try {
// update time on meshcore device
await connection.setDeviceTime(Math.floor(Date.now() / 1000));
} catch(e) {
// ignore sync error
}
}
async function onContactMessageReceived(message) {
console.log("Received contact message", message);