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()
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()

View file

@ -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()
}

View file

@ -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 ? `<tr><th>Firmware</th><td>${html(fwVersion)}</td></tr>` : ''}
${region ? `<tr><th>Region</th><td>${html(region)}</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>` : ''}
${chUtil ? `<tr><th>ChUtil</th><td>${chUtil.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>` : ''}
${onlineLocalNodes ? `<tr><th>Online local nodes</th><td>${onlineLocalNodes}</td></tr>` : ''}
${precision && precisionMargins[precision-1] ?
`<tr><th>Location precision</th><td>&#177; ${precisionMargins[precision-1].toLocaleString()} m (orange circle)</td></tr>` : ''
}