From f7fb45692c1e13c3368eec437c724ad4897f3e7f Mon Sep 17 00:00:00 2001 From: Brian <165865819+brianshea2@users.noreply.github.com> Date: Tue, 28 May 2024 13:27:51 -0400 Subject: [PATCH] add online local nodes --- cmd/meshobserv/meshobserv.go | 7 ++++--- internal/meshtastic/node.go | 15 +++++++++------ website/index.html | 5 +++-- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/cmd/meshobserv/meshobserv.go b/cmd/meshobserv/meshobserv.go index f2e3ec4..605dc62 100644 --- a/cmd/meshobserv/meshobserv.go +++ b/cmd/meshobserv/meshobserv.go @@ -138,13 +138,14 @@ func handleMessage(from uint32, topic string, portNum generated.PortNum, payload region := mapReport.GetRegion().String() modemPreset := mapReport.GetModemPreset().String() hasDefaultCh := mapReport.GetHasDefaultChannel() + onlineLocalNodes := mapReport.GetNumOnlineLocalNodes() latitude := mapReport.GetLatitudeI() longitude := mapReport.GetLongitudeI() precision := mapReport.GetPositionPrecision() log.Printf( - "[msg] %v (%v) %s: {\"%v\" \"%v\" %v %v %v %v %v %v} (%v, %v) %v/32", + "[msg] %v (%v) %s: {\"%v\" \"%v\" %v %v %v %v %v %v %v} (%v, %v) %v/32", from, topic, portNum, - longName, shortName, hwModel, role, fwVersion, region, modemPreset, hasDefaultCh, + longName, shortName, hwModel, role, fwVersion, region, modemPreset, hasDefaultCh, onlineLocalNodes, latitude, longitude, precision, ) if len(longName) == 0 { @@ -158,7 +159,7 @@ func handleMessage(from uint32, topic string, portNum generated.PortNum, payload Nodes[from] = meshtastic.NewNode(topic) } Nodes[from].UpdateUser(longName, shortName, hwModel, role) - Nodes[from].UpdateMapReport(fwVersion, region, modemPreset, hasDefaultCh) + Nodes[from].UpdateMapReport(fwVersion, region, modemPreset, hasDefaultCh, onlineLocalNodes) Nodes[from].UpdatePosition(latitude, longitude, precision) Nodes[from].UpdateSeenBy(topic) NodesMutex.Unlock() diff --git a/internal/meshtastic/node.go b/internal/meshtastic/node.go index 505a5f2..c08db75 100644 --- a/internal/meshtastic/node.go +++ b/internal/meshtastic/node.go @@ -24,11 +24,12 @@ type Node struct { HwModel string `json:"hwModel"` Role string `json:"role"` // MapReport - FwVersion string `json:"fwVersion,omitempty"` - Region string `json:"region,omitempty"` - ModemPreset string `json:"modemPreset,omitempty"` - HasDefaultCh bool `json:"hasDefaultCh,omitempty"` - LastMapReport int64 `json:"lastMapReport,omitempty"` + FwVersion string `json:"fwVersion,omitempty"` + Region string `json:"region,omitempty"` + ModemPreset string `json:"modemPreset,omitempty"` + HasDefaultCh bool `json:"hasDefaultCh,omitempty"` + OnlineLocalNodes uint32 `json:"onlineLocalNodes,omitempty"` + LastMapReport int64 `json:"lastMapReport,omitempty"` // Position Latitude int32 `json:"latitude"` Longitude int32 `json:"longitude"` @@ -66,6 +67,7 @@ func (node *Node) ClearMapReportData() { node.Region = "" node.ModemPreset = "" node.HasDefaultCh = false + node.OnlineLocalNodes = 0 node.LastMapReport = 0 } @@ -136,11 +138,12 @@ func (node *Node) UpdateDeviceMetrics(batteryLevel uint32, voltage, chUtil, airU node.LastDeviceMetrics = time.Now().Unix() } -func (node *Node) UpdateMapReport(fwVersion, region, modemPreset string, hasDefaultCh bool) { +func (node *Node) UpdateMapReport(fwVersion, region, modemPreset string, hasDefaultCh bool, onlineLocalNodes uint32) { node.FwVersion = fwVersion node.Region = region node.ModemPreset = modemPreset node.HasDefaultCh = hasDefaultCh + node.OnlineLocalNodes = onlineLocalNodes node.LastMapReport = time.Now().Unix() } diff --git a/website/index.html b/website/index.html index 9ddcaa0..7f1cb5c 100644 --- a/website/index.html +++ b/website/index.html @@ -217,7 +217,7 @@ const updateNodes = data => Object.entries(data).forEach(([nodeNum, node]) => { const { longName, shortName, hwModel, role, - fwVersion, region, modemPreset, hasDefaultCh, + fwVersion, region, modemPreset, hasDefaultCh, onlineLocalNodes, latitude, longitude, precision, batteryLevel, voltage, chUtil, airUtilTx, uptime, neighbors, seenBy @@ -239,11 +239,12 @@ ${fwVersion ? `Firmware${html(fwVersion)}` : ''} ${region ? `Region${html(region)}` : ''} ${modemPreset ? `Modem preset${html(modemPreset)}` : ''} - ${hasDefaultCh ? `Has default channelYes` : ''} + ${hasDefaultCh ? `Has default channel?Yes` : ''} ${batteryLevel ? `Power${batteryLevel > 100 ? 'Plugged in' : `${batteryLevel}%`}${voltage ? ` (${voltage.toFixed(1)}V)` : ''}` : ''} ${chUtil ? `ChUtil${chUtil.toFixed(1)}%` : ''} ${airUtilTx ? `AirUtilTX${airUtilTx.toFixed(1)}%` : ''} ${uptime ? `Uptime${duration(uptime)}` : ''} + ${onlineLocalNodes ? `Online local nodes${onlineLocalNodes}` : ''} ${precision && precisionMargins[precision-1] ? `Location precision± ${precisionMargins[precision-1].toLocaleString()} m (orange circle)` : '' }