9
9
import time
10
10
import json
11
11
import sys
12
-
13
- try :
14
- from pymesh_debug import print_debug
15
- except :
16
- from _pymesh_debug import print_debug
12
+ import _thread
17
13
18
14
try :
19
15
from gps import Gps
20
16
except :
21
17
from _gps import Gps
22
18
23
- __version__ = '2 '
19
+ __version__ = '3 '
24
20
"""
21
+ __version__ = '3'
22
+ * added dynamic start/stop CLI
23
+ * h = help, listing all commands
24
+ * added tx_pow and s(send) packets with repetitions
25
+ * debug can also read the current level
26
+
25
27
__version__ = '2'
26
28
* added pause/resume and factory reset
27
29
@@ -92,6 +94,8 @@ def process(self, arg1, arg2):
92
94
print ('last_mesh_pairs' , json .dumps (last_mesh_pairs ))
93
95
94
96
elif cmd == 's' :
97
+ interval = 0
98
+ repetitions = 0
95
99
try :
96
100
to = int (input ('(to)<' ))
97
101
# typ = input('(type, 0=text, 1=file, Enter for text)<')
@@ -100,6 +104,9 @@ def process(self, arg1, arg2):
100
104
# else:
101
105
# typ = int(typ)
102
106
txt = input ('(message)<' )
107
+ repetitions = int (input ('(repetitions)' ))
108
+ if repetitions > 1 :
109
+ interval = int (input ('(interval in seconds)' ))
103
110
except :
104
111
continue
105
112
data = {
@@ -109,7 +116,13 @@ def process(self, arg1, arg2):
109
116
'id' : 12345 ,
110
117
'ts' : int (time .time ()),
111
118
}
112
- print (self .mesh .send_message (data ))
119
+ while repetitions > 0 :
120
+ print (self .mesh .send_message (data ))
121
+ repetitions = repetitions - 1
122
+ if repetitions > 0 :
123
+ print ("Remaining TX packets:" , repetitions )
124
+ time .sleep (interval )
125
+
113
126
114
127
elif cmd == 'ws' :
115
128
to = int (input ('(to)<' ))
@@ -241,9 +254,9 @@ def process(self, arg1, arg2):
241
254
ret = input ('(debug level[0-5])<' )
242
255
try :
243
256
level = int (ret )
244
- self .mesh .debug_level (level )
257
+ self .pymesh .debug_level (level )
245
258
except :
246
- print_debug ( 1 , "error parsing" )
259
+ print ( self . pymesh . debug_level () )
247
260
248
261
elif cmd == "config" :
249
262
print (self .mesh .config )
@@ -253,38 +266,58 @@ def process(self, arg1, arg2):
253
266
254
267
elif cmd == "resume" :
255
268
self .pymesh .resume ()
269
+
270
+ elif cmd == "tx_pow" :
271
+ print ("LoRa stats:" , self .pymesh .mesh .mesh .mesh .lora .stats ())
272
+ tx_str = input ('(tx_pow[2-20])<' )
273
+ try :
274
+ tx_pow = int (tx_str )
275
+ self .pymesh .pause ()
276
+ print ("Change TX power to" , tx_pow )
277
+ time .sleep (1 )
278
+ self .pymesh .resume (tx_pow )
279
+ except :
280
+ print ("Invalid value" )
281
+
282
+ elif cmd == "stop" :
283
+ self .pymesh .cli = None
284
+ _thread .exit ()
256
285
257
- else :
286
+ elif cmd == "h" :
258
287
print ("List of available commands" )
288
+ print ("br - enable/disable or display the current Border Router functionality" )
289
+ print ("brs - send packet for Mesh-external, to BR, if any" )
290
+ print ("buf - display buffer info" )
291
+ print ("config - print config file contents" )
292
+ print ("debug - set debug level" )
293
+ print ("gps - get/set location coordinates" )
294
+ print ("h - help, list of commands" )
259
295
print ("ip - display current IPv6 unicast addresses" )
260
296
print ("mac - set or display the current LoRa MAC address" )
261
- print ("self - display all info about current node" )
262
297
print ("mml - display the Mesh Mac List (MAC of all nodes inside this Mesh), also inquires Leader" )
263
298
print ("mp - display the Mesh Pairs (Pairs of all nodes connections), also inquires Leader" )
264
- print ("s - send message" )
265
- print ("ws - verifies if message sent was acknowledged" )
299
+ print ("ot - sends command to openthread internal CLI" )
300
+ print ("pause - suspend Pymesh" )
301
+ print ("resume - resume Pymesh" )
266
302
print ("rm - verifies if any message was received" )
303
+ print ("rst - reset NOW, including NVM Pymesh IPv6" )
304
+ print ("s - send message" )
305
+ print ("self - display all info about current node" )
267
306
print ("sleep - deep-sleep" )
268
307
# print("stat - start statistics")
269
308
# print("stat? - display statistics")
270
- print ("br - enable/disable or display the current Border Router functionality" )
271
- print ("brs - send packet for Mesh-external, to BR, if any" )
272
- print ("rst - reset NOW, including NVM Pymesh IPv6" )
273
- print ("pause - suspend Pymesh" )
274
- print ("resume - resume Pymesh" )
275
- print ("buf - display buffer info" )
276
- print ("ot - sends command to openthread internal CLI" )
277
- print ("debug - set debug level" )
278
- print ("config - print config file contents" )
279
- print ("gps - get/set location coordinates" )
309
+ print ("stop - close this CLI" )
310
+ print ("tx_pow - set LoRa TX power in dBm (2-20)" )
311
+ print ("ws - verifies if message sent was acknowledged" )
280
312
281
313
except KeyboardInterrupt :
282
- print ('cli Got Ctrl-C' )
314
+ print ('CLI Ctrl-C' )
283
315
except Exception as e :
284
316
sys .print_exception (e )
285
317
finally :
286
- print ('cli finally' )
287
- self .sleep (0 )
318
+ print ('CLI stopped' )
319
+ if self .pymesh .cli is not None :
320
+ self .sleep (0 )
288
321
289
322
def new_br_message_cb (self , rcv_ip , rcv_port , rcv_data , dest_ip , dest_port ):
290
323
''' callback triggered when a new packet arrived for the current Border Router,
0 commit comments