Skip to content

Commit

Permalink
breaking: major code restructure and added support for esp32s3
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikMeinders committed Dec 23, 2024
1 parent dfc8a55 commit 6989a46
Show file tree
Hide file tree
Showing 72 changed files with 966 additions and 1,101 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
.DS*
Binary file modified examples/.DS_Store
Binary file not shown.
57 changes: 57 additions & 0 deletions examples/basic/boards/esp32-s3-devkitc1-n32r8.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"build": {
"arduino": {
"partitions": "default.csv",
"memory_type": "opi_opi"
},
"core": "esp32",
"extra_flags": [
"-DARDUINO_ESP32S3_DEV",
"-DARDUINO_RUNNING_CORE=1",
"-DARDUINO_EVENT_RUNNING_CORE=1",
"-DBOARD_HAS_PSRAM",
"-D_NEOPIXEL_PIN=38"

],
"f_cpu": "240000000L",
"f_flash": "80000000L",
"flash_mode": "opi",
"psram_type": "opi",
"hwids": [
[
"0x303A",
"0x1001"
]
],
"mcu": "esp32s3",
"variant": "esp32s3"
},
"connectivity": [
"wifi",
"bluetooth"
],
"debug": {
"default_tool": "esp-builtin",
"onboard_tools": [
"esp-builtin"
],
"openocd_target": "esp32s3.cfg"
},
"frameworks": [
"arduino",
"espidf"
],
"platforms": [
"espressif32"
],
"name": "Espressif ESP32-S3-DevKitC-1-N32R8V (32 MB Flash Octal, 8 MB PSRAM Octal)",
"upload": {
"flash_size": "32MB",
"maximum_ram_size": 327680,
"maximum_size": 33554432,
"require_upload_port": true,
"speed": 921600
},
"url": "https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/hw-reference/esp32s3/user-guide-devkitc-1.html",
"vendor": "Espressif"
}
17 changes: 12 additions & 5 deletions examples/basic/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
; https://docs.platformio.org/page/projectconf.html

[platformio]
default_envs = basic-esp8266, basic-esp32, basic-esp32s3
default_envs = basic-esp32s3
workspace_dir = .pio.nosync

[env]
Expand All @@ -14,14 +14,20 @@ lib_ldf_mode = deep+

lib_deps =
symlink://${PROJECT_DIR}/../.. ; Reference to the local knx_platformio library
adafruit/Adafruit NeoPixel@^1.12.2

build_flags =
; KNXMedia control
-DMASK_VERSION=0x57B0
; Feature flags
-DNO_HEARTBEAT
-DHOSTNAME='"knx-web"'
-DNETWORK_ONDEMAND
-DKNXP_NO_HEARTBEAT
; -DKNXP_NO_KNX
; -DKNXP_NO_WIFI
; -DKNXP_NO_TELNET
; -DKNXP_NO_MDNS
-DKNXP_PROG_PIN=0
-DKNXP_HOSTNAME='"knx-web"'
-DKNXP_LOG_LEVEL=6
; Warning suppressions
-Wno-unknown-pragmas
-Wno-unused-function
Expand Down Expand Up @@ -49,10 +55,11 @@ build_flags =

[env:basic-esp32s3]
platform = espressif32
board = esp32-s3-devkitc-1
board = esp32-s3-devkitc1-n32r8
build_type = debug
build_flags =
${env.build_flags}
-DESP32
-DESP32S3
-DCORE_DEBUG_LEVEL=5
-DKNXP_NEOPIXEL_PIN=38
2 changes: 2 additions & 0 deletions examples/basic/src/arduino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

void setup()
{
Println("Your setup");
knxAppInstance.setup();
Println("Your setup completed");
}

void loop()
Expand Down
4 changes: 3 additions & 1 deletion examples/basic/src/knxapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ knxapp knxAppInstance;

void knxapp::setup()
{

_knxapp::setup(); // Call base class implementation first
Println("Your setup completed");
}

void knxapp::loop()
Expand All @@ -26,7 +28,7 @@ void knxapp::loop()
void knxapp::knx_setup()
{
Println("Your KNX setup");

return;
setGroupObjectCount(1);
knx.getGroupObject(1).dataPointType(DPT_Value_Temp);
knx.getGroupObject(1).value(19.8);
Expand Down
57 changes: 57 additions & 0 deletions examples/webpage/boards/esp32-s3-devkitc1-n32r8.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"build": {
"arduino": {
"partitions": "default.csv",
"memory_type": "opi_opi"
},
"core": "esp32",
"extra_flags": [
"-DARDUINO_ESP32S3_DEV",
"-DARDUINO_RUNNING_CORE=1",
"-DARDUINO_EVENT_RUNNING_CORE=1",
"-DBOARD_HAS_PSRAM",
"-D_NEOPIXEL_PIN=38"

],
"f_cpu": "240000000L",
"f_flash": "80000000L",
"flash_mode": "opi",
"psram_type": "opi",
"hwids": [
[
"0x303A",
"0x1001"
]
],
"mcu": "esp32s3",
"variant": "esp32s3"
},
"connectivity": [
"wifi",
"bluetooth"
],
"debug": {
"default_tool": "esp-builtin",
"onboard_tools": [
"esp-builtin"
],
"openocd_target": "esp32s3.cfg"
},
"frameworks": [
"arduino",
"espidf"
],
"platforms": [
"espressif32"
],
"name": "Espressif ESP32-S3-DevKitC-1-N32R8V (32 MB Flash Octal, 8 MB PSRAM Octal)",
"upload": {
"flash_size": "32MB",
"maximum_ram_size": 327680,
"maximum_size": 33554432,
"require_upload_port": true,
"speed": 921600
},
"url": "https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/hw-reference/esp32s3/user-guide-devkitc-1.html",
"vendor": "Espressif"
}
30 changes: 30 additions & 0 deletions examples/webpage/data/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# KNX Temperature Monitor Web Interface

