Skip to content

Commit

Permalink
use regex to read bluetooth address from cache
Browse files Browse the repository at this point in the history
  • Loading branch information
William C Bonner committed Oct 4, 2023
1 parent a6eeb17 commit 453f3d4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ if (POLICY CMP0141)
endif()

project (GoveeBTTempLogger
VERSION 2.20231003.1
VERSION 2.20231004.1
DESCRIPTION "Listen and log Govee Thermometer Bluetooth Low Energy Advertisments"
HOMEPAGE_URL https://github.com/wcbonner/GoveeBTTempLogger
)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ ExecStart=/usr/local/bin/goveebttemplogger \
--verbose 0 \
--log /var/log/goveebttemplogger \
--time 60 \
--svg /var/www/html/goveebttemplogger --battery 8 --minmax 8 --titlemap /var/www/html/goveebttemplogger/gvh-titlemap.txt \
--svg /var/www/html/goveebttemplogger --battery 8 --minmax 8 \
--cache /var/cache/goveebttemplogger \
--download
KillSignal=SIGINT
Expand Down
35 changes: 25 additions & 10 deletions goveebttemplogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1158,18 +1158,23 @@ void ReadCacheDirectory(void)
// I should check to make sure the version is compatible
if (std::regex_match(TheLine, CacheFirstLineRegex))
{
bdaddr_t TheBlueToothAddress;
str2ba(TheLine.substr(7, 17).c_str(), &TheBlueToothAddress);
std::vector<Govee_Temp> FakeMRTGFile;
FakeMRTGFile.reserve(2 + DAY_COUNT + WEEK_COUNT + MONTH_COUNT + YEAR_COUNT); // this might speed things up slightly
while (std::getline(TheFile, TheLine))
const std::regex BluetoothAddressRegex("((([[:xdigit:]]{2}:){5}))[[:xdigit:]]{2}");
auto btaddress_begin = std::sregex_iterator(TheLine.begin(), TheLine.end(), BluetoothAddressRegex);
if (btaddress_begin != std::sregex_iterator()) // double check that address was properly found
{
Govee_Temp value;
value.ReadCache(TheLine);
FakeMRTGFile.push_back(value);
bdaddr_t TheBlueToothAddress;
str2ba(btaddress_begin->str().c_str(), &TheBlueToothAddress);
std::vector<Govee_Temp> FakeMRTGFile;
FakeMRTGFile.reserve(2 + DAY_COUNT + WEEK_COUNT + MONTH_COUNT + YEAR_COUNT); // this might speed things up slightly
while (std::getline(TheFile, TheLine))
{
Govee_Temp value;
value.ReadCache(TheLine);
FakeMRTGFile.push_back(value);
}
if (FakeMRTGFile.size() == (2 + DAY_COUNT + WEEK_COUNT + MONTH_COUNT + YEAR_COUNT)) // simple check to see if we are the right size
GoveeMRTGLogs.insert(std::pair<bdaddr_t, std::vector<Govee_Temp>>(TheBlueToothAddress, FakeMRTGFile));
}
if (FakeMRTGFile.size() == (2 + DAY_COUNT + WEEK_COUNT + MONTH_COUNT + YEAR_COUNT)) // simple check to see if we are the right size
GoveeMRTGLogs.insert(std::pair<bdaddr_t, std::vector<Govee_Temp>>(TheBlueToothAddress, FakeMRTGFile));
}
}
TheFile.close();
Expand Down Expand Up @@ -1709,6 +1714,16 @@ void ReadLoggedData(const std::filesystem::path& filename)
bdaddr_t TheBlueToothAddress;
str2ba(ssBTAddress.c_str(), &TheBlueToothAddress);

//const std::regex BluetoothAddressRegex("[[:xdigit:]]{12}");
//auto btaddress_begin = std::sregex_iterator(filename.stem().string().begin(), filename.stem().string().end(), BluetoothAddressRegex);
//if (btaddress_begin != std::sregex_iterator()) // double check that address was properly found
//{
// std::string ssBTAddress(btaddress_begin->str());
// for (auto index = ssBTAddress.length() - 2; index > 0; index -= 2)
// ssBTAddress.insert(index, ":");
// bdaddr_t TheBlueToothAddress;
// str2ba(ssBTAddress.c_str(), &TheBlueToothAddress);

// Only read the file if it's newer than what we may have cached
bool bReadFile = true;
struct stat64 FileStat;
Expand Down

0 comments on commit 453f3d4

Please sign in to comment.