Config
Custom code for locking, unlocking etc.
Locking
Unlocking
Opening Trunk
Staring Engine
Other Events
OnConnected & OnDisconnected
bluetooth.h
onConnected
onDisconnected
onLocked
onUnlocked
onTrunkOpened
onEngineStarted
deviceConnected
autoLocking
isLocked
setupBluetooth
bluetoothLoop
Ble communication protocol
Open platformio.ini. There you can set your password (LOCK_PIN) and BLE device name (DEVICE_NAME).
To handle locking you need to assign a function to onLocked in setup() like (in src/main.cpp):
void lock(bool proximity)
{
//Your code for locking
Serial.println("Locked");
}
void setup()
{
// Other code..
onLocked = lock;
// Other code..
}To handle unlocking you need to assign a function to onUnlocked in setup() like (in src/main.cpp):
void unlock(bool proximity)
{
//Your code for unlocking
Serial.println("Unlocked");
}
void setup()
{
// Other code..
onUnlocked = unlock;
// Other code..
}To handle trunk opening you need to assign a function to onTrunkOpened in setup() like (in src/main.cpp):
void openTrunk()
{
//Your code for opening trunk
Serial.println("Trunk Opened");
}
void setup()
{
// Other code..
onTrunkOpened = openTrunk;
// Other code..
}To handle starting of the engine you need to assign a function to onEngineStarted in setup() like (in src/main.cpp):
void startEngine()
{
//Your code for staring engine
Serial.println("Engine Started");
}
void setup()
{
// Other code..
onEngineStarted = startEngine;
// Other code..
}If you want to call custom code when the app connects ot disconnects you can do the same as before for onConnected and onDisconnected
void connected()
{
Serial.println("App connected");
}
void disconnected()
{
}
void setup()
{
// Other code..
onConnected = connected;
onDisconnected = disconnected;
// Other code..
}Everything you can access from main.cpp (#include "bluetooth.h")
extern void (*onConnected)()Called when the device is connected (for additional custom actions)
extern void (*onDisconnected)()Called when the device is disconnected (for additional custom actions)
extern void (*onLocked)(bool proximity)Called when the car gets locked
extern void (*onUnlocked)(bool proximity)Called when the car gets unlocked
extern void (*onTrunkOpened)()Called when the trunk gets opened
extern void (*onEngineStarted)()Called when the engine gets started from the app
extern bool deviceConnectedIs the ESP is connected to the phone
extern bool autoLockingIs proximity key enabled
extern bool isLockedIs the car locked
void setupBluetooth()Sets up bluetooth
void bluetoothLoop()Loop need for bluetooth to work
Communication protocol between ESP and App.
32 byte HMAC + 1 byte command (+ optional additional data length + bytes)
1 byte command (+ optional additional data length + bytes)
| Message | Response |
|---|---|
0x00 (GET_VERSION) |
0x01 + {Current protocol version str} (VERSION) |
| Anything with no/invalid rolling code (HMAC) | 0x00 (INVALID_HMAC) |
0x01 (GET_DATA) |
0x02 (LOCKED) or 0x04 (UNLOCKED) |
0x02 (LOCK_DOORS) |
0x02 (LOCKED) |
0x03 (UNLOCK_DOORS) |
0x04 (UNLOCKED) |
0x04 (OPEN_TRUNK) |
None |
0x05 (START_ENGINE) |
None |
0x06 (STOP_ENGINE) |
None |
0x07 (PROXIMITY_KEY_ON) |
None |
0x08 (PROXIMITY_KEY_OFF) |
None |
0x09 + {Proximity cooldown float in min} (PROXIMITY_COOLDOWN) |
None |
0x0A + {Rssi float, Rssi dead zone float} (RSSI_TRIGGER) |
None |
0x0B (GET_RSSI) |
0x06 + {Rssi float} (RSSI) can take 500ms |
0x0C (GET_FEATURES) |
0x07 + {int bitmask} (FEATURES) |
RSSI_TRIGGER (0x0A) sets the rssi strength where proximity key will unlock and the zone (in rough meters) where nothing will happen. Eg. 5m: After the car was locked you have to get around 5m closer to it to unlock again. This is to prevent rapid locking and unlocking if you are at the exact trigger distance
| Message from ESP | Description |
|---|---|
0x03 (PROXIMITY_LOCKED) |
Vehicle was locked using proximity key |
0x05 (PROXIMITY_UNLOCKED) |
Vehicle was unlocked using proximity key |