138 lines
3.1 KiB
YAML
138 lines
3.1 KiB
YAML
|
|
esphome:
|
||
|
|
name: oled-test
|
||
|
|
friendly_name: oled test
|
||
|
|
|
||
|
|
esp32:
|
||
|
|
board: esp32-c3-devkitm-1
|
||
|
|
framework:
|
||
|
|
type: esp-idf
|
||
|
|
|
||
|
|
# Enable logging
|
||
|
|
logger:
|
||
|
|
|
||
|
|
# Enable Home Assistant API
|
||
|
|
api:
|
||
|
|
encryption:
|
||
|
|
key: "rNfuxXEaIvVuOHvYVdb4QpW8fezbbkKn3wvjkHdHGkY="
|
||
|
|
|
||
|
|
ota:
|
||
|
|
- platform: esphome
|
||
|
|
password: "5aa6ac416280761455b83922c266822b"
|
||
|
|
|
||
|
|
wifi:
|
||
|
|
ssid: !secret wifi_ssid
|
||
|
|
password: !secret wifi_password
|
||
|
|
|
||
|
|
# Enable fallback hotspot (captive portal) in case wifi connection fails
|
||
|
|
ap:
|
||
|
|
ssid: "Esp32-C3-Oled-Test"
|
||
|
|
password: "Zto2fEEcWgnS"
|
||
|
|
|
||
|
|
captive_portal:
|
||
|
|
|
||
|
|
|
||
|
|
web_server:
|
||
|
|
|
||
|
|
i2c:
|
||
|
|
id: bus_oled
|
||
|
|
sda: GPIO5
|
||
|
|
scl: GPIO6
|
||
|
|
frequency: 100kHz
|
||
|
|
scan: true
|
||
|
|
|
||
|
|
# --- Czcionki do wyświetlacza (wygodne, ale możesz zmienić na swoje) ---
|
||
|
|
font:
|
||
|
|
- file: "fonts/Roboto-Regular.ttf"
|
||
|
|
id: f12
|
||
|
|
size: 9
|
||
|
|
- file: "fonts/Roboto-Bold.ttf"
|
||
|
|
id: f20
|
||
|
|
size: 11
|
||
|
|
|
||
|
|
# --- Przydatne sensory do pokazania na ekranie ---
|
||
|
|
sensor:
|
||
|
|
- platform: wifi_signal
|
||
|
|
name: "WiFi RSSI"
|
||
|
|
id: wifi_rssi
|
||
|
|
update_interval: 30s
|
||
|
|
|
||
|
|
- platform: uptime
|
||
|
|
name: "Uptime (s)"
|
||
|
|
id: uptime_s
|
||
|
|
update_interval: 60s
|
||
|
|
|
||
|
|
text_sensor:
|
||
|
|
- platform: wifi_info
|
||
|
|
ip_address:
|
||
|
|
name: "IP"
|
||
|
|
id: ip_addr
|
||
|
|
ssid:
|
||
|
|
name: "SSID"
|
||
|
|
id: wifi_ssid
|
||
|
|
|
||
|
|
# --- Przycisk BOOT (ten „użytkowy”; RESET/EN nie da się odczytać) ---
|
||
|
|
binary_sensor:
|
||
|
|
- platform: gpio
|
||
|
|
pin:
|
||
|
|
number: GPIO9 # BOOT na większości C3
|
||
|
|
mode: INPUT_PULLUP
|
||
|
|
inverted: true
|
||
|
|
name: "BOOT Button"
|
||
|
|
id: btn_boot
|
||
|
|
|
||
|
|
# --- Prosty przełącznik stron na OLED ---
|
||
|
|
globals:
|
||
|
|
- id: page
|
||
|
|
type: int
|
||
|
|
restore_value: no
|
||
|
|
initial_value: '0'
|
||
|
|
|
||
|
|
interval:
|
||
|
|
- interval: 1s
|
||
|
|
then:
|
||
|
|
- if:
|
||
|
|
condition:
|
||
|
|
binary_sensor.is_on: btn_boot
|
||
|
|
then:
|
||
|
|
- lambda: |-
|
||
|
|
static uint32_t last = 0;
|
||
|
|
if (millis() - last > 300) { // debouncing + auto-repeat off
|
||
|
|
id(page) = (id(page) + 1) % 2;
|
||
|
|
last = millis();
|
||
|
|
}
|
||
|
|
|
||
|
|
# --- Wyświetlacz OLED ---
|
||
|
|
display:
|
||
|
|
- platform: ssd1306_i2c
|
||
|
|
model: "SSD1306 72x40"
|
||
|
|
address: 0x3C
|
||
|
|
rotation: 0
|
||
|
|
i2c_id: bus_oled # <- to jest kluczowe
|
||
|
|
lambda: |-
|
||
|
|
if (id(page) == 0) {
|
||
|
|
// Strona 1: tytuł + IP + sygnał WiFi
|
||
|
|
it.printf(0, 0, id(f20), "C3 OLED");
|
||
|
|
if (id(ip_addr).has_state()) {
|
||
|
|
it.printf(0, 14, id(f12), "IP: %s", id(ip_addr).state.c_str());
|
||
|
|
} else {
|
||
|
|
it.printf(0, 14, id(f12), "IP: (brak)");
|
||
|
|
}
|
||
|
|
if (id(wifi_rssi).has_state()) {
|
||
|
|
it.printf(0, 20, id(f12), "RSSI: %.0f dBm", id(wifi_rssi).state);
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
// Strona 2: SSID + uptime
|
||
|
|
if (id(wifi_ssid).has_state()) {
|
||
|
|
it.printf(0, 0, id(f12), "SSID: %s", id(wifi_ssid).state.c_str());
|
||
|
|
}
|
||
|
|
if (id(uptime_s).has_state()) {
|
||
|
|
int t = (int) id(uptime_s).state;
|
||
|
|
int h = t / 3600;
|
||
|
|
int m = (t % 3600) / 60;
|
||
|
|
int s = t % 60;
|
||
|
|
it.printf(0, 14, id(f12), "Uptime: %02d:%02d:%02d", h, m, s);
|
||
|
|
}
|
||
|
|
it.printf(0, 26, id(f12), "BOOT: zmiana strony");
|
||
|
|
}
|
||
|
|
|
||
|
|
|