remove hotspot exceptions in uploader (#2319)

* remove hotspot exceptions

* skip net check while onroad
old-commit-hash: ee37d03c1f
commatwo_master
Adeeb Shihadeh 5 years ago committed by GitHub
parent b1a9214f8f
commit de4c543e63
  1. 28
      selfdrive/loggerd/uploader.py

@ -4,14 +4,11 @@ import inspect
import json import json
import os import os
import random import random
import re import requests
import subprocess
import threading import threading
import time import time
import traceback import traceback
import requests
from cereal import log from cereal import log
from common.hardware import HARDWARE from common.hardware import HARDWARE
from common.api import Api from common.api import Api
@ -74,16 +71,6 @@ def clear_locks(root):
def is_on_wifi(): def is_on_wifi():
return HARDWARE.get_network_type() == NetworkType.wifi return HARDWARE.get_network_type() == NetworkType.wifi
def is_on_hotspot():
try:
result = subprocess.check_output(["ifconfig", "wlan0"], stderr=subprocess.STDOUT, encoding='utf8')
result = re.findall(r"inet addr:((\d+\.){3}\d+)", result)[0][0]
return (result.startswith('192.168.43.') or # android
result.startswith('172.20.10.') or # ios
result.startswith('10.0.2.')) # toyota entune
except Exception:
return False
class Uploader(): class Uploader():
def __init__(self, dongle_id, root): def __init__(self, dongle_id, root):
self.dongle_id = dongle_id self.dongle_id = dongle_id
@ -238,25 +225,22 @@ def uploader_fn(exit_event):
backoff = 0.1 backoff = 0.1
counter = 0 counter = 0
should_upload = False on_wifi = False
while not exit_event.is_set(): while not exit_event.is_set():
offroad = params.get("IsOffroad") == b'1' offroad = params.get("IsOffroad") == b'1'
allow_raw_upload = (params.get("IsUploadRawEnabled") != b"0") and offroad allow_raw_upload = (params.get("IsUploadRawEnabled") != b"0") and offroad
check_network = (counter % 12 == 0 if offroad else True) if offroad and counter % 12 == 0:
if check_network:
on_hotspot = is_on_hotspot()
on_wifi = is_on_wifi() on_wifi = is_on_wifi()
should_upload = on_wifi and not on_hotspot
d = uploader.next_file_to_upload(with_raw=allow_raw_upload and should_upload)
counter += 1 counter += 1
d = uploader.next_file_to_upload(with_raw=allow_raw_upload and on_wifi and offroad)
if d is None: # Nothing to upload if d is None: # Nothing to upload
time.sleep(60 if offroad else 5) time.sleep(60 if offroad else 5)
continue continue
key, fn = d key, fn = d
cloudlog.event("uploader_netcheck", is_on_hotspot=on_hotspot, is_on_wifi=on_wifi) cloudlog.event("uploader_netcheck", is_on_wifi=on_wifi)
cloudlog.info("to upload %r", d) cloudlog.info("to upload %r", d)
success = uploader.upload(key, fn) success = uploader.upload(key, fn)
if success: if success:

Loading…
Cancel
Save