meshcore-cli 1.5.6__tar.gz → 1.6.0__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.
@@ -0,0 +1,2 @@
1
+ buy_me_a_coffee: fdlamotte
2
+ github: meshcore-dev
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: meshcore-cli
3
- Version: 1.5.6
3
+ Version: 1.6.0
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.6
14
+ Requires-Dist: meshcore>=2.3.8
15
15
  Requires-Dist: prompt-toolkit>=3.0.50
16
16
  Requires-Dist: requests>=2.28.0
17
17
  Description-Content-Type: text/markdown
@@ -75,6 +75,7 @@ Arguments mostly deals with connection to the node
75
75
  <pre>
76
76
  -h : prints this help
77
77
  -v : prints version
78
+ -i : force interactive mode even if there are commands (replaces chat command)
78
79
  -j : json output (disables init file)
79
80
  -D : debug
80
81
  -S : scan for devices and show a selector
@@ -98,8 +99,6 @@ Commands are given after arguments, they can be chained and some have shortcuts.
98
99
  <pre>
99
100
  ?&lt;cmd&gt; may give you some more help about cmd
100
101
  General commands
101
- chat : enter the chat (interactive) mode
102
- chat_to &lt;ct&gt; : enter chat with contact to
103
102
  script &lt;filename&gt; : execute commands in filename
104
103
  infos : print informations about the node i
105
104
  self_telemetry : print own telemtry t
@@ -109,6 +108,11 @@ Commands are given after arguments, they can be chained and some have shortcuts.
109
108
  sleep &lt;secs&gt; : sleeps for a given amount of secs s
110
109
  wait_key : wait until user presses &lt;Enter&gt; wk
111
110
  apply_to &lt;f&gt; &lt;cmds&gt; : sends cmds to contacts matching f at
111
+ alias &lt;key&gt; &lt;cmd&gt; : create an alias for key, see ?alias
112
+ aliases : list all aliases
113
+ aliases_load : load aliases from a file
114
+ handler_attach &lt;d&gt; &lt;c&gt; : attach c as a handler for d (rxlog|msgs)
115
+ handler_detach &lt;n&gt; : detach an handler (from its handle n)
112
116
  Messaging
113
117
  msg &lt;name&gt; &lt;msg&gt; : send message to node by name m {
114
118
  wait_ack : wait an ack wa }
@@ -166,7 +170,7 @@ Commands are given after arguments, they can be chained and some have shortcuts.
166
170
 
167
171
  aka Instant Message or chat mode ...
168
172
 
169
- Chat mode lets you interactively interact with your node or remote nodes. It is automatically triggered when no option is given on the command line.
173
+ Chat mode lets you interactively interact with your node or remote nodes. It is automatically triggered when no option is given on the command line and can be summoned using the `-i` parameter.
170
174
 
171
175
  You'll get a prompt with the name of your node. From here you can type meshcore-cli commands. The prompt has history and a basic completion (pressing tab will display possible command or argument options).
172
176
 
@@ -184,13 +188,25 @@ The `/` character is used to bypass the node you have currently selected using `
184
188
  - `/<node>/<cmd>` will send cmd to selected node
185
189
  - `/<dest> <msg>` will send msg to dest (channel or node)
186
190
 
191
+ You can redirect output of a command using `>`, `>>` or `|` symbols at the start of a line, followed by a file or a shell command :
192
+ - `>`: redirects the output to a file in overwrite mode
193
+ - `>>`: redirects to the file in append mode
194
+ - `|`: redirects to the input of shell command (pipe)
195
+
196
+ You can also do the other way around and use a shell script or command into a meshcore command, this is done prefixing with `<|` (for input pipe). Use `{}` or `{0}` as defaultplaceholder in your meshcli line to replace with the output of the shell command, you can specify your own key between `<` and `|` (and chain the input pipes) so
197
+ - `<name| whoami set name {name}`: will give your unix username to your node
198
+
199
+ If you start the line with `.` it activates `json_output` for this execution, letting you output json for feeding `jq`.
200
+
201
+ Some examples are available in the [examples scripts directory](scripts).
202
+
187
203
  #### Flood Scope in interactive mode
188
204
 
189
205
  Flood scope has recently been introduced in meshcore (from `v1.10.0`). It limits the scope of packets to regions, using transport codes in the frame.
190
206
 
191
- When entering chat mode, scope will be reset to `*`, meaning classic flood.
207
+ When entering chat mode, scope will be set to "0" meaning default scope of the node will be used (settable using `set default_scope`). The scope will not be shown on the prompt.
192
208
 
193
- You can switch scope using the `scope` command, or postfixing the `to` command with `%<scope>`.
209
+ You can switch scope using the `scope` command or postfixing the `to` command with `%<scope>`, this is a temporary scope that will be shown on the prompt. If you want to send unscoped message, do it by issuing `scope *`.
194
210
 
195
211
  Scope can also be applied to a command using `%` before the scope name. For instance `login%#Morbihan` will limit diffusion of the login command (which is usually sent flood to get the path to a repeater) to the `#Morbihan` region.
