Skip to content

Commit 201ec80

Browse files
committed
v2.1.19
update testing as well
1 parent b393f5e commit 201ec80

5 files changed

Lines changed: 38 additions & 34 deletions

File tree

meshtastic_listener/__main__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,12 @@ def __print_packet_received__(self, logger: Callable, message: dict) -> None:
143143

144144
channel = message.get('channel', 0)
145145
packet = message.get('decoded', {})
146-
snr = message.get('rxSnr', "N/A")
147-
rx_rssi = message.get('rxRssi', "N/A")
148146
msg_type = packet.get('portnum', 'UNKNOWN')
149147

150148
shortname = self.db.get_shortname(node_num)
151149
log_insert = self.__sanitize_string__(f"node {node_num}" if str(shortname) == str(node_num) else f"{node_num} ({shortname})")
152150

153-
logger(f"Received {msg_type} payload from {log_insert} on channel {channel} ({rx_rssi} dB rxRssi, {snr} rxSNR): {json.dumps(packet)}")
151+
logger(f"Received {msg_type} payload from {log_insert} on channel {channel}: {json.dumps(packet)}")
154152

155153
def __human_readable_ts__(self, rxTime: int | None = None) -> str:
156154
if rxTime is None:

meshtastic_listener/commands/cmd_handler.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import logging
22
import inspect
3+
from time import time
4+
from datetime import timedelta
35

46
from meshtastic_listener.data_structures import MessageReceived, NodeHealthCheck
5-
from meshtastic_listener.commands.subscriptions import handle_subscription_command
67
from meshtastic_listener.listener_db.listener_db import ListenerDb, Waypoints
78

89
logger = logging.getLogger(__name__)
@@ -70,7 +71,9 @@ def cmd_traceroute_health(self) -> str:
7071
'''
7172
5: !t - Get traceroute health summary
7273
'''
73-
response = ''
74+
lookback_ts = int(time()) - timedelta(days=1).total_seconds()
75+
76+
response = 'Traceroute Summary:\n'
7477
nodes = self.db.get_favorite_nodes()
7578
if len(nodes) == 0:
7679
return 'No favorite nodes found'
@@ -80,13 +83,15 @@ def cmd_traceroute_health(self) -> str:
8083
continue
8184
results = self.db.get_traceroute_results_by_node(
8285
source_id=self.server_node_id,
83-
target_id=node.nodeNum
86+
target_id=node.nodeNum,
87+
lookback_ts=lookback_ts
8488
)
8589
if len(results) == 0:
8690
response += f'{node.shortName}: No traces\n'
8791
else:
8892
successes = sum(1 for r in results if r.rxTime is not None)
89-
response += f'{node.shortName}: {successes}/{len(results)}\n'
93+
percentage = int((successes / len(results)) * 100)
94+
response += f'{node.shortName}: {successes}/{len(results)} {percentage}%\n'
9095
return response.strip()
9196

9297
# def cmd_subscriptions(self, context: MessageReceived) -> str:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "meshtatic_listener"
3-
version = "2.1.18"
3+
version = "2.1.19"
44
description = "A server for connecting to a Meshtastic device and responding to commands."
55
authors = [{ name = "Michael Gillett", email = "51103663+migillett@users.noreply.github.com" }]
66
requires-python = ">=3.10,<3.14"

tests/test_listener.py

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,38 @@ def test_listener():
8787
message_received = json.load(json_file)
8888
listener.__on_receive__(packet=message_received)
8989

90+
message_received = {
91+
"from": 1111111111,
92+
"to": 1234567890,
93+
"decoded": {
94+
"portnum": "TEXT_MESSAGE_APP",
95+
"bitfield": 0,
96+
"text": ""
97+
},
98+
"id": 222222222,
99+
"rxTime": 0,
100+
"rxSnr": 6.75,
101+
"hopLimit": 7,
102+
"wantAck": True,
103+
"rxRssi": -35,
104+
"hopStart": 7,
105+
"publicKey": "asdfasdfasdfasdfasdfasdfasdf=",
106+
"pkiEncrypted": True,
107+
"fromId": "!12345678",
108+
"toId": "!12345678"
109+
}
110+
90111
# a list of commands and the expected response from the BBS
91112
# we'll do a check of response.startswith(expected_response) for each command
92113
test_commands = [
93114
(None, ''),
94-
('!h', ''), # this message will be long, so just check for a basic response
95-
('!r', 'RX HOPS:'),
115+
('!r', 'RX HOPS: 7 / 7\nRX SNR: 6.75\nRX RSSI: -35'),
96116
('!w', 'Sent 1 waypoint to your map'), # we created 1 waypoint using the JSON test above
97-
('!i', 'Meshtastic Listener testing'),
98-
('!l', '1234567890 (TEST): testing'),
99117
('!c', 'No health check data available.'), # no health check data in the test messages
118+
('!l', '1234567890 (TEST): testing'),
119+
('!t', 'Traceroute Summary:'),
120+
('!i', 'Meshtastic Listener testing'),
121+
('!h', ''), # this message will be long, so just check for a basic response
100122

101123
# SUBSCRIPTIONS
102124
# ('!s', 'Subscription Commands:'),
@@ -113,27 +135,6 @@ def test_listener():
113135
# ('!s add *', 'Successfully subscribed to all topics'),
114136
]
115137

116-
message_received = {
117-
"from": 1234567890,
118-
"to": 1234567890,
119-
"decoded": {
120-
"portnum": "TEXT_MESSAGE_APP",
121-
"bitfield": 0,
122-
"text": ""
123-
},
124-
"id": 1234567890,
125-
"rxTime": 0,
126-
"rxSnr": 6.75,
127-
"hopLimit": 7,
128-
"wantAck": True,
129-
"rxRssi": -35,
130-
"hopStart": 7,
131-
"publicKey": "asdfasdfasdfasdfasdfasdfasdf=",
132-
"pkiEncrypted": True,
133-
"fromId": "!12345678",
134-
"toId": "!12345678"
135-
}
136-
137138
for message in test_commands:
138139
print(f'Sending message: {message[0]}')
139140
message_received['rxTime'] = int(time())

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)