mirror of
https://gitee.com/qpy-solutions/tracker-v2.git
synced 2025-05-19 02:58:25 +08:00
update: net status check
This commit is contained in:
parent
90a79fd0dc
commit
a4f1a28073
@ -92,6 +92,7 @@ class GPS(Singleton):
|
||||
break
|
||||
|
||||
self.break_flag = 0
|
||||
log.debug('utc_time: %s' % self.read_location_utc(data))
|
||||
return data
|
||||
|
||||
def quecgnss_read(self):
|
||||
@ -145,6 +146,14 @@ class GPS(Singleton):
|
||||
return speed_re.group(0)[3:-3]
|
||||
return ""
|
||||
|
||||
def read_location_utc(self, gps_data):
|
||||
gga_data = self.read_location_GxGGA(gps_data)
|
||||
if gga_data:
|
||||
utc_re = ure.search(r"GGA,[0-9]+\.[0-9]+,", gga_data)
|
||||
if utc_re:
|
||||
return utc_re.group(0)[4:-1]
|
||||
return ""
|
||||
|
||||
def read_quecIot(self):
|
||||
data = []
|
||||
gps_data = self.read()
|
||||
|
@ -161,6 +161,8 @@ def uplink_process(argv):
|
||||
# Read history data that didn't send to server intime to hist-dictionary.
|
||||
hist = self.read_history()
|
||||
try:
|
||||
if self.tracker.net_enable is False:
|
||||
raise RemoteError('Net Is Disconnected.')
|
||||
for key, value in hist.items():
|
||||
# Check if non_loca data (sensor or device info data) or location gps data or location non-gps data (cell/wifi-locator data)
|
||||
if key == 'hist_data':
|
||||
@ -193,27 +195,16 @@ def uplink_process(argv):
|
||||
# Flush data in hist-dictionary to tracker_data.hist file.
|
||||
self.refresh_history(hist)
|
||||
|
||||
'''
|
||||
If history data exists, put a empty msg to uplink_queue to trriger the return of self.uplink_queue.get() API below.
|
||||
So that history data could be processed again immediately.
|
||||
Without this, history data could only be processed after new data being put into uplink_queue.
|
||||
But is this necessary ???
|
||||
'''
|
||||
# TODO: dataCall nw_callback to put
|
||||
if len(hist.get('hist_data', [])):
|
||||
self.uplink_queue.put(())
|
||||
|
||||
# When comes to this, wait for new data coming into uplink_queue.
|
||||
data = self.uplink_queue.get()
|
||||
if data:
|
||||
if data[1]:
|
||||
if not self.cloud.post_data(data[1]):
|
||||
if self.tracker.net_enable is True:
|
||||
if self.cloud.post_data(data[1]):
|
||||
sys_bus.publish(data[0], 'true')
|
||||
continue
|
||||
self.add_history(data[1])
|
||||
sys_bus.publish(data[0], 'false')
|
||||
else:
|
||||
sys_bus.publish(data[0], 'true')
|
||||
else:
|
||||
sys_bus.publish(data[0], 'true')
|
||||
|
||||
|
||||
class Remote(Singleton):
|
||||
|
@ -122,7 +122,7 @@ class default_values_app(object):
|
||||
|
||||
work_mode = _work_mode.cycle
|
||||
|
||||
work_cycle_period = 60
|
||||
work_cycle_period = 30
|
||||
|
||||
low_power_alert_threshold = 20
|
||||
|
||||
@ -192,7 +192,7 @@ class default_values_sys(object):
|
||||
|
||||
ota_status = _ota_status.none
|
||||
|
||||
cloud = _cloud.quecIot
|
||||
cloud = _cloud.AliYun
|
||||
|
||||
cloud_init_params = {}
|
||||
|
||||
|
@ -50,6 +50,8 @@ class Tracker(Singleton):
|
||||
self.num_iter = numiter()
|
||||
self.num_lock = _thread.allocate_lock()
|
||||
|
||||
self.net_enable = True
|
||||
|
||||
if PowerKey is not None:
|
||||
self.power_key = PowerKey()
|
||||
self.power_key.powerKeyEventRegister(self.pwk_callback)
|
||||
@ -105,10 +107,12 @@ class Tracker(Singleton):
|
||||
sensor_check_res = self.check.sensor_check()
|
||||
|
||||
if net_check_res == (3, 1) and gps_check_res and sensor_check_res:
|
||||
self.net_enable = True
|
||||
self.running_led.period = 2
|
||||
else:
|
||||
self.running_led.period = 0.5
|
||||
if net_check_res != (3, 1):
|
||||
self.net_enable = False
|
||||
fault_code = 20001
|
||||
alert_info = {'fault_code': fault_code, 'local_time': utime.mktime(utime.localtime())}
|
||||
alert_data_res = self.get_alert_data(alert_code, alert_info)
|
||||
@ -215,15 +219,15 @@ class Tracker(Singleton):
|
||||
def nw_callback(self, args):
|
||||
net_check_res = self.check.net_check()
|
||||
if args[1] != 1:
|
||||
# TODO: Check Internet disconected then do something
|
||||
if net_check_res[0] == 0 or (net_check_res[0] == 1 and net_check_res[1] == 0):
|
||||
self.net_enable = False
|
||||
if net_check_res == (1, 0):
|
||||
alert_code = 30004
|
||||
alert_info = {'local_time': utime.mktime(utime.localtime())}
|
||||
alert_data = self.get_alert_data(alert_code, alert_info)
|
||||
self.device_data_report(event_data=alert_data)
|
||||
else:
|
||||
# TODO: Check Internet conected then do something
|
||||
pass
|
||||
if net_check_res == (3, 1):
|
||||
self.net_enable = True
|
||||
|
||||
|
||||
class SelfCheck(object):
|
||||
|
Loading…
x
Reference in New Issue
Block a user