196
212
 
@@ -210,6 +226,25 @@ f1down/#fdl|*> 8
210
226
  #fdl f1down: 8 [2521] 1.00-109
211
227
  ```
212
228
 
229
+ #### Aliases
230
+
231
+ You can set aliases to quickly access complex commands. Aliases are managed using the `alias` command (see `?alias` from meshcore-cli). They can then be recalled prefixing your line with `@`.
232
+
233
+ You can use placeholders using python format syntax `{}`, which will be replaced by parameters given on the command line. The special `{c}` placeholder is used to specify contact name, when in a contact it will be replaced by the contact name, and outside by the first parameter.
234
+
235
+ Aliases can be saved using a redirection `> filename aliases` and loaded from a json file using `aliases_load`. For instance you can add in your `init` file a `aliases_load ~/.config/meshcore/aliases.json` to load your own aliases at startup (there is no default aliases file).
236
+
237
+ #### Handlers
238
+
239
+ Shell processes can be attached to `rxlog` or `msgs` using `handler_attach` and `handler_detach` commands.
240
+
241
+ For instance:
242
+ ```
243
+ handler_attach rxlog cat
244
+ ```
245
+
246
+ Will print out the content of `rx_log` as it comes in.
247
+
213
248
  ### Contact management
214
249
 
215
250
  To receive a message from another user, it is necessary to have its public key. This key is stored on a contact list in the device, and this list has a finite size (50 when meshcore started, now over 350 for most devices).
@@ -326,7 +361,7 @@ $ meshcli msg t114_fdl hello wa | jq -cs
326
361
  # But this could have been done interactively using the chat mode
327
362
  # Here from the techo side. Note that un-acked messages will be
328
363
  # signaled with an ! at the start of the prompt (or red color in color mode)
329
- $ meshcli chat
364
+ $ meshcli -i
330
365
  INFO:meshcore:BLE Connection started
331
366
  Interactive mode, most commands from terminal chat should work.
332
367
  Use "to" to selects contact, "list" to list contacts, "send" to send a message ...
@@ -57,6 +57,7 @@ Arguments mostly deals with connection to the node
57
57
  <pre>
58
58
  -h : prints this help
59
59
  -v : prints version
60
+ -i : force interactive mode even if there are commands (replaces chat command)
60
61
  -j : json output (disables init file)
61
62
  -D : debug
62
63
  -S : scan for devices and show a selector
@@ -80,8 +81,6 @@ Commands are given after arguments, they can be chained and some have shortcuts.
80
81
  <pre>
81
82
  ?&lt;cmd&gt; may give you some more help about cmd
82
83
  General commands
83
- chat : enter the chat (interactive) mode
84
- chat_to &lt;ct&gt; : enter chat with contact to
85
84
  script &lt;filename&gt; : execute commands in filename
86
85
  infos : print informations about the node i
87
86
  self_telemetry : print own telemtry t
@@ -91,6 +90,11 @@ Commands are given after arguments, they can be chained and some have shortcuts.
91
90
  sleep &lt;secs&gt; : sleeps for a given amount of secs s
92
91
  wait_key : wait until user presses &lt;Enter&gt; wk
93
92
  apply_to &lt;f&gt; &lt;cmds&gt; : sends cmds to contacts matching f at
93
+ alias &lt;key&gt; &lt;cmd&gt; : create an alias for key, see ?alias
94
+ aliases : list all aliases
95
+ aliases_load : load aliases from a file
96
+ handler_attach &lt;d&gt; &lt;c&gt; : attach c as a handler for d (rxlog|msgs)
97
+ handler_detach &lt;n&gt; : detach an handler (from its handle n)
94
98
  Messaging
95
99
  msg &lt;name&gt; &lt;msg&gt; : send message to node by name m {
96
100
  wait_ack : wait an ack wa }
@@ -148,7 +152,7 @@ Commands are given after arguments, they can be chained and some have shortcuts.
148
152
 
149
153
  aka Instant Message or chat mode ...
150
154
 
151
- Chat mode lets you interactively interact with your node or remote nodes. It is automatically triggered when no option is given on the command line.
155
+ Chat mode lets you interactively interact with your node or remote nodes. It is automatically triggered when no option is given on the command line and can be summoned using the `-i` parameter.
152
156
 
153
157
  You'll get a prompt with the name of your node. From here you can type meshcore-cli commands. The prompt has history and a basic completion (pressing tab will display possible command or argument options).
154
158
 
@@ -166,13 +170,25 @@ The `/` character is used to bypass the node you have currently selected using `
166
170
  - `/<node>/<cmd>` will send cmd to selected node
