Pico fixes
This commit is contained in:
@@ -12,13 +12,16 @@ SERVER_PORT = 3000
|
|||||||
SERVER_IP_LOWER = 100
|
SERVER_IP_LOWER = 100
|
||||||
SERVER_IP_UPPER = 102
|
SERVER_IP_UPPER = 102
|
||||||
|
|
||||||
|
#SERVER_IP_LOWER = 120
|
||||||
|
#SERVER_IP_UPPER = 123
|
||||||
|
|
||||||
# Initialize I2C and OLED
|
# Initialize I2C and OLED
|
||||||
i2c = I2C(0, sda=Pin(8), scl=Pin(9), freq=400000)
|
i2c = I2C(0, sda=Pin(8), scl=Pin(9), freq=400000)
|
||||||
display = SSD1306_I2C(128, 64, i2c)
|
display = SSD1306_I2C(128, 64, i2c)
|
||||||
|
|
||||||
# connect to laptop hotspot
|
# connect to laptop hotspot
|
||||||
wifi_client.wifi_connect(SSID, PASSWORD)
|
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)
|
#wifi_client.send_request(42)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ def refresh_display(message=None):
|
|||||||
DISPLAY.text(rating_text, 60, 30)
|
DISPLAY.text(rating_text, 60, 30)
|
||||||
|
|
||||||
DISPLAY.show()
|
DISPLAY.show()
|
||||||
|
print("Updating screen.")
|
||||||
|
|
||||||
# initialize a specific Pin as Input with a pull-down resistor
|
# initialize a specific Pin as Input with a pull-down resistor
|
||||||
def initialize_pin(pin_number:int):
|
def initialize_pin(pin_number:int):
|
||||||
@@ -66,6 +67,9 @@ def initialize_pin(pin_number:int):
|
|||||||
# Hardware Interrupt: rate button is pressed
|
# Hardware Interrupt: rate button is pressed
|
||||||
def rate_button_pressed(pin:Pin) -> None:
|
def rate_button_pressed(pin:Pin) -> None:
|
||||||
global pending_rate_button, last_interrupt_time
|
global pending_rate_button, last_interrupt_time
|
||||||
|
|
||||||
|
print("rate button pressed:", pin)
|
||||||
|
|
||||||
|
|
||||||
current_time = time.ticks_ms()
|
current_time = time.ticks_ms()
|
||||||
# Simple software debounce
|
# Simple software debounce
|
||||||
@@ -80,6 +84,8 @@ def rate_button_pressed(pin:Pin) -> None:
|
|||||||
# Hardware Interrupt: Send/Confirm button is pressed
|
# Hardware Interrupt: Send/Confirm button is pressed
|
||||||
def sendButton_pressed(pin:Pin) -> None:
|
def sendButton_pressed(pin:Pin) -> None:
|
||||||
global pending_send_button, last_interrupt_time
|
global pending_send_button, last_interrupt_time
|
||||||
|
|
||||||
|
print("send button pressed:", pin)
|
||||||
|
|
||||||
current_time = time.ticks_ms()
|
current_time = time.ticks_ms()
|
||||||
if time.ticks_diff(current_time, last_interrupt_time) > DEBOUNCE_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)
|
# Process the rate button press (Called from the main loop)
|
||||||
def process_rate_button(button_index: int):
|
def process_rate_button(button_index: int):
|
||||||
global USER_ID, RATING, CURRENT_STATE
|
global USER_ID, RATING, CURRENT_STATE
|
||||||
|
|
||||||
|
|
||||||
if CURRENT_STATE == STATE_USER_ID:
|
if CURRENT_STATE == STATE_USER_ID:
|
||||||
bit_pos = 4 - button_index
|
bit_pos = 4 - button_index
|
||||||
@@ -126,6 +133,7 @@ def process_send_button():
|
|||||||
refresh_display("Success")
|
refresh_display("Success")
|
||||||
else:
|
else:
|
||||||
refresh_display("Error")
|
refresh_display("Error")
|
||||||
|
print("Error sending rating.")
|
||||||
|
|
||||||
time.sleep(3) # Display status for 3 seconds
|
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 = []
|
RATE_BUTTONS = []
|
||||||
for pin_num in rate_button_pins:
|
for pin_num in rate_button_pins:
|
||||||
button = initialize_pin(pin_num)
|
button = initialize_pin(pin_num)
|
||||||
|
print("Setting up pin:", pin_num)
|
||||||
button.irq(trigger=Pin.IRQ_RISING, handler=rate_button_pressed)
|
button.irq(trigger=Pin.IRQ_RISING, handler=rate_button_pressed)
|
||||||
RATE_BUTTONS.append(button)
|
RATE_BUTTONS.append(button)
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import ssl
|
|||||||
|
|
||||||
# global variable for the IP-Adress of the laptop hotspot
|
# global variable for the IP-Adress of the laptop hotspot
|
||||||
IP_ADRESS_SERVER:str = '192.168.0.100' #None
|
IP_ADRESS_SERVER:str = '192.168.0.100' #None
|
||||||
|
#IP_ADRESS_SERVER:str = '10.232.67.121' #None
|
||||||
IP_ADRESS_ACCESSPOINT = None
|
IP_ADRESS_ACCESSPOINT = None
|
||||||
SERVER_PORT:int = 3000 #None
|
SERVER_PORT:int = 3000 #None
|
||||||
|
|
||||||
@@ -29,7 +30,7 @@ def wifi_connect(SSID:str, PASSWORD:str) -> None:
|
|||||||
print("Connected to", SSID)
|
print("Connected to", SSID)
|
||||||
# geat and print IP-adress of raspberry
|
# geat and print IP-adress of raspberry
|
||||||
ip_adress_pico = wifi.ifconfig()[0]
|
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
|
# get ip-adress of access point and store it in the global variable
|
||||||
global IP_ADRESS_ACCESSPOINT
|
global IP_ADRESS_ACCESSPOINT
|
||||||
IP_ADRESS_ACCESSPOINT = wifi.ifconfig()[2]
|
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:
|
def send_request(user_id:int, rating:int) -> bool:
|
||||||
|
|
||||||
# create HTTP-URL
|
# 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)
|
print(URL)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# create request
|
# create request
|
||||||
response = urequests.get(URL)
|
response = urequests.get(URL, timeout=5.0)
|
||||||
|
|
||||||
# print HTTP-answer of the access point
|
# print HTTP-answer of the access point
|
||||||
print("Server response:")
|
print("Server response:")
|
||||||
|
|||||||
Reference in New Issue
Block a user