I can’t get the program to see my override buttons

I want to be able to press the puttons on the web app to change the lights but I also want to be able to overide the web app with physical buttons to change the leds like the web app can. This is for a prototype for a wireless pool pump controller im making for my dad. Im using a pico w with micropython.

I tried putting the buttons code above all the network stuff with a while true loop and that did let me connect to the network, I tried just an or with the requests for example if request == '/low?' or lowButton.value() == 0: but that would only read the button when I interacted with the web app and I want the button to work on its own. I tried making the “if button pressed do this” part a function and then adress the function in the “try” code and the very end and I got the same result. It just seems like nothing is working

import network
import socket
from time import sleep
from machine import Pin
import machine
import utime

ssid = 'ssid'
password = 'password'

lowTime = 5 #when the pump kicks on low speed
highTime = 22 #when the pump kicks on high speed

lowSpeed = Pin(0, Pin.OUT) #the pins for the contactors right now they are just leds
highSpeed = Pin(1, Pin.OUT)

lowButton = Pin(6, Pin.IN, Pin.PULL_UP) #the overide switches
highButton = Pin(7, Pin.IN, Pin.PULL_UP)
offButton = Pin(8, Pin.IN, Pin.PULL_UP)
timeButton = Pin(9, Pin.IN, Pin.PULL_UP) #the same as schedule

lowLed = Pin(10, Pin.OUT) #the status lights for each mode
highLed = Pin(11, Pin.OUT)
offLed = Pin(12, Pin.OUT)
timeLed = Pin(13, Pin.OUT)
#I got the networking code from a raspberry pi pico w networking tutorial
def connect():
    wlan = network.WLAN(network.STA_IF)
    wlan.active(True)
    wlan.connect(ssid, password)
    while wlan.isconnected() == False:
        print('Waiting for connection...')
        sleep(1)
    ip = wlan.ifconfig()[0]
    print(f'Connected on {ip}')
    return ip
def open_socket(ip):
    address = (ip, 80)
    connection = socket.socket()
    connection.bind(address)
    connection.listen(1)
    return connection
    
def webpage():
    html = f"""
             <!DOCTYPE html>
                <html>
                    <head>
                        <meta charset="UTF-8">
                        <meta content="width=device-width, initial-scale=1.0">
                    </head>
                    <body style="background-color: black; text-align: center; vertical-align: middle; line-height: 100px;">
                        <h1 style="color:aliceblue; font-size: 300%;">
                            Father's Pool Pump Controll (PPC)
                        </h1>
                        <form action="./low">
                            <input type="submit" value="Low" style="height:350px; width:600px; border-radius: 40px; font-size:xx-large; background-color: rgb(0, 123, 254); color: aliceblue; font-weight: bold; border-color: aliceblue;"/>
                        </form>
                        <form action="./high">
                            <input type="submit" value="High" style="height:350px; width:600px; border-radius: 40px; font-size:xx-large; background-color: rgb(0, 123, 254); color: aliceblue; font-weight: bold; border-color: aliceblue;"/>
                        </form>
                        <form action="./off">
                            <input type="submit" value="OFF" style="height:350px; width:600px; border-radius: 40px; font-size:xx-large; background-color: rgb(0, 123, 254); color: aliceblue; font-weight: bold; border-color: aliceblue;"/>
                        </form>
                        <form action="./schedule">
                            <input type="submit" value="Schedule" style="height:350px; width:600px; border-radius: 40px; font-size:xx-large; background-color: rgb(0, 123, 254); color: aliceblue; font-weight: bold; border-color: aliceblue;"/>
                        </form>
                    </body>
                </html>
            """
    return str(html)
def serve(connection):
    while True:
        client = connection.accept()[0]
        request = client.recv(1024)
        request = str(request)
        try:
            request = request.split()[1]
        except IndexError:
            pass
        if request == '/low?':
            lowSpeed.on()
            highSpeed.off()
            print("Low Selected!!!")
            lowLed.value(1)
            highLed.value(0)
            offLed.value(0)
            timeLed.value(0)
        if request == '/high?':
            lowSpeed.off()
            highSpeed.on()
            print("High Selected!!!")
            lowLed.value(0)
            highLed.value(1)
            offLed.value(0)
            timeLed.value(0)
        if request == '/off?':
            lowSpeed.off()
            highSpeed.off()
            print("Off Selected!!!")
            lowLed.value(0)
            highLed.value(0)
            offLed.value(1)
            timeLed.value(0)
        if request == '/schedule?':
            print("Schedule Seleceted!!!")
            if utime.localtime()[3] >= highTime or utime.localtime()[3] < lowTime:
                lowSpeed.off()
                highSpeed.on()
                print("Switching to High!!!")
            if utime.localtime()[3] >= lowTime or utime.localtime()[3] < highTime:
                lowSpeed.on()
                highSpeed.off()
                print("Switching to Low!!!")
            lowLed.value(0)
            highLed.value(0)
            offLed.value(0)
            timeLed.value(1)
        html = webpage()
        client.send(html)
        client.close()
try:
    ip = connect()
    connection = open_socket(ip)
    serve(connection)
# here is my code for the override buttons but im not sure where to put it to the code to read them
# it is basically the same as above just not in a function 
# I tried putting the lowButton.value() == 0 part after the requests with an or statment but that didn't work
    if lowButton.value() == 0:
        lowSpeed.on()
        highSpeed.off()
        print("Low Selected!!!")
        lowLed.value(1)
        highLed.value(0)
        offLed.value(0)
        timeLed.value(0)
    if highButton.value() == 0:
        lowSpeed.off()
        highSpeed.on()
        print("High Selected!!!")
        lowLed.value(0)
        highLed.value(1)
        offLed.value(0)
        timeLed.value(0)
    if offButton.value() == 0:
        lowSpeed.off()
        highSpeed.off()
        print("Off Selected!!!")
        lowLed.value(0)
        highLed.value(0)
        offLed.value(1)
        timeLed.value(0)
    if timeButton.value() == 0:
        if utime.localtime()[3] >= highTime or utime.localtime()[3] < lowTime:
            lowSpeed.off()
            highSpeed.on()
            print("Switching to High!!!")
        if utime.localtime()[3] >= lowTime or utime.localtime()[3] < highTime:
            lowSpeed.on()
            highSpeed.off()
            print("Switching to Low!!!")
        lowLed.value(0)
        highLed.value(0)
        offLed.value(0)
        timeLed.value(1)
 # here is where the button code ends
except KeyboardInterrupt:
    machine.reset()
    

New contributor

Paxton M is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật