Skip to content

Commit

Permalink
sensor logging. (#14)
Browse files Browse the repository at this point in the history
* Show sensor errors on oled, tft and web interface.

Added a url '/api/setdevice/sensorlogging?sensorlogging=true' to control logging during runtime.

* Added sensor logging options to the web interface.

* Increased size of tftButton::text to 25 chars.

* Removed function 'checkAuth' and whitespace.

* Show branch in version string if not master.

* Simplify code.

* Flash and compile script cleaned.
  • Loading branch information
CelliesProjects authored May 27, 2019
1 parent e326a5e commit c903297
Show file tree
Hide file tree
Showing 12 changed files with 1,226 additions and 1,176 deletions.
10 changes: 5 additions & 5 deletions aquacontrol32.ino
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,10 @@ struct channelData_t

struct sensorData_t /* struct to keep track of Dallas DS18B20 sensors */
{
byte addr[8];
float tempCelcius;
char name[15];
byte addr[8];
float tempCelcius;
char name[15];
bool error = false;
};

/* const */
Expand Down Expand Up @@ -191,10 +192,9 @@ uint8_t tftOrientation = TFT_ORIENTATION_NORMAL;
uint8_t oledContrast; /* 0 .. 15 */
uint8_t oledOrientation = OLED_ORIENTATION_NORMAL;

bool LOG_SENSOR_ERRORS = false;
/*****************************************************************************************
end of global variables
*****************************************************************************************/
void tftTask( void * pvParameters );
void oledTask( void * pvParameters );
Expand Down
11 changes: 5 additions & 6 deletions compile.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
echo Compiling aquacontrol32 version: $(git describe --tags --always)
echo Branch: $(git branch | grep \* | cut -d ' ' -f2)
echo
currentVersion=""
if [ $(git branch | grep \* | cut -d ' ' -f2) == "master" ]
then
echo "const char * sketchVersion = \"$(git describe --tags --always)\";" > gitTagVersion.h
currentVersion=$(git describe --tags --always)
else
echo "const char * sketchVersion = \"$(git describe --tags --always):$(git branch | grep \* | cut -d ' ' -f2)\";" > gitTagVersion.h
currentVersion=$(git branch | grep \* | cut -d ' ' -f2):$(git rev-parse --short HEAD)
fi
echo $(git describe --tags --always):$(git branch | grep \* | cut -d ' ' -f2)
echo "const char * sketchVersion = \"$currentVersion\";" > gitTagVersion.h
echo Compiling aquacontrol32 version: $currentVersion
~/arduino-1.8.9/arduino --board espressif:esp32:mhetesp32minikit --verify test.ino --pref custom_DebugLevel=esp32_none --port /dev/ttyUSB0 --pref upload.speed=921600 --pref build.path=temp --preserve-temp-files --pref build.partition=default_ffat
rm gitTagVersion.h
11 changes: 5 additions & 6 deletions flash.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
echo Compiling and flashing aquacontrol32 version: $(git describe --tags --always)
echo Branch: $(git branch | grep \* | cut -d ' ' -f2)
echo
currentVersion=""
if [ $(git branch | grep \* | cut -d ' ' -f2) == "master" ]
then
echo "const char * sketchVersion = \"$(git describe --tags --always)\";" > gitTagVersion.h
currentVersion=$(git describe --tags --always)
else
echo "const char * sketchVersion = \"$(git describe --tags --always):$(git branch | grep \* | cut -d ' ' -f2)\";" > gitTagVersion.h
currentVersion=$(git branch | grep \* | cut -d ' ' -f2):$(git rev-parse --short HEAD)
fi
echo $(git describe --tags --always):$(git branch | grep \* | cut -d ' ' -f2)
echo "const char * sketchVersion = \"$currentVersion\";" > gitTagVersion.h
echo Compiling and flashing aquacontrol32 version: $currentVersion
~/arduino-1.8.9/arduino --board espressif:esp32:mhetesp32minikit --upload test.ino --pref custom_DebugLevel=esp32_none --port /dev/ttyUSB0 --pref upload.speed=921600 --preserve-temp-files --pref build.path=temp --pref build.partition=default_ffat --pref build.flash_freq=80m
rm gitTagVersion.h
16 changes: 16 additions & 0 deletions loggertask.ino
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,19 @@ const char * resetString( const RESET_REASON reason )
};
return resetStr[reason];
}

void writeSensorErrorLog( const uint8_t &whichSensor, const char * errorStr, const byte data[9] )
{
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
char timeBuff[20];
strftime ( timeBuff, sizeof(timeBuff), "%x %X", timeinfo );
char buffer[100];
snprintf( buffer, sizeof( buffer ), "%s - sensor: '%s' %s %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X", timeBuff, sensor[whichSensor].name, errorStr,
data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8] );

