From 13c0fd32d6c540c6df4b792384bfe0fc8cf791cb Mon Sep 17 00:00:00 2001 From: structix Date: Thu, 2 Apr 2026 21:48:31 +0200 Subject: [PATCH] Pico fixes --- pico_2026/main.py | 5 ++++- pico_2026/rate.py | 9 +++++++++ pico_2026/wifi_client.py | 7 ++++--- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/pico_2026/main.py b/pico_2026/main.py index ea22565..838ad99 100644 --- a/pico_2026/main.py +++ b/pico_2026/main.py @@ -12,13 +12,16 @@ SERVER_PORT = 3000 SERVER_IP_LOWER = 100 SERVER_IP_UPPER = 102 +#SERVER_IP_LOWER = 120 +#SERVER_IP_UPPER = 123 + # Initialize I2C and OLED i2c = I2C(0, sda=Pin(8), scl=Pin(9), freq=400000) display = SSD1306_I2C(128, 64, i2c) # connect to laptop hotspot wifi_client.wifi_connect(SSID, PASSWORD) -wifi_client.search_server(SERVER_IP_LOWER, SERVER_IP_UPPER, SERVER_PORT) +#wifi_client.search_server(SERVER_IP_LOWER, SERVER_IP_UPPER, SERVER_PORT) #wifi_client.send_request(42) diff --git a/pico_2026/rate.py b/pico_2026/rate.py index 437f4e0..7b68511 100644 --- a/pico_2026/rate.py +++ b/pico_2026/rate.py @@ -57,6 +57,7 @@ def refresh_display(message=None): DISPLAY.text(rating_text, 60, 30) DISPLAY.show() + print("Updating screen.") # initialize a specific Pin as Input with a pull-down resistor def initialize_pin(pin_number:int): @@ -66,6 +67,9 @@ def initialize_pin(pin_number:int): # Hardware Interrupt: rate button is pressed def rate_button_pressed(pin:Pin) -> None: global pending_rate_button, last_interrupt_time + + print("rate button pressed:", pin) + current_time = time.ticks_ms() # Simple software debounce @@ -80,6 +84,8 @@ def rate_button_pressed(pin:Pin) -> None: # Hardware Interrupt: Send/Confirm button is pressed def sendButton_pressed(pin:Pin) -> None: global pending_send_button, last_interrupt_time + + print("send button pressed:", pin) current_time = time.ticks_ms() if time.ticks_diff(current_time, last_interrupt_time) > DEBOUNCE_MS: @@ -89,6 +95,7 @@ def sendButton_pressed(pin:Pin) -> None: # Process the rate button press (Called from the main loop) def process_rate_button(button_index: int): global USER_ID, RATING, CURRENT_STATE + if CURRENT_STATE == STATE_USER_ID: bit_pos = 4 - button_index @@ -126,6 +133,7 @@ def process_send_button(): refresh_display("Success") else: refresh_display("Error") + print("Error sending rating.") time.sleep(3) # Display status for 3 seconds @@ -146,6 +154,7 @@ def start_rating(rate_button_pins:list, button_send_pin:int, oled_display=None) RATE_BUTTONS = [] for pin_num in rate_button_pins: button = initialize_pin(pin_num) + print("Setting up pin:", pin_num) button.irq(trigger=Pin.IRQ_RISING, handler=rate_button_pressed) RATE_BUTTONS.append(button) diff --git a/pico_2026/wifi_client.py b/pico_2026/wifi_client.py index 1707334..59d0964 100644 --- a/pico_2026/wifi_client.py +++ b/pico_2026/wifi_client.py @@ -7,6 +7,7 @@ import ssl # global variable for the IP-Adress of the laptop hotspot IP_ADRESS_SERVER:str = '192.168.0.100' #None +#IP_ADRESS_SERVER:str = '10.232.67.121' #None IP_ADRESS_ACCESSPOINT = None SERVER_PORT:int = 3000 #None @@ -29,7 +30,7 @@ def wifi_connect(SSID:str, PASSWORD:str) -> None: print("Connected to", SSID) # geat and print IP-adress of raspberry ip_adress_pico = wifi.ifconfig()[0] - print("IP-Adresse Pico:", ip_adress_pico) + print("IP-Adress Pico:", ip_adress_pico) # get ip-adress of access point and store it in the global variable global IP_ADRESS_ACCESSPOINT IP_ADRESS_ACCESSPOINT = wifi.ifconfig()[2] @@ -42,12 +43,12 @@ def wifi_connect(SSID:str, PASSWORD:str) -> None: def send_request(user_id:int, rating:int) -> bool: # create HTTP-URL - URL = f"http://{IP_ADRESS_SERVER}:{str(SERVER_PORT)}/ratings/{user_id}/{rating}" + URL = f"http://{IP_ADRESS_SERVER}:{str(SERVER_PORT)}/{user_id}/{rating}" print(URL) try: # create request - response = urequests.get(URL) + response = urequests.get(URL, timeout=5.0) # print HTTP-answer of the access point print("Server response:")