Skip to content

Fix repeater echo correlation by removing trailing whitespace in buildPayload()#62

Merged
MrAlders0n merged 2 commits intodevfrom
copilot/fix-message-correlation-issue
Dec 19, 2025
Merged

Fix repeater echo correlation by removing trailing whitespace in buildPayload()#62
MrAlders0n merged 2 commits intodevfrom
copilot/fix-message-correlation-issue

Conversation

Copy link
Contributor

Copilot AI commented Dec 19, 2025

Repeater echo tracking was failing because buildPayload() added trailing whitespace when no power setting was specified, causing includes() comparison to fail against echoed messages.

Problem
When messages are echoed through repeaters, Meshtastic adds the sender's device name as a prefix:

  • Sent: "@[MapperBot] 45.26900, -75.77755"
  • Echoed: "MrAlders0n: @[MapperBot] 45.26900, -75.77755"

The correlation logic uses decryptedMessage.includes(originalPayload) to match echoes, but failed because buildPayload() created payloads with trailing space:

// Before: adds trailing space when suffix is empty
return `${PING_PREFIX} ${coordsStr} ${suffix}`;  // "@[MapperBot] 45.26900, -75.77755 "

Changes

  • Modified buildPayload() to trim trailing whitespace:
// After: removes trailing whitespace
return `${PING_PREFIX} ${coordsStr}${suffix}`.trim();  // "@[MapperBot] 45.26900, -75.77755"

This ensures the payload comparison correctly matches echoed messages that contain the payload after the sender prefix.

Original prompt

Problem

The repeater echo tracking message correlation is failing because when messages are echoed back through repeaters, they include the sender's device name as a prefix.

Console Log Evidence

[DEBUG] [MESSAGE_CORRELATION] Decrypted: "MrAlders0n: @[MapperBot] 45.26900, -75.77755" (44 chars)
[DEBUG] [MESSAGE_CORRELATION] Expected:  "@[MapperBot] 45.26900, -75.77755 " (33 chars)
[DEBUG] [MESSAGE_CORRELATION] ❌ REJECT: Message content mismatch (not an echo of our ping)
[DEBUG] [MESSAGE_CORRELATION] This is a different message on the same channel

Root Cause

Two issues are causing the mismatch:

  1. Sender name prefix: The decrypted message includes "MrAlders0n: " before the actual payload, but the comparison doesn't account for this properly.

  2. Trailing whitespace: The buildPayload() function at line 893-898 creates a payload with a trailing space when no power setting is specified:

    function buildPayload(lat, lon) {
      const coordsStr = `${lat.toFixed(5)}, ${lon.toFixed(5)}`;
      const power = getCurrentPowerSetting();
      const suffix = power ? ` [${power}]` : "";
      return `${PING_PREFIX} ${coordsStr} ${suffix}`;  // Trailing space when suffix is empty!
    }

Solution

Fix the buildPayload() function in content/wardrive.js to trim trailing whitespace:

function buildPayload(lat, lon) {
  const coordsStr = `${lat.toFixed(5)}, ${lon.toFixed(5)}`;
  const power = getCurrentPowerSetting();
  const suffix = power ? ` [${power}]` : "";
  return `${PING_PREFIX} ${coordsStr}${suffix}`.trim();
}

This ensures the expected payload doesn't have trailing whitespace, which will allow the existing decryptedMessage.includes(originalPayload) check at line 1253 to correctly match the echoed message (which contains the payload after the sender prefix).

This pull request was created from Copilot chat.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…ion issue

Co-authored-by: MrAlders0n <55921894+MrAlders0n@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix message correlation for echoed messages Fix repeater echo correlation by removing trailing whitespace in buildPayload() Dec 19, 2025
Copilot AI requested a review from MrAlders0n December 19, 2025 04:58
@MrAlders0n MrAlders0n marked this pull request as ready for review December 19, 2025 04:59
@MrAlders0n MrAlders0n merged commit 6f7be90 into dev Dec 19, 2025
@MrAlders0n MrAlders0n deleted the copilot/fix-message-correlation-issue branch December 20, 2025 05:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants