import network import requests import utime import ujson import ntptime from machine import I2C,Pin from pico_i2c_lcd import I2cLcd #----------------------------------------------------- #----------------------Load json---------------------- #----------------------------------------------------- with open("config.json") as f: config = ujson.load(f) ssidlist = config["ssidlist"] passlist = config["passlist"] webhookurl = config["webhookurl"] #----------------------------------------------------- #-----------------------Prepare----------------------- #----------------------------------------------------- i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000) I2C_ADDR = 39 lcd = I2cLcd(i2c, I2C_ADDR, 2, 16) lcd.backlight_off() buttongreen = Pin(15, Pin.IN, Pin.PULL_UP) buttonyellow = Pin(13, Pin.IN, Pin.PULL_UP) buttonred = Pin(12, Pin.IN, Pin.PULL_UP) buttonblue = Pin(11, Pin.IN, Pin.PULL_UP) infoled = Pin(14,Pin.OUT) backlighton = True version = "1.5.12" #----------------------------------------------------- #--------------------Define things-------------------- #----------------------------------------------------- #check is todays date dst def is_dst(): t = utime.localtime() month = t[1] day = t[2] hour = t[3] # DST starts on the second Sunday of March if month < 3 or month > 10: return 3600 elif month == 3: if day < 8: return 3600 elif day >= 8 and hour < 2: return 3600 else: return 0 elif month == 10: if day < 1: return 0 elif day >= 1 and hour < 2: return 0 else: return 3600 else: return 0 #make the thing go into standby mode def standby(): lcd.blink_cursor_off() lcd.clear() t = utime.localtime(utime.time()+3600+3600) lcd.move_to(0,0) lcd.putstr("Time: {:02d}:{:02d}:{:02d}".format(t[3], t[4], t[5])) lcd.backlight_off() #read content using a get request def getcontentget(getip): if backlighton == True: lcd.backlight_on() lcd.clear() lcd.blink_cursor_on() lcd.putstr("Sending request!\n Please wait!") try: response = requests.get(getip) response_code = response.status_code response_content = response.content lcd.blink_cursor_off() print('Response code: ', response_code) print('Response content:', response_content) utime.sleep(0.2) if response_code == 200: infoled.value(True) utime.sleep(0.2) infoled.value(False) utime.sleep(0.2) tmptextnum=0 lcd.clear() while True: bettertext = str(response_content)[1:len(str(response_content))-1] tmp = bettertext[1+tmptextnum:16+tmptextnum] lcd.move_to(0,0) lcd.putstr(tmp+" "*(16-len(tmp))) lcd.putstr("\n"+str(tmptextnum)+"/"+str(len(bettertext))) utime.sleep(0.1) if buttonblue.value() == 0: lcd.clear() lcd.putstr(" End display?\n Hold if yes!") utime.sleep(0.5) lcd.clear() if buttonblue.value() == 0: lcd.clear() break elif buttonred.value() == 0: lcd.clear() if tmptextnum > 4 : tmptextnum-=5 elif buttongreen.value() == 0: lcd.clear() if tmptextnum < len(bettertext) : tmptextnum+=5 else: utime.sleep(0.2) lcd.clear() while buttonblue.value() == 0: lcd.move_to(0,0) lcd.putstr("Stop pressing!") utime.sleep(0.1) lcd.clear() whattoreturn = 0 else: lcd.clear() lcd.putstr(str(response_code)+" "+str(response_content)) infoled.value(True) utime.sleep(3) infoled.value(False) except: lcd.clear() lcd.putstr("ERROR") print("ERROR") utime.sleep(2) whattoreturn = 1 return whattoreturn #send a webhook message def webhookbutton(jsontosend): lcd.clear() if backlighton == True: lcd.backlight_on() lcd.blink_cursor_on() lcd.putstr("Sending request!\n Please wait!") try: response = requests.post(webhookurl,json=jsontosend) response_code = response.status_code response_content = response.content print('Response code: ', response_code) print('Response content:', response_content) lcd.blink_cursor_off() lcd.clear() if response_code == 204 : lcd.putstr("Succesfully sent") infoled.value(True) utime.sleep(1) infoled.value(False) else: lcd.putstr("Failed send code:"+str(response_code)+"\n"+str(response_content)) infoled.value(True) utime.sleep(3) infoled.value(False) utime.sleep(2) except: infoled.value(True) lcd.blink_cursor_off() lcd.putstr("Failed to send!") utime.sleep(2) infoled.value(False) lcd.clear() #clock menu def clockmenu(): while buttonred.value() == 0: lcd.putstr("Stop pressing!") utime.sleep(0.5) lcd.clear() lcd.clear() while True: if backlighton == True: lcd.backlight_on() lcd.move_to(0,0) lcd.putstr("Red - high acc Green - low acc") #High accuracy clock if buttonred.value() == 0: lcd.clear() if backlighton == True: lcd.backlight_on() lcd.putstr("Syncing!") #try to sync and start the clock try: ntptime.settime() lefttosync = 10 while True: lefttosync -= 1 t = utime.localtime(utime.time()+3600+3600) lcd.move_to(0,0) lcd.putstr("Time: {:02d}:{:02d}:{:02d}".format(t[3], t[4], t[5])) lcd.putstr(" \nLps till sync:"+str(lefttosync)) utime.sleep(0.5) if buttonyellow.value() == 0: break if lefttosync < 1: lefttosync = 10 try: ntptime.settime() except: lcd.putstr("Sync fail") utime.sleep(1) lcd.clear() if buttonblue.value() == 0: try: ntptime.settime() except: lcd.putstr("Sync fail") utime.sleep(1) lcd.clear() except: lcd.clear() lcd.putstr("Syncing failed!") utime.sleep(2) while buttonyellow.value() == 0: lcd.putstr("Stop pressing!") utime.sleep(0.5) lcd.clear() utime.sleep(0.1) lcd.clear() utime.sleep(0.1) #Low accuracy clock if buttongreen.value() == 0: lcd.clear() if backlighton == True: lcd.backlight_on() lcd.putstr("Syncing!") #try to sync and start the clock try: ntptime.settime() while True: t = utime.localtime(utime.time()+3600+3600) lcd.move_to(0,0) lcd.putstr("Time: {:02d}:{:02d}:{:02d}".format(t[3], t[4], t[5])) lcd.move_to(0,1) lcd.putstr("Blue resync`s") utime.sleep(0.5) if buttonblue.value() == 0: try: ntptime.settime() except: lcd.putstr("Sync fail") utime.sleep(1) lcd.clear() if buttonyellow.value() == 0: break except: lcd.clear() lcd.putstr("Syncing failed!") utime.sleep(2) while buttonyellow.value() == 0: lcd.putstr("Stop pressing!") utime.sleep(0.1) lcd.clear() lcd.clear() #Break if buttonyellow.value() == 0: break while buttonyellow.value() == 0: lcd.putstr("Stop pressing!") utime.sleep(0.5) lcd.clear() lcd.clear() #system menu def systemmenu(): if backlighton == True: lcd.backlight_on() option = 1 lcd.clear() while buttonyellow.value() == 0: lcd.putstr("Stop pressing!") utime.sleep(1) lcd.clear() while True: optiondisplayname = systemmenucontent[option-1][0] optioncommand = systemmenucontent[option-1][1] lcd.move_to(0,0) lcd.putstr(optiondisplayname) lcd.move_to(0,1) lcd.putstr(str(option)+"/"+str(len(systemmenucontent))) utime.sleep(0.2) if buttonblue.value() == 0: lcd.clear() lcd.putstr(" Ru sure? \nHold if yes!") utime.sleep(1) lcd.clear() if buttonblue.value() == 0: optioncommand() if buttonred.value() == 0: lcd.clear() if option > 1 : option-=1 else: option = len(systemmenucontent) if buttongreen.value() == 0: lcd.clear() if option < len(systemmenucontent) : option+=1 else: option = 1 if buttonyellow.value() == 0: lcd.clear() lcd.putstr(" Quiting! \n") utime.sleep(1) lcd.clear() break while buttonyellow.value() == 0: lcd.putstr("Stop pressing!") utime.sleep(0.5) lcd.clear() #Exit the loop def exitloop(): lcd.clear() lcd.putstr("Ru sure? Hold if you do!") utime.sleep(2) if buttongreen.value == 0: lcd.clear() global Running Running = False lcd.putstr("Exit the menus!") utime.sleep(2) lcd.clear() #Update System Remotly (manual check) def updatesystem(): global Running utime.sleep(0.5) lcd.clear() lcd.putstr("Update in progress...") try: updatecontent=requests.get("http://192.168.0.17:7878/updates/").content utime.sleep(1) lcd.clear() lcd.putstr("Update complete!Trying update!") utime.sleep(2) try: file = open("update.py","w") file.write(updatecontent) file.close() exec(updatecontent) file = open("main.py","w") file.write(updatecontent) file.close() except: lcd.clear() lcd.putstr("Failsafe activated!") utime.sleep(2) except: lcd.clear() lcd.putstr("Using playit.gg!") try: updatecontent=requests.get("http://147.185.221.22:42661/updates/").content utime.sleep(1) lcd.clear() lcd.putstr("Update complete!Trying update!") utime.sleep(2) try: file = open("update.py","w") file.write(updatecontent) file.close() exec(updatecontent) file = open("main.py","w") file.write(updatecontent) file.close() except: lcd.clear() lcd.putstr("Failsafe activated!") utime.sleep(2) except: lcd.clear() lcd.putstr("Failed to update!") utime.sleep(2) lcd.clear() if backlighton == True: lcd.backlight_on() Running = True #update system (automatically) def autoupdatesystem(): global Running utime.sleep(0.5) lcd.clear() lcd.putstr("Update in progress...") try: updatecontent=requests.get("http://192.168.0.17:7878/updates/").content utime.sleep(1) lcd.clear() lcd.putstr("Update complete!Trying update!") utime.sleep(2) try: file = open("update.py","w") file.write(updatecontent) file.close() file = open("updatelock.txt","w") file.write("on") file.close() exec(updatecontent) file = open("updatelock.txt","w") file.write("off") file.close() file = open("main.py","w") file.write(updatecontent) file.close() except: lcd.clear() lcd.putstr("Failsafe activated!") utime.sleep(2) except: lcd.clear() lcd.putstr("Using playit.gg!") try: updatecontent=requests.get("http://147.185.221.22:42661/updates/").content utime.sleep(1) lcd.clear() lcd.putstr("Update complete!Trying update!") utime.sleep(2) try: file = open("update.py","w") file.write(updatecontent) file.close() file = open("updatelock.txt","w") file.write("on") file.close() exec(updatecontent) file = open("main.py","w") file.write(updatecontent) file.close() file = open("updatelock.txt","w") file.write("off") file.close() except: lcd.clear() lcd.putstr("Failsafe activated!") utime.sleep(2) except: lcd.clear() lcd.putstr("Failed to update!") utime.sleep(2) lcd.clear() if backlighton == True: lcd.backlight_on() Running = True #shows current default network def defaultnetwork(): lastnetwork = open("lastwifinetid.txt") lcd.clear() lcd.putstr("SSID:"+ssidlist[int(lastnetwork.read().split("\n")[0])]) utime.sleep(3) lcd.clear() lastnetwork.close() #uses the internet to run the code def netboot(): utime.sleep(0.5) lcd.clear() lcd.putstr("Downloading in progress...") try: netbootcontent=requests.get("http://192.168.0.17:7878/netboot/").content utime.sleep(1) lcd.clear() lcd.putstr("Download finish! Trying to run!") utime.sleep(2) try: exec(netbootcontent) except: lcd.clear() lcd.putstr("Failsafe activated!") utime.sleep(2) except: lcd.clear() lcd.putstr("Using playit.gg!") try: netbootcontent=requests.get("http://147.185.221.22:42661/netboot/").content utime.sleep(1) lcd.clear() lcd.putstr("Download finish! Trying to run!") utime.sleep(2) try: exec(netbootcontent) except: lcd.clear() lcd.putstr("Failsafe activated!") utime.sleep(2) except: lcd.clear() lcd.putstr("Failed to download!") utime.sleep(2) lcd.clear() if backlighton == True: lcd.backlight_on() #change is backlight on def backlighttoggle(): global backlighton if backlighton == True: backlighton = False lcd.backlight_off() else: backlighton = True lcd.backlight_on() #shows current default network def versiondisplay(): lcd.clear() lcd.move_to(0,0) lcd.putstr("MicroPy v1.22.2") lcd.move_to(0,1) lcd.putstr("RP2040 Welcome(:") utime.sleep(3) lcd.clear() #menu for chooseing what to send def sendmenu(): lcd.clear() if backlighton == True: lcd.backlight_on() option = 1 lcd.clear() while buttonyellow.value() == 0: lcd.putstr("Stop pressing!") utime.sleep(0.1) lcd.clear() while True: optiondisplayname = sendmenucontent[option-1][0] optioncommand = sendmenucontent[option-1][1] lcd.move_to(0,0) lcd.putstr(optiondisplayname) lcd.move_to(0,1) lcd.putstr(str(option)+"/"+str(len(sendmenucontent))) utime.sleep(0.2) if buttonblue.value() == 0: optioncommand() if buttonred.value() == 0: lcd.clear() if option > 1 : option-=1 else: option = len(sendmenucontent) if buttongreen.value() == 0: lcd.clear() if option < len(sendmenucontent) : option+=1 else: option = 1 if buttonyellow.value() == 0: lcd.clear() lcd.putstr(" Quiting! \n") utime.sleep(1) lcd.clear() break while buttonyellow.value() == 0: lcd.putstr("Stop pressing!") utime.sleep(0.5) lcd.clear() #sends some letters def sendletters(): lcd.clear() if backlighton == True: lcd.backlight_on() option = 1 lcd.clear() utime.sleep(1) while buttonyellow.value() == 0: lcd.putstr("Stop pressing!") utime.sleep(1) lcd.clear() letters = "" while True: optiondisplayname = sendlettercontent[option-1] letterset = sendlettercontent[option-1] lcd.move_to(0,0) lcd.putstr(optiondisplayname) lcd.move_to(0,1) lcd.putstr(str(option)+"/"+str(len(sendlettercontent))+" "+letters[len(letters)-10:len(letters)]) if buttonblue.value() == 0: try: letters += chooseletter(letterset,letters) lcd.clear() except: lcd.clear() elif buttonred.value() == 0: lcd.clear() if option > 1 : option-=1 else: option = len(sendlettercontent) elif buttongreen.value() == 0: lcd.clear() if option < len(sendlettercontent) : option+=1 else: option = 1 elif buttonyellow.value() == 0: lcd.clear() lcd.putstr(" Quiting! \n") utime.sleep(1) lcd.clear() break else: utime.sleep(0.2) if letters != "": jsoncontenttosend = { "content":letters, "username":"CUSTOM button" } webhookbutton(jsoncontenttosend) while buttonyellow.value() == 0: lcd.putstr("Stop pressing!") utime.sleep(0.5) lcd.clear() #chose a letter from a letterset def chooseletter(letterset,display): lcd.clear() if backlighton == True: lcd.backlight_on() option = 1 lcd.clear() while buttonblue.value() == 0: lcd.move_to(0,0) lcd.putstr("Stop pressing!") lcd.clear() while True: optiondisplayname = letterset[option-1] lettertoreturn = letterset[option-1] lcd.move_to(0,0) lcd.putstr(optiondisplayname) lcd.move_to(0,1) lcd.putstr(str(option)+"/"+str(len(letterset))+" "+display[len(display)-10:len(display)]) utime.sleep(0.2) if buttonblue.value() == 0: return lettertoreturn if buttonred.value() == 0: lcd.clear() if option > 1 : option-=1 else: option = len(letterset) if buttongreen.value() == 0: lcd.clear() if option < len(letterset) : option+=1 else: option = 1 if buttonyellow.value() == 0: break while buttonyellow.value() == 0: lcd.putstr("Stop pressing!") utime.sleep(0.5) lcd.clear() #yellowbuttonmenu def sendpredefinedmessages(): option=1 while True: optiondisplayname = content[option-1][0] optionjson = content[option-1][1] lcd.move_to(0,0) lcd.putstr(optiondisplayname) lcd.move_to(0,1) lcd.putstr(str(option)+"/"+str(len(content))) utime.sleep(0.2) if buttonblue.value() == 0: lcd.clear() lcd.putstr(" Send? \nHold if yes!") utime.sleep(0.2) lcd.clear() if buttonblue.value() == 0: webhookbutton(optionjson) if buttonred.value() == 0: lcd.clear() if option > 1 : option-=1 else: option = len(content) if buttongreen.value() == 0: lcd.clear() if option < len(content) : option+=1 else: option = 1 if buttonyellow.value() == 0: lcd.clear() lcd.putstr(" Quiting! \n") utime.sleep(1) lcd.clear() break #change default ip`s def changedefaultip(): filemainip = open("mainip.txt") filesecondaryip = open("secondaryip.txt") mainipadress = filemainip.read().split("\n")[0] secondaryipadress = filesecondaryip.read().split("\n")[0] lcd.clear() lcd.putstr("New:"+secondaryipadress) utime.sleep(3) lcd.clear() filemainip.close() filesecondaryip.close() filemainip = open("mainip.txt","w") filesecondaryip = open("secondaryip.txt","w") filemainip.write(secondaryipadress) filesecondaryip.write(mainipadress) filemainip.close() filesecondaryip.close() #----------------------------------------------------- #---------------Network connection-------------------- #----------------------------------------------------- #prepare currentnetnum = 0 lastnetwork = open("lastwifinetid.txt") currentnetnum = int(lastnetwork.read().split("\n")[0]) lastnetwork.close() wlan = network.WLAN(network.STA_IF) wlan.active(True) attempts = 0 #get the 1st password currentssid = ssidlist[currentnetnum] currentpassword = passlist[currentnetnum] wlan.connect(currentssid, currentpassword) #checking for fails to connect and trying to connect to 2nd network while wlan.isconnected() == False: print('Waiting for connection...'+ str(currentssid)) lcd.putstr("connecting try:"+str(attempts)+"\nssid:"+str(currentssid)) #skip connection if blue button is held if buttonblue.value() == 0: #reset the counters and get the newest passwords if currentnetnum+1 == len(ssidlist): lcd.putstr("Failed to connect!") if backlighton == True: lcd.backlight_on() utime.sleep(2) lcd.backlight_off() lcd.clear() currentnetnum = -1 attempts = 0 currentnetnum += 1 currentssid = ssidlist[currentnetnum] currentpassword = passlist[currentnetnum] lcd.clear() lcd.putstr("Connection skip!\nTrying "+str(currentssid)) if backlighton == True: lcd.backlight_on() utime.sleep(2) lcd.backlight_off() lcd.clear() #check is the button held so you dont accidently skip while buttonblue.value() == 0: lcd.putstr("Stop pressing!") utime.sleep(0.5) lcd.clear() #finally connect to wifi wlan.connect(currentssid, currentpassword) utime.sleep(1) lcd.clear() attempts += 1 if attempts > 9: if currentnetnum+1 == len(ssidlist): lcd.putstr("Failed to connect!") if backlighton == True: lcd.backlight_on() utime.sleep(2) lcd.backlight_off() lcd.clear() currentnetnum = -1 attempts = 0 currentnetnum += 1 currentssid = ssidlist[currentnetnum] currentpassword = passlist[currentnetnum] lcd.clear() lcd.putstr("Connection fail!\nTrying "+str(currentssid)) if backlighton == True: lcd.backlight_on() utime.sleep(2) lcd.backlight_off() lcd.clear() wlan.connect(currentssid, currentpassword) lastnetwork = open("lastwifinetid.txt","w") lastnetwork.write(str(currentnetnum)) lastnetwork.close() #----------------------------------------------------- #-------------------Clock Sync------------------------ #----------------------------------------------------- lcd.clear() lcd.putstr("Syncing clock!") try: ntptime.settime() lcd.clear() lcd.putstr("Synced successfully!") except: if backlighton == True: lcd.backlight_on() lcd.clear() lcd.putstr("Clock sync fail!\nTrying again!") try: utime.sleep(10) # adjust the delta to your timezone ntptime.settime() lcd.putstr("Synced successfully!") except: if backlighton == True: lcd.backlight_on() lcd.clear() lcd.putstr("Failed to sync clock!") utime.sleep(2) lcd.backlight_off() lcd.clear() #----------------------------------------------------- #-------------------Json Defines---------------------- #----------------------------------------------------- jsoncontentgreen = {"username":"QUICK button","content":"Im alive triggred!"} content = [ [ "Im alive!", {"username":"ALIVE button","content":"Im alive triggred!"} ], [ "Status online.", {"username":"STATUS button","content":"Status update (online)"} ], [ "Status offline.", {"username":"STATUS button","content":"Status update (offline)"} ], [ "Afk parents.", {"username":"AFK button","content":"Afk for a sec (parents)"} ], [ "Afk other.", {"username":"AFK button","content":"Afk for a sec (other)"} ], [ "Got to sleep!", {"username":"STATUS button","content":"I got to go (sleep)"} ], [ "Status busy.", {"username":"STATUS button","content":"Status update (busy)"} ], [ "Status washing.", {"username":"STATUS button","content":"Status update (Washing)"} ], [ "Lesson", {"username":"STATUS button","content":"Lesson ahh"} ], [ "Break", {"username":"STATUS button","content":"in on Break!"} ], [ "Circuit broke.", {"username":"FAULT button","content":"Device status (circuit broke)"} ], [ "Outa battery.", {"username":"FAULT button","content":"Device status (running out of battery)"} ], [ "Con problem!", {"username":"FAULT button","content":"Connetction problems"} ], [ "Devices outa pwr!", {"username":"FAULT button","content":"Devices out of power"} ], [ "Yes!", {"username":"QUESTION button","content":"Yes"} ], [ "No!", {"username":"QUESTION button","content":"No"} ], [ "Ok!", {"username":"QUESTION button","content":"ok"} ], [ "Huh!", {"username":"QUESTION button","content":"Huh"} ], [ "Maybe!", {"username":"QUESTION button","content":"Maybe"} ], [ "Idk!", {"username":"QUESTION button","content":"Idk"} ], [ "Con to smthin?", {"username":"QUESTION button","content":"Connect to something?"} ], [ "Ping Steven", {"username":"PING button","content":"<@745246319387476078> "} ], [ "Ping Hashtags", {"username":"PING button","content":"<@465535359292538880> "} ], [ "STOP IT", {"username":"WARNING button","content":"STOP IT"} ], [ "\"Please Stream\"", {"username":"REQUEST button","content":"<@745246319387476078> start stream"} ], [ "\"Prep Gitea\"", {"username":"REQUEST button","content":"<@745246319387476078> Prep gitea"} ], [ "\"Look Gitea\"", {"username":"REQUEST button","content":"<@745246319387476078> Look at gitea"} ], [ "\"Wanna talk?\"", {"username":"REQUEST button","content":"Wanna talk?"} ], [ "I Have my phone", {"username":"INFO button","content":"I can use phone!"} ], [ "No phone", {"username":"INFO button","content":"I cant use phone!"} ], [ "No pockbook", {"username":"INFO button","content":"I cant use pocketbook!"} ], [ "Cant read msg!", {"username":"INFO button","content":"I cant read messages!"} ] ] systemmenucontent = [ [ "YouOs "+version, versiondisplay ], [ "Exit loop", exitloop ], [ "Update system", updatesystem ], [ "Auto Update sys", autoupdatesystem ], [ "Netboot", netboot ], [ "Default network", defaultnetwork ], [ "Change dif ip", changedefaultip ], [ "Back Light on", backlighttoggle ] ] sendmenucontent = [ [ "Predefined msg", sendpredefinedmessages ], [ "Custom message", sendletters ] ] sendlettercontent =[ "abc", "def", "ghi", "jkl", "mno", "prs", "tuw", "xyz", "vq~", " ?!", "123", "456", "789", "*0#", "@$%", "^&(", ")-+", "_+/" ] #----------------------------------------------------- #-----------Preparations to main loop----------------- #----------------------------------------------------- cyclestilltime = 5 #display ready Running = True infoled.value(True) print('Ready') lcd.backlight_off() lcd.blink_cursor_off() utime.sleep(1) infoled.value(False) lcd.clear() lcd.putstr("Ready\n") lcd.backlight_off() file = open("updatelock.txt") if file.read() == "on": lcd.clear() lcd.putstr("Update in progress\n") if backlighton == True: lcd.backlight_on() lcd.putstr("Blue to Cancel") utime.sleep(2) if buttonblue.value == False: filetwo = open("updatelock.txt","w") filetwo.write("off") filetwo.close() Running = True else: Running = False file.close() #----------------------------------------------------- #--------------------Main Loop------------------------ #----------------------------------------------------- while Running == True: #----------------------------------------------------- #-----------On button press send message------------- #----------------------------------------------------- if buttongreen.value() == 0: webhookbutton(jsoncontentgreen) standby() #----------------------------------------------------- #-----------------Send message menu------------------- #----------------------------------------------------- elif buttonyellow.value() == 0: if backlighton == True: lcd.backlight_on() option = 1 lcd.clear() utime.sleep(1) while buttonyellow.value() == 0: lcd.putstr("Stop pressing!") utime.sleep(1) lcd.clear() sendmenu() while buttonyellow.value() == 0: lcd.putstr("Stop pressing!") utime.sleep(1) lcd.clear() standby() #----------------------------------------------------- #--------------------Other menu----------------------- #----------------------------------------------------- elif buttonred.value() == 0: if backlighton == True: lcd.backlight_on() lcd.clear() while buttonred.value() == 0: lcd.putstr("Stop pressing!") utime.sleep(0.5) lcd.clear() utime.sleep(0.1) lcd.clear() utime.sleep(0.1) while True: if backlighton == True: lcd.backlight_on() lcd.move_to(0,0) lcd.putstr("Red - clock Green - system") #clock menu if buttonred.value() == 0: clockmenu() if buttongreen.value() == 0: systemmenu() if buttonyellow.value() == 0: break while buttonyellow.value() == 0: lcd.putstr("Stop pressing!") utime.sleep(0.5) lcd.clear() lcd.clear() standby() #----------------------------------------------------- #-------------------Read messages--------------------- #----------------------------------------------------- elif buttonblue.value() == 0: filemainip = open("mainip.txt") filesecondaryip = open("secondaryip.txt") mainipadress = filemainip.read().split("\n")[0] secondaryipadress = filesecondaryip.read().split("\n")[0] filemainip.close() filesecondaryip.close() if getcontentget(mainipadress) == 1 : lcd.clear() lcd.putstr("Fail using:"+mainipadress) if backlighton == True: lcd.backlight_on() utime.sleep(1) if getcontentget(secondaryipadress) == 1 : lcd.clear() lcd.putstr("Fail using:"+secondaryipadress) if backlighton == True: lcd.backlight_on() utime.sleep(1) standby() else: filemainip = open("mainip.txt","w") filesecondaryip = open("secondaryip.txt","w") filemainip.write(secondaryipadress) filesecondaryip.write(mainipadress) filemainip.close() filesecondaryip.close() standby() #----------------------------------------------------- #----------------------Standby------------------------ #----------------------------------------------------- else : if wlan.isconnected() == True: infoled.value(True) utime.sleep(0.001) infoled.value(False) utime.sleep(1.999) cyclestilltime-=1 if cyclestilltime < 1: cyclestilltime = 5 t = utime.localtime(utime.time()+3600+3600) lcd.move_to(0,0) lcd.putstr("Time: {:02d}:{:02d}:{:02d}".format(t[3], t[4], t[5])) else: utime.sleep(3) #----------------------------------------------------- #------------------End of mainloop-------------------- #----------------------------------------------------- lcd.clear() file = open("updatelock.txt","w") file.write("off") file.close() lcd.backlight_on() lcd.putstr("Quitting") utime.sleep(5) lcd.clear() lcd.backlight_off()