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

Skip to content

Commit 16d5c89

Browse files
author
Catalin Ioana
committed
[Pymesh] Added GPS feature
1 parent 51f3614 commit 16d5c89

File tree

7 files changed

+126
-24
lines changed

7 files changed

+126
-24
lines changed

pymesh/pymesh_frozen/lib/ble_rpc.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
except:
2525
from _pymesh_config import PymeshConfig
2626

27+
try:
28+
from gps import Gps
29+
except:
30+
from _gps import Gps
31+
2732
class BleRpc:
2833

2934
def __init__(self, config, mesh):
@@ -223,9 +228,9 @@ def mesh_ip(self):
223228
ip = self.mesh.ip()
224229
return ip
225230

226-
def set_gps(self, lng, lat):
231+
def set_gps(self, latitude, longitude):
227232
print('settings gps!')
228-
# Gps.set_location(lat, lng)
233+
Gps.set_location(latitude, longitude)
229234
# with open('/flash/gps', 'w') as fh:
230235
# fh.write('{};{}'.format(lng, lat))
231236

pymesh/pymesh_frozen/lib/ble_services.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ def _init(self):
2525
}
2626

2727
bluetooth = Bluetooth(modem_sleep=False)
28-
# bluetooth = Bluetooth()
29-
# bluetooth.set_advertisement(name='PyGo (mac:' + str(self.mesh_mac) + ')', service_uuid=0xec00)
3028
adv_name = self.ble_name
3129
bluetooth.set_advertisement(name=adv_name, service_uuid=0xec00)
3230
print("BLE name:", adv_name)

pymesh/pymesh_frozen/lib/cli.py

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
except:
1616
from _pymesh_debug import print_debug
1717

18+
try:
19+
from gps import Gps
20+
except:
21+
from _gps import Gps
22+
1823
__version__ = '1'
1924
"""
2025
* initial draft
@@ -41,7 +46,9 @@ def process(self, arg1, arg2):
4146
while True:
4247
time.sleep(.1)
4348
cmd = input('>')
44-
# print(cmd)
49+
# cmd = " "
50+
# time.sleep(3)
51+
# print("cli")
4552

4653
# if cmd == 'rb':
4754
# print('resetting unpacker buffer')
@@ -118,14 +125,16 @@ def process(self, arg1, arg2):
118125
elif cmd == 'rm':
119126
print(self.mesh.get_rcv_message())
120127

121-
# elif cmd == 'gg':
122-
# print("Gps:", (Gps.lat, Gps.lon))
123-
124-
# elif cmd == 'gs':
125-
# lat = float(input('(lat)<'))
126-
# lon = float(input('(lon)<'))
127-
# Gps.set_location(lat, lon)
128-
# print("Gps:", (Gps.lat, Gps.lon))
128+
elif cmd == 'gps':
129+
try:
130+
lat = float(input('(lat [Enter for read])<'))
131+
lon = float(input('(lon)<'))
132+
except:
133+
print("Gps:", (Gps.lat, Gps.lon))
134+
continue
135+
136+
Gps.set_location(lat, lon)
137+
print("Gps:", (Gps.lat, Gps.lon))
129138

130139
elif cmd == 'sleep':
131140
try:
@@ -163,11 +172,11 @@ def process(self, arg1, arg2):
163172
# res = self.mesh.statistics_get(id)
164173
# print("ok? ", res)
165174

166-
# elif cmd == "rst":
167-
# print("Mesh Reset NVM settings ... ")
168-
# self.mesh.mesh.mesh.mesh.deinit()
169-
# if self.sleep:
170-
# self.sleep(1)
175+
elif cmd == "rst":
176+
print("Mesh Reset NVM settings ... ")
177+
self.mesh.mesh.mesh.mesh.deinit()
178+
if self.sleep:
179+
self.sleep(1)
171180

172181
# elif cmd == "pyb":
173182
# # print("Pybytes debug menu, Pybytes connection is ", Pybytes_wrap.is_connected())
@@ -262,6 +271,7 @@ def process(self, arg1, arg2):
262271
print("ot - sends command to openthread internal CLI")
263272
print("debug - set debug level")
264273
print("config - print config file contents")
274+
print("gps - get/set location coordinates")
265275

266276
except KeyboardInterrupt:
267277
print('cli Got Ctrl-C')

pymesh/pymesh_frozen/lib/gps.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
2+
# Copyright (c) 2019, Pycom Limited.
3+
#
4+
# This software is licensed under the GNU GPL version 3 or any
5+
# later version, with permitted additional terms. For more information
6+
# see the Pycom Licence v1.0 document supplied with this file, or
7+
# available at https://www.pycom.io/opensource/licensing
8+
9+
__version__ = '1'
10+
"""
11+
* initial version
12+
"""
13+
14+
import time
15+
# from pytrack import Pytrack
16+
# from L76GNSS import L76GNSS
17+
from machine import Timer
18+
19+
class Gps:
20+
# Pycom office GPS coordinates
21+
lat = 51.45
22+
lon = 5.45313
23+
24+
l76 = None
25+
_timer = None
26+
#is_set = False
27+
28+
@staticmethod
29+
def set_location(latitude, longitude):
30+
dlat = str(type(latitude))
31+
dlon = str(type(longitude))
32+
if dlat == dlon == "<class 'float'>":
33+
Gps.lat = latitude
34+
Gps.lon = longitude
35+
is_set = True
36+
else:
37+
print("Error parsing ", latitude, longitude)
38+
39+
@staticmethod
40+
def get_location():
41+
return (Gps.lat, Gps.lon)
42+
43+
# @staticmethod
44+
# def init_static():
45+
# is_pytrack = True
46+
# try:
47+
# py = Pytrack()
48+
# Gps.l76 = L76GNSS(py, timeout=30)
49+
# #l76.coordinates()
50+
# Gps._timer = Timer.Alarm(Gps.gps_periodic, 30, periodic=True)
51+
# print("Pytrack detected")
52+
# except:
53+
# is_pytrack = False
54+
# print("Pytrack NOT detected")
55+
# #TODO: how to check if GPS is conencted
56+
# return is_pytrack
57+
58+
# @staticmethod
59+
# def gps_periodic(alarm):
60+
# t0 = time.ticks_ms()
61+
# coord = Gps.l76.coordinates()
62+
# if coord[0] != None:
63+
# Gps.lat, Gps.lon = coord
64+
# print("New coord ", coord)
65+
# dt = time.ticks_ms() - t0
66+
# print(" =====>>>> gps_periodic ", dt)
67+
68+
# @staticmethod
69+
# def terminate():
70+
# if Gps._timer is not None:
71+
# Gps._timer.cancel()
72+
# pass
73+
74+
"""
75+
from pytrack import Pytrack
76+
from L76GNSS import L76GNSS
77+
py = Pytrack()
78+
l76 = L76GNSS(py, timeout=30)
79+
t0 = time.ticks_ms()
80+
l76.coordinates()
81+
y = time.ticks_ms() - t0
82+
y
83+
"""

pymesh/pymesh_frozen/lib/loramesh.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
except:
2121
from _pymesh_debug import print_debug
2222

23+
try:
24+
from gps import Gps
25+
except:
26+
from _gps import Gps
27+
2328
__version__ = '6'
2429
"""
2530
__version__ = '6'
@@ -274,7 +279,7 @@ def neighbors_update(self):
274279
self.router_data.rloc16 = self.rloc16
275280
self.router_data.role = self.state
276281
self.router_data.ts = time.time()
277-
self.router_data.coord = (1,2) #Gps.get_location()
282+
self.router_data.coord = Gps.get_location()
278283

279284
for nei_rec in x:
280285
# nei_rec = (role=3, rloc16=10240, rssi=0, age=28, mac=5)
@@ -452,7 +457,7 @@ def node_info_get(self, mac):
452457
data['a'] = node.age
453458
elif role is self.STATE_ROUTER:
454459
data['a'] = time.time() - node.ts
455-
data['l'] = {'lng':node.coord[1], 'lat':node.coord[0]}
460+
data['l'] = {'lat':node.coord[0], 'lng':node.coord[1]}
456461
data['nn'] = node.neigh_num()
457462
nei_macs = node.get_macs_set()
458463
data['nei'] = list()
@@ -534,7 +539,7 @@ def __init__(self, data = None):
534539
self.ts = 0
535540
self.dict = {}
536541
self.pack_index_last = 0
537-
self.coord = (0.0, 0.0)
542+
self.coord = Gps.get_location()
538543

539544
if data is None:
540545
return
@@ -624,8 +629,8 @@ def as_dict(self):
624629
dict['ip'] = self.rloc16
625630
dict['role'] = self.role
626631
dict['age'] = time.time() - self.ts
627-
dict['loc'] = self.coord[0]
628-
dict['ble'] = self.coord[1]
632+
dict['loc'] = {"lat":self.coord[0], "lng":self.coord[1]}
633+
dict['ble'] = "ble"
629634
return dict
630635

631636
def get_all_pairs(self):

pymesh/pymesh_frozen/lib/pymesh.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ def process(self, arg1, arg2):
102102
# Pybytes_wrap.process()
103103

104104
time.sleep(.5)
105+
# time.sleep(1)
105106
# print("loop")
106107
pass
107108

pymesh/pymesh_frozen/lib/pymesh_debug.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import pycom
1010

11-
# debug level from the most verbose to off
11+
# recommended debug levels, from the most verbose to off
1212
DEBUG_DEBG = const(5)
1313
DEBUG_INFO = const(4)
1414
DEBUG_NOTE = const(3)

0 commit comments

Comments
 (0)