167
171
  - `/<dest> <msg>` will send msg to dest (channel or node)
168
172
 
173
+ You can redirect output of a command using `>`, `>>` or `|` symbols at the start of a line, followed by a file or a shell command :
174
+ - `>`: redirects the output to a file in overwrite mode
175
+ - `>>`: redirects to the file in append mode
176
+ - `|`: redirects to the input of shell command (pipe)
177
+
178
+ You can also do the other way around and use a shell script or command into a meshcore command, this is done prefixing with `<|` (for input pipe). Use `{}` or `{0}` as defaultplaceholder in your meshcli line to replace with the output of the shell command, you can specify your own key between `<` and `|` (and chain the input pipes) so
179
+ - `<name| whoami set name {name}`: will give your unix username to your node
180
+
181
+ If you start the line with `.` it activates `json_output` for this execution, letting you output json for feeding `jq`.
182
+
183
+ Some examples are available in the [examples scripts directory](scripts).
184
+
169
185
  #### Flood Scope in interactive mode
170
186
 
171
187
  Flood scope has recently been introduced in meshcore (from `v1.10.0`). It limits the scope of packets to regions, using transport codes in the frame.
172
188
 
173
- When entering chat mode, scope will be reset to `*`, meaning classic flood.
189
+ When entering chat mode, scope will be set to "0" meaning default scope of the node will be used (settable using `set default_scope`). The scope will not be shown on the prompt.
174
190
 
175
- You can switch scope using the `scope` command, or postfixing the `to` command with `%<scope>`.
191
+ You can switch scope using the `scope` command or postfixing the `to` command with `%<scope>`, this is a temporary scope that will be shown on the prompt. If you want to send unscoped message, do it by issuing `scope *`.
176
192
 
177
193
  Scope can also be applied to a command using `%` before the scope name. For instance `login%#Morbihan` will limit diffusion of the login command (which is usually sent flood to get the path to a repeater) to the `#Morbihan` region.
178
194
 
@@ -192,6 +208,25 @@ f1down/#fdl|*> 8
192
208
  #fdl f1down: 8 [2521] 1.00-109
193
209
  ```
194
210
 
211
+ #### Aliases
212
+
213
+ You can set aliases to quickly access complex commands. Aliases are managed using the `alias` command (see `?alias` from meshcore-cli). They can then be recalled prefixing your line with `@`.
214
+
215
+ You can use placeholders using python format syntax `{}`, which will be replaced by parameters given on the command line. The special `{c}` placeholder is used to specify contact name, when in a contact it will be replaced by the contact name, and outside by the first parameter.
216
+
217
+ Aliases can be saved using a redirection `> filename aliases` and loaded from a json file using `aliases_load`. For instance you can add in your `init` file a `aliases_load ~/.config/meshcore/aliases.json` to load your own aliases at startup (there is no default aliases file).
218
+
219
+ #### Handlers
220
+
221
+ Shell processes can be attached to `rxlog` or `msgs` using `handler_attach` and `handler_detach` commands.
222
+
223
+ For instance:
224
+ ```
225
+ handler_attach rxlog cat
226
+ ```
227
+
228
+ Will print out the content of `rx_log` as it comes in.
229
+
195
230
  ### Contact management
196
231
 
197
232
  To receive a message from another user, it is necessary to have its public key. This key is stored on a contact list in the device, and this list has a finite size (50 when meshcore started, now over 350 for most devices).
@@ -308,7 +343,7 @@ $ meshcli msg t114_fdl hello wa | jq -cs
308
343
  # But this could have been done interactively using the chat mode
309
344
  # Here from the techo side. Note that un-acked messages will be
310
345
  # signaled with an ! at the start of the prompt (or red color in color mode)
311
- $ meshcli chat
346
+ $ meshcli -i
312
347
  INFO:meshcore:BLE Connection started
313
348
  Interactive mode, most commands from terminal chat should work.
314
349
  Use "to" to selects contact, "list" to list contacts, "send" to send a message ...
@@ -17,12 +17,12 @@
17
17
 
18
18
  meshcore = python3Packages.buildPythonPackage rec {
19
19
  pname = "meshcore";
20
- version = "2.3.6";
20
+ version = "2.3.8";
21
21
  pyproject = true;
22
22
 
23
23
  src = python3Packages.fetchPypi {
24
24
  inherit pname version;
25
- sha256 = "sha256-EUK0iFaCN2tpOL3XL2ejVLGz/gLTdvzPpvgBxETLL3w=";
25
+ sha256 = "sha256-ItV9u1kYavbtIwP9FJY1AimJpPjchnxymm8KvDStOqs=";
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.5.6"
7
+ version = "1.6.0"
8
8
  authors = [
9
9
  { name="Florent de Lamotte", email="florent@frizoncorrea.fr" },
10
10
  ]
@@ -17,8 +17,8 @@ classifiers = [
17
17
  ]
18
18
  license = "MIT"
19
19
  license-files = ["LICEN[CS]E*"]
20
- dependencies = [ "meshcore >= 2.3.6",
21
- "bleak >= 0.22",
20
+ dependencies = [ "meshcore >= 2.3.8",
21
+ "bleak >= 0.22",
22
22
  "prompt_toolkit >= 3.0.50",
23
23
  "requests >= 2.28.0" ]
24
24
 
@@ -0,0 +1,67 @@
1
+ # Some example scripts to interact with meshcore-cli
2
+
3
+ Since version 1.16 it is possible to interact with external scripts through a redirection mechanism.
4
+
5
+ Result of meshcore-cli commands can be redirected to files or processes, starting your lines with `|`, `>` or `>>`. While it is possible to inject the stdout from a command inside the meshcore-cli line using `<|`
6
+
7
+ ## Redirecting output to a command
8
+
9
+ `contact_markers.sh` and `neighbour_map.sh` are example tools that process the output of meshcore-cli command (as json), they are used along with [coords2img](https://github.com/fdlamotte/coords2img) to output images directly in the terminal.
10
+
11
+ ### `contact_markers.sh`
12
+
13
+ You can call [`contact_markers`](contact_markers.sh) using:
14
+ ```
15
+ |contact markers.sh get coords |.lc
16
+ ```
17
+
18
+ It will first store the result of `get coords` into two variables to specify the center of the map (node's position) and then send the result of `lc` to a `jc` query that will produce a file for `coords2img`. `contact_markers.sh` accepts a parameter for specifying the zoom of the map. So you can call it this way to use zoom 18:
19
+ ```
20
+ |"contact markers.sh 18" get coords |.lc
21
+ ```
22
+
23
+ If you want to make an alias, you can them use the zoom as a parameter to your alias:
24
+ ```
25
+ alias contacts_map '|"contact_markers.sh {0}" get coords |.lc'
26
+ @contacts_map 20
27
+ ```
28
+
29
+ ### `neighbour_map.sh`
30
+
31
+ [`neighbour_map`](neighbour_map.sh) Will produce a neighbour map from nodes list and the output of the `request_neighbours` command.
32
+ Call it this way to get a map zoomed at 16 and a marker for your repeater:
33
+ ```
34
+ .|"neighbour_map.sh -sm -z16" lc | rn af
35
+ ```
36
+
37
+ And you can do an alias to call it easily, here I used `{c}` and so the alias can be called either from root (giving the node name or `pubke_pre` as parameter) or directly from within a repeater.
38
+ ```
39
+ alias nmap ".|\"neighbour_map.sh -s -z17 -m -p carto -f1.5\" /lc | /rn {c}"
40
+ @nmap af
41
+ ```
42
+
43
+ ## Feeding output of shell commands to meshcore-cli
44
+
45
+ `<|` will let you put the result of a script (its stdout not return value) in a meshcore line, substituting the elements between curlies.
46
+
47
+ [`ask_mepo_coords.sh`](ask_mepo_coords.sh) is such a command, it will show you a `mepo` instance configured in such a way that if you do a long click (or long press on a phone) it will output clicked coordinates on its stdout. The script adds `lat` and `lon` parameters to output either latitude or longitude and `keep`parameter that will keep previous result instead of asking for a new one.
48
+
49
+ Here is an alias to get a chooser for the position of your node:
50
+ ```
51
+ alias mepo_set_coords '<lat| "ask_mepo_coords.sh lat" <lon| "mepo_coords keep lon" set lat {lat} | set lon {lon}'
52
+ @mepo_set_coords
53
+ ```
54
+
55
+ The `getpos.py` python script can be used to query the position of your device (especially for linux phones) through `geoclue`.
56
+
57
+ ## Aliases
58
+
59
+ If the scripts given above are in your `PATH`, you can use the following alias to access the commands (using `aliases_load`).
60
+
61
+ ```json
62
+ {
63
+ "mepo_set_coords": "<lat| \"mepo_coords lat\" <lon| \"mepo_coords keep lon\" set lat {lat} | set lon {lon}",
64
+ "nmap": ".|\"neighbour_map.sh -s -z17 -m -p carto -f1.5\" /lc | /rn {c}",
65
+ "contacts_map": "|\"contact_markers.sh {0}\" get coords |.lc"
66
+ }
67
+ ```
@@ -0,0 +1,18 @@
1
+ #!/bin/sh
2
+ # don't run mepo if keep parameter is given (use last request)
3
+ # permit to run subsequent query
4
+ if [ "$#" -ge 1 ] && [ "keep" = "$1" ]; then
5
+ shift
6
+ else
7
+ # run mepo binding long click (/press) to output position in /tmp/coords
8
+ echo '[{"cmd": "bind_click", "args": { "button": 1, "clicks": -1, "exps": [{"cmd": "shellpipe_sync", "args": {"shellcode": "echo $MEPO_CURSOR_LAT,$MEPO_CURSOR_LON > /tmp/coords"}},{"cmd": "quit", "args": {}}]}}]'|mepo -i 2> /dev/null
9
+ fi
10
+
11
+ if [ "$#" -ge 1 ] && [ "lat" = "$1" ]; then
12
+ sed -e "s/,.*$//" /tmp/coords
13
+ elif [ "$#" -ge 1 ] && [ "lon" = "$1" ]; then
14
+ sed -e "s/^.*,//" /tmp/coords
15
+ else
16
+ cat /tmp/coords
17
+ fi
18
+
@@ -0,0 +1,22 @@
1
+ #!/bin/bash
2
+ # makes markers on a map from a contact list using coords2img
3
+ # params: zoom
4
+ # stdin:
5
+ # - coordinates first
6
+ # - then a json array (produced by .lc in mccli)
7
+
8
+ if [ -n "$1" ]; then
9
+ zoom="$1"
10
+ else
11
+ zoom=14
12
+ fi
13
+
14
+ # should receive node coordinates as first line
15
+ read coords
16
+
17
+ # let's interpret them
18
+ lat=$(echo "$coords"|sed -e "s/,.*$//")
19
+ lon=$(echo "$coords"|sed -e "s/^.*,//")
20
+
21
+ # feed the rest to jq up to coords2img (should be json values)
22
+ jq '[.[] | select(.adv_lat != 0.0 or .adv_lon != 0.0) | {lat: .adv_lat, lon: .adv_lon, caption: (.adv_name // .public_key[0:8])}]' |coords2img -s --lat $lat --lon $lon -z $zoom -J -m -f1.4 -p google_sat
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/python
2
+ # queries geoclue for current position of a linux device and print coordinates
3
+
4
+ import gi
5
+ gi.require_version('Geoclue', '2.0')
6
+ from gi.repository import Geoclue
7
+
8
+ # Initialisation du client Geoclue simple
9
+ clue = Geoclue.Simple.new_sync('mon-app-id', Geoclue.AccuracyLevel.EXACT, None)
10
+
11
+ # Récupération de l'objet de localisation (proxy D-Bus)
12
+ loc = clue.get_location()
13
+
14
+ # Extraction des propriétés réelles de l'objet
15
+ latitude = loc.get_property('latitude')
16
+ longitude = loc.get_property('longitude')
17
+ altitude = loc.get_property('altitude')
18
+
19
+ # Affichage des coordonnées numériques
20
+ print(f"{latitude},{longitude}")
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env bash
2
+ # read nodes names and neighbours output to draw a map with coords2img
3
+ jq -n '
4
+ (input) as $N
5
+ | (input) as $NB
6
+
7
+ | $NB.pubkey_prefix as $self_pk
8
+ | ($N | to_entries[] | select(.value.public_key | startswith($self_pk)) | .value) as $self
9
+
10
+ | {
11
+ lat: $self.adv_lat,
12
+ lon: $self.adv_lon,
13
+ markers: [
14
+ $NB.neighbours[]
15
+ | . as $n
16
+ | ($N | to_entries[] | select(.value.public_key | startswith($n.pubkey)) | .value) as $node
17
+ | select($node != null)
18
+ | {
19
+ lat: $node.adv_lat,
20
+ lon: $node.adv_lon,
21
+ caption: ($node.adv_name + " (" + ($n.snr | tostring) + " dB)")
22
+ }
23
+ ]
24
+ }
25
+ ' | coords2img -J "$@"