meshcore-cli 1.5.7__tar.gz → 1.6.1__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.
- meshcore_cli-1.6.1/.github/funding.yml +2 -0
- {meshcore_cli-1.5.7 → meshcore_cli-1.6.1}/PKG-INFO +44 -9
- {meshcore_cli-1.5.7 → meshcore_cli-1.6.1}/README.md +41 -6
- {meshcore_cli-1.5.7 → meshcore_cli-1.6.1}/flake.nix +2 -2
- {meshcore_cli-1.5.7 → meshcore_cli-1.6.1}/pyproject.toml +3 -3
- meshcore_cli-1.6.1/scripts/README.md +67 -0
- meshcore_cli-1.6.1/scripts/ask_mepo_coords +18 -0
- meshcore_cli-1.6.1/scripts/contact_markers.sh +22 -0
- meshcore_cli-1.6.1/scripts/getpos.py +144 -0
- meshcore_cli-1.6.1/scripts/neighbour_map.sh +25 -0
- {meshcore_cli-1.5.7 → meshcore_cli-1.6.1}/src/meshcore_cli/meshcore_cli.py +1384 -867
- meshcore_cli-1.6.1/sxmo/sxmo_accel.sh +46 -0
- meshcore_cli-1.6.1/sxmo/sxmo_mc.sh +145 -0
- {meshcore_cli-1.5.7 → meshcore_cli-1.6.1}/.gitignore +0 -0
- {meshcore_cli-1.5.7 → meshcore_cli-1.6.1}/LICENSE +0 -0
- {meshcore_cli-1.5.7 → meshcore_cli-1.6.1}/REPEATER_COMMANDS.md +0 -0
- {meshcore_cli-1.5.7 → meshcore_cli-1.6.1}/flake.lock +0 -0
- {meshcore_cli-1.5.7 → meshcore_cli-1.6.1}/src/meshcore_cli/__init__.py +0 -0
- {meshcore_cli-1.5.7 → meshcore_cli-1.6.1}/src/meshcore_cli/__main__.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
2
|
Name: meshcore-cli
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.6.1
|
|
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.
|
|
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
|
?<cmd> may give you some more help about cmd
|
|
100
101
|
General commands
|
|
101
|
-
chat : enter the chat (interactive) mode
|
|
102
|
-
chat_to <ct> : enter chat with contact to
|
|
103
102
|
script <filename> : 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 <secs> : sleeps for a given amount of secs s
|
|
110
109
|
wait_key : wait until user presses <Enter> wk
|
|
111
110
|
apply_to <f> <cmds> : sends cmds to contacts matching f at
|
|
111
|
+
alias <key> <cmd> : create an alias for key, see ?alias
|
|
112
|
+
aliases : list all aliases
|
|
113
|
+
aliases_load : load aliases from a file
|
|
114
|
+
handler_attach <d> <c> : attach c as a handler for d (rxlog|msgs)
|
|
115
|
+
handler_detach <n> : detach an handler (from its handle n)
|
|
112
116
|
Messaging
|
|
113
117
|
msg <name> <msg> : 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
|
|
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
|
|
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
|
|
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
|
?<cmd> may give you some more help about cmd
|
|
82
83
|
General commands
|
|
83
|
-
chat : enter the chat (interactive) mode
|
|
84
|
-
chat_to <ct> : enter chat with contact to
|
|
85
84
|
script <filename> : 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 <secs> : sleeps for a given amount of secs s
|
|
92
91
|
wait_key : wait until user presses <Enter> wk
|
|
93
92
|
apply_to <f> <cmds> : sends cmds to contacts matching f at
|
|
93
|
+
alias <key> <cmd> : create an alias for key, see ?alias
|
|
94
|
+
aliases : list all aliases
|
|
95
|
+
aliases_load : load aliases from a file
|
|
96
|
+
handler_attach <d> <c> : attach c as a handler for d (rxlog|msgs)
|
|
97
|
+
handler_detach <n> : detach an handler (from its handle n)
|
|
94
98
|
Messaging
|
|
95
99
|
msg <name> <msg> : 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
|
|
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
|
|
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
|
|
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.
|
|
20
|
+
version = "2.3.8";
|
|
21
21
|
pyproject = true;
|
|
22
22
|
|
|
23
23
|
src = python3Packages.fetchPypi {
|
|
24
24
|
inherit pname version;
|
|
25
|
-
sha256 = "sha256-
|
|
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.
|
|
7
|
+
version = "1.6.1"
|
|
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.
|
|
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,144 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Get the current position (latitude, longitude, accuracy/precision) via GeoClue2.
|
|
4
|
+
|
|
5
|
+
Requirements:
|
|
6
|
+
sudo apt install gir1.2-geoclue-2.0 python3-gi
|
|
7
|
+
GeoClue2 daemon (package "geoclue-2.0") must be installed and running.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import argparse
|
|
11
|
+
import json
|
|
12
|
+
import sys
|
|
13
|
+
|
|
14
|
+
import gi
|
|
15
|
+
gi.require_version("Geoclue", "2.0")
|
|
16
|
+
from gi.repository import GLib, Geoclue
|
|
17
|
+
|
|
18
|
+
def get_current_position(app_id="my-python-app",
|
|
19
|
+
accuracy_level=Geoclue.AccuracyLevel.EXACT,
|
|
20
|
+
timeout_seconds=15,
|
|
21
|
+
max_accuracy_meters=None,
|
|
22
|
+
on_update=None):
|
|
23
|
+
loop = GLib.MainLoop()
|
|
24
|
+
result = {}
|
|
25
|
+
error_holder = {}
|
|
26
|
+
simple_holder = {}
|
|
27
|
+
|
|
28
|
+
def meets_threshold(location):
|
|
29
|
+
if max_accuracy_meters is None:
|
|
30
|
+
return True
|
|
31
|
+
accuracy = location.get_property("accuracy")
|
|
32
|
+
return accuracy is not None and accuracy <= max_accuracy_meters
|
|
33
|
+
|
|
34
|
+
def capture(location):
|
|
35
|
+
result["latitude"] = location.get_property("latitude")
|
|
36
|
+
result["longitude"] = location.get_property("longitude")
|
|
37
|
+
result["accuracy"] = location.get_property("accuracy")
|
|
38
|
+
if on_update is not None:
|
|
39
|
+
on_update(dict(result))
|
|
40
|
+
|
|
41
|
+
def on_location_notify(simple, param):
|
|
42
|
+
location = simple.get_location()
|
|
43
|
+
if location is None:
|
|
44
|
+
return
|
|
45
|
+
capture(location)
|
|
46
|
+
if meets_threshold(location):
|
|
47
|
+
loop.quit()
|
|
48
|
+
|
|
49
|
+
def on_client_ready(source, res, user_data=None):
|
|
50
|
+
try:
|
|
51
|
+
simple = Geoclue.Simple.new_finish(res)
|
|
52
|
+
except GLib.Error as e:
|
|
53
|
+
error_holder["error"] = e
|
|
54
|
+
loop.quit()
|
|
55
|
+
return
|
|
56
|
+
|
|
57
|
+
simple_holder["simple"] = simple
|
|
58
|
+
|
|
59
|
+
location = simple.get_location()
|
|
60
|
+
if location is not None:
|
|
61
|
+
capture(location)
|
|
62
|
+
if meets_threshold(location):
|
|
63
|
+
loop.quit()
|
|
64
|
+
return
|
|
65
|
+
|
|
66
|
+
simple.connect("notify::location", on_location_notify)
|
|
67
|
+
|
|
68
|
+
def on_timeout():
|
|
69
|
+
if "latitude" not in result:
|
|
70
|
+
error_holder["error"] = TimeoutError(
|
|
71
|
+
f"No location fix received within {timeout_seconds}s"
|
|
72
|
+
)
|
|
73
|
+
loop.quit()
|
|
74
|
+
return False
|
|
75
|
+
|
|
76
|
+
GLib.timeout_add_seconds(timeout_seconds, on_timeout)
|
|
77
|
+
|
|
78
|
+
Geoclue.Simple.new(app_id, accuracy_level, None, on_client_ready)
|
|
79
|
+
|
|
80
|
+
loop.run()
|
|
81
|
+
|
|
82
|
+
if "error" in error_holder:
|
|
83
|
+
raise error_holder["error"]
|
|
84
|
+
|
|
85
|
+
return result
|
|
86
|
+
|
|
87
|
+
def parse_args():
|
|
88
|
+
parser = argparse.ArgumentParser(
|
|
89
|
+
description="Get the current position via GeoClue2."
|
|
90
|
+
)
|
|
91
|
+
parser.add_argument(
|
|
92
|
+
"-t", "--timeout",
|
|
93
|
+
type=float,
|
|
94
|
+
default=15,
|
|
95
|
+
metavar="SECONDS",
|
|
96
|
+
help="max time to wait for a location fix (default: 15)",
|
|
97
|
+
)
|
|
98
|
+
parser.add_argument(
|
|
99
|
+
"-a", "--accuracy",
|
|
100
|
+
type=float,
|
|
101
|
+
default=600,
|
|
102
|
+
metavar="METERS",
|
|
103
|
+
help=("keep waiting for fixes until accuracy is reached"),
|
|
104
|
+
)
|
|
105
|
+
parser.add_argument(
|
|
106
|
+
"-v", "--verbose",
|
|
107
|
+
action="store_true",
|
|
108
|
+
help="print every position fix as it's acquired, not just the final one",
|
|
109
|
+
)
|
|
110
|
+
parser.add_argument(
|
|
111
|
+
"-vo", "--verbose-stdout",
|
|
112
|
+
action="store_true",
|
|
113
|
+
help=("print intermediate positions to stdout"),
|
|
114
|
+
)
|
|
115
|
+
return parser.parse_args()
|
|
116
|
+
|
|
117
|
+
def main():
|
|
118
|
+
args = parse_args()
|
|
119
|
+
if args.verbose_stdout:
|
|
120
|
+
args.verbose = True
|
|
121
|
+
|
|
122
|
+
def print_update(fix):
|
|
123
|
+
stream = sys.stdout if args.verbose_stdout else sys.stderr
|
|
124
|
+
print(json.dumps(fix), file=stream)
|
|
125
|
+
|
|
126
|
+
try:
|
|
127
|
+
loc = get_current_position(
|
|
128
|
+
accuracy_level=Geoclue.AccuracyLevel.EXACT,
|
|
129
|
+
timeout_seconds=args.timeout,
|
|
130
|
+
max_accuracy_meters=args.accuracy,
|
|
131
|
+
on_update=print_update if args.verbose else None,
|
|
132
|
+
)
|
|
133
|
+
except Exception as e:
|
|
134
|
+
print(f"Failed to get location: {e}", file=sys.stderr)
|
|
135
|
+
sys.exit(1)
|
|
136
|
+
|
|
137
|
+
print(json.dumps({
|
|
138
|
+
"lat": loc["latitude"],
|
|
139
|
+
"lon": loc["longitude"],
|
|
140
|
+
"accuracy": loc["accuracy"],
|
|
141
|
+
}))
|
|
142
|
+
|
|
143
|
+
if __name__ == "__main__":
|
|
144
|
+
main()
|
|
@@ -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 "$@"
|