Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 4 additions & 29 deletions components/tesla_ble_listener/tesla_ble_listener.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#include "tesla_ble_listener.h"
#include "esphome/core/log.h"
#include "mbedtls/sha1.h"
#include <vin_utils.h>
#include <string>
#include <cinttypes>

namespace esphome
{
Expand All @@ -12,33 +11,9 @@ namespace esphome

std::string get_vin_advertisement_name(const char *vin)
{
// * BLE advertisement local name: `S + <ID> + C`, where `<ID>` is the
// lower-case hex-encoding of the first eight bytes of the SHA1 digest of the
// Vehicle Identification Number (VIN). For example, If the VIN is
// `5YJS0000000000000`, then the BLE advertisement Local Name is
// `S1a87a5a75f3df858C`.

unsigned char vin_sha1[20];
size_t vin_length = 17; // Assuming standard VIN length
int return_code = mbedtls_sha1((const unsigned char *)vin, vin_length, vin_sha1);
if (return_code != 0)
{
ESP_LOGE(TAG, "Failed to calculate SHA1 of VIN");
return "";
}

char result[19]; // 'S' + 16 hex chars + 'C' + null terminator
result[0] = 'S';
for (int i = 0; i < 8; i++)
{
snprintf(&result[1 + i * 2], 3, "%02x", vin_sha1[i]);
}
result[17] = 'C';
result[18] = '\0'; // Null terminator for safe printing

std::string result_str(result);
ESP_LOGD(TAG, "VIN advertisement name: %s", result_str.c_str());
return result_str;
std::string result = TeslaBLE::getVINAdvertisementName(vin);
ESP_LOGD(TAG, "VIN advertisement name: %s", result.c_str());
return result;
}

bool TeslaBLEListener::parse_device(const esp32_ble_tracker::ESPBTDevice &device)
Expand Down
2 changes: 1 addition & 1 deletion packages/board.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ esp32:
components:
- name: tesla-ble
source: https://github.com/yoziru/tesla-ble.git
ref: v3.3.2
ref: v3.4.0