# # Petcard Bootloader - v1.0 # Copyright (c) 2025 FreedTapestry21 # from machine import Pin import network, urequest, machine # Define variables CONSOLE_WELCOME = """ Petcard Bootloader - v1.0 Copyright (c) 2025 FreedTapestry21 Licensed under the MIT license """ UPDATE = False MIRROR = "https://mirror.pixelated.sh/dev/petcard" # Initialize OK button (with pull down resistor) ok = Pin(0, Pin.IN, Pin.PULL_DOWN) # Define functions def download(file, name): print("Downloading " + name + "...") f = open(file) r = urequests.get(MIRROR + "/" + file) f.write(r.text) f.close() r.close print("Downloaded " + name + "!") def connect(ssid, psk): nic = network.WLAN(network.WLAN.IF_STA) nic.active(True) nic.connect(ssid, psk) while not sta_if.isconnected(): pass def boot(): import system init() # Check if button is pressed for recovery/update process if __name__ == '__main__': print(CONSOLE_WELCOME) if ok.value() == 1: UPDATE = True if UPDATE == True: print("Petcard bootloader has been interupted by the OK button") inp = input("Are you sure you want to enter the Petcard recovery process? (y/N)") if inp == "" or inp == "n" or inp == "N": print("Rebooting to resume boot process...") if inp == "y" or inp == "Y": print("Entering Petcard recovery process...") print("Please enter your Wi-Fi credentials") ssid = input("SSID: ") psk = input("Password: ") connect(ssid, psk) print('Connected to network "' + str(ssid) + '"') # Downloading system.py download("system.py", "Petcard system") download("petcard.py", "Petcard") print("System recovery complete, restarting system...") machine.reset() else: print("'" + inp + "' is not recognized as an option! Rebooting...") machine.reset() else: boot()