99import time
1010import json
1111import sys
12-
13- try :
14- from pymesh_debug import print_debug
15- except :
16- from _pymesh_debug import print_debug
12+ import _thread
1713
1814try :
1915 from gps import Gps
2016except :
2117 from _gps import Gps
2218
23- __version__ = '2 '
19+ __version__ = '3 '
2420"""
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+
2527__version__ = '2'
2628* added pause/resume and factory reset
2729
@@ -92,6 +94,8 @@ def process(self, arg1, arg2):
9294 print ('last_mesh_pairs' , json .dumps (last_mesh_pairs ))
9395
9496 elif cmd == 's' :
97+ interval = 0
98+ repetitions = 0
9599 try :
96100 to = int (input ('(to)<' ))
97101 # typ = input('(type, 0=text, 1=file, Enter for text)<')
@@ -100,6 +104,9 @@ def process(self, arg1, arg2):
100104 # else:
101105 # typ = int(typ)
102106 txt = input ('(message)<' )
107+ repetitions = int (input ('(repetitions)' ))
108+ if repetitions > 1 :
109+ interval = int (input ('(interval in seconds)' ))
103110 except :
104111 continue
105112 data = {
@@ -109,7 +116,13 @@ def process(self, arg1, arg2):
109116 'id' : 12345 ,
110117 'ts' : int (time .time ()),
111118 }
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+
113126
114127 elif cmd == 'ws' :
115128 to = int (input ('(to)<' ))
@@ -241,9 +254,9 @@ def process(self, arg1, arg2):
241254 ret = input ('(debug level[0-5])<' )
242255 try :
243256 level = int (ret )
244- self .mesh .debug_level (level )
257+ self .pymesh .debug_level (level )
245258 except :
246- print_debug ( 1 , "error parsing" )
259+ print ( self . pymesh . debug_level () )
247260
248261 elif cmd == "config" :
249262 print (self .mesh .config )
@@ -253,38 +266,58 @@ def process(self, arg1, arg2):
253266
254267 elif cmd == "resume" :
255268 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 ()
256285
257- else :
286+ elif cmd == "h" :
258287 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" )
259295 print ("ip - display current IPv6 unicast addresses" )
260296 print ("mac - set or display the current LoRa MAC address" )
261- print ("self - display all info about current node" )
262297 print ("mml - display the Mesh Mac List (MAC of all nodes inside this Mesh), also inquires Leader" )
263298 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" )
266302 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" )
267306 print ("sleep - deep-sleep" )
268307 # print("stat - start statistics")
269308 # 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" )
280312
281313 except KeyboardInterrupt :
282- print ('cli Got Ctrl-C' )
314+ print ('CLI Ctrl-C' )
283315 except Exception as e :
284316 sys .print_exception (e )
285317 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 )
288321
289322 def new_br_message_cb (self , rcv_ip , rcv_port , rcv_data , dest_ip , dest_port ):
290323 ''' callback triggered when a new packet arrived for the current Border Router,
0 commit comments