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
isAuthenticated
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()
{
//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()
{
//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)()Called when the car gets locked
extern void (*onUnlocked)()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 isAuthenticatedIs the currently connected phone authenticated
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.
| Message | Response |
|---|---|
AUTH:{Password String} |
AUTH_OK or AUTH_FAIL |
| Anything while not authenticated | NOT_AUTH |
SEND_DATA |
LOCKED or UNLOCKED |
LOCK |
LOCKED |
UNLOCK |
UNLOCKED |
OPEN_TRUNK |
None |
START_ENGINE |
None |
PROX_KEY_ON |
None |
PROX_KEY_OFF |
None |
RSSI_TRIG:{Rssi float, Rssi dead zone float} |
None |
PROX_COOLD:{Proximity cooldown float in min} |
None |
RSSI |
RSSI:{Rssi float} can take 500ms |
RSSI_TRIG: 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 |
|---|---|
UNLOCKED_PROX |
Vehicle was unlocked using proximity key |
LOCKED_PROX |
Vehicle was locked using proximity key |