Skip to content

Commit 4c2940c

Browse files
wcbonnerWilliam C Bonner
andauthored
Syslog report dbus download (#86)
* syslog message when data is requested * Log requesting data and most recent data * Only outpuit LastDownloadTime if it is nonzero * add ThermometerType to Last Download message * fix inclorrect indenting * fix regression of version number --------- Co-authored-by: William C Bonner <[email protected]>
1 parent 0c34329 commit 4c2940c

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ endif()
2323
add_compile_definitions(_BLUEZ_HCI_)
2424

2525
project (GoveeBTTempLogger
26-
VERSION 3.20250618.0
26+
VERSION 3.20250623.0
2727
DESCRIPTION "Listen and log Govee Thermometer Bluetooth Low Energy Advertisments via BlueZ and DBus"
2828
HOMEPAGE_URL https://github.com/wcbonner/GoveeBTTempLogger
2929
)

goveebttemplogger.cpp

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4290,6 +4290,16 @@ void bluez_device_download(DBusConnection* dbus_conn, const char* adapter_path,
42904290
ssOutput << std::dec << std::endl;
42914291
}
42924292
dbus_message_unref(dbus_msg_write);
4293+
4294+
if (ConsoleVerbosity > 0)
4295+
ssOutput << "[" << getTimeISO8601(true) << "] ";
4296+
ssOutput << "Request Download from device: [" << ba2string(dbusBTAddress) << "]";
4297+
ssOutput << " " << timeToExcelLocal(TimeDownloadStart-(DataPointsToRequest*60)) << " " << timeToExcelLocal(TimeDownloadStart);
4298+
ssOutput << " (" << std::dec << DataPointsToRequest << ")";
4299+
auto downloadtype = GoveeThermometers.find(dbusBTAddress);
4300+
if (downloadtype != GoveeThermometers.end())
4301+
ssOutput << " " << ThermometerType2String(downloadtype->second);
4302+
ssOutput << std::endl;
42934303
}
42944304
}
42954305
#ifdef OLD_GET_UUIDS
@@ -4716,6 +4726,24 @@ std::string bluez_dbus_msg_iter(DBusMessageIter& array_iter, const bdaddr_t& dbu
47164726
if (ConsoleVerbosity > 3)
47174727
ssOutput << " " << Key << ": " << std::boolalpha << bool(value.bool_val);
47184728
bluez_in_use = bool(value.bool_val);
4729+
if (!bool(value.bool_val))
4730+
{
4731+
time_t LastDownloadTime = 0;
4732+
auto RecentDownload = GoveeLastDownload.find(dbusBTAddress);
4733+
if (RecentDownload != GoveeLastDownload.end())
4734+
LastDownloadTime = RecentDownload->second;
4735+
if (LastDownloadTime != 0)
4736+
{
4737+
if (!ssOutput.str().empty())
4738+
ssOutput << std::endl << ssStartLine.str();
4739+
ssOutput << " Last Download from device: [" << ba2string(dbusBTAddress) << "] " << timeToExcelLocal(LastDownloadTime);;
4740+
auto downloadtype = GoveeThermometers.find(dbusBTAddress);
4741+
if (downloadtype != GoveeThermometers.end())
4742+
ssOutput << " " << ThermometerType2String(downloadtype->second);
4743+
if (ConsoleVerbosity < 1)
4744+
ssOutput << std::endl;
4745+
}
4746+
}
47194747
}
47204748
}
47214749
else if (!Key.compare("ServicesResolved"))
@@ -4818,13 +4846,7 @@ std::string bluez_dbus_msg_iter(DBusMessageIter& array_iter, const bdaddr_t& dbu
48184846
LastReportedTime = localTemp.Time;
48194847
}
48204848
if (LastReportedTime != 0)
4821-
{
4822-
auto RecentDownload = GoveeLastDownload.find(dbusBTAddress);
4823-
if (RecentDownload != GoveeLastDownload.end())
4824-
RecentDownload->second = LastReportedTime;
4825-
else
4826-
GoveeLastDownload.insert_or_assign(dbusBTAddress, LastReportedTime);
4827-
}
4849+
GoveeLastDownload.insert_or_assign(dbusBTAddress, LastReportedTime);
48284850
if (offset < 1) // If offset is 6 or less we are in the last bit of data, and as soon as we decode it we can close the connection.
48294851
bluez_disconnect = true;
48304852
}
@@ -5078,6 +5100,8 @@ void bluez_dbus_msg_InterfacesAdded(DBusMessage* dbus_msg, bdaddr_t & dbusBTAddr
50785100
}
50795101
if (ConsoleVerbosity > 1)
50805102
std::cout << ssOutput.str();
5103+
else
5104+
std::cerr << ssOutput.str();
50815105
}
50825106
void bluez_dbus_msg_PropertiesChanged(DBusMessage* dbus_msg, bdaddr_t& dbusBTAddress, const std::set<bdaddr_t> & BT_WhiteList, const time_t& TimeNow)
50835107
{
@@ -5115,6 +5139,8 @@ void bluez_dbus_msg_PropertiesChanged(DBusMessage* dbus_msg, bdaddr_t& dbusBTAdd
51155139
}
51165140
if (ConsoleVerbosity > 1)
51175141
std::cout << ssOutput.str();
5142+
else
5143+
std::cerr << ssOutput.str();
51185144
}
51195145
/////////////////////////////////////////////////////////////////////////////
51205146
time_t ConnectAndDownload(DBusConnection* dbus_conn, const char* adapter_path, const bdaddr_t& dbusBTAddress, const time_t GoveeLastReadTime = 0, const int BatteryToRecord = 0)

0 commit comments

Comments
 (0)