From 4925d7fa4f531af1270595fdb32d0cd897d62ad6 Mon Sep 17 00:00:00 2001 From: liamcottle Date: Sun, 9 Mar 2025 13:31:30 +1300 Subject: [PATCH] set device time on connect --- examples/tcp_command_bot.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/examples/tcp_command_bot.js b/examples/tcp_command_bot.js index c244dc5..824f4e2 100644 --- a/examples/tcp_command_bot.js +++ b/examples/tcp_command_bot.js @@ -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);