Skip to content

Commit

Permalink
Pevent missing packet.to from crashing Log UI #19
Browse files Browse the repository at this point in the history
  • Loading branch information
Soltares committed Oct 10, 2024
1 parent 6201b12 commit 5f7383b
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 8 deletions.
9 changes: 6 additions & 3 deletions api/src/vars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export type DeviceMetrics = {
voltage: number
channelUtilization: number
airUtilTx: number
uptimeSeconds?: number
}

export type NodeInfo = {
Expand Down Expand Up @@ -132,7 +133,7 @@ export type MeshPacket = {
channel: number
encrypted?: string
decoded?: any
payloadVariant: any
payloadVariant?: any
// {
// case: 'decoded',
// value: Data {
Expand All @@ -150,11 +151,13 @@ export type MeshPacket = {
rxSnr: number
hopLimit: number
wantAck: boolean
priority: number
priority: any
rxRssi: number
delayed: number
delayed: any
viaMqtt: boolean
hopStart: number
publicKey?: string
pkiEncrypted?: boolean
data?: string
message?: Message
deviceMetrics?: DeviceMetrics
Expand Down
2 changes: 1 addition & 1 deletion electron/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "meshsense",
"version": "1.0.15-beta.2",
"version": "1.0.15-beta.3",
"description": "MeshSense is a simple, open-source application that monitors, maps and graphically displays all the vital stats of your area's Meshtastic network including connected nodes, signal reports, trace routes and more!",
"main": "./out/main/index.js",
"author": "Affirmatech Inc.",
Expand Down
9 changes: 6 additions & 3 deletions ui/src/Log.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import { broadcastId, channels, myNodeNum, nodes, packets, type MeshPacket } from 'api/src/vars'
import { broadcastId, channels, myNodeNum, nodes, packets, version, type MeshPacket } from 'api/src/vars'
import Card from './lib/Card.svelte'
import { getNodeNameById, scrollToBottom } from './lib/util'
import { getNodeNameById, scrollToBottom, testPacket } from './lib/util'
import Modal from './lib/Modal.svelte'
import { messageDestination } from './Message.svelte'
import { tick } from 'svelte'
Expand Down Expand Up @@ -87,7 +87,7 @@
<img class="h-4 inline-block" src="https://icongaga-api.bytedancer.workers.dev/api/genHexer?name={packet.from}" alt="Node {packet.from}" />
{getNodeNameById(packet.from)}
</div>
{#if packet.to != 4294967295}
{#if packet.to && packet.to != 4294967295}
<div>to</div>
<div class="">{getNodeNameById(packet.to)}</div>
{/if}
Expand Down Expand Up @@ -150,6 +150,9 @@
{#if filterText}<button on:click={() => (filterText = '')} class="btn text-sm !py-0">Clear</button>{/if}
<button class="btn btn-sm text-xs" on:click={() => generateCSV()}>CSV</button>
{#if unseenMessages}<button class="btn !py-0 bottom-10" on:click={() => scrollToBottom(packetsDiv, true, (unseen) => (unseenMessages = unseen))}>Jump to new messages</button>{/if}
{#if !$version}
<button class="btn text-xs" on:click={testPacket}>Test Packet</button>
{/if}
</label>
</h2>
</Card>
40 changes: 39 additions & 1 deletion ui/src/lib/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,48 @@ packets.on('upsert', (e) => {

export function getNodeNameById(id: number) {
if (id == broadcastId) return 'all'
if (id == undefined) return 'unknown'
let node = nodes.value.find((node) => node.num == id)
return node ? getNodeName(node) : `!${id.toString(16)}`
return node ? getNodeName(node) : `!${id?.toString(16)}`
}

export function getNodeName(node: NodeInfo) {
return node?.user?.shortName || node?.user?.id || '!' + node?.num?.toString(16)
}

export function testPacket() {
packets.push({
from: 2171857383,
to: 4294967295,
channel: 0,
decoded: {
portnum: 'TELEMETRY_APP',
payload: 'DTHrB2cSFQhlFXnpgkAd6LSBPyXxhoc/KNjmCA==',
wantResponse: false,
dest: 0,
source: 0,
requestId: 0,
replyId: 0,
emoji: 0
},
id: 1727925148,
rxTime: 1728572132,
rxSnr: 6,
hopLimit: 7,
wantAck: false,
priority: 'UNSET',
rxRssi: -84,
delayed: 'NO_DELAY',
viaMqtt: false,
hopStart: 7,
publicKey: '',
pkiEncrypted: false,
deviceMetrics: {
batteryLevel: 101,
voltage: 4.091000080108643,
channelUtilization: 1.0133333206176758,
airUtilTx: 1.0588055849075317,
uptimeSeconds: 144216
}
})
}

0 comments on commit 5f7383b

Please sign in to comment.