writelnFile( FFat, "/sensor_error.txt", buffer );
ESP_LOGE( TAG, "%s", buffer );
}
6 changes: 4 additions & 2 deletions oledtask.ino
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ void IRAM_ATTR oledTask( void * pvParameters )
uint8_t charCount = 0;
for ( uint8_t sensorNumber = 0; sensorNumber < numberOfFoundSensors; sensorNumber++ )
{
charCount += snprintf( content + charCount, sizeof( content ) - charCount, "%.1f°C " , sensor[sensorNumber].tempCelcius );
if ( !sensor[sensorNumber].error )
charCount += snprintf( content + charCount, sizeof( content ) - charCount, "%.1f°C " , sensor[sensorNumber].tempCelcius );
else
charCount += snprintf( content + charCount, sizeof( content ) - charCount, "ERROR " , sensor[sensorNumber].tempCelcius );
}
}
else
Expand All @@ -93,4 +96,3 @@ void IRAM_ATTR oledTask( void * pvParameters )
vTaskDelay( oledTaskdelayTime );
}
}

10 changes: 7 additions & 3 deletions temptask.ino
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,16 @@ void IRAM_ATTR tempTask( void * pvParameters )
break;
default:
ESP_LOGE( TAG, "OneWire device is not a DS18x20 family device.");
return;
}

int16_t raw;
if ( OneWire::crc8(data, 8) != data[8])
if ( data[8] == 0xFF || OneWire::crc8(data, 8) != data[8])
{

// CRC of temperature reading indicates an error, so we print a error message and discard this reading
ESP_LOGE( TAG, "%u - CRC error from device %u", millis() / 1000.0, thisSensor );
sensor[thisSensor].error = true;
if ( LOG_SENSOR_ERRORS ) writeSensorErrorLog( thisSensor, "BAD_CRC", data );
ESP_LOGE( TAG, "Sensor %i error. data: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X", thisSensor, data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8] );
}
else
{
Expand All @@ -107,8 +109,10 @@ void IRAM_ATTR tempTask( void * pvParameters )
else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
//// default is 12 bit resolution, 750 ms conversion time

}
sensor[thisSensor].tempCelcius = raw / 16.0;
sensor[thisSensor].error = false;
}
}
}
Expand Down
25 changes: 15 additions & 10 deletions tfttask.ino
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class tftButton
uint16_t bordercolor;
uint16_t labelcolor;
tftFontsize_t fontsize;
char text[20];
char text[25];
char label[15];
};

Expand Down Expand Up @@ -491,26 +491,31 @@ static inline __attribute__((always_inline)) void showIPAddress( )
tft.print( buff );
}

static inline __attribute__((always_inline)) void drawSensors( const bool &forceDraw )
void drawSensors( const bool &forceDraw )
{
if ( numberOfFoundSensors )
{
static float currentTemp[MAX_NUMBER_OF_SENSORS];

for ( uint8_t thisSensor = 0; thisSensor < numberOfFoundSensors; thisSensor++ )
{
if ( sensor[ thisSensor ].tempCelcius != currentTemp[ thisSensor ] || forceDraw ) /* only update temp if changed */
if ( sensor[ thisSensor ].tempCelcius != currentTemp[ thisSensor ] || sensor[thisSensor].error || forceDraw ) /* only update temp if changed */
{
if ( sensor[ thisSensor ].tempCelcius < -55 || sensor[ thisSensor ].tempCelcius > 125 ) /* temp is outside DS18B20 specs */
if ( sensor[ thisSensor ].error )
{
tempArea[thisSensor].labelcolor = ILI9341_RED; /* show temp as in error */
ESP_LOGE( TAG, "Out of range temperature." );
sensor[ thisSensor ].tempCelcius = currentTemp[ thisSensor ]; /* show previous temp */
tempArea[thisSensor].labelcolor = ILI9341_YELLOW; /* show temp as in error */
snprintf( tempArea[thisSensor].text, sizeof( tempArea[thisSensor].text ), " ERROR " );
button.updateText( tempArea[thisSensor] );
currentTemp[thisSensor] = -273;
return;
}
else
{
snprintf( tempArea[thisSensor].text, sizeof( tempArea[thisSensor].text ), " %.1f%c ", sensor[thisSensor].tempCelcius, char(247) );
button.updateText( tempArea[thisSensor] );
}
snprintf( tempArea[thisSensor].text, sizeof( tempArea[thisSensor].text ), " %.1f%c ", sensor[thisSensor].tempCelcius, char(247) );
button.updateText( tempArea[thisSensor] );
currentTemp[ thisSensor ] = sensor[ thisSensor ].tempCelcius;
}
currentTemp[ thisSensor ] = sensor[ thisSensor ].tempCelcius;
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion webif/index.htm
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@
while ( channelValue[sensorNumber + 7].length > 0 )
{
var temp = channelValue[sensorNumber + 7].split(",");
str += String( '<p class="tempStr">' + temp[0].toLowerCase() + "<br>" + temp[1].substring( 0, temp[1].indexOf( "." ) + 2 ) + "°</p>" );
console.log(temp);
if ( temp[1] != "ERROR" )
str += String( '<p class="tempStr">' + temp[0].toLowerCase() + "<br>" + temp[1].substring( 0, temp[1].indexOf( "." ) + 2 ) + "°</p>" );
else
str += String( '<p class="tempStr">' + temp[0].toLowerCase() + "<br>ERROR</p>" );
sensorNumber++;
}
if (str.length)
Expand Down
Loading

0 comments on commit c903297

Please sign in to comment.