In this example, we look at how to establish and see if the Wi-Fi is connected to Quarky or not. The code will connect the Quarky to a specified Wi–Fi network and show a green status if the connection is successful, or a red status if the connection fails.
# imported modules from quarky import * import iot # Create a Wi-Fi object wifi = iot.wifi() # Change the Wi-Fi Name and Password wifi.connecttowifi("IoT", "12345678") # Run the loop to check if the Wi-Fi is connected while True: # Check if the Wi-Fi is connected if wifi.iswificonnected(): # Draw a pattern on the quarky quarky.drawpattern("ccccccccccccccccccccccccccccccccccc") else: # Draw a different pattern on the quarky quarky.drawpattern("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")
- This code is using the Quarky library to draw a pattern depending on the status of the Wi–Fi connection. If the Wi–Fi connection is successful, it will draw the green light on the Quarky LEDs. If the Wi-Fi connection is unsuccessful, it will draw a red light on the Quarky LEDs.
- Additionally, it imports the iot module and connects to a Wi-Fi network with the name specified name and the password.
- It also has a while loop that checks to see if the Wi-Fi is connected and will draw the appropriate pattern accordingly.
- If the Green Light is displayed, your Wi-Fi is connected.
- If the Red Light is displayed, your Wi-Fi is not connected. Change the Wi-Fi and the password and try again.
- If the Red Cross sign is displayed, a Python error has occurred in Quarky. Check the serial monitor and try to reset the Quarky.