New user here, I have used Arduinos and Python before, but am just starting in OpenMV with my new Portenta H7 and vision shield. I have taken some code from the examples and put them together into something that scans a QR code with WiFi details formatted like this: ssid-pass::IP to ping (I have not done anything with the IP yet but have a few ideas). I want it to connect to that WiFi network and then get data from the host “google.com” like in the examples. When I run the code, it scans the QR code correctly and gets the WiFi details right, but hangs when actually connecting. I get an “OSError: [Errno 110] ETIMEDOUT”… I am sure the WiFi details are correct and don’t know what the problem might be. Can anyone help me?
The code works the first time I try it then fails the rest of the time after changing nothing
OpenMV IDE 4.1.4-[latest]
Arduino Portenta H7 with ethernet vision shield
#WiFi getter and connector import sensor, image, time, pyb, network, socket redLED = pyb.LED(1) # built-in red LED greenLED = pyb.LED(2) # built-in green LED blueLED = pyb.LED(3) # built-in blue LED sensor.reset() sensor.set_pixformat(sensor.GRAYSCALE) sensor.set_framesize(sensor.QVGA) sensor.set_windowing((240, 240)) # look at center 240x240 pixels of the VGA resolution. sensor.skip_frames(time = 2000) sensor.set_auto_gain(False) # must turn this off to prevent image washout... clock = time.clock() #while(True): #clock.tick() img = sensor.snapshot() ssid = "" password = "" ip = "0.0.0.0" is_handled = False while is_handled == False: img = sensor.snapshot() for code in img.find_qrcodes(): if (code != None): img.draw_rectangle(code.rect(), color = 127) #print(code) # prints URL/payload print("Payload: " + code.payload()) # also prints URL/payload # Payload is formatted as ssid-pass::IP payload = str(code.payload()) #print(payload[0:12]) ssid_pos = payload.find("-") ssid = payload[0:ssid_pos] #print(ssid) pass_pos = ssid_pos + 1 #password = payload[pass_pos:] ip_pos = payload.find("::") + 2 ip = payload[ip_pos:] password = payload[pass_pos:ip_pos - 2] is_handled = True #print(password) # commented this out so I could see the debug output #print(clock.fps()) redLED.on() greenLED.on() blueLED.on() sensor.shutdown(True) time.sleep(1) print("SSID:--" + ssid + "--") print("Password:--" + password + "--") print("IP to ping:--" + ip + "--") time.sleep(5) redLED.off() greenLED.off() blueLED.off() PORT = 80 HOST = "www.google.com" #HOST = ip # Init wlan module and connect to network print("Trying to connect. Note this may take a while...") wlan = network.WLAN(network.STA_IF) wlan.deinit() wlan.active(True) wlan.connect(ssid, password, timeout=60000) # We should have a valid IP now via DHCP print("WiFi Connected ", wlan.ifconfig()) # Get addr info via DNS addr = socket.getaddrinfo(HOST, PORT) print(addr) # Create a new socket and connect to addr client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) client.connect(addr) # Set timeout client.settimeout(3.0) # Send HTTP request and recv response client.send("GET / HTTP/1.1\r\nHost: %s\r\n\r\n"%(HOST)) print(client.recv(1024)) # Close socket client.close()