Skip to content

Commit d49ca6d

Browse files
authored
Merge pull request #1 from kind3r/NimBLE
Refactor to NimBLE + AP setup & web UI
2 parents b866a1e + a530eef commit d49ca6d

31 files changed

+1403
-170
lines changed

README.md

+9-8
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ Feeling generous and want to support my work, here is [my PayPal link](https://p
77

88

99
## What works for now
10-
- WiFi init
11-
- BLE init
10+
- WiFi init with AP style configuration via HTTPS web page
1211
- Websocket communication and AES 128 CBC auth
1312
- Start/stop BLE scan
1413
- Discover devices
@@ -29,11 +28,15 @@ This short guide explains how to install the gateway and configure the [TTLock H
2928

3029
### Preparing the ESP32
3130

32-
Open the cloned repo in VSCode and PlatformIO should automatically install all the required dependencies. After this is done, you need to create a `config.cpp` file in the src folder based on the `config.cpp.example` template. Update this config file with your WiFi credentials and a **random generated 128 bit AES key** that will be used for encryption during the authentication phase. You can use [online tools](https://www.allkeysgenerator.com/Random/Security-Encryption-Key-Generator.aspx) to generate the key.
31+
Open the cloned repo in VSCode and PlatformIO should automatically install all the required dependencies. You need to modify `sdkconfig.h` located in `.platformio/packages/framework-arduinoespressif32/tools/sdk/include/config` and change `CONFIG_ARDUINO_LOOP_STACK_SIZE` to `10240`. This is because the HTTPS certificate generation takes more stack space.
3332

3433
> At the moment, the project is only configured to work on **ESP32-WROVER boards**. If you have a different board, you need to edit the `platformio.ini` file and create your own env configuration. As of this writing the code takes about 1.5Mb so I'm using the `min_spiffs.csv` partition scheme in order to be able to hopefully do OTA in the future.
3534
36-
Connect your ESP32 to the PC, go to PlatformIO menu (the alien head on the VSCode's left toolbar, where you have files, search, plugins etc.) then in **Project Tasks** choose **env:esp-wrover** -> **General** -> **Upload and Monitor**. This should start the build process and once it is finished the compiled result will be uploaded to the ESP32. Once the upload finishes you should start seeing some debug output, including if the WiFi connection was succesfull and the **IP address of the device** (which you need for configuring the TTLock Home Assistant addon).
35+
Connect your ESP32 to the PC, go to PlatformIO menu (the alien head on the VSCode's left toolbar, where you have files, search, plugins etc.) then in **Project Tasks** choose **env:esp-wrover** -> **General** -> **Upload and Monitor**. This should start the build process and once it is finished the compiled result will be uploaded to the ESP32.
36+
37+
Once the upload finishes you should start seeing some debug output, including the status of the WiFi AP and HTTPS certificate generation status (it will take quite some time so be patient). After the startup is completed, you can connect to ESP's AP named **ESP32GW** with password **87654321** and access [https://esp32gw.local](https://esp32gw.local). The browser will complain about the self-signed certificate but you can ignore and continue. The default username and password are **admin/admin**. Configure your wifi credentials and copy the **AES Key** which you need to setup in the **TTLock Home Assistant addon**.
38+
39+
After saving the new configuration, the ESP will reboot, connect to your WiFi and output it's **IP address** on the serial port (it will also generate a new HTTPS certificate if you changed it's name). It will also be accessible via `esp32gw.local` (or the new name you gave it) via MDNS if this service is working in your network. You can still make configuration changes by accessing it's IP address in the browser.
3740

3841
### Setting up HA
3942

@@ -42,7 +45,7 @@ Once you have the ESP runing the gateway software, go to the **TTLock Home Assis
4245
```yaml
4346
gateway: noble
4447
gateway_host: IP_ADDRESS_OF_YOUR_ESP
45-
gateway_port: 80
48+
gateway_port: 8080
4649
gateway_key: AES_KEY_FROM_ESP_CONFIG
4750
gateway_user: admin
4851
gateway_pass: admin
@@ -60,10 +63,8 @@ If everything was done correctly you should not be able to use the addon using t
6063
- check if multiple connections to multiple devices are possible (`BLEDevice::createClient` seems to store only 1 `BLEClient`, but we could just create the client ourselfs)
6164
- Service UUID filtering for scan and allow/disallow duplicates
6265
- Timeout for non-authenticated connections
63-
- Initial wifi AP based setup
64-
- Web configuration for AES key and credentials
6566
- Investigate unstable wifi (sometimes it connects but there is no traffic; try to ping gw during setup)
66-
- Troubleshoot random crashes
67+
- Optimize memory fragmentation
6768

6869
### Random thoughts
6970

data/index.html.gz

136 KB
Binary file not shown.

platformio.ini

+16-6
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,28 @@ framework = arduino
1414
monitor_speed = 921600
1515
upload_speed = 921600
1616
lib_deps =
17-
bblanchon/ArduinoJson @ ^6.17.2
17+
bblanchon/ArduinoJson@^6.17.2
1818
links2004/WebSockets@^2.3.3
19+
; h2zero/NimBLE-Arduino@^1.1.0
20+
[email protected]:h2zero/NimBLE-Arduino.git#refactor-advertised-device
21+
esp32_https_server@^1.0.0
1922
monitor_filters = esp32_exception_decoder
20-
build_type = debug
2123
platform_packages =
22-
platformio/framework-arduinoespressif32 @ https://github.com/kind3r/arduino-esp32.git
24+
platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git
2325
board_build.partitions = min_spiffs.csv
2426

25-
[env:esp-wrover]
27+
[env:esp-wrover-debug]
2628
board = esp-wrover-kit
29+
build_type = debug
2730
build_flags =
31+
-DCORE_DEBUG_LEVEL=5
2832
; -DBOARD_HAS_PSRAM
29-
; -DCONFIG_LOG_DEFAULT_LEVEL=5
33+
; -mfix-esp32-psram-cache-issue
3034
-DLOG_LOCAL_LEVEL=ESP_LOG_VERBOSE
31-
; -DCONFIG_LOG_DEFAULT_LEVEL=ESP_LOG_DEBUG
35+
36+
[env:esp-wrover]
37+
board = esp-wrover-kit
38+
build_flags =
39+
; -DBOARD_HAS_PSRAM
40+
; -mfix-esp32-psram-cache-issue
41+
; -DCORE_DEBUG_LEVEL=5

0 commit comments

Comments
 (0)