How to scan for OpenMV Wifi shield

I want to do OpenMV wifi shield scan to detect the presence of the shield. In the same way one can scan for I2C devices and can get the address of the I2C device that is connected to a board, I want to do same to be able to detect when the OpenMV wifi shield is connected to the board.
I will appreciate if anyone can help out with a working code.
Thank you

There’s no way to scan or detect it, it’s on SPI, you can try to initialize and it will fail if it’s not connected

import network
wlan = None
try:
    wlan = network.WINC()
except OSError:
    pass
    
if wlan:
    print("WiFi shield connected")
    print("\nFirmware version:", wlan.fw_version())
else:
    print("No WiFi")

Thank you for the response. I have tried to implement what you just did earlier and this line of code gave me a syntax error
wlan = network.WINC()

Is there a way to handle syntax error exceptions? I mean a way to bypass it and the code will still run

There’s no error in the code I sent above, syntax or otherwise, I tested it before posting.

You should not try to catch syntax errors you should fix them.

Thanks for the clarification. In my application because I need to initialize the wifi shield in AP mode, this is how I did the initialization which gave me a syntax error.

wlan = network.WINC(mode=network.WINC.MODE_AP)
wlan.start_ap(SSID, key=KEY, security=wlan.WEP, channel=2)

What did I not do right?
I will appreciate if you can help out.
Thanks.

There’s no error in this either, and the example code runs fine:

I meant when I initialize it in AP mode using the try statement, it gives a syntax error.
This is the code:

import time, network, usocket, sys

SSID ='OPENMV_AP'    # Network SSID
KEY  ='1234567890'    # Network key (must be 10 chars)
HOST = ''           # Use first available interface
PORT = 8080         # Arbitrary non-privileged port

wlan = None
try:
wlan = network.WINC(mode=network.WINC.MODE_AP)
wlan.start_ap(SSID, key=KEY, security=wlan.WEP, channel=2)
except OSError:
    pass

if wlan:
    print("WiFi shield connected")
    print("\nFirmware version:", wlan.fw_version())
else:
    print("No WiFi")

When I run this code, these lines of code gives a syntax error

wlan = network.WINC(mode=network.WINC.MODE_AP)
wlan.start_ap(SSID, key=KEY, security=wlan.WEP, channel=2)

Kindly help me check,
Thanks

You need to indent these two lines like this:

try:
    wlan = network.WINC(mode=network.WINC.MODE_AP)
    wlan.start_ap(SSID, key=KEY, security=wlan.WEP, channel=2)
except OSError:
    pass

In the future please make sure there’s an actual problem before posting, this isn’t the right place for basic questions like these.

Thanks