Skip to content

Commit

Permalink
reduce syslog message while allowing download attempts
Browse files Browse the repository at this point in the history
  • Loading branch information
William C Bonner committed Sep 6, 2023
1 parent 81cd2f0 commit 5e78e87
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
2 changes: 1 addition & 1 deletion GoveeBTTempLogger/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: GoveeBTTempLogger
Version: 2.20230902-1
Version: 2.20230906-1
Section: custom
Priority: optional
Architecture: armhf
Expand Down
40 changes: 22 additions & 18 deletions goveebttemplogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
#include "uuid.h"

/////////////////////////////////////////////////////////////////////////////
static const std::string ProgramVersionString("GoveeBTTempLogger Version 2.20230902-1 Built on: " __DATE__ " at " __TIME__);
static const std::string ProgramVersionString("GoveeBTTempLogger Version 2.20230906-1 Built on: " __DATE__ " at " __TIME__);
/////////////////////////////////////////////////////////////////////////////
std::string timeToISO8601(const time_t & TheTime, const bool LocalTime = false)
{
Expand Down Expand Up @@ -2114,9 +2114,18 @@ int bt_LEScan(int BlueToothDevice_Handle, const bool enable, const std::set<bdad
else
{
if (ConsoleVerbosity > 0)
std::cout << "[" << getTimeISO8601() << "] Scanning Started. ScanInterval(" << double(bt_ScanInterval)*0.625 << " msec) ScanWindow(" << double(bt_ScanWindow)*0.625 << " msec) ScanType(" << uint(bt_ScanType) << ")" << std::endl;
std::cout << "[" << getTimeISO8601() << "] Scanning Started. ScanInterval(" << double(bt_ScanInterval) * 0.625 << " msec) ScanWindow(" << double(bt_ScanWindow) * 0.625 << " msec) ScanType(" << uint(bt_ScanType) << ")" << std::endl;
else
std::cerr << ProgramVersionString << " (listening for Bluetooth Low Energy Advertisements) ScanInterval(" << double(bt_ScanInterval) * 0.625 << " msec) ScanWindow(" << double(bt_ScanWindow) * 0.625 << " msec) ScanType(" << uint(bt_ScanType) << ")" << std::endl;
{
time_t TimeNow;
time(&TimeNow);
static time_t LastScanEnableMessage = TimeNow;
if (difftime(TimeNow, LastScanEnableMessage) > (60 * 5)) // Reduce Spamming Syslog
{
LastScanEnableMessage = TimeNow;
std::cerr << ProgramVersionString << " (listening for Bluetooth Low Energy Advertisements) ScanInterval(" << double(bt_ScanInterval) * 0.625 << " msec) ScanWindow(" << double(bt_ScanWindow) * 0.625 << " msec) ScanType(" << uint(bt_ScanType) << ")" << std::endl;
}
}
}
}
}
Expand Down Expand Up @@ -3275,24 +3284,19 @@ int main(int argc, char **argv)
LastDownloadTime = RecentDownload->second;
time_t TimeNow;
time(&TimeNow);
static time_t LastDownloadAttemptTime = TimeNow;
if (difftime(TimeNow, LastDownloadAttemptTime) > (60 * 5)) // Only attempt a download if it's been longer than 5 minutes since the last attempt
// Don't try to download more often than once a week, because it uses more battery than just the advertisments
if (difftime(TimeNow, LastDownloadTime) > (60 * 60 * 24 * DaysBetweenDataDownload))
{
LastDownloadAttemptTime = TimeNow;
// Don't try to download more often than once a week, because it uses more battery than just the advertisments
if (difftime(TimeNow, LastDownloadTime) > (60 * 60 * 24 * DaysBetweenDataDownload))
bt_LEScan(BlueToothDevice_Handle, false, BT_WhiteList);
time_t DownloadTime = ConnectAndDownload(BlueToothDevice_Handle, info->bdaddr, LastDownloadTime, BatteryToRecord);
if (DownloadTime > 0)
{
bt_LEScan(BlueToothDevice_Handle, false, BT_WhiteList);
time_t DownloadTime = ConnectAndDownload(BlueToothDevice_Handle, info->bdaddr, LastDownloadTime, BatteryToRecord);
if (DownloadTime > 0)
{
if (RecentDownload != GoveeLastDownload.end())
RecentDownload->second = DownloadTime;
else
GoveeLastDownload.insert(std::pair<bdaddr_t, time_t>(info->bdaddr, DownloadTime));
}
bt_LEScan(BlueToothDevice_Handle, true, BT_WhiteList);
if (RecentDownload != GoveeLastDownload.end())
RecentDownload->second = DownloadTime;
else
GoveeLastDownload.insert(std::pair<bdaddr_t, time_t>(info->bdaddr, DownloadTime));
}
bt_LEScan(BlueToothDevice_Handle, true, BT_WhiteList);
}
}
}
Expand Down

0 comments on commit 5e78e87

Please sign in to comment.