Skip to content

Commit 348517a

Browse files
committed
Add local doorbell test demo
1 parent c14a6cb commit 348517a

25 files changed

+2540
-2
lines changed

.gitlab/ci/build_webrtc_solutions.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ build_matrix:
4545
IDF_TARGET: ["esp32p4"]
4646
- CI_BUILD_FOLDER: ["whip_demo"]
4747
IDF_TARGET: ["esp32p4"]
48+
- CI_BUILD_FOLDER: ["doorbell_local"]
49+
IDF_TARGET: ["esp32p4"]
4850

4951
stages:
5052
- build

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ It includes the `esp_webrtc` core code along with its dependent components, such
77
- **`esp_capture`**: For capturing media data
88
- **`av_render`**: For playing media data
99

10-
Additionally, the repository contains three simple demo applications that demonstrate how to use `esp_webrtc`.
10+
Additionally, the repository contains three several demo applications that demonstrate how to use `esp_webrtc`.
1111

1212
## Solutions
1313

@@ -28,3 +28,7 @@ This demo show how to use `esp_webrtc` data channel to build up video call appli
2828

2929
### 5. WHIP Publisher Solution
3030
This demo show how to use `esp_webrtc` to publish streaming data to WHIP server.
31+
32+
### 6. Doorbell Local Demo
33+
This demo sets up a local doorbell application that operates without external signaling servers.
34+
An ESP32 series board acts as the signaling server, allowing users to connect directly for WebRTC testing.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# The following lines of boilerplate have to be in your project's CMakeLists
2+
# in this exact order for cmake to work correctly
3+
cmake_minimum_required(VERSION 3.5)
4+
5+
# include($ENV{ADF_PATH}/CMakeLists.txt)
6+
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
7+
8+
if("${IDF_TARGET}" STREQUAL "esp32p4")
9+
set(EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/examples/ethernet/basic/components/ethernet_init")
10+
endif()
11+
12+
list(APPEND EXTRA_COMPONENT_DIRS "../../components")
13+
14+
list(APPEND EXTRA_COMPONENT_DIRS "../common")
15+
16+
project(doorbell_demo)

solutions/doorbell_local/README.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
2+
# Doorbell Local Demo
3+
4+
## Overview
5+
6+
This demo shows how to use `esp_webrtc` to build a local doorbell application. An ESP32 series board acts as an HTTPS signaling server.
7+
8+
## Hardware Requirements
9+
10+
The default hardware setup uses the [ESP32P4-Function-Ev-Board](https://docs.espressif.com/projects/esp-dev-kits/en/latest/esp32p4/esp32-p4-function-ev-board/user_guide.html), which includes an SC2336 camera.
11+
12+
## Build Instructions
13+
14+
### ESP-IDF Version
15+
16+
Use either the **IDF master branch** or **release v5.4**.
17+
18+
### Dependencies
19+
20+
This demo depends only on **ESP-IDF**. All other required components will be automatically fetched from the [ESP-IDF Component Registry](https://components.espressif.com/).
21+
22+
### Configuration
23+
24+
1. **Wi-Fi Settings**
25+
Set your Wi-Fi SSID and password in [`settings.h`](main/settings.h).
26+
27+
2. **Camera Configuration**
28+
If using a different camera model or resolution, update the corresponding settings in [`settings.h`](main/settings.h).
29+
30+
3. **USB-JTAG Download (Optional)**
31+
If using USB-JTAG, uncomment the following line in [`sdkconfig.defaults.esp32p4`](sdkconfig.defaults.esp32p4):
32+
```c
33+
CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=y
34+
```
35+
36+
### Build and Flash
37+
38+
```bash
39+
idf.py -p YOUR_SERIAL_DEVICE flash monitor
40+
```
41+
42+
## Testing
43+
44+
After the board boots, it will connect to the configured Wi-Fi. To switch to a different Wi-Fi network dynamically, use the CLI:
45+
46+
```bash
47+
wifi YOUR_SSID YOUR_PASSWORD
48+
```
49+
50+
Once connected, the board will start the signaling server and wait for a peer to connect. A test URL will be printed in the console:
51+
52+
```
53+
Webrtc_Test: Use browser to enter https://192.168.10.33/webrtc/test for test
54+
```
55+
56+
You can stop or restart signaling with:
57+
58+
```bash
59+
stop
60+
start
61+
```
62+
63+
### Browser Access
64+
65+
Open **Chrome** or **Edge** and visit the printed URL. Since the site uses a self-signed certificate, you may need to trust the page manually.
66+
67+
Also, disable mDNS ICE candidates to ensure proper WebRTC connectivity:
68+
69+
- **Chrome**: `chrome://flags/#enable-webrtc-hide-local-ips-with-mdns`
70+
- **Edge**: `edge://flags/#enable-webrtc-hide-local-ips-with-mdns`
71+
72+
Disable the option: **WebRTC mDNS ICE candidates**
73+
Restart the browser for the change to take effect.
74+
75+
### Interactions
76+
77+
After opening the page in the browser:
78+
79+
1. **Open Door**
80+
- Click the **Door** icon.
81+
- The board will play a "Door is opened" tone.
82+
- The browser will display: `Receiving Door opened event`.
83+
84+
2. **Calling (Ring Button)**
85+
- Press the **boot key** on the board.
86+
- The board plays ring music, and the browser shows **Accept Call** and **Deny Call** icons.
87+
- If accepted: starts **two-way audio** and **one-way video** (board → browser).
88+
- If denied: the call ends.
89+
- To change the ring button, modify `DOOR_BELL_RING_BUTTON` in [`settings.h`](main/settings.h).
90+
91+
3. **End Call / Cleanup**
92+
- In the browser: click the **Hangup** icon.
93+
- On the board: run the `stop` command.
94+
95+
## Technical Details
96+
97+
This demo use SSE to send instant message to browser and use POST to receive instant message from browser.
98+
99+
### Enhancements in `esp_webrtc`
100+
101+
- **`no_auto_reconnect`**: Disables automatic peer connection setup on signaling connect.
102+
- **`esp_webrtc_enable_peer_connection()`**: Explicit API to control peer connection lifecycle.
103+
104+
For a detailed call flow, refer to the [esp_webrtc connection flow](../../components/esp_webrtc/README.md#typical-call-sequence-of-esp_webrtc).
105+
106+
### Limitations
107+
108+
- Only one peer can connect at a time.
109+
- A heartbeat timeout of 5 seconds is enforced.
110+
- If the peer leaves unexpectedly, wait a few seconds before reconnecting.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
idf_component_register(SRCS "webrtc.c" "main.c" "board.c" "media_sys.c" "webrtc_http_server.c"
2+
EMBED_TXTFILES "ring.aac" "open.aac" "join.aac" "webrtc_test.html"
3+
"certs/servercert.pem" "certs/prvtkey.pem"
4+
INCLUDE_DIRS ".")

solutions/doorbell_local/main/board.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* Do simple board initialize
2+
3+
This example code is in the Public Domain (or CC0 licensed, at your option.)
4+
5+
Unless required by applicable law or agreed to in writing, this
6+
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
7+
CONDITIONS OF ANY KIND, either express or implied.
8+
*/
9+
10+
#include <stdio.h>
11+
#include "esp_log.h"
12+
#include "codec_init.h"
13+
#include "codec_board.h"
14+
#include "esp_codec_dev.h"
15+
#include "sdkconfig.h"
16+
#include "settings.h"
17+
18+
static const char *TAG = "Board";
19+
20+
void init_board()
21+
{
22+
ESP_LOGI(TAG, "Init board.");
23+
set_codec_board_type(TEST_BOARD_NAME);
24+
// Notes when use playback and record at same time, must set reuse_dev = false
25+
codec_init_cfg_t cfg = {.reuse_dev = false};
26+
init_codec(&cfg);
27+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
-----BEGIN PRIVATE KEY-----
2+
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCwYp7epz++0QkH
3+
JioMD7U7BitLgpcYPi8Cid1l7snt6Kp546iQsDBJ3l8xnRtPU7ANEsjT8KxIHmyw
4+
h/NGp94FlOKRw3ahh3yUGtowS9vdHv+S+TAfuj07NjSnKIyv5KnGZJ+fDFl4Q1tT
5+
aQJybY1Z4itirL6/2CGEm8g/iYhLNDBsRMfpDpfXe4URyWiM3Rhf7ztqZdveb9al
6+
3pAJZIDTLWCFQI1MvQjKamkAQkES/gZj0iUZFwbGJPBj54nkuLFLKedw7DbwgrVg
7+
0+n3fQ9b/gQepw5PxQjyobY2DsDgGZV+MFjUmaUTa+XX68SrG4wJ+DwrkdmpHReB
8+
vFi1Hg1hAgMBAAECggEAaTCnZkl/7qBjLexIryC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CVr77iUuC3wtAoGBAIBrOGunv1qZMfqmwAY2
25+
lxlzRgxgSiaev0lTNxDzZkmU/u3dgdTwJ5DDANqPwJc6b8SGYTp9rQ0mbgVHnhIB
26+
jcJQBQkTfq6Z0H6OoTVi7dPs3ibQJFrtkoyvYAbyk36quBmNRjVh6rc8468bhXYr
27+
v/t+MeGJP/0Zw8v/X2CFll96
28+
-----END PRIVATE KEY-----
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIIDKzCCAhOgAwIBAgIUBxM3WJf2bP12kAfqhmhhjZWv0ukwDQYJKoZIhvcNAQEL
3+
BQAwJTEjMCEGA1UEAwwaRVNQMzIgSFRUUFMgc2VydmVyIGV4YW1wbGUwHhcNMTgx
4+
MDE3MTEzMjU3WhcNMjgxMDE0MTEzMjU3WjAlMSMwIQYDVQQDDBpFU1AzMiBIVFRQ
5+
UyBzZXJ2ZXIgZXhhbXBsZTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB
6+
ALBint6nP77RCQcmKgwPtTsGK0uClxg+LwKJ3WXuye3oqnnjqJCwMEneXzGdG09T
7+
sA0SyNPwrEgebLCH80an3gWU4pHDdqGHfJQa2jBL290e/5L5MB+6PTs2NKcojK/k
8+
qcZkn58MWXhDW1NpAnJtjVniK2Ksvr/YIYSbyD+JiEs0MGxEx+kOl9d7hRHJaIzd
9+
GF/vO2pl295v1qXekAlkgNMtYIVAjUy9CMpqaQBCQRL+BmPSJRkXBsYk8GPnieS4
10+
sUsp53DsNvCCtWDT6fd9D1v+BB6nDk/FCPKhtjYOwOAZlX4wWNSZpRNr5dfrxKsb
11+
jAn4PCuR2akdF4G8WLUeDWECAwEAAaNTMFEwHQYDVR0OBBYEFMnmdJKOEepXrHI/
12+
ivM6mVqJgAX8MB8GA1UdIwQYMBaAFMnmdJKOEepXrHI/ivM6mVqJgAX8MA8GA1Ud
13+
EwEB/wQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEBADiXIGEkSsN0SLSfCF1VNWO3
14+
emBurfOcDq4EGEaxRKAU0814VEmU87btIDx80+z5Dbf+GGHCPrY7odIkxGNn0DJY
15+
W1WcF+DOcbiWoUN6DTkAML0SMnp8aGj9ffx3x+qoggT+vGdWVVA4pgwqZT7Ybntx
16+
bkzcNFW0sqmCv4IN1t4w6L0A87ZwsNwVpre/j6uyBw7s8YoJHDLRFT6g7qgn0tcN
17+
ZufhNISvgWCVJQy/SZjNBHSpnIdCUSJAeTY2mkM4sGxY0Widk8LnjydxZUSxC3Nl
18+
hb6pnMh3jRq4h0+5CZielA4/a+TdrNPv/qok67ot/XJdY3qHCCd8O2b14OVq9jo=
19+
-----END CERTIFICATE-----
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/* Door Bell Demo
2+
3+
This example code is in the Public Domain (or CC0 licensed, at your option.)
4+
5+
Unless required by applicable law or agreed to in writing, this
6+
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
7+
CONDITIONS OF ANY KIND, either express or implied.
8+
*/
9+
10+
#pragma once
11+
12+
#include "settings.h"
13+
#include "media_sys.h"
14+
#include "network.h"
15+
#include "sys_state.h"
16+
17+
#ifdef __cplusplus
18+
extern "C" {
19+
#endif
20+
21+
/**
22+
* @brief Initialize for board
23+
*/
24+
void init_board(void);
25+
26+
/**
27+
* @brief Start WebRTC
28+
*
29+
* @param[in] url Signaling URL
30+
*
31+
* @return
32+
* - 0 On success
33+
* - Others Fail to start
34+
*/
35+
int start_webrtc(char *url);
36+
37+
/**
38+
* @brief Query WebRTC status
39+
*/
40+
void query_webrtc(void);
41+
42+
/**
43+
* @brief Stop WebRTC
44+
*
45+
* @return
46+
* - 0 On success
47+
* - Others Fail to stop
48+
*/
49+
int stop_webrtc(void);
50+
51+
/**
52+
* @brief Send command to peer
53+
*/
54+
void send_cmd(char *cmd);
55+
56+
#ifdef __cplusplus
57+
}
58+
#endif
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
## IDF Component Manager Manifest File
2+
dependencies:
3+
## Required IDF version
4+
idf:
5+
version: ">=5.0"
6+
## Import needed components only
7+
capture_audio_src:
8+
path: ../../../components/esp_capture/src/impl/capture_audio_src
9+
capture_video_src:
10+
path: ../../../components/esp_capture/src/impl/capture_video_src
11+
capture_audio_enc:
12+
path: ../../../components/esp_capture/src/impl/capture_audio_enc
13+
capture_video_enc:
14+
path: ../../../components/esp_capture/src/impl/capture_video_enc
15+
peer_default:
16+
path: ../../../components/esp_webrtc/impl/peer_default
17+
render_impl:
18+
path: ../../../components/av_render/render_impl
19+
espressif/esp_h264:
20+
version: "1.0.4"
21+
rules:
22+
- if: target in [esp32p4, esp32s3]
23+
espressif/esp_video:
24+
version: "^0.8.0"
25+
rules:
26+
- if: target in [esp32p4]

0 commit comments

Comments
 (0)