#Version-4 import machine import network import urequests import os import time import gc # ----------------------- # WIFI # ----------------------- SSID = "YOUR_WIFI" PASSWORD = "YOUR_PASSWORD" wlan = network.WLAN(network.STA_IF) wlan.active(True) if not wlan.isconnected(): print("Connecting to WiFi...") wlan.connect(SSID, PASSWORD) timeout = 20 while timeout > 0 and not wlan.isconnected(): time.sleep(1) print(".", end="") timeout -= 1 print("\nConnected:", wlan.isconnected()) print("IP:", wlan.ifconfig()[0]) # ----------------------- # CONFIG # ----------------------- BASE_URL = "https://git.ultiware.co.za/Raymond_Bailie/TANK-GIT/raw/branch/master/" FILES = [ "update.py", # "calibrate.py", "main.py", # "wifi.py", # "sensors.py", # "display.py", # "webserver.py", # "reboot.py", # "scan-i2c.py", # "timeutil.py", # "config.py", # "html/index.html", # "html/app.js", # "html/favicon.ico", # "lib/hx710b.py", # "lib/ssd1306.py", ] # ----------------------- # HELPERS # ----------------------- def make_dirs(filepath): parts = filepath.split("/")[:-1] current = "" for part in parts: current = current + "/" + part if current else part try: os.mkdir(current) except OSError: pass # ----------------------- # DOWNLOAD # ----------------------- for filename in FILES: try: url = BASE_URL + filename print("\nDownloading:") print(url) make_dirs(filename) r = urequests.get(url) print("HTTP:", r.status_code) if r.status_code == 200: with open(filename, "wb") as f: f.write(r.content) print("Saved:", filename) else: print("Failed:", filename) r.close() del r gc.collect() except Exception as e: print("Error:", e) print("\nDownload complete") print("Rebooting in 3 seconds...") time.sleep(3) machine.reset() # import urequests # # BASE_URL = "https://git.ultiware.co.za/Raymond_Bailie/WaterTank/raw/branch/master/" # # files = [ # "calibrate.py", # "main.py", # "wifi.py", # "sensors.py", # "display.py", # "webserver.py", # "reboot.py", # "scan-i2c.py", # "timeutil.py", # "config.py", # "html/index.html", # "html/app.js", # "html/favicon.ico", # "lib/hx710b.py", # "lib/ssd1306.py", # ] # # for filename in files: # try: # #print("Downloading", filename) # print(BASE_URL + filename) # # r = urequests.get(BASE_URL + filename) # # if r.status_code == 200: # with open(filename, "wb") as f: # f.write(r.content) # print(" OK") # else: # print(" Failed:", r.status_code) # # r.close() # # except Exception as e: # print(" Error:", e) # # print("Done")