|
33 | 33 | from meshcore import MeshCore, EventType, logger |
34 | 34 |
|
35 | 35 | # Version |
36 | | -VERSION = "v1.2.6" |
| 36 | +VERSION = "v1.2.7" |
37 | 37 |
|
38 | 38 | # default ble address is stored in a config file |
39 | 39 | MCCLI_CONFIG_DIR = str(Path.home()) + "/.config/meshcore/" |
@@ -451,6 +451,7 @@ def make_completion_dict(contacts, pending={}, to=None, channels=None): |
451 | 451 | "share_contact" : contact_list, |
452 | 452 | "path": contact_list, |
453 | 453 | "disc_path" : contact_list, |
| 454 | + "node_discover": {"all":None, "sens":None, "rep":None, "comp":None, "room":None, "cli":None}, |
454 | 455 | "trace" : None, |
455 | 456 | "reset_path" : contact_list, |
456 | 457 | "change_path" : contact_list, |
@@ -580,6 +581,7 @@ def make_completion_dict(contacts, pending={}, to=None, channels=None): |
580 | 581 | "neighbors" : None, |
581 | 582 | "req_acl":None, |
582 | 583 | "setperm":contact_list, |
| 584 | + "region" : {"get":None, "allowf": None, "denyf": None, "put": None, "remove": None, "save": None, "home": None}, |
583 | 585 | "gps" : {"on":None,"off":None,"sync":None,"setloc":None, |
584 | 586 | "advert" : {"none": None, "share": None, "prefs": None}, |
585 | 587 | }, |
@@ -2217,7 +2219,7 @@ async def next_cmd(mc, cmds, json_output=False): |
2217 | 2219 | argnum = 2 |
2218 | 2220 | dest = None |
2219 | 2221 |
|
2220 | | - if len(cmds[1]) == 12: # possibly an hex prefix |
| 2222 | + if len(cmds[1]) == 12: # possibly an hex prefix |
2221 | 2223 | try: |
2222 | 2224 | dest = bytes.fromhex(cmds[1]) |
2223 | 2225 | except ValueError: |
@@ -2415,6 +2417,52 @@ async def next_cmd(mc, cmds, json_output=False): |
2415 | 2417 | inp = inp if inp != "" else "direct" |
2416 | 2418 | print(f"Path for {contact['adv_name']}: out {outp}, in {inp}") |
2417 | 2419 |
|
| 2420 | + case "node_discover"|"nd" : |
| 2421 | + argnum = 1 |
| 2422 | + try: # try to decode type as int |
| 2423 | + types = int(cmds[1]) |
| 2424 | + except ValueError: |
| 2425 | + if "all" in cmds[1]: |
| 2426 | + types = 0xFF |
| 2427 | + else : |
| 2428 | + types = 0 |
| 2429 | + if "rep" in cmds[1]: |
| 2430 | + types = types | 4 |
| 2431 | + if "cli" in cmds[1] or "comp" in cmds[1]: |
| 2432 | + types = types | 2 |
| 2433 | + if "room" in cmds[1]: |
| 2434 | + types = types | 8 |
| 2435 | + if "sens" in cmds[1]: |
| 2436 | + types = types | 16 |
| 2437 | + |
| 2438 | + res = await mc.commands.send_node_discover_req(types) |
| 2439 | + if res is None or res.type == EventType.ERROR: |
| 2440 | + print("Error sending discover request") |
| 2441 | + else: |
| 2442 | + exp_tag = res.payload["tag"].to_bytes(4, "little").hex() |
| 2443 | + dn = [] |
| 2444 | + while True: |
| 2445 | + r = await mc.wait_for_event( |
| 2446 | + EventType.DISCOVER_RESPONSE, |
| 2447 | + attribute_filters={"tag":exp_tag}, |
| 2448 | + timeout = 5 |
| 2449 | + ) |
| 2450 | + if r is None or r.type == EventType.ERROR: |
| 2451 | + break |
| 2452 | + else: |
| 2453 | + dn.append(r.payload) |
| 2454 | + |
| 2455 | + if json_output: |
| 2456 | + print(json.dumps(dn)) |
| 2457 | + else: |
| 2458 | + await mc.ensure_contacts() |
| 2459 | + print(f"Discovered {len(dn)} nodes:") |
| 2460 | + for n in dn: |
| 2461 | + name = mc.get_contact_by_key_prefix(n["pubkey"])['adv_name'] |
| 2462 | + if name is None: |
| 2463 | + name = n["pubkey"][0:12] |
| 2464 | + print(f" {name:12} type {n['node_type']} SNR: {n['SNR_in']:6,.2f}->{n['SNR']:6,.2f} RSSI: ->{n['RSSI']:4}") |
| 2465 | + |
2418 | 2466 | case "req_btelemetry"|"rbt" : |
2419 | 2467 | argnum = 1 |
2420 | 2468 | await mc.ensure_contacts() |
@@ -2968,6 +3016,7 @@ def command_help(): |
2968 | 3016 | time <epoch> : sets time to given epoch |
2969 | 3017 | clock : get current time |
2970 | 3018 | clock sync : sync device clock st |
| 3019 | + node_discover <filter> : discovers nodes based on their type nd |
2971 | 3020 | Contacts |
2972 | 3021 | contacts / list : gets contact list lc |
2973 | 3022 | reload_contacts : force reloading all contacts rc |
@@ -3041,7 +3090,18 @@ def get_help_for (cmdname, context="line") : |
3041 | 3090 | at t=2,u>1d,d cn trace |
3042 | 3091 | # tries to do flood login to all repeaters |
3043 | 3092 | at t=2 rp login |
3044 | | - """) |
| 3093 | +""") |
| 3094 | + |
| 3095 | + if cmdname == "node_discover" or cmdname == "nd" : |
| 3096 | + print("""node_discover <filter> : discovers 0-hop nodes and displays signal info |
| 3097 | +
|
| 3098 | + filter can be "all" for all types or nodes or a comma separated list consisting of : |
| 3099 | + - cli or comp for companions |
| 3100 | + - rep for repeaters |
| 3101 | + - sens for sensors |
| 3102 | + - room for chat rooms |
| 3103 | +""") |
| 3104 | + |
3045 | 3105 | else: |
3046 | 3106 | print(f"Sorry, no help yet for {cmdname}") |
3047 | 3107 |
|
|
0 commit comments