Skip to content

Commit

Permalink
Set unique bluetooth name and allow customization (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
nisargjhaveri authored Sep 20, 2024
1 parent b4c85d8 commit 6aecca6
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ You may want to update the `country_code` in the `/etc/hostapd.conf` file.
- On **Raspberry Pi Zero W** and **Raspberry Pi Zero 2 W**: Use the second micro-usb port marked "USB" and not "PWR".
- On **Raspberry Pi 3 A+**: Use the only USB-A port with an USB-A to USB-A cable.
- On **Raspberry Pi 4**, use the USB-C port user for normally powering the board.
- Open Bluetooth settings and pair the new device called "AndroidAuto-Dongle" or "AA Wireless Dongle" on your phone.
- Open Bluetooth settings and pair the new device called `AndroidAuto-Dongle-*` or `WirelessAADongle-*` on your phone.
- After this phone should automatically connect via Wifi and the dongle will connect to the headunit via USB and start Android Auto on the car screen.

### Subsequent connections
Expand Down
5 changes: 5 additions & 0 deletions aa_wireless_dongle/board/common/rootfs_overlay/etc/aawgd.env
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@
# 1 - Phone first (default). Waits for the phone bluetooth and wifi to connect first, and then starts the usb connection.
# 2 - Usb first. Waits for the usb to connect first, and then starts the bluetooth and wifi connection with phone.
AAWG_CONNECTION_STRATEGY=1


# Override bluetooth name suffix
# Set a custom suffix to replace unique id used in "WirelessAADongle-<suffix>" or "AndroidAuto-Dongle-<suffix>"
#AAWG_UNIQUE_NAME_SUFFIX=
9 changes: 6 additions & 3 deletions aa_wireless_dongle/package/aawg/src/bluetoothHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include "bluetoothProfiles.h"
#include "bluetoothAdvertisement.h"

static constexpr const char* ADAPTER_ALIAS = "AA Wireless Dongle";
static constexpr const char* ADAPTER_ALIAS_DONGLE = "AndroidAuto-Dongle";
static constexpr const char* ADAPTER_ALIAS_PREFIX = "WirelessAADongle-";
static constexpr const char* ADAPTER_ALIAS_DONGLE_PREFIX = "AndroidAuto-Dongle-";

static constexpr const char* BLUEZ_BUS_NAME = "org.bluez";
static constexpr const char* BLUEZ_ROOT_OBJECT_PATH = "/";
Expand Down Expand Up @@ -90,6 +90,7 @@ void BluetoothHandler::initAdapter() {
else {
m_adapter = BluezAdapterProxy::create(m_connection, adapter_path);
m_adapter->alias->set_value(m_adapterAlias);
Logger::instance()->info("Bluetooth adapter alias: %s\n", m_adapterAlias.c_str());
}
}

Expand Down Expand Up @@ -248,7 +249,9 @@ void BluetoothHandler::init() {
m_dispatcher = DBus::StandaloneDispatcher::create();
m_connection = m_dispatcher->create_connection( DBus::BusType::SYSTEM );

m_adapterAlias = (Config::instance()->getConnectionStrategy() == ConnectionStrategy::DONGLE_MODE) ? ADAPTER_ALIAS_DONGLE : ADAPTER_ALIAS;
std::string adapterAliasPrefix = (Config::instance()->getConnectionStrategy() == ConnectionStrategy::DONGLE_MODE) ? ADAPTER_ALIAS_DONGLE_PREFIX : ADAPTER_ALIAS_PREFIX;

m_adapterAlias = adapterAliasPrefix + Config::instance()->getUniqueSuffix();

initAdapter();
exportProfiles();
Expand Down
17 changes: 17 additions & 0 deletions aa_wireless_dongle/package/aawg/src/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,23 @@ std::string Config::getMacAddress(std::string interface) {
return macAddress;
}

std::string Config::getUniqueSuffix() {
std::string uniqueSuffix = getenv("AAWG_UNIQUE_NAME_SUFFIX", "");
if (!uniqueSuffix.empty()) {
return uniqueSuffix;
}

std::ifstream serialNumberFile("/sys/firmware/devicetree/base/serial-number");

std::string serialNumber;
getline(serialNumberFile, serialNumber);

// Removing trailing null from serialNumber, pad at the beginning
serialNumber = std::string("00000000") + serialNumber.c_str();

return serialNumber.substr(serialNumber.size() - 6);
}

WifiInfo Config::getWifiInfo() {
return {
getenv("AAWG_WIFI_SSID", "AAWirelessDongle"),
Expand Down
2 changes: 2 additions & 0 deletions aa_wireless_dongle/package/aawg/src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class Config {

WifiInfo getWifiInfo();
ConnectionStrategy getConnectionStrategy();

std::string getUniqueSuffix();
private:
Config() = default;

Expand Down

0 comments on commit 6aecca6

Please sign in to comment.