From 8a9fd2236d179e752777ef9b5c22694c4494e837 Mon Sep 17 00:00:00 2001 From: Emmo00 Date: Tue, 7 Oct 2025 15:39:41 +0100 Subject: [PATCH 1/2] ... --- src/logic/mqtt.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/logic/mqtt.ts b/src/logic/mqtt.ts index 7d22e33..8a7b289 100644 --- a/src/logic/mqtt.ts +++ b/src/logic/mqtt.ts @@ -206,7 +206,7 @@ export async function handleMessage(blob: Buffer) { } const state = - decoded.nonce === expectedNonce ? { is_on: true } : { nonce: m3ter.latestNonce - 1, is_on: true }; + decoded.nonce === expectedNonce ? { is_on: true } : { nonce: m3ter.latestNonce, is_on: true }; // TODO: remove the following block after testing // if transaction nonce is 0 and the latest nonce is 0 From 8ba7aa2b75a7021ed556efd56cba8a5a9afc1b93 Mon Sep 17 00:00:00 2001 From: Emmo00 Date: Tue, 7 Oct 2025 16:13:55 +0100 Subject: [PATCH 2/2] fix: enhance logging for public key presence and meter retrieval in handleMessage function --- src/logic/mqtt.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/logic/mqtt.ts b/src/logic/mqtt.ts index 8a7b289..a3e9966 100644 --- a/src/logic/mqtt.ts +++ b/src/logic/mqtt.ts @@ -85,6 +85,7 @@ export async function handleMessage(blob: Buffer) { console.log("[info] Verified signature"); if (payloadHadPublicKey) { + console.log("[info] Payload contained public key:", publicKey); // save public key with device EUI mapping if not already saved const existingMeter = getMeterByPublicKey(`0x${publicKey}`); @@ -127,6 +128,8 @@ export async function handleMessage(blob: Buffer) { throw new Error("Meter not found for public key: " + publicKey); } + console.log("[info] Found meter:", m3ter); + if (m3ter.latestNonce % SYNC_EPOCH === 0) { // sync with blockchain every SYNC_EPOCH transactions await pruneAndSyncOnchain(m3ter.tokenId); @@ -185,6 +188,8 @@ export async function handleMessage(blob: Buffer) { updateMeterNonce(`0x${publicKey}`, expectedNonce); + console.log("[debug] Current all meters:", getAllMeterRecords()); + console.log("[info] Updated meter nonce to:", expectedNonce); try {