meshcore-cli 1.6.10__tar.gz → 1.6.11__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.10
3
+ Version: 1.6.11
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
@@ -11,7 +11,7 @@ Classifier: Operating System :: OS Independent
11
11
  Classifier: Programming Language :: Python :: 3
12
12
  Requires-Python: >=3.10
13
13
  Requires-Dist: bleak>=0.22
14
- Requires-Dist: meshcore>=2.3.16
14
+ Requires-Dist: meshcore>=2.3.22
15
15
  Requires-Dist: prompt-toolkit>=3.0.50
16
16
  Requires-Dist: requests>=2.28.0
17
17
  Description-Content-Type: text/markdown
@@ -111,7 +111,7 @@ Commands are given after arguments, they can be chained and some have shortcuts.
111
111
  alias <key> <cmd> : create an alias for key, see ?alias
112
112
  aliases : list all aliases
113
113
  aliases_load : load aliases from a file
114
- handler_attach <d> <c> : attach c as a handler for d (rxlog|msgs)
114
+ handler_attach <d> <c> : attach c as a handler for d (rxlog|msgs|chan_data|telemetry)
115
115
  handler_detach <n> : detach an handler (from its handle n)
116
116
  Messaging
117
117
  msg <name> <msg> : send message to node by name m {
@@ -153,6 +153,7 @@ Commands are given after arguments, they can be chained and some have shortcuts.
153
153
  change_path <ct> <pth> : change the path to a contact cp
154
154
  change_flags <ct> <f> : change contact flags (tel_l|tel_a|star)cf
155
155
  req_telemetry <ct> : prints telemetry data as json rt
156
+ sub_telemetry : subscribes to push telemetry
156
157
  req_mma <ct> : requests min/max/avg for a sensor rm
157
158
  req_acl <ct> : requests access control list for sensor
158
159
  pending_contacts : show pending contacts
@@ -238,7 +239,7 @@ Aliases can be saved using a redirection `> filename aliases` and loaded from a
238
239
 
239
240
  #### Handlers
240
241
 
241
- Shell processes can be attached to `rxlog` or `msgs` using `handler_attach` and `handler_detach` commands.
242
+ Shell processes can be attached to `rxlog`, `msgs`, `chan_data` or `telemetry` using `handler_attach` and `handler_detach` commands.
242
243
 
243
244
  For instance:
244
245
  ```
@@ -93,7 +93,7 @@ Commands are given after arguments, they can be chained and some have shortcuts.
93
93
  alias <key> <cmd> : create an alias for key, see ?alias
94
94
  aliases : list all aliases
95
95
  aliases_load : load aliases from a file
96
- handler_attach <d> <c> : attach c as a handler for d (rxlog|msgs)
96
+ handler_attach <d> <c> : attach c as a handler for d (rxlog|msgs|chan_data|telemetry)
97
97
  handler_detach <n> : detach an handler (from its handle n)
98
98
  Messaging
99
99
  msg <name> <msg> : send message to node by name m {
@@ -135,6 +135,7 @@ Commands are given after arguments, they can be chained and some have shortcuts.
135
135
  change_path <ct> <pth> : change the path to a contact cp
136
136
  change_flags <ct> <f> : change contact flags (tel_l|tel_a|star)cf
137
137
  req_telemetry <ct> : prints telemetry data as json rt
138
+ sub_telemetry : subscribes to push telemetry
138
139
  req_mma <ct> : requests min/max/avg for a sensor rm
139
140
  req_acl <ct> : requests access control list for sensor
140
141
  pending_contacts : show pending contacts
@@ -220,7 +221,7 @@ Aliases can be saved using a redirection `> filename aliases` and loaded from a
220
221
 
221
222
  #### Handlers
222
223
 
223
- Shell processes can be attached to `rxlog` or `msgs` using `handler_attach` and `handler_detach` commands.
224
+ Shell processes can be attached to `rxlog`, `msgs`, `chan_data` or `telemetry` using `handler_attach` and `handler_detach` commands.
224
225
 
225
226
  For instance:
226
227
  ```
@@ -17,12 +17,12 @@
17
17
 
18
18
  meshcore = python3Packages.buildPythonPackage rec {
19
19
  pname = "meshcore";
20
- version = "2.3.16";
20
+ version = "2.3.22";
21
21
  pyproject = true;
22
22
 
23
23
  src = python3Packages.fetchPypi {
24
24
  inherit pname version;
25
- sha256 = "sha256-HU3D2oJKwtecMJHv7zGUjIuuk+hPfRBZQTMaSNamR9A=";
25
+ sha256 = "sha256-dxiG5cJcteqXP0+XWVfnPpb0Mp+8oes5FvrFfBMzUBA=";
26
26
  };
27
27
 
28
28
  build-system = [ python3Packages.hatchling ];
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "meshcore-cli"
7
- version = "1.6.10"
7
+ version = "1.6.11"
8
8
  authors = [
9
9
  { name="Florent de Lamotte", email="florent@frizoncorrea.fr" },
10
10
  ]
@@ -17,7 +17,7 @@ classifiers = [
17
17
  ]
18
18
  license = "MIT"
19
19
  license-files = ["LICEN[CS]E*"]
20
- dependencies = [ "meshcore >= 2.3.16",
20
+ dependencies = [ "meshcore >= 2.3.22",
21
21
  "bleak >= 0.22",
22
22
  "prompt_toolkit >= 3.0.50",
23
23
  "requests >= 2.28.0" ]
@@ -35,7 +35,7 @@ except ImportError:
35
35
  from meshcore import MeshCore, EventType, logger
36
36
 
37
37
  # Version
38
- VERSION = "v1.6.10"
38
+ VERSION = "v1.6.11"
39
39
 
40
40
  # default ble address is stored in a config file
41
41
  MCCLI_CONFIG_DIR = os.path.expanduser("~/.config/meshcore/")
@@ -118,6 +118,7 @@ HANDLERS = { # dicts that will be indexed by numbers
118
118
  "rxlog" : {},
119
119
  "msgs" : {},
120
120
  "chan_data" : {},
121
+ "telemetry" : {},
121
122
  }
122
123
  LAST_HANDLER_ID = 0
123
124
  HANDLER_QUEUE_SIZE = 100
@@ -523,6 +524,9 @@ handle_log_rx.advert_echoes = False
523
524
  handle_log_rx.mc = None
524
525
  handle_log_rx.echo_unk_chans=False
525
526
 
527
+ async def handle_telemetry(event):
528
+ enqueue_handler_event("telemetry", event.payload)
529
+
526
530
  async def handle_advert(event):
527
531
  if not handle_advert.print_adverts:
528
532
  return
@@ -745,7 +749,7 @@ def make_completion_dict(contacts, pending=None, to=None, channels=None):
745
749
  "aliases" : None,
746
750
  "aliases_load" : None,
747
751
  "alias" : None,
748
- "handler_attach": {"rxlog":None, "msgs":None, "chan_data":None},
752
+ "handler_attach": {"rxlog":None, "msgs":None, "chan_data":None, "telemetry":None},
749
753
  "handler_detach": None,
750
754
  "handlers": None,
751
755
  "login" : contact_list,
@@ -754,6 +758,8 @@ def make_completion_dict(contacts, pending=None, to=None, channels=None):
754
758
  "req_neighbours": contact_list,
755
759
  "logout" : contact_list,
756
760
  "req_telemetry" : contact_list,
761
+ "sub_telemetry" : contact_list,
762
+ "unsub_telemetry" : contact_list,
757
763
  "req_binary" : contact_list,
758
764
  "req_mma" : contact_list,
759
765
  "req_owner" : contact_list,
@@ -944,6 +950,8 @@ def make_completion_dict(contacts, pending=None, to=None, channels=None):
944
950
  "change_flags" : None,
945
951
  "reset_advert_time" : None,
946
952
  "req_telemetry" : None,
953
+ "sub_telemetry" : None,
954
+ "unsub_telemetry" : None,
947
955
  "req_binary" : None,
948
956
  "forget_password" : None,
949
957
  }
@@ -1798,6 +1806,7 @@ async def process_contact_chat_line(mc, contact, line, inside=False, json_output
1798
1806
  line.startswith("path ") or line == "path" or\
1799
1807
  line.startswith("advert_path") or line == "ap" or line.startswith("ap ") or\
1800
1808
  line.startswith("reset_advert_time") or\
1809
+ line.startswith("unsub_telemetry") or\
1801
1810
  line.startswith("logout") :
1802
1811
  args = [line.split()[0], contact['adv_name']]
1803
1812
  out_str = ""
@@ -1906,6 +1915,12 @@ async def process_contact_chat_line(mc, contact, line, inside=False, json_output
1906
1915
  await process_cmds(mc, args, json_output=json_output, sink=sink)
1907
1916
  return True
1908
1917
 
1918
+ cmds = line.split(" ")
1919
+ if cmds[0] == "sub_telemetry":
1920
+ args = [cmds[0], contact['adv_name'], cmds[1], cmds[2]]
1921
+ await process_cmds(mc, args, json_output=json_output, sink=sink)
1922
+ return True
1923
+
1909
1924
  if line == "login": # use stored password or prompt for it
1910
1925
  password_file = ""
1911
1926
  password = ""
@@ -3728,6 +3743,58 @@ async def next_cmd(mc, cmds, json_output=False, sink=sys.stdout, end="\n"):
3728
3743
  "lpp": res,
3729
3744
  }, indent = 4) + end
3730
3745
 
3746
+ case "sub_telemetry" :
3747
+ argnum = 3
3748
+ await mc.ensure_contacts()
3749
+ contact = await get_contact_from_arg(mc, cmds[1])
3750
+ if contact is None:
3751
+ if json_output :
3752
+ output_str += json.dumps({"error" : "unknown contact"})+end
3753
+ else:
3754
+ output_str += f"Unknown contact {cmds[1]}{end}"
3755
+ else:
3756
+ if cmds[2].endswith("m"):
3757
+ duration = int(cmds[2][:-1]) * 60
3758
+ elif cmds[2].endswith("h"):
3759
+ duration = int(cmds[2][:-1]) * 3600
3760
+ else:
3761
+ duration = int(cmds[2])
3762
+ if cmds[3].startswith('[') or cmds[3].startswith('{'): # json
3763
+ min_deltas = json.loads(cmds[3])
3764
+ else: # custom formating: chan:type:value,
3765
+ min_deltas = []
3766
+ for d in cmds[3].split(","):
3767
+ fields = d.split(":")
3768
+ if len(fields) < 3:
3769
+ raise(ValueError(f"incorrect encoding for min_delta: {d}"))
3770
+ try:
3771
+ lpp_type = int(fields[1])
3772
+ except ValueError:
3773
+ lpp_type = fields[1]
3774
+ min_deltas.append({
3775
+ "channel": int(fields[0]),
3776
+ "type": lpp_type,
3777
+ "value": float(fields[2]),
3778
+ })
3779
+ timeout = 0 if not "timeout" in contact else contact["timeout"]
3780
+ res = await mc.commands.telemetry_subscribe(contact, duration, min_deltas, timeout=timeout)
3781
+ output_str += str(res) + end
3782
+
3783
+ case "unsub_telemetry" :
3784
+ argnum = 1
3785
+ await mc.ensure_contacts()
3786
+ contact = await get_contact_from_arg(mc, cmds[1])
3787
+ if contact is None:
3788
+ if json_output :
3789
+ output_str += json.dumps({"error" : "unknown contact"})+end
3790
+ else:
3791
+ output_str += f"Unknown contact {cmds[1]}{end}"
3792
+ else:
3793
+ timeout = 0 if not "timeout" in contact else contact["timeout"]
3794
+ res = await mc.commands.req_unsubscribe_sync(contact)
3795
+ output_str += "OK" if res else "ERROR"
3796
+ output_str += end
3797
+
3731
3798
  case "req_status"|"rs" :
3732
3799
  argnum = 1
3733
3800
  contact = await get_contact_from_arg(mc, cmds[1])
@@ -4502,7 +4569,7 @@ async def next_cmd(mc, cmds, json_output=False, sink=sys.stdout, end="\n"):
4502
4569
  process = None
4503
4570
 
4504
4571
  try:
4505
- if not htype in ["msgs", "rxlog", "chan_data"]:
4572
+ if not htype in ["msgs", "rxlog", "chan_data", "telemetry"]:
4506
4573
  raise ValueError (f"Unknown handler type {htype}")
4507
4574
  process = await asyncio.create_subprocess_exec(
4508
4575
  *shlex.split(cmd, posix=True),
@@ -4540,7 +4607,7 @@ async def next_cmd(mc, cmds, json_output=False, sink=sys.stdout, end="\n"):
4540
4607
  case "handler_detach":
4541
4608
  argnum = 1
4542
4609
  nb = int(cmds[1])
4543
- handlers = HANDLERS["msgs"]|HANDLERS["rxlog"]|HANDLERS["chan_data"]
4610
+ handlers = HANDLERS["msgs"]|HANDLERS["rxlog"]|HANDLERS["chan_data"]|HANDLERS["telemetry"]
4544
4611
  handler = handlers[nb]
4545
4612
  handler["closed"] = True
4546
4613
  for task_name in ("writer_task", "output_task"):
@@ -4650,7 +4717,7 @@ def command_help():
4650
4717
  alias <key> <cmd> : create an alias for key, see ?alias
4651
4718
  aliases : list all aliases
4652
4719
  aliases_load : load aliases from a file
4653
- handler_attach <d> <c> : attach c as a handler for d (rxlog|msgs)
4720
+ handler_attach <d> <c> : attach c as a handler for d
4654
4721
  handler_detach <n> : detach an handler (from its handle n)
4655
4722
  Messaging
4656
4723
  msg <name> <msg> : send message to node by name m {
@@ -4696,6 +4763,8 @@ def command_help():
4696
4763
  change_flags <ct> <f> : change contact flags (tel_l|tel_a|star)cf
4697
4764
  req_acl <ct> : requests access control list for node ra
4698
4765
  req_telemetry <ct> : prints telemetry data as json rt
4766
+ sub_telemetry c d md : subscribe to pushed telemetry
4767
+ unsub_telemetry c : unsubscribe to pushed telemetry
4699
4768
  req_regions <ct> : prints regions from repeater rr
4700
4769
  req_owner <ct> : prints owner for a repeater ro
4701
4770
  req_clock <ct> : prints repeater timestamp (for sync)
@@ -5065,6 +5134,34 @@ Output format is given as a string with one character by field. Name is always d
5065
5134
  Use get/set lc_output_format to get or set default value
5066
5135
  """)
5067
5136
 
5137
+ elif "telemetry" in cmdname :
5138
+ print("""req_telemetry/sub_telemetry/unsub_telemetry: telemetry management in meshcore-cli
5139
+
5140
+ There are two ways to deal with telemetry in meshcore:
5141
+
5142
+ Pulled telemetry is the historical way. In meshcore-cli this is done by issuing a `req_telemetry` command on a contact. A json structure obtained from lpp encoded value will be returned if you have the rights to access telemetry.
5143
+
5144
+ There is also a pushed telemetry way. You have to subscribe to the node for getting the data, which will be pushed to you whenever a change is noticed.
5145
+
5146
+ In meshcore-cli, to subscribe for telemetry you have to issue a `sub_telemetry` command. This commands has three arguments: the contact, the duration of the registration (in seconds by default but can be specified by appending m or h) and the min_deltas structure, which describes the triggers for telemety push. Min_delta can be sent as a json_encoding structure (same as the one issued by req_telemetry) or a compact structure, where each sensor is specified using the chan:lpp_type:delta format (ex: 1:voltage:0.1,1:temperature:0.5 will look for .1 variation in voltage and .5 variation in temperature from channel 1).
5147
+
5148
+ Once you are subscribed, handlers mechanisms can be used to print the value using your own filters. You can subscribe to the telemetry handler by using `handler_attach telemetry <command>`.
5149
+
5150
+ To unsubscribe to pushed telemetry call `unsub_telemetry
5151
+
5152
+ """)
5153
+
5154
+ elif "handler" in cmdname :
5155
+ print("""handler_attach/handler_detach/handlers: special handling for incoming data
5156
+
5157
+ meshcore-cli lets you attach shell process to msg rx_log chan_data or telemetry
5158
+
5159
+ * `handler_attach <d> <c>` attaches command `c` to the handler `d` (which can be msgs, rxlog, chan_data or telemetry). It returns an handle number.
5160
+
5161
+ * `handler_detach <n>` detaches handler with number `n`
5162
+ * `handlers` lists current handlers
5163
+ """)
5164
+
5068
5165
  else:
5069
5166
  print(f"Sorry, no help yet for {cmdname}")
5070
5167
 
@@ -5783,6 +5880,7 @@ async def main(argv):
5783
5880
  mc.subscribe(EventType.PATH_UPDATE, handle_path_update)
5784
5881
  mc.subscribe(EventType.NEW_CONTACT, handle_new_contact)
5785
5882
  mc.subscribe(EventType.RX_LOG_DATA, handle_log_rx)
5883
+ mc.subscribe(EventType.PUSHED_TELEMETRY, handle_telemetry)
5786
5884
 
5787
5885
  mc.auto_update_contacts = True
5788
5886
  mc.set_decrypt_channel_logs(True)
File without changes
File without changes
File without changes