add online local nodes

This commit is contained in:
Brian 2024-05-28 13:27:51 -04:00
parent 980822d8d0
commit f7fb45692c
3 changed files with 16 additions and 11 deletions

View file

@ -138,13 +138,14 @@ func handleMessage(from uint32, topic string, portNum generated.PortNum, payload
region := mapReport.GetRegion().String() region := mapReport.GetRegion().String()
modemPreset := mapReport.GetModemPreset().String() modemPreset := mapReport.GetModemPreset().String()
hasDefaultCh := mapReport.GetHasDefaultChannel() hasDefaultCh := mapReport.GetHasDefaultChannel()
onlineLocalNodes := mapReport.GetNumOnlineLocalNodes()
latitude := mapReport.GetLatitudeI() latitude := mapReport.GetLatitudeI()
longitude := mapReport.GetLongitudeI() longitude := mapReport.GetLongitudeI()
precision := mapReport.GetPositionPrecision() precision := mapReport.GetPositionPrecision()
log.Printf( 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, from, topic, portNum,
longName, shortName, hwModel, role, fwVersion, region, modemPreset, hasDefaultCh, longName, shortName, hwModel, role, fwVersion, region, modemPreset, hasDefaultCh, onlineLocalNodes,
latitude, longitude, precision, latitude, longitude, precision,
) )
if len(longName) == 0 { 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] = meshtastic.NewNode(topic)
} }
Nodes[from].UpdateUser(longName, shortName, hwModel, role) 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].UpdatePosition(latitude, longitude, precision)
Nodes[from].UpdateSeenBy(topic) Nodes[from].UpdateSeenBy(topic)
NodesMutex.Unlock() NodesMutex.Unlock()

View file

@ -28,6 +28,7 @@ type Node struct {
Region string `json:"region,omitempty"` Region string `json:"region,omitempty"`
ModemPreset string `json:"modemPreset,omitempty"` ModemPreset string `json:"modemPreset,omitempty"`
HasDefaultCh bool `json:"hasDefaultCh,omitempty"` HasDefaultCh bool `json:"hasDefaultCh,omitempty"`
OnlineLocalNodes uint32 `json:"onlineLocalNodes,omitempty"`
LastMapReport int64 `json:"lastMapReport,omitempty"` LastMapReport int64 `json:"lastMapReport,omitempty"`
// Position // Position
Latitude int32 `json:"latitude"` Latitude int32 `json:"latitude"`
@ -66,6 +67,7 @@ func (node *Node) ClearMapReportData() {
node.Region = "" node.Region = ""
node.ModemPreset = "" node.ModemPreset = ""
node.HasDefaultCh = false node.HasDefaultCh = false
node.OnlineLocalNodes = 0
node.LastMapReport = 0 node.LastMapReport = 0
} }
@ -136,11 +138,12 @@ func (node *Node) UpdateDeviceMetrics(batteryLevel uint32, voltage, chUtil, airU
node.LastDeviceMetrics = time.Now().Unix() 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.FwVersion = fwVersion
node.Region = region node.Region = region
node.ModemPreset = modemPreset node.ModemPreset = modemPreset
node.HasDefaultCh = hasDefaultCh node.HasDefaultCh = hasDefaultCh
node.OnlineLocalNodes = onlineLocalNodes
node.LastMapReport = time.Now().Unix() node.LastMapReport = time.Now().Unix()
} }

View file

@ -217,7 +217,7 @@
const updateNodes = data => Object.entries(data).forEach(([nodeNum, node]) => { const updateNodes = data => Object.entries(data).forEach(([nodeNum, node]) => {
const { const {
longName, shortName, hwModel, role, longName, shortName, hwModel, role,
fwVersion, region, modemPreset, hasDefaultCh, fwVersion, region, modemPreset, hasDefaultCh, onlineLocalNodes,
latitude, longitude, precision, latitude, longitude, precision,
batteryLevel, voltage, chUtil, airUtilTx, uptime, batteryLevel, voltage, chUtil, airUtilTx, uptime,
neighbors, seenBy neighbors, seenBy
@ -239,11 +239,12 @@
${fwVersion ? `<tr><th>Firmware</th><td>${html(fwVersion)}</td></tr>` : ''} ${fwVersion ? `<tr><th>Firmware</th><td>${html(fwVersion)}</td></tr>` : ''}
${region ? `<tr><th>Region</th><td>${html(region)}</td></tr>` : ''} ${region ? `<tr><th>Region</th><td>${html(region)}</td></tr>` : ''}
${modemPreset ? `<tr><th>Modem preset</th><td>${html(modemPreset)}</td></tr>` : ''} ${modemPreset ? `<tr><th>Modem preset</th><td>${html(modemPreset)}</td></tr>` : ''}
${hasDefaultCh ? `<tr><th>Has default channel</th><td>Yes</td></tr>` : ''} ${hasDefaultCh ? `<tr><th>Has default channel?</th><td>Yes</td></tr>` : ''}
${batteryLevel ? `<tr><th>Power</th><td>${batteryLevel > 100 ? 'Plugged in' : `${batteryLevel}%`}${voltage ? ` (${voltage.toFixed(1)}V)` : ''}</td></tr>` : ''} ${batteryLevel ? `<tr><th>Power</th><td>${batteryLevel > 100 ? 'Plugged in' : `${batteryLevel}%`}${voltage ? ` (${voltage.toFixed(1)}V)` : ''}</td></tr>` : ''}
${chUtil ? `<tr><th>ChUtil</th><td>${chUtil.toFixed(1)}%</td></tr>` : ''} ${chUtil ? `<tr><th>ChUtil</th><td>${chUtil.toFixed(1)}%</td></tr>` : ''}
${airUtilTx ? `<tr><th>AirUtilTX</th><td>${airUtilTx.toFixed(1)}%</td></tr>` : ''} ${airUtilTx ? `<tr><th>AirUtilTX</th><td>${airUtilTx.toFixed(1)}%</td></tr>` : ''}
${uptime ? `<tr><th>Uptime</th><td>${duration(uptime)}</td></tr>` : ''} ${uptime ? `<tr><th>Uptime</th><td>${duration(uptime)}</td></tr>` : ''}
${onlineLocalNodes ? `<tr><th>Online local nodes</th><td>${onlineLocalNodes}</td></tr>` : ''}
${precision && precisionMargins[precision-1] ? ${precision && precisionMargins[precision-1] ?
`<tr><th>Location precision</th><td>&#177; ${precisionMargins[precision-1].toLocaleString()} m (orange circle)</td></tr>` : '' `<tr><th>Location precision</th><td>&#177; ${precisionMargins[precision-1].toLocaleString()} m (orange circle)</td></tr>` : ''
} }