keyble-bridge

Forked from https://github.com/lumokitho/esp32-keyble
License: eQ3 lib is LGPL, everything else MPL
Last update: Tue Feb 21 16:43:56 2023 +0100
Download: git clone https://www.erwinsaumweber.com/repos/keyble-bridge.git

Control an eQ-3 equiva Key-BLE “Bluetooth® Smart Türschlossantrieb” lock via wifi, serial or usb connection. It uses an ESP32 for bridging bluetooth to serial and an ESP8266 for bridging serial to wifi.

You can use the supplied node.js client or write your own. It’s a simple text-based protocol.

Assembled keyble-bridge electronics

Differences to lumikitho/esp32-keyble

Getting started

Prerequisites

Wifi bridge setup (ESP32 + ESP8266)

In the keyble-serial-bridge folder:

In the serial-websocket-bridge folder:

Solder four wires to connect the boards: 5V to 5V, GND to GND, RX to TX and TX to RX. You can find the serial GPIO numbers in the defines in the two main.cpp files.

In the node-client folder:

Serial over USB setup (ESP32)

The protocol messages get intermixed with debug messages. A prefix is used to differentiate them.

In the keyble-serial-bridge folder:

In the node-client folder:

Serial setup (ESP32)

Connect the ESP32’s serial2 RX and TX pins to another 3.3V serial port, e.g. a Raspberry Pi’s UART TX and RX. If you use separate power sources, connect GND, too.

In the node-client folder:

Serial protocol

Have a look at the node-client, it’s not complicated.

The node-client’s changeState events

lock_status string

If needs_open ist true, UNKNOWN really means the position is unknown. Otherwise it means the position is somewhere between locked and unlocked.

battery_low flag

The lock sets this flag if the voltage drops below a certain threshold. While using a lab power supply I found out it does not get cleared if you turn the voltage up again. You need to power cycle the lock.

needs_open flag

After the lock was without power by a battery change, the Android app only allows you to trigger the open action. This seems to be necessary for the lock to get into a known state. Until then, the unlock action does nothing. Curiously, the lock action always works despite the display in the app. If you ever only use lock and open you can ignore this flag.

Also, if the battery is low, the lock does not get out of needs_open state.

Miscellaneous

Troubleshooting

Look at the output of the ESP’s usb-serial to narrow down what’s not working by running pio device monitor. If you connect both boards at the same time, unsolder the GND and 5V wire to avoid loops.

The ESP32 is quite sensible to the power supply

Use a good power supply. If using the Micro-USB connector, prefer to connect to the ESP32 board. Power issues did manifest on my setup by going into boot loop by crashing on BLEDevice::init("");.

The bridge needs to be close to the lock

To get a reliable connection there should be no object between the bridge and the lock. 2-3m distance should be fine, depending on the bridge encasing.

The node interface is not a drop-in replacement for oyooyo’s keyble lib

Although similar, some things are handled differently:

The led turns off when …

Contrary to its name, the node client is a server

I did not find an example of setting up a SSL websocket server on the ESP8266, so now it is the other way round.

The websocket connection uses an SHA-1 fingerprint, which is insecure

If your biggest concern is that an attacker spends some thousand dollars on GPU time to break the encryption, please fix the websocket library to use another hashing algorithm. In my usage scenario this is no issue.

Thanks

Thanks go to lumokitho, RoP09, tc-maxx, henfri, MariusSchiffer and of course oyooyo for their brilliant work!