meshcore-cli 1.6.7__tar.gz → 1.6.8__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: meshcore-cli
3
- Version: 1.6.7
3
+ Version: 1.6.8
4
4
  Summary: Command line interface to meshcore companion radios and repeaters
5
5
  Project-URL: Homepage, https://github.com/fdlamotte/meshcore-cli
6
6
  Project-URL: Issues, https://github.com/fdlamotte/meshcore-cli/issues
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "meshcore-cli"
7
- version = "1.6.7"
7
+ version = "1.6.8"
8
8
  authors = [
9
9
  { name="Florent de Lamotte", email="florent@frizoncorrea.fr" },
10
10
  ]
@@ -35,7 +35,7 @@ except ImportError:
35
35
  from meshcore import MeshCore, EventType, logger
36
36
 
37
37
  # Version
38
- VERSION = "v1.6.7"
38
+ VERSION = "v1.6.8"
39
39
 
40
40
  # default ble address is stored in a config file
41
41
  MCCLI_CONFIG_DIR = os.path.expanduser("~/.config/meshcore/")
@@ -154,6 +154,8 @@ LC_DISPLAY_TYPES = [1, 2, 3, 4]
154
154
  LC_OUTPUT_FORMAT = "tkah"
155
155
  LC_SORT_ORDER = ""
156
156
 
157
+ LAST_DISCOVERED_NODES = []
158
+
157
159
  def time_ago_from_timestamp (timestamp):
158
160
  if timestamp == 0:
159
161
  return "0"
@@ -663,6 +665,7 @@ def make_completion_dict(contacts, pending=None, to=None, channels=None):
663
665
  pending = pending or {}
664
666
  contact_list = {}
665
667
  pending_list = {}
668
+ discovered_list = {"-a":None}
666
669
  to_list = {}
667
670
 
668
671
  to_list["~"] = None
@@ -683,6 +686,8 @@ def make_completion_dict(contacts, pending=None, to=None, channels=None):
683
686
  for c in pit :
684
687
  pending_list[c[1]['public_key']] = None
685
688
 
689
+ for n in LAST_DISCOVERED_NODES:
690
+ discovered_list[n['pubkey'][:16]] = None
686
691
  to_list.update(contact_list)
687
692
 
688
693
  to_list["ch"] = None
@@ -725,7 +730,9 @@ def make_completion_dict(contacts, pending=None, to=None, channels=None):
725
730
  "path": contact_list,
726
731
  "disc_path" : contact_list,
727
732
  "advert_path" : contact_list | pending_list,
728
- "node_discover": {"all":None, "sens":None, "rep":None, "comp":None, "room":None, "cli":None},
733
+ "node_discover": {"-tall":None, "-tsens":None, "-trep":None, "-tcomp":None, "-troom":None, "-tcli":None},
734
+ "list_discovered": None,
735
+ "add_discovered": discovered_list,
729
736
  "trace" : None,
730
737
  "reset_path" : contact_list,
731
738
  "change_path" : contact_list,
@@ -2414,6 +2421,7 @@ async def next_cmd(mc, cmds, json_output=False, sink=sys.stdout, end="\n"):
2414
2421
  """
2415
2422
  global ARROW_HEAD, SLASH_START, SLASH_END, INVERT_SLASH, LAST_HANDLER_ID
2416
2423
  global LC_DISPLAY_TYPES, LC_OUTPUT_FORMAT, LC_SORT_ORDER
2424
+ global LAST_DISCOVERED_NODES
2417
2425
  output_str = ""
2418
2426
  try :
2419
2427
  argnum = 0
@@ -3540,6 +3548,7 @@ async def next_cmd(mc, cmds, json_output=False, sink=sys.stdout, end="\n"):
3540
3548
  else:
3541
3549
  exp_tag = res.payload["tag"].to_bytes(4, "little").hex()
3542
3550
  dn = []
3551
+ LAST_DISCOVERED_NODES = []
3543
3552
  while True:
3544
3553
  r = await mc.wait_for_event(
3545
3554
  EventType.DISCOVER_RESPONSE,
@@ -3549,7 +3558,12 @@ async def next_cmd(mc, cmds, json_output=False, sink=sys.stdout, end="\n"):
3549
3558
  if r is None or r.type == EventType.ERROR:
3550
3559
  break
3551
3560
  else:
3552
- dn.append(r.payload)
3561
+ n = r.payload
3562
+ dn.append(n)
3563
+ if len(n['pubkey']) == 64:
3564
+ contact = mc.get_contact_by_key_prefix(n['pubkey'])
3565
+ if contact is None:
3566
+ LAST_DISCOVERED_NODES.append(n)
3553
3567
 
3554
3568
  if json_output:
3555
3569
  output_str += json.dumps(dn)+end
@@ -3568,6 +3582,57 @@ async def next_cmd(mc, cmds, json_output=False, sink=sys.stdout, end="\n"):
3568
3582
 
3569
3583
  output_str += f" {name:28} {type:>4} SNR: {n['SNR_in']:6,.2f}->{n['SNR']:6,.2f} RSSI: ->{n['RSSI']:4}\n"
3570
3584
 
3585
+ case "list_discovered" :
3586
+ output_str += json.dumps(LAST_DISCOVERED_NODES, indent=4) + end
3587
+
3588
+ case "add_discovered" :
3589
+ name = None
3590
+ args = cmds[1:]
3591
+ add_all = False
3592
+ argnum = 1
3593
+
3594
+ while len(args) > 0 and args[0][0] == "-":
3595
+ if args[0].startswith('-n'): # name
3596
+ name = args[0][2:]
3597
+
3598
+ if args[0].startswith('-a'):
3599
+ add_all = True
3600
+ argnum = argnum - 1
3601
+
3602
+ argnum += 1
3603
+ args = args[1:]
3604
+
3605
+ if not add_all:
3606
+ prefix = args[0]
3607
+ nodes = 0
3608
+ jout = []
3609
+ for n in LAST_DISCOVERED_NODES[:]:
3610
+ if add_all or n['pubkey'].startswith(prefix):
3611
+ LAST_DISCOVERED_NODES.remove(n)
3612
+ if add_all or name is None:
3613
+ name = n['pubkey'][0:8]
3614
+ contact = {
3615
+ "public_key": n['pubkey'],
3616
+ "type" : n['node_type'],
3617
+ "flags" : 0,
3618
+ "out_path_len" : -1,
3619
+ "out_path" : "",
3620
+ "out_path_hash_mode" : 0,
3621
+ "adv_name" : name,
3622
+ "adv_lat" : 0,
3623
+ "adv_lon" : 0,
3624
+ "last_advert" : 0,
3625
+ }
3626
+ res = await mc.commands.update_contact(contact)
3627
+ logger.debug(res)
3628
+ if res.type == EventType.ERROR:
3629
+ output_str += f"Error adding contact: {res}\n"
3630
+ else :
3631
+ jout.append(json.dumps({'name':name, 'pubkey':n['pubkey'], 'type':n['node_type']}))
3632
+
3633
+ await mc.commands.get_contacts() # reload contacts
3634
+ output_str += json.dumps([json.loads(x) for x in jout]) + end
3635
+
3571
3636
  case "req_regions"|"rr":
3572
3637
  argnum = 1
3573
3638
  await mc.ensure_contacts()
@@ -4643,6 +4708,8 @@ def command_help():
4643
4708
  wmt8 : wait for a msg (reply) with a timeout ]
4644
4709
  req_status <name> : requests status from a node rs
4645
4710
  req_neighbours <name> : requests for neighbours in binary form rn
4711
+ node_discover : lauch a local node discovery
4712
+ add_discovered <key> : add a discovered node (repeater) to the list
4646
4713
  trace <path> : run a trace, path is comma separated""")
4647
4714
 
4648
4715
  def usage () :
@@ -4704,7 +4771,7 @@ def get_help_for (cmdname, context="line") :
4704
4771
  at t=2 rp login
4705
4772
  """)
4706
4773
 
4707
- elif cmdname == "node_discover" or cmdname == "nd" :
4774
+ elif cmdname == "node_discover" or cmdname == "nd" or cmdname == "list_discovered" or cmdname == "add_discovered" :
4708
4775
  print("""node_discover [-t<filter>] [-f] : discovers 0-hop nodes and displays signal info
4709
4776
 
4710
4777
  `-t` asks for nodes regarding filter.
@@ -4717,6 +4784,15 @@ def get_help_for (cmdname, context="line") :
4717
4784
  `-f` or `-full`: will ask for the full key of the node
4718
4785
 
4719
4786
  BEWARE: filter option have changed since v1.6.4, using -t is now mandatory !!!
4787
+
4788
+ Once node_discover has been performed with -f (to get full key) you can add the node using `add_discovered` or list them with `list_discovered`. The discovered list is emptied at each node discovery.
4789
+
4790
+ add_discovered [-n<name>] [-a] <pubkey_prefix>
4791
+
4792
+ `-n`: to give a name to the node
4793
+ `-a`: will add all found nodes (won't use the provided name though)
4794
+ <pubkey_prefix>: to identify the node to add if `-a` has not been used
4795
+
4720
4796
  """)
4721
4797
 
4722
4798
  elif cmdname == "get" :
File without changes
File without changes
File without changes
File without changes
File without changes