mirror of
https://gitee.com/qpy-solutions/tracker-v2.git
synced 2025-05-19 02:58:25 +08:00
update: gps read; add: quec & ali cloud params
This commit is contained in:
parent
3c589d966c
commit
2e8d8b3472
@ -13,6 +13,7 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import ure
|
import ure
|
||||||
|
import utime
|
||||||
import osTimer
|
import osTimer
|
||||||
import cellLocator
|
import cellLocator
|
||||||
import usr.settings as settings
|
import usr.settings as settings
|
||||||
@ -80,7 +81,12 @@ class GPS(Singleton):
|
|||||||
gps_data_retrieve_queue = Queue(maxsize=8)
|
gps_data_retrieve_queue = Queue(maxsize=8)
|
||||||
|
|
||||||
def gps_timer_callback(self, args):
|
def gps_timer_callback(self, args):
|
||||||
self.break_flag = 1
|
if self.break_flag == 0:
|
||||||
|
self.break_flag = 1
|
||||||
|
elif self.break_flag == 1:
|
||||||
|
self.break_flag = 2
|
||||||
|
if gps_data_retrieve_queue is not None:
|
||||||
|
gps_data_retrieve_queue.put(0)
|
||||||
|
|
||||||
def uart_read(self):
|
def uart_read(self):
|
||||||
global gps_data_retrieve_queue
|
global gps_data_retrieve_queue
|
||||||
@ -95,21 +101,24 @@ class GPS(Singleton):
|
|||||||
rmc_data = ''
|
rmc_data = ''
|
||||||
gga_data = ''
|
gga_data = ''
|
||||||
vtg_data = ''
|
vtg_data = ''
|
||||||
while True:
|
while self.break_flag == 1:
|
||||||
|
self.gps_timer.start(3000, 1, self.gps_timer_callback)
|
||||||
nread = gps_data_retrieve_queue.get()
|
nread = gps_data_retrieve_queue.get()
|
||||||
udata = self.uart_obj.read(nread).decode()
|
if nread:
|
||||||
if not rmc_data:
|
udata = self.uart_obj.read(nread).decode()
|
||||||
rmc_data = self.read_location_GxRMC(udata)
|
if not rmc_data:
|
||||||
if not gga_data:
|
rmc_data = self.read_location_GxRMC(udata)
|
||||||
gga_data = self.read_location_GxGGA(udata)
|
if not gga_data:
|
||||||
if not vtg_data:
|
gga_data = self.read_location_GxGGA(udata)
|
||||||
vtg_data = self.read_location_GxVTG(udata)
|
if not vtg_data:
|
||||||
if rmc_data or gga_data or vtg_data:
|
vtg_data = self.read_location_GxVTG(udata)
|
||||||
data += udata
|
if rmc_data or gga_data or vtg_data:
|
||||||
if rmc_data and gga_data and vtg_data:
|
data += udata
|
||||||
break
|
if rmc_data and gga_data and vtg_data:
|
||||||
|
self.break_flag = 2
|
||||||
|
self.gps_timer.stop()
|
||||||
self.break_flag = 0
|
self.break_flag = 0
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def quecgnss_read(self):
|
def quecgnss_read(self):
|
||||||
@ -125,21 +134,30 @@ class GPS(Singleton):
|
|||||||
rmc_data = ''
|
rmc_data = ''
|
||||||
gga_data = ''
|
gga_data = ''
|
||||||
vtg_data = ''
|
vtg_data = ''
|
||||||
while True:
|
count = 0
|
||||||
|
while self.break_flag == 1:
|
||||||
|
self.gps_timer.start(3000, 1, self.gps_timer_callback)
|
||||||
gnss_data = quecgnss.read(4096)
|
gnss_data = quecgnss.read(4096)
|
||||||
udata = gnss_data[1].decode() if len(gnss_data) > 1 and gnss_data[1] else ''
|
if gnss_data and gnss_data[1]:
|
||||||
if not rmc_data:
|
udata = gnss_data[1].decode() if len(gnss_data) > 1 and gnss_data[1] else ''
|
||||||
rmc_data = self.read_location_GxRMC(udata)
|
if not rmc_data:
|
||||||
if not gga_data:
|
rmc_data = self.read_location_GxRMC(udata)
|
||||||
gga_data = self.read_location_GxGGA(udata)
|
if not gga_data:
|
||||||
if not vtg_data:
|
gga_data = self.read_location_GxGGA(udata)
|
||||||
vtg_data = self.read_location_GxVTG(udata)
|
if not vtg_data:
|
||||||
if rmc_data or gga_data or vtg_data:
|
vtg_data = self.read_location_GxVTG(udata)
|
||||||
data += udata
|
if rmc_data or gga_data or vtg_data:
|
||||||
if rmc_data and gga_data and vtg_data:
|
data += udata
|
||||||
break
|
if rmc_data and gga_data and vtg_data:
|
||||||
|
self.break_flag = 2
|
||||||
|
self.gps_timer.stop()
|
||||||
|
|
||||||
|
if count > 5:
|
||||||
|
self.break_flag = 2
|
||||||
|
count += 1
|
||||||
|
utime.sleep_ms(300)
|
||||||
self.break_flag = 0
|
self.break_flag = 0
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def read(self):
|
def read(self):
|
||||||
@ -182,8 +200,10 @@ class GPS(Singleton):
|
|||||||
return ""
|
return ""
|
||||||
|
|
||||||
def read_quecIot(self):
|
def read_quecIot(self):
|
||||||
|
res = {}
|
||||||
data = []
|
data = []
|
||||||
gps_data = self.read()
|
gps_data = self.read()
|
||||||
|
log.debug('read_quecIot gps_data: %s' % gps_data)
|
||||||
r = self.read_location_GxRMC(gps_data)
|
r = self.read_location_GxRMC(gps_data)
|
||||||
if r:
|
if r:
|
||||||
data.append(r)
|
data.append(r)
|
||||||
@ -195,13 +215,16 @@ class GPS(Singleton):
|
|||||||
r = self.read_location_GxVTG(gps_data)
|
r = self.read_location_GxVTG(gps_data)
|
||||||
if r:
|
if r:
|
||||||
data.append(r)
|
data.append(r)
|
||||||
|
if data:
|
||||||
|
res = {'gps': data}
|
||||||
|
|
||||||
return {'gps': data}
|
return res
|
||||||
|
|
||||||
def read_aliyun(self):
|
def read_aliyun(self):
|
||||||
|
gps_info = {}
|
||||||
gps_data = self.read()
|
gps_data = self.read()
|
||||||
gga_data = self.read_location_GxGGA(gps_data)
|
gga_data = self.read_location_GxGGA(gps_data)
|
||||||
data = {'CoordinateSystem': 1}
|
data = {}
|
||||||
if gga_data:
|
if gga_data:
|
||||||
Latitude_re = ure.search(r",[0-9]+\.[0-9]+,[NS],", gga_data)
|
Latitude_re = ure.search(r",[0-9]+\.[0-9]+,[NS],", gga_data)
|
||||||
if Latitude_re:
|
if Latitude_re:
|
||||||
@ -212,7 +235,10 @@ class GPS(Singleton):
|
|||||||
Altitude_re = ure.search(r"-*[0-9]+\.[0-9]+,M,", gga_data)
|
Altitude_re = ure.search(r"-*[0-9]+\.[0-9]+,M,", gga_data)
|
||||||
if Altitude_re:
|
if Altitude_re:
|
||||||
data['Altitude'] = round(float(Altitude_re.group(0)[:-3]), 2)
|
data['Altitude'] = round(float(Altitude_re.group(0)[:-3]), 2)
|
||||||
gps_info = {'GeoLocation': data}
|
if data:
|
||||||
|
data['CoordinateSystem'] = 1
|
||||||
|
if data:
|
||||||
|
gps_info = {'GeoLocation': data}
|
||||||
return gps_info
|
return gps_info
|
||||||
|
|
||||||
|
|
||||||
@ -233,8 +259,10 @@ class CellLocator(object):
|
|||||||
return {'non_gps': ['LBS']}
|
return {'non_gps': ['LBS']}
|
||||||
|
|
||||||
def read_aliyun(self):
|
def read_aliyun(self):
|
||||||
|
gps_info = {}
|
||||||
gps_data = self.read()
|
gps_data = self.read()
|
||||||
gps_info = {'GeoLocation': {'Longtitude': round(gps_data[0], 2), 'Latitude': round(gps_data[1], 2), 'Altitude': 0.0, 'CoordinateSystem': 1}}
|
if gps_data:
|
||||||
|
gps_info = {'GeoLocation': {'Longtitude': round(gps_data[0], 2), 'Latitude': round(gps_data[1], 2), 'Altitude': 0.0, 'CoordinateSystem': 1}}
|
||||||
return gps_info
|
return gps_info
|
||||||
|
|
||||||
|
|
||||||
@ -246,11 +274,14 @@ class WiFiLocator(object):
|
|||||||
return self.wifilocator_obj.getwifilocator()
|
return self.wifilocator_obj.getwifilocator()
|
||||||
|
|
||||||
def read_quecIot(self):
|
def read_quecIot(self):
|
||||||
return {'non_gps': []}
|
# TODO: {'non_gps': []}
|
||||||
|
return {}
|
||||||
|
|
||||||
def read_aliyun(self):
|
def read_aliyun(self):
|
||||||
|
gps_info = {}
|
||||||
gps_data = self.read()
|
gps_data = self.read()
|
||||||
gps_info = {'GeoLocation': {'Longtitude': round(gps_data[0], 2), 'Latitude': round(gps_data[1], 2), 'Altitude': 0.0, 'CoordinateSystem': 1}}
|
if gps_data:
|
||||||
|
gps_info = {'GeoLocation': {'Longtitude': round(gps_data[0], 2), 'Latitude': round(gps_data[1], 2), 'Altitude': 0.0, 'CoordinateSystem': 1}}
|
||||||
return gps_info
|
return gps_info
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ log = getLogger(__name__)
|
|||||||
|
|
||||||
PROJECT_NAME = 'QuecPython_Tracker'
|
PROJECT_NAME = 'QuecPython_Tracker'
|
||||||
|
|
||||||
PROJECT_VERSION = '2.0.0'
|
PROJECT_VERSION = '2.0.1'
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
import utime
|
||||||
import osTimer
|
import osTimer
|
||||||
import quecIot
|
import quecIot
|
||||||
|
|
||||||
@ -70,13 +71,28 @@ class QuecThing(object):
|
|||||||
self.downlink_queue = downlink_queue
|
self.downlink_queue = downlink_queue
|
||||||
self.post_result_wait_queue = Queue(maxsize=16)
|
self.post_result_wait_queue = Queue(maxsize=16)
|
||||||
self.quec_timer = osTimer()
|
self.quec_timer = osTimer()
|
||||||
|
self.queciot_init(pk, ps, dk, ds)
|
||||||
|
|
||||||
|
def queciot_init(self, pk, ps, dk, ds):
|
||||||
quecIot.init()
|
quecIot.init()
|
||||||
quecIot.setEventCB(self.eventCB)
|
quecIot.setEventCB(self.eventCB)
|
||||||
quecIot.setProductinfo(pk, ps)
|
quecIot.setProductinfo(pk, ps)
|
||||||
quecIot.setDkDs(dk, ds)
|
quecIot.setDkDs(dk, ds)
|
||||||
quecIot.setServer(1, "iot-south.quectel.com:2883")
|
quecIot.setServer(1, "iot-south.quectel.com:2883")
|
||||||
quecIot.setConnmode(1)
|
quecIot.setConnmode(1)
|
||||||
|
if not ds and dk:
|
||||||
|
count = 0
|
||||||
|
while count < 3:
|
||||||
|
ndk, nds = quecIot.getDkDs()
|
||||||
|
if nds:
|
||||||
|
break
|
||||||
|
count += 1
|
||||||
|
utime.sleep(count)
|
||||||
|
current_settings = settings.get()
|
||||||
|
cloud_init_params = current_settings['sys']['cloud_init_params']
|
||||||
|
cloud_init_params['DS'] = nds
|
||||||
|
settings.set('cloud_init_params', cloud_init_params)
|
||||||
|
settings.save()
|
||||||
|
|
||||||
def get_post_res(self):
|
def get_post_res(self):
|
||||||
current_settings = settings.get()
|
current_settings = settings.get()
|
||||||
|
@ -12,18 +12,17 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import ql_fs
|
|
||||||
import ujson
|
|
||||||
import uos
|
import uos
|
||||||
import ure
|
import ure
|
||||||
|
import ql_fs
|
||||||
|
import ujson
|
||||||
import _thread
|
import _thread
|
||||||
import quecIot
|
|
||||||
from machine import UART
|
from machine import UART
|
||||||
from usr.common import Singleton
|
from usr.common import Singleton
|
||||||
|
|
||||||
PROJECT_NAME = 'QuecPython_Tracker'
|
PROJECT_NAME = 'QuecPython_Tracker'
|
||||||
|
|
||||||
PROJECT_VERSION = '2.0.0'
|
PROJECT_VERSION = '2.0.1'
|
||||||
|
|
||||||
DATA_NON_LOCA = 0x0
|
DATA_NON_LOCA = 0x0
|
||||||
DATA_LOCA_NON_GPS = 0x1
|
DATA_LOCA_NON_GPS = 0x1
|
||||||
@ -131,7 +130,7 @@ class default_values_app(object):
|
|||||||
|
|
||||||
phone_num = ''
|
phone_num = ''
|
||||||
|
|
||||||
loc_method = _loc_method.gps
|
loc_method = _loc_method.all
|
||||||
|
|
||||||
work_mode = _work_mode.cycle
|
work_mode = _work_mode.cycle
|
||||||
|
|
||||||
@ -213,6 +212,7 @@ class default_values_sys(object):
|
|||||||
|
|
||||||
ali_burning_method = _ali_burning_method.one_machine_one_density
|
ali_burning_method = _ali_burning_method.one_machine_one_density
|
||||||
|
|
||||||
|
# trackdev0304
|
||||||
_quecIot = {
|
_quecIot = {
|
||||||
'PK': 'p11275',
|
'PK': 'p11275',
|
||||||
'PS': 'Q0ZQQndaN3pCUFd6',
|
'PS': 'Q0ZQQndaN3pCUFd6',
|
||||||
@ -220,6 +220,22 @@ class default_values_sys(object):
|
|||||||
'DS': '8eba9389af434974c3c846d1922d949f',
|
'DS': '8eba9389af434974c3c846d1922d949f',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# # trackerdemo0326
|
||||||
|
# _quecIot = {
|
||||||
|
# 'PK': 'p11275',
|
||||||
|
# 'PS': 'Q0ZQQndaN3pCUFd6',
|
||||||
|
# 'DK': 'trackerdemo0326',
|
||||||
|
# 'DS': '32d540996e32f95c58dd98f18d473d52',
|
||||||
|
# }
|
||||||
|
|
||||||
|
# _quecIot = {
|
||||||
|
# 'PK': 'p11275',
|
||||||
|
# 'PS': 'Q0ZQQndaN3pCUFd6',
|
||||||
|
# 'DK': '',
|
||||||
|
# 'DS': '',
|
||||||
|
# }
|
||||||
|
|
||||||
|
# TrackerEC600N
|
||||||
_AliYun = {
|
_AliYun = {
|
||||||
'PK': 'guqqtu3edVY',
|
'PK': 'guqqtu3edVY',
|
||||||
'PS': 'xChL7HREtPyYCtPM',
|
'PS': 'xChL7HREtPyYCtPM',
|
||||||
@ -227,6 +243,22 @@ class default_values_sys(object):
|
|||||||
'DS': 'a3153ed0c2f68db6e2f47e0769f966a2',
|
'DS': 'a3153ed0c2f68db6e2f47e0769f966a2',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# # alitrackerdemo0326
|
||||||
|
# _AliYun = {
|
||||||
|
# 'PK': 'guqqtu3edVY',
|
||||||
|
# 'PS': 'xChL7HREtPyYCtPM',
|
||||||
|
# 'DK': 'alitrackerdemo0326',
|
||||||
|
# 'DS': 'b01307100686698bbc71fc4af230baf9',
|
||||||
|
# }
|
||||||
|
|
||||||
|
# # ali_tracker_demo_0306_jun
|
||||||
|
# _AliYun = {
|
||||||
|
# 'PK': 'guqqtu3edVY',
|
||||||
|
# 'PS': 'xChL7HREtPyYCtPM',
|
||||||
|
# 'DK': 'ali_tracker_demo_0306_jun',
|
||||||
|
# 'DS': '38d78764407d08776c74e319a7802d88',
|
||||||
|
# }
|
||||||
|
|
||||||
_JTT808 = {
|
_JTT808 = {
|
||||||
'PK': '',
|
'PK': '',
|
||||||
'PS': '',
|
'PS': '',
|
||||||
@ -276,7 +308,6 @@ class default_values_sys(object):
|
|||||||
|
|
||||||
if cloud & default_values_sys._cloud.quecIot:
|
if cloud & default_values_sys._cloud.quecIot:
|
||||||
cloud_init_params = default_values_sys._quecIot
|
cloud_init_params = default_values_sys._quecIot
|
||||||
cloud_init_params = default_values_sys._quecIot_init_params(cloud_init_params)
|
|
||||||
if cloud & default_values_sys._cloud.AliYun:
|
if cloud & default_values_sys._cloud.AliYun:
|
||||||
cloud_init_params = default_values_sys._AliYun
|
cloud_init_params = default_values_sys._AliYun
|
||||||
if cloud & default_values_sys._cloud.JTT808:
|
if cloud & default_values_sys._cloud.JTT808:
|
||||||
@ -284,17 +315,6 @@ class default_values_sys(object):
|
|||||||
|
|
||||||
return cloud_init_params
|
return cloud_init_params
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _quecIot_init_params(cloud_init_params):
|
|
||||||
if not cloud_init_params['DK'] or not cloud_init_params['DS']:
|
|
||||||
if quecIot.init():
|
|
||||||
if quecIot.setProductinfo(cloud_init_params['PK'], cloud_init_params['PS']):
|
|
||||||
if quecIot.setDkDs(cloud_init_params['DK'], cloud_init_params['DS']):
|
|
||||||
ndk, nds = quecIot.getDkDs()
|
|
||||||
cloud_init_params['DK'] = ndk
|
|
||||||
cloud_init_params['DS'] = nds
|
|
||||||
return cloud_init_params
|
|
||||||
|
|
||||||
|
|
||||||
class Settings(Singleton):
|
class Settings(Singleton):
|
||||||
|
|
||||||
@ -389,12 +409,17 @@ class Settings(Singleton):
|
|||||||
if opt == 'sw_log':
|
if opt == 'sw_log':
|
||||||
if not isinstance(val, bool):
|
if not isinstance(val, bool):
|
||||||
return False
|
return False
|
||||||
self.current_settings['app'][opt] = val
|
self.current_settings['sys'][opt] = val
|
||||||
return True
|
return True
|
||||||
elif opt == 'ota_status':
|
elif opt == 'ota_status':
|
||||||
if not isinstance(val, int):
|
if not isinstance(val, int):
|
||||||
return False
|
return False
|
||||||
self.current_settings['app'][opt] = val
|
self.current_settings['sys'][opt] = val
|
||||||
|
return True
|
||||||
|
elif opt == 'cloud_init_params':
|
||||||
|
if not isinstance(val, dict):
|
||||||
|
return False
|
||||||
|
self.current_settings['sys'][opt] = val
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
@ -73,9 +73,6 @@ def test_settings():
|
|||||||
log.info('[x] start test_settings')
|
log.info('[x] start test_settings')
|
||||||
current_settings = settings.settings.get()
|
current_settings = settings.settings.get()
|
||||||
log.info("current_settings", current_settings)
|
log.info("current_settings", current_settings)
|
||||||
settings.Settings().reset()
|
|
||||||
current_settings = settings.settings.get()
|
|
||||||
log.info("current_settings", current_settings)
|
|
||||||
log.info('[x] end test_settings')
|
log.info('[x] end test_settings')
|
||||||
|
|
||||||
|
|
||||||
|
@ -99,6 +99,7 @@ class Tracker(Singleton):
|
|||||||
|
|
||||||
loc_info = self.locator.read()
|
loc_info = self.locator.read()
|
||||||
if loc_info:
|
if loc_info:
|
||||||
|
log.debug('loc_method: %s' % loc_info[0])
|
||||||
device_data.update(loc_info[1])
|
device_data.update(loc_info[1])
|
||||||
|
|
||||||
current_settings = settings.settings.get()
|
current_settings = settings.settings.get()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user