def find_wifi_shield(self, shield_name=None, wifi_shield_cb=None): """Detects Ganglion board MAC address -- if more than 1 around, will select first. Needs root privilege.""" if self.log: print("Scanning nearby devices for %d seconds..." % self.timeout) list_ip = [] list_id = [] found_shield = False def wifi_shield_found(response): res = requests.get(response.location, verify=False).text # print("res:", res) device_description = xmltodict.parse(res) try: cur_shield_name = str( device_description['root']['device']['serialNumber']) cur_base_url = str(device_description['root']['URLBase']) cur_ip_address = re.findall(r'[0-9]+(?:\.[0-9]+){3}', cur_base_url)[0] list_id.append(cur_shield_name) list_ip.append(cur_ip_address) found_shield = True print("Found WiFi Shield %s with IP Address %s" % (cur_shield_name, cur_ip_address)) if shield_name is None: # print("Found WiFi Shield %s with IP Address %s" % (cur_shield_name, cur_ip_address)) if wifi_shield_cb is not None: # print("Proceeding with WiFi Shield %s" % (cur_shield_name)) wifi_shield_cb(cur_ip_address, cur_shield_name, device_description) else: if shield_name == cur_shield_name: if wifi_shield_cb is not None: # print("Proceeding with WiFi Shield %s" % (cur_shield_name)) wifi_shield_cb(cur_ip_address, cur_shield_name, device_description) except Exception as e: print("exception in discovery") pass ssdp_hits = ssdp.discover("urn:schemas-upnp-org:device:Basic:1", timeout=self.timeout, wifi_found_cb=wifi_shield_found, all_ip_addresses=self.local_ip_addresses ) # send multicast on all local interfaces # ssdp_hits = ssdp.discover("urn:schemas-upnp-org:device:Basic:1", timeout=self.timeout, wifi_found_cb=wifi_shield_found) nb_wifi_shields = len(list_id) if nb_wifi_shields < 1: # print("No WiFi Shields found ;(") raise OSError('Cannot find OpenBCI WiFi Shield with local name')
def find_wifi_shield(self, shield_name=None, wifi_shield_cb=None): """Detects Ganglion board MAC address -- if more than 1 around, will select first. Needs root privilege.""" if self.log: print("Try to find WiFi shields on your local wireless network") print("Scanning for %d seconds nearby devices..." % self.timeout) list_ip = [] list_id = [] found_shield = False def wifi_shield_found(response): res = urllib2.urlopen(response.location).read() device_description = xmltodict.parse(res) cur_shield_name = str( device_description['root']['device']['serialNumber']) cur_base_url = str(device_description['root']['URLBase']) cur_ip_address = re.findall(r'[0-9]+(?:\.[0-9]+){3}', cur_base_url)[0] list_id.append(cur_shield_name) list_ip.append(cur_ip_address) found_shield = True if shield_name is None: print("Found WiFi Shield %s with IP Address %s" % (cur_shield_name, cur_ip_address)) if wifi_shield_cb is not None: wifi_shield_cb(cur_ip_address) else: if shield_name == cur_shield_name: if wifi_shield_cb is not None: wifi_shield_cb(cur_ip_address) ssdp_hits = ssdp.discover("urn:schemas-upnp-org:device:Basic:1", timeout=self.timeout, wifi_found_cb=wifi_shield_found) nb_wifi_shields = len(list_id) if nb_wifi_shields < 1: print("No WiFi Shields found ;(") raise OSError('Cannot find OpenBCI WiFi Shield with local name') if nb_wifi_shields > 1: print("Found " + str(nb_wifi_shields) + ", selecting first named: " + list_id[0] + " with IPV4: " + list_ip[0]) return list_ip[0]
def find_wifi_shield(self, shield_name=None, wifi_shield_cb=None): """Detects Ganglion board MAC address if more than 1, will select first. Needs root.""" if self.log: print("Try to find WiFi shields on your local wireless network") print("Scanning for %d seconds nearby devices..." % self.timeout) list_ip = [] list_id = [] found_shield = False def wifi_shield_found(response): res = requests.get(response.location, verify=False).text device_description = xmltodict.parse(res) cur_shield_name = str( device_description['root']['device']['serialNumber']) cur_base_url = str(device_description['root']['URLBase']) cur_ip_address = re.findall(r'[0-9]+(?:\.[0-9]+){3}', cur_base_url)[0] list_id.append(cur_shield_name) list_ip.append(cur_ip_address) found_shield = True if shield_name is None: print("Found WiFi Shield %s with IP Address %s" % (cur_shield_name, cur_ip_address)) if wifi_shield_cb is not None: wifi_shield_cb(cur_ip_address) else: if shield_name == cur_shield_name: if wifi_shield_cb is not None: wifi_shield_cb(cur_ip_address) ssdp_hits = ssdp.discover("urn:schemas-upnp-org:device:Basic:1", timeout=self.timeout, wifi_found_cb=wifi_shield_found) nb_wifi_shields = len(list_id) if nb_wifi_shields < 1: print("No WiFi Shields found ;(") raise OSError('Cannot find OpenBCI WiFi Shield with local name') if nb_wifi_shields > 1: print( "Found " + str(nb_wifi_shields) + ", selecting first named: " + list_id[0] + " with IPV4: " + list_ip[0]) return list_ip[0]