This directory contains two versions of the web interface for different WebSocket implementations:

## 1. WebSocket with /ws prefix (index-ws.html)
- Uses the standard HTTP port with a `/ws` path prefix for WebSocket connections
- Suitable for ESP32 using standard WebServer
- Files:
- `index-ws.html`: Main HTML file
- `script-ws.js`: WebSocket client implementation

## 2. WebSocket on Port 81 (index-port81.html)
- Uses a dedicated WebSocket server on port 81
- Suitable for ESP8266 or when using AsyncWebServer
- Files:
- `index-port81.html`: Main HTML file
- `script-port81.js`: WebSocket client implementation

## Usage
1. Choose the appropriate HTML file based on your ESP device and web server implementation:
- For standard WebServer with `/ws` prefix: Use `index-ws.html`
- For dedicated WebSocket server on port 81: Use `index-port81.html`
2. Upload the corresponding files to your device's filesystem
3. Access the web interface through your device's IP address

Both versions provide the same functionality:
- Real-time temperature display
- Connection status indication
- Automatic reconnection attempts
- JSON message parsing
23 changes: 23 additions & 0 deletions examples/webpage/data/index-port81.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>KNX Temperature Monitor (Port 81)</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<h1>KNX Temperature Monitor</h1>
<div class="temperature-display">
<div class="value">--.-</div>
<div class="unit">°C</div>
</div>
<div class="status">
<div class="connection-status">Connecting...</div>
</div>
<div class="info">Using WebSocket port 81</div>
</div>
<script src="script-port81.js"></script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>KNX Temperature Monitor</title>
<title>KNX Temperature Monitor (WS)</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
Expand All @@ -16,7 +16,8 @@ <h1>KNX Temperature Monitor</h1>
<div class="status">
<div class="connection-status">Connecting...</div>
</div>
<div class="info">Using WebSocket /ws prefix</div>
</div>
<script src="script.js"></script>
<script src="script-ws.js"></script>
</body>
</html>
59 changes: 59 additions & 0 deletions examples/webpage/data/script-port81.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
document.addEventListener('DOMContentLoaded', () => {
const temperatureValue = document.querySelector('.value');
const connectionStatus = document.querySelector('.connection-status');
let ws = null;
let reconnectAttempts = 0;
const maxReconnectAttempts = 5;

function connect() {
// Use secure WebSocket if page is served over HTTPS
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
const wsUrl = `${protocol}//${window.location.hostname}:81`;

console.log('Connecting to WebSocket:', wsUrl);
ws = new WebSocket(wsUrl);

ws.onopen = () => {
console.log('WebSocket connected');
connectionStatus.textContent = 'Connected';
connectionStatus.classList.add('connected');
connectionStatus.classList.remove('disconnected');
reconnectAttempts = 0;
};

ws.onclose = () => {
console.log('WebSocket disconnected');
connectionStatus.textContent = 'Disconnected';
connectionStatus.classList.add('disconnected');
connectionStatus.classList.remove('connected');

// Attempt to reconnect
if (reconnectAttempts < maxReconnectAttempts) {
reconnectAttempts++;
connectionStatus.textContent = `Reconnecting (${reconnectAttempts}/${maxReconnectAttempts})...`;
setTimeout(connect, 3000);
} else {
connectionStatus.textContent = 'Connection failed. Please refresh the page.';
}
};

ws.onerror = (error) => {
console.error('WebSocket error:', error);
};

ws.onmessage = (event) => {
console.log('WebSocket message:', event.data);
try {
const data = JSON.parse(event.data);
if (data.temperature !== undefined) {
temperatureValue.textContent = data.temperature.toFixed(1);
}
} catch (e) {
console.error('Error parsing WebSocket message:', e);
}
};
}

// Initial connection
connect();
});
File renamed without changes.
2 changes: 1 addition & 1 deletion examples/webpage/data/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ document.addEventListener('DOMContentLoaded', () => {
function connect() {
// Use secure WebSocket if page is served over HTTPS
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
const wsUrl = `${protocol}//${window.location.hostname}:81`;
const wsUrl = `${protocol}//${window.location.hostname}/ws`;

console.log('Connecting to WebSocket:', wsUrl);
ws = new WebSocket(wsUrl);
Expand Down
9 changes: 9 additions & 0 deletions examples/webpage/data/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,12 @@ h1 {
.disconnected {
color: #f44336;
}

.info {
margin-top: 1rem;
font-size: 0.8rem;
color: #666;
padding: 0.5rem;
background-color: #f5f5f5;
border-radius: 4px;
}
Loading

0 comments on commit 6989a46

Please sign in to comment.