37 lines
1.3 KiB
Python
37 lines
1.3 KiB
Python
|
|
import wifi
|
||
|
|
import time
|
||
|
|
import controller_config as config
|
||
|
|
|
||
|
|
def rssi_to_percent(rssi):
|
||
|
|
"""Converts RSSI (dBm) to a 0-100% signal strength."""
|
||
|
|
MIN_RSSI = -90; MAX_RSSI = -30
|
||
|
|
if rssi <= MIN_RSSI: return 0
|
||
|
|
if rssi >= MAX_RSSI: return 100
|
||
|
|
percent = ((rssi - MIN_RSSI) * 100) / (MAX_RSSI - MIN_RSSI)
|
||
|
|
return int(percent)
|
||
|
|
|
||
|
|
def setup_wifi_ap(ssid, password, channel):
|
||
|
|
"""
|
||
|
|
Configures the device as a Wi-Fi Access Point (AP).
|
||
|
|
"""
|
||
|
|
print(f"Setting up Wi-Fi AP: {ssid} on channel {channel}")
|
||
|
|
try:
|
||
|
|
wifi.radio.enabled = True
|
||
|
|
wifi.radio.start_ap(ssid=ssid, password=password, channel=channel, max_connections=4)
|
||
|
|
print(f"AP Started. IP: {wifi.radio.ipv4_address_ap}")
|
||
|
|
print(f"Waiting for clients... (SSID is VISIBLE: {ssid})")
|
||
|
|
|
||
|
|
except Exception as ex:
|
||
|
|
print(f"Error starting AP: {ex}")
|
||
|
|
raise
|
||
|
|
|
||
|
|
def print_help_file():
|
||
|
|
"""Reads and prints the help file specified in config."""
|
||
|
|
print("\n--- ⌨️ KBD Bot Command List ---")
|
||
|
|
try:
|
||
|
|
with open(config.HELP_FILE, "r") as f:
|
||
|
|
for line in f:
|
||
|
|
print(line.strip())
|
||
|
|
except OSError:
|
||
|
|
print(f"ERROR: Help file not found: {config.HELP_FILE}")
|
||
|
|
print("---------------------------------")
|