def checkConnectivity(controller=None): """Check for Internet connectivity - if no Internet connectivity is available, wait for up to 30 seconds and then fail (this is used to handle cases where the device was offline and the Internet connection is just being established)""" status = modrana.dmod.connectivity_status if status is constants.CONNECTIVITY_UNKNOWN: # Connectivity status monitoring not supported return status # skip elif status is constants.ONLINE: return status # Internet connectivity is most probably available elif status is constants.OFFLINE: startTimestamp = time.time() elapsed = 0 if controller: controller.status = "waiting for Internet connectivity" while elapsed < constants.INTERNET_CONNECTIVITY_TIMEOUT: status = modrana.dmod.connectivity_status log.info('waiting for internet connectivity') log.info(status) if status == True or status is None: break # check if the thread was cancelled if controller and controller.callback is None: # the thread was cancelled log.info("connectivity status check cancelled") status = constants.CONNECTIVITY_UNKNOWN break time.sleep(1) elapsed = time.time() - startTimestamp if status is constants.OFFLINE: modrana.notify("requirements: failed to connect to the Internet") return status else: log.warning('warning, unknown connection status:') log.warning(status) return status
def checkConnectivity(controller=None): """Check for Internet connectivity - if no Internet connectivity is available, wait for up to 30 seconds and then fail (this is used to handle cases where the device was offline and the Internet connection is just being established)""" status = modrana.dmod.connectivityStatus if status is constants.CONNECTIVITY_UNKNOWN: # Connectivity status monitoring not supported return status # skip elif status is constants.ONLINE: return status # Internet connectivity is most probably available elif status is constants.OFFLINE: startTimestamp = time.time() elapsed = 0 if controller: controller.status = "waiting for Internet connectivity" while elapsed < constants.INTERNET_CONNECTIVITY_TIMEOUT: status = modrana.dmod.connectivityStatus log.info('waiting for internet connectivity') log.info(status) if status == True or status is None: break # check if the thread was cancelled if controller and controller.callback is None: # the thread was cancelled log.info("connectivity status check cancelled") status = constants.CONNECTIVITY_UNKNOWN break time.sleep(1) elapsed = time.time() - startTimestamp if status is constants.OFFLINE: modrana.notify("requirements: failed to connect to the Internet") return status else: log.warning('warning, unknown connection status:') log.warning(status) return status
def locateCurrentPosition(controller=None): """Try to locate current position and return it when done or time out""" result = None sleepTime = 0.5 # in seconds pos = modrana.get('pos', None) fix = modrana.get('fix', 1) # check if GPS usage is explicitly disabled in modRana gpsEnabled = modrana.get('GPSEnabled') if gpsEnabled == False: if pos: modrana.notify("GPS OFF, using last known position", 5000) return Point(*pos) else: modrana.notify("GPS OFF, no last known position", 5000) return None if fix > 1 and pos: return Point(*pos) # fix found, return it at once # check if GPS hardware has been enabled location = modrana.m.get("location") if not location.enabled: # location usage has not be disabled but location # has not been started, so start location location.start_location() # wait for the fix startTimestamp = time.time() elapsed = 0 if controller: controller.status = "GPS fix in progress" while elapsed < constants.LOCATION_TIMEOUT: pos = modrana.get('pos', None) fix = modrana.get('fix', 1) if fix > 1 and pos: break time.sleep(sleepTime) elapsed = time.time() - startTimestamp if fix > 1 and pos: # got GPS fix ? return Point(*pos) else: # no GPS lock pos = modrana.get("pos") if pos: modrana.notify("no fix, using last known position", 5000) return Point(*pos) else: modrana.notify("failed to get GPS fix", 5000) return None
def locateCurrentPosition(controller=None): """Try to locate current position and return it when done or time out""" result = None sleepTime = 0.5 # in seconds pos = modrana.get('pos', None) fix = modrana.get('fix', 1) # check if GPS usage is explicitly disabled in modRana gpsEnabled = modrana.get('GPSEnabled') if gpsEnabled == False: if pos: modrana.notify("GPS OFF, using last known position", 5000) return Point(*pos) else: modrana.notify("GPS OFF, no last known position", 5000) return None if fix > 1 and pos: return Point(*pos) # fix found, return it at once # check if GPS hardware has been enabled location = modrana.m.get("location") if not location.enabled: # location usage has not be disabled but location # has not been started, so start location location.startLocation() # wait for the fix startTimestamp = time.time() elapsed = 0 if controller: controller.status = "GPS fix in progress" while elapsed < constants.LOCATION_TIMEOUT: pos = modrana.get('pos', None) fix = modrana.get('fix', 1) if fix > 1 and pos: break time.sleep(sleepTime) elapsed = time.time() - startTimestamp if fix > 1 and pos: # got GPS fix ? return Point(*pos) else: # no GPS lock pos = modrana.get("pos") if pos: modrana.notify("no fix, using last known position", 5000) return Point(*pos) else: modrana.notify("failed to get GPS fix", 5000) return None