Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Sep 10, 2024. It is now read-only.

Commit 48fc4a8

Browse files
author
Catalin Ioana
authored
Merge pull request #126 from pycom/features/pymesh_v1.0.1
[pymesh] Updated to v1.0.1 (fw release v1.20.2.rc11, pybytes v1.5.2)
2 parents eae5fd8 + 09255b2 commit 48fc4a8

File tree

11 files changed

+283
-211
lines changed

11 files changed

+283
-211
lines changed

pymesh/pymesh_frozen/lib/cli.py

Lines changed: 59 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,21 @@
99
import time
1010
import json
1111
import sys
12-
13-
try:
14-
from pymesh_debug import print_debug
15-
except:
16-
from _pymesh_debug import print_debug
12+
import _thread
1713

1814
try:
1915
from gps import Gps
2016
except:
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,

pymesh/pymesh_frozen/lib/gps.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,21 @@
66
# see the Pycom Licence v1.0 document supplied with this file, or
77
# available at https://www.pycom.io/opensource/licensing
88

9-
__version__ = '1'
10-
"""
11-
* initial version
12-
"""
13-
9+
try:
10+
from pymesh_debug import print_debug
11+
except:
12+
from _pymesh_debug import print_debug
13+
1414
import time
1515
# from pytrack import Pytrack
1616
# from L76GNSS import L76GNSS
1717
from machine import Timer
1818

19+
__version__ = '1'
20+
"""
21+
* initial version
22+
"""
23+
1924
class Gps:
2025
# Pycom office GPS coordinates
2126
lat = 51.45
@@ -34,7 +39,7 @@ def set_location(latitude, longitude):
3439
Gps.lon = longitude
3540
is_set = True
3641
else:
37-
print("Error parsing ", latitude, longitude)
42+
print_debug(3, "Error parsing ", latitude, longitude)
3843

3944
@staticmethod
4045
def get_location():
@@ -48,10 +53,10 @@ def get_location():
4853
# Gps.l76 = L76GNSS(py, timeout=30)
4954
# #l76.coordinates()
5055
# Gps._timer = Timer.Alarm(Gps.gps_periodic, 30, periodic=True)
51-
# print("Pytrack detected")
56+
# print_debug(3, "Pytrack detected")
5257
# except:
5358
# is_pytrack = False
54-
# print("Pytrack NOT detected")
59+
# print_debug(3, "Pytrack NOT detected")
5560
# #TODO: how to check if GPS is conencted
5661
# return is_pytrack
5762

@@ -61,9 +66,9 @@ def get_location():
6166
# coord = Gps.l76.coordinates()
6267
# if coord[0] != None:
6368
# Gps.lat, Gps.lon = coord
64-
# print("New coord ", coord)
69+
# print_debug(3, "New coord ", coord)
6570
# dt = time.ticks_ms() - t0
66-
# print(" =====>>>> gps_periodic ", dt)
71+
# print_debug(3, " =====>>>> gps_periodic ", dt)
6772

6873
# @staticmethod
6974
# def terminate():

0 commit comments

Comments
 (0)