Skip to content

Commit

Permalink
Add hci_le_set_random_address function to fix #50
Browse files Browse the repository at this point in the history
  • Loading branch information
William C Bonner committed Nov 29, 2023
1 parent e917527 commit 537e621
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ if (CMAKE_VERSION VERSION_GREATER 3.22)
endif()

project (GoveeBTTempLogger
VERSION 2.20231127.0
VERSION 2.20231129.0
DESCRIPTION "Listen and log Govee Thermometer Bluetooth Low Energy Advertisments"
HOMEPAGE_URL https://github.com/wcbonner/GoveeBTTempLogger
)
Expand Down
24 changes: 24 additions & 0 deletions goveebttemplogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,29 @@ int hci_le_set_ext_scan_enable(int dd, uint8_t enable, uint8_t filter_dup, int t
return 0;
}
#endif // !BT_HCI_CMD_LE_SET_EXT_SCAN_ENABLE
#ifndef BT_HCI_CMD_LE_SET_RANDOM_ADDRESS
// 2023-11-29 Added this function to fix problem with Raspberry Pi Zero 2 W Issue https://github.com/wcbonner/GoveeBTTempLogger/issues/50
int hci_le_set_random_address(int dd, int to)
{
le_set_random_address_cp scan_cp; //TODO: this should be initialized, right now I'm letting it use random data from the stack.
uint8_t status;
struct hci_request rq;
memset(&rq, 0, sizeof(rq));
rq.ogf = OGF_LE_CTL;
rq.ocf = OCF_LE_SET_RANDOM_ADDRESS;
rq.cparam = &scan_cp;
rq.clen = sizeof(scan_cp);
rq.rparam = &status;
rq.rlen = 1;
if (hci_send_req(dd, &rq, to) < 0)
return -1;
if (status) {
errno = EIO;
return -1;
}
return 0;
}
#endif // BT_HCI_CMD_LE_SET_RANDOM_ADDRESS
/////////////////////////////////////////////////////////////////////////////
int ConsoleVerbosity(1);
bool UseBluetooth(true);
Expand Down Expand Up @@ -3257,6 +3280,7 @@ int main(int argc, char **argv)
std::cerr << "[ ] Error: Could set device to non-blocking: " << strerror(errno) << std::endl;
else
{
hci_le_set_random_address(BlueToothDevice_Handle, bt_TimeOut); // 2023-11-29 Added this command to fix problem with Raspberry Pi Zero 2 W Issue #50
char LocalName[HCI_MAX_NAME_LENGTH] = { 0 };
hci_read_local_name(BlueToothDevice_Handle, sizeof(LocalName), LocalName, bt_TimeOut);

Expand Down

0 comments on commit 537e621

Please sign in to comment.