Debian Codegraph @

PKG-INFO

raw
1 Metadata-Version: 2.4
2 Name: meshcore-cli
3 Version: 1.5.7
4 Summary: Command line interface to meshcore companion radios and repeaters
5 Project-URL: Homepage, https://github.com/fdlamotte/meshcore-cli
6 Project-URL: Issues, https://github.com/fdlamotte/meshcore-cli/issues
7 Author-email: Florent de Lamotte <[email protected]>
8 License-Expression: MIT
9 License-File: LICENSE
10 Classifier: Operating System :: OS Independent
11 Classifier: Programming Language :: Python :: 3
12 Requires-Python: >=3.10
13 Requires-Dist: bleak>=0.22
14 Requires-Dist: meshcore>=2.3.7
15 Requires-Dist: prompt-toolkit>=3.0.50
16 Requires-Dist: requests>=2.28.0
17 Description-Content-Type: text/markdown
18
19 # meshcore-cli
20
21 meshcore-cli : CLI interface to MeshCore companion app over BLE, TCP or Serial
22
23 ## About
24
25 meshcore-cli is a tool that connects to your companion radio node (meshcore client) over BLE, TCP or Serial and lets you interact with it from a terminal using a command line interface.
26
27 You can send commands as parameters to the meshcore-cli command (from your shell) either interactively or through a script.
28
29 There is also an interactive mode (this is the default when no command is passed). In interactive mode you can enter a contact (another client a repeater, a sensor or a room) and interact with it. For clients, interaction consists in sending/receiving messages. For repeaters, rooms or sensors it will directly give you the remote cli (you can still send messages to rooms using double quote prefix or msg command).
30
31 By default meshcore-cli interacts with companion radios (through BLE, Serial or TCP). A serial repeater mode has been introduced, which is triggered using `-r`, which mainly adds line editing, history and completion to the serial interface, adds time syncing through `clock sync` and let you download/upload regions specs from a file.
32
33 Also, most meshcore companions only have one interface compiled in at a time. So you can't connect via Serial to a node, which has been compiled as a BLE companion.
34
35 ## Install
36
37 Meshcore-cli depends on the [python meshcore](https://github.com/fdlamotte/meshcore_py) package. You can install both via `pip` or `pipx` using the command:
38
39 <pre>
40 $ pipx install meshcore-cli
41 </pre>
42
43 It will install you `meshcore-cli` and `meshcli`, which is an alias to the former.
44
45 You can use the flake under [nix](https://nixos.org/):
46
47 <pre>
48 $ nix run github:meshcore-dev/meshcore-cli#meshcore-cli
49 </pre>
50
51 If you want meshcore-cli to remember last BLE device, you should have some `$HOME/.config/meshcore` where configuration for meschcore-cli will be stored (if not it will use first device it finds).
52
53 ## Usage
54
55 <pre>
56 $ meshcli &lt;args&gt; &lt;commands&gt;
57 </pre>
58
59 If using BLE, don't forget to pair your device first (using `bluetoothctl` for instance on Linux) or meshcli won't be able to communicate. There is a device selector for BLE, you'll just have to use `meshcli -S` to select your device, subsequent calls to meshcli will be send to that device.
60
61 ### Configuration
62
63 Configuration files are stored in `$HOME/.config/meshcore`
64
65 If the directory exists, default BLE address and history will be stored there.
66
67 If there is an initialization script file called `init`, it will be executed just before the commands provided on command line are executed (and after evaluation of the arguments).
68
69 Init files can also be defined for a given device, meshcore-cli will look for `<device-name>.init` file in configuration directory (useful to specify timeout for contacts that are behind bridges with `contact_timeout` command).
70
71 ### Arguments
72
73 Arguments mostly deals with connection to the node
74
75 <pre>
76 -h : prints this help
77 -v : prints version
78 -j : json output (disables init file)
79 -D : debug
80 -S : scan for devices and show a selector
81 -l : list available ble/serial devices and exit
82 -T &lt;timeout&gt; : timeout for the ble scan (-S and -l) default 2s
83 -a &lt;address&gt; : specifies device address (can be a name)
84 -d &lt;name&gt; : filter meshcore devices with name or address
85 -P : forces pairing via the OS
86 -t &lt;hostname&gt; : connects via tcp/ip
87 -p &lt;port&gt; : specifies tcp port (default 5000)
88 -s &lt;port&gt; : use serial port &lt;port&gt;
89 -b &lt;baudrate&gt; : specify baudrate
90 -C : toggles classic mode for prompt
91 -c &lt;on/off&gt; : disables most of color output if off
92 </pre>
93
94 ### Available Commands
95
96 Commands are given after arguments, they can be chained and some have shortcuts. Also prefixing a command with a dot `.` will force it to output json instead of synthetic result.
97
98 <pre>
99 ?&lt;cmd&gt; may give you some more help about cmd
100 General commands
101 chat : enter the chat (interactive) mode
102 chat_to &lt;ct&gt; : enter chat with contact to
103 script &lt;filename&gt; : execute commands in filename
104 infos : print informations about the node i
105 self_telemetry : print own telemtry t
106 card : export this node URI e
107 ver : firmware version v
108 reboot : reboots node
109 sleep &lt;secs&gt; : sleeps for a given amount of secs s
110 wait_key : wait until user presses &lt;Enter&gt; wk
111 apply_to &lt;f&gt; &lt;cmds&gt; : sends cmds to contacts matching f at
112 Messaging
113 msg &lt;name&gt; &lt;msg&gt; : send message to node by name m {
114 wait_ack : wait an ack wa }
115 chan &lt;nb&gt; &lt;msg&gt; : send message to channel number &lt;nb&gt; ch
116 public &lt;msg&gt; : send message to public channel (0) dch
117 recv : reads next msg r
118 wait_msg : wait for a message and read it wm
119 sync_msgs : gets all unread msgs from the node sm
120 msgs_subscribe : display msgs as they arrive ms
121 get_channels : prints all channel info
122 get_channel &lt;n&gt; : get info for channel (by number or name)
123 set_channel n nm k : set channel info (nb, name, key)
124 remove_channel &lt;n&gt; : remove channel (by number or name)
125 scope &lt;s&gt; : sets node's flood scope
126 Management
127 advert : sends advert a
128 floodadv : flood advert
129 get &lt;param&gt; : gets a param, \"get help\" for more
130 set &lt;param&gt; &lt;value&gt; : sets a param, \"set help\" for more
131 time &lt;epoch&gt; : sets time to given epoch
132 clock : get current time
133 clock sync : sync device clock st
134 node_discover &lt;filter&gt; : discovers nodes based on their type nd
135 Contacts
136 contacts / list : gets contact list lc
137 reload_contacts : force reloading all contacts rc
138 contact_info &lt;ct&gt; : prints information for contact ct ci
139 contact_timeout &lt;ct&gt; v : sets temp default timeout for contact
140 share_contact &lt;ct&gt; : share a contact with others sc
141 export_contact &lt;ct&gt; : get a contact's URI ec
142 import_contact &lt;URI&gt; : import a contact from its URI ic
143 remove_contact &lt;ct&gt; : removes a contact from this node
144 path &lt;ct&gt; : diplays path for a contact
145 disc_path &lt;ct&gt; : discover new path and display dp
146 reset_path &lt;ct&gt; : resets path to a contact to flood rp
147 change_path &lt;ct&gt; &lt;pth&gt; : change the path to a contact cp
148 change_flags &lt;ct&gt; &lt;f&gt; : change contact flags (tel_l|tel_a|star)cf
149 req_telemetry &lt;ct&gt; : prints telemetry data as json rt
150 req_mma &lt;ct&gt; : requests min/max/avg for a sensor rm
151 req_acl &lt;ct&gt; : requests access control list for sensor
152 pending_contacts : show pending contacts
153 add_pending &lt;pending&gt; : manually add pending contact
154 flush_pending : flush pending contact list
155 Repeaters
156 login &lt;name&gt; &lt;pwd&gt; : log into a node (rep) with given pwd l
157 logout &lt;name&gt; : log out of a repeater
158 cmd &lt;name&gt; &lt;cmd&gt; : sends a command to a repeater (no ack) c [
159 wmt8 : wait for a msg (reply) with a timeout ]
160 req_status &lt;name&gt; : requests status from a node rs
161 req_neighbours &lt;name&gt; : requests for neighbours in binary form rn
162 trace &lt;path&gt; : run a trace, path is comma separated
163 </pre>
164
165 ### Interactive Mode
166
167 aka Instant Message or chat mode ...
168
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.
170
171 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
173 The `to` command is specific to chat mode, it lets you enter the recipient for next command. By default you're on your node but you can enter other nodes or public rooms. Here are some examples :
174
175 - `to <dest>` : will enter dest (node or channel)
176 - `to /`, `to ~` : will go to the root (your node)
177 - `to ..` : will go to the last node (it will switch between the two last nodes, this is just a 1-depth history)
178 - `to !` : will switch to the node you received last message from
179
180 When you are in a node, the behaviour will depend on the node type, if you're on a chat node, it will send messages by default and you can chat. On a repeater or a room server, it will send commands (autocompletion has been set to comply with the CommonCli class of meshcore). To send a message through a room you'll have to prefix the message with a quote or use the send command.
181
182 The `/` character is used to bypass the node you have currently selected using `to`:
183 - `/<cmd>` issues cmd command on the root
184 - `/<node>/<cmd>` will send cmd to selected node
185 - `/<dest> <msg>` will send msg to dest (channel or node)
186
187 #### Flood Scope in interactive mode
188
189 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
191 When entering chat mode, scope will be reset to `*`, meaning classic flood.
192
193 You can switch scope using the `scope` command, or postfixing the `to` command with `%<scope>`.
194
195 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
197 #### Channel echoes
198
199 It's sometimes interesting to know the path taken by a message received from a channel or which repeaters have repeated a sent message.
200
201 The app give you the information by listening `rx_log` from the device, when obtained the information is attached to the message and can be read.
202
203 In meshcore-cli I went lower-level by implementing channel echoes. When activated (with `/set channel_echoes on`), all the channel messages will be printed on the terminal along with the SNR and path taken. When sending a message, you'll have all the repeats from 0-hop repeaters as echoes, and when a message is received, you should see information about the received message, but also all the instances of the same message that might have reached you from another path.
204
205 In the example below, a msg has been sent between two repeaters, 21 and 25. 25 repeated the message and 21 the repeat and both echoes came back to the node with different SNRs.
206
207 ```
208 f1down/#fdl|*> 8
209 #fdl f1down: 8 [25] -4.75-112
210 #fdl f1down: 8 [2521] 1.00-109
211 ```
212
213 ### Contact management
214
215 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).
216
217 By default contacts are automatically added to the device contact list when an advertisement is received, so as soon as you receive an advert, you can talk with your buddy.
218
219 With growing number of users, it becomes necessary to manage contact list and one of the ways is to add contacts manually to the device. This is done by turning on `manual_add_contacts`. Once this option has been turned on, a pending list is built by meshcore-cli from the received adverts. You can view the list issuing a `pending_contacts` command, flush the list using `flush_pending` or add a contact from the list with `add_pending` followed by the key of the contact or its name (both will be auto-completed with tab).
220
221 This feature only really works in interactive mode.
222
223 Note: There is also an `auto_update_contacts` setting that has nothing to do with adding contacts, it permits to automatically sync contact lists between device and meshcore-cli (when there is an update in name, location or path).
224
225 ### Issuing batch commands to contacts with apply to
226
227 `apply_to <f> <cmd>` : applies cmd to contacts matching filter `<f>` it can be used to apply the same command to a pool of repeaters, or remove some contacts matching a condition.
228
229 Filter is constructed with comma separated fields :
230
231 - `u`, matches modification time `<` or `>` than a timestamp (can also be days hours or minutes ago if followed by `d`,`h` or `m`)
232 - `t`, matches the type (1: client, 2: repeater, 3: room, 4: sensor)
233 - `h`, matches number of hops
234 - `d`, direct, similar to `h>-1`
235 - `f`, flood, similar to `h<0` or `h=-1`
236
237 Commands should be written as if in interactive mode, if writing from the commandline don't forget to use commas to clearly delimit fields.
238
239 Note: Some commands like `contact_name` (aka `cn`), `reset_path` (aka `rp`), `forget_password` (aka `fp`) can be chained. There is also a `sleep` command taking an optional time parameter. The sleep will be issued after the command, it helps limiting rate through repeaters ...
240
241 #### Examples
242
243 ```
244 # removes all clients that have not been updated in last 2 days
245 at u<2d,t=1 remove_contact
246 # gives traces to repeaters that have been updated in the last 24h and are direct
247 at t=2,u>1d,d cn trace
248 # tries to do flood login to all repeaters
249 at t=2 rp login
250 ```
251
252 ## Examples
253
254 <pre>
255 # gets info from first ble MC device it finds (was -s but now used for serial port)
256 $ meshcore-cli -d "" infos
257 INFO:meshcore:Scanning for devices
258 INFO:meshcore:Found device : C2:2B:A1:D5:3E:B6: MeshCore-t114_fdl
259 INFO:meshcore:BLE Connection started
260 {
261 "adv_type": 1,
262 "tx_power": 22,
263 "max_tx_power": 22,
264 "public_key": "993acd42fc779962c68c627829b32b111fa27a67d86b75c17460ff48c3102db4",
265 "adv_lat": 47.794,
266 "adv_lon": -3.428,
267 "radio_freq": 869.525,
268 "radio_bw": 250.0,
269 "radio_sf": 11,
270 "radio_cr": 5,
271 "name": "t114_fdl"
272 }
273
274 # getting time
275 $ meshcli -a C2:2B:A1:D5:3E:B6 clock
276 INFO:meshcore:BLE Connection started
277 Current time : 2025-04-18 08:19:26 (1744957166)
278
279 # If you're familiar with meshcli, you should have noted that
280 # now output is not json only, to get json output, use -j
281 # or prefix your commands with a dot
282 $ meshcli -a C2:2B:A1:D5:3E:B6 .clock
283 INFO:meshcore:BLE Connection started
284 {
285 "time": 1744957249
286 }
287
288 # Using -j, meshcli will return replies in json format ...
289 $ meshcli -j -a C2:2B:A1:D5:3E:B6 clock
290 {
291 "time": 1744957261
292 }
293
294 # So if I reboot the node, and want to set time, I can chain the commands
295 # and get that kind of output (even better by feeding it to jq)
296 $ meshcli reboot
297 INFO:meshcore:BLE Connection started
298 $ meshcli -j clock clock sync clock | jq -c
299 { "time": 1715770371 }
300 { "ok": "time synced" }
301 { "time": 1745996105 }
302
303 # Now check if time is ok with human output (I don't read epoch time yet)
304 $ meshcli clock
305 INFO:meshcore:BLE Connection started
306 Current time : 2025-04-30 08:56:27 (1745996187)
307
308 # Now you'll probably want to send some messages ...
309 # For that, there is the msg command, wait_ack
310 $ meshcli msg Techo_fdl "Hello T-Echo" wa
311 INFO:meshcore:BLE Connection started
312 Msg acked
313
314 # I can check the message on the techo
315 $ meshcli -d Techo sm
316 INFO:meshcore:Scanning for devices
317 INFO:meshcore:Found device : DE:B6:D0:68:D5:62: MeshCore-Techo_fdl
318 INFO:meshcore:BLE Connection started
319 t114_fdl(0): Hello T-Echo
320
321 # And reply using json output for more verbosity
322 # here I've used jq with -cs to get a compact array
323 $ meshcli msg t114_fdl hello wa | jq -cs
324 [{"type":0,"expected_ack":"4802ed93","suggested_timeout":2970},{"code":"4802ed93"}]
325
326 # But this could have been done interactively using the chat mode
327 # Here from the techo side. Note that un-acked messages will be
328 # signaled with an ! at the start of the prompt (or red color in color mode)
329 $ meshcli chat
330 INFO:meshcore:BLE Connection started
331 Interactive mode, most commands from terminal chat should work.
332 Use "to" to selects contact, "list" to list contacts, "send" to send a message ...
333 Line starting with "$" or "." will issue a meshcli command.
334 "quit" or "q" will end interactive mode
335 t114_fdl(D): Hello T-Echo
336 EnsibsRoom> Hi
337 !EnsibsRoom> to t114_fdl
338 t114_fdl> Hi
339 t114_fdl(D): It took you long to reply ...
340 t114_fdl> I forgot to set the recipient with the to command
341 t114_fdl(D): It happens ...
342 t114_fdl>
343
344 # Loging into repeaters and sending commands is also possible
345 # directly from the chat, because we can use meshcli commands ;)
346 $ meshcli chat (pending msgs are shown at connexion ...)
347 INFO:meshcore:BLE Connection started
348 Interactive mode, most commands from terminal chat should work.
349 Use "to" to selects contact, "list" to list contacts, "send" to send a message ...
350 Line starting with "$" or "." will issue a meshcli command.
351 "quit" or "q" will end interactive mode
352 Techo_fdl(0): Cool to receive some msgs from you
353 Techo_fdl(D): Hi
354 Techo_fdl(D): I forgot to set the recipient with the to command
355 FdlRoom> login password
356 Login success
357 FdlRoom> clock
358 FdlRoom(0): 06:40 - 18/4/2025 UTC
359 FdlRoom>
360 </pre>