Skip to content

Commit

Permalink
Minor data check when reading log files
Browse files Browse the repository at this point in the history
  • Loading branch information
wcbonner committed Mar 14, 2021
1 parent f60a44d commit 041eecb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 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.20210308-1
Version: 2.20210314-1
Section: custom
Priority: optional
Architecture: armhf
Expand Down
22 changes: 13 additions & 9 deletions goveebttemplogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@


/////////////////////////////////////////////////////////////////////////////
static const std::string ProgramVersionString("GoveeBTTempLogger Version 2.20210308-1 Built on: " __DATE__ " at " __TIME__);
static const std::string ProgramVersionString("GoveeBTTempLogger Version 2.20210314-1 Built on: " __DATE__ " at " __TIME__);
/////////////////////////////////////////////////////////////////////////////
std::string timeToISO8601(const time_t & TheTime)
{
Expand Down Expand Up @@ -1188,14 +1188,18 @@ void ReadLoggedData(void)
char buffer[256];
if (TheLine.size() < sizeof(buffer))
{
TheLine.copy(buffer, TheLine.size());
buffer[TheLine.size()] = '\0';
std::string theDate(strtok(buffer, "\t"));
std::string theTemp(strtok(NULL, "\t"));
std::string theHumidity(strtok(NULL, "\t"));
std::string theBattery(strtok(NULL, "\t"));
Govee_Temp TheValue(ISO8601totime(theDate), atof(theTemp.c_str()), atof(theHumidity.c_str()), atol(theBattery.c_str()));
UpdateMRTGData(TheBlueToothAddress, TheValue);
// minor garbage check looking for corrupt data with no tab characters
if (TheLine.find('\t') != std::string::npos)
{
TheLine.copy(buffer, TheLine.size());
buffer[TheLine.size()] = '\0';
std::string theDate(strtok(buffer, "\t"));
std::string theTemp(strtok(NULL, "\t"));
std::string theHumidity(strtok(NULL, "\t"));
std::string theBattery(strtok(NULL, "\t"));
Govee_Temp TheValue(ISO8601totime(theDate), atof(theTemp.c_str()), atof(theHumidity.c_str()), atol(theBattery.c_str()));
UpdateMRTGData(TheBlueToothAddress, TheValue);
}
}
}
TheFile.close();
Expand Down

0 comments on commit 041eecb

Please sign in to comment.