Skip to content

Commit

Permalink
Make web call handlers re-entrant.
Browse files Browse the repository at this point in the history
  • Loading branch information
CelliesProjects committed Jul 11, 2019
1 parent 6fa531c commit 1016ca8
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions webservertask.ino
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void webServerTask ( void * pvParameters )

server.on( "/api/getdevice", HTTP_GET, []( AsyncWebServerRequest * request)
{
AsyncResponseStream *response;
//AsyncResponseStream *response;
if ( request->hasArg( "boottime" ) )
{
char response[25];
Expand All @@ -141,7 +141,7 @@ void webServerTask ( void * pvParameters )

else if ( request->hasArg( "channelcolors" ) )
{
response = request->beginResponseStream( HEADER_HTML );
AsyncResponseStream *response = request->beginResponseStream( HEADER_HTML );
for ( uint8_t channelNumber = 0; channelNumber < NUMBER_OF_CHANNELS; channelNumber++ )
{
response->printf( "%s\n", channel[channelNumber].color );
Expand All @@ -151,7 +151,7 @@ void webServerTask ( void * pvParameters )

else if ( request->hasArg( "channelnames" ) )
{
response = request->beginResponseStream( HEADER_HTML );
AsyncResponseStream *response = request->beginResponseStream( HEADER_HTML );
for ( uint8_t channelNumber = 0; channelNumber < NUMBER_OF_CHANNELS; channelNumber++ )
{
response->printf( "%s\n", channel[channelNumber].name );
Expand All @@ -161,7 +161,7 @@ void webServerTask ( void * pvParameters )

else if ( request->hasArg( "diskspace" ) )
{
response = request->beginResponseStream( HEADER_HTML );
AsyncResponseStream *response = request->beginResponseStream( HEADER_HTML );
response->printf( "%lu", FFat.freeBytes() );
return request->send( response );
}
Expand All @@ -182,7 +182,7 @@ void webServerTask ( void * pvParameters )
{
return request->send( 404 );
}
response = request->beginResponseStream( HEADER_HTML );
AsyncResponseStream *response = request->beginResponseStream( HEADER_HTML );
while ( file )
{
if ( !file.isDirectory() )
Expand All @@ -201,7 +201,7 @@ void webServerTask ( void * pvParameters )

else if ( request->hasArg( "minimumlevels" ) )
{
response = request->beginResponseStream( HEADER_HTML );
AsyncResponseStream *response = request->beginResponseStream( HEADER_HTML );
for ( uint8_t channelNumber = 0; channelNumber < NUMBER_OF_CHANNELS; channelNumber++ )
{
response->printf( "%.2f\n", channel[channelNumber].minimumLevel );
Expand All @@ -215,7 +215,7 @@ void webServerTask ( void * pvParameters )
{
return request->send( 501, HEADER_HTML, NOT_PRESENT_ERROR_501 );
}
response = request->beginResponseStream( HEADER_HTML );
AsyncResponseStream *response = request->beginResponseStream( HEADER_HTML );
response->printf( "%i\n%.4f\n", moonData.angle, moonData.percentLit );
return request->send( response );
}
Expand All @@ -226,7 +226,7 @@ void webServerTask ( void * pvParameters )
{
return request->send( 501, HEADER_HTML, NOT_PRESENT_ERROR_501 );
}
response = request->beginResponseStream( HEADER_HTML );
AsyncResponseStream *response = request->beginResponseStream( HEADER_HTML );
response->printf( "%i", oledContrast );
return request->send( response );
}
Expand All @@ -242,14 +242,14 @@ void webServerTask ( void * pvParameters )

else if ( request->hasArg( "pwmdepth" ) )
{
response = request->beginResponseStream( HEADER_HTML );
AsyncResponseStream *response = request->beginResponseStream( HEADER_HTML );
response->printf( "%i", ledcNumberOfBits );
return request->send( response );
}

else if ( request->hasArg( "pwmfrequency" ) )
{
response = request->beginResponseStream( HEADER_HTML );
AsyncResponseStream *response = request->beginResponseStream( HEADER_HTML );
response->printf( "%.0f", ledcActualFrequency );
return request->send( response );
}
Expand All @@ -260,7 +260,7 @@ void webServerTask ( void * pvParameters )
if ( !request->hasArg( "number" ) ) return request->send( 400, HEADER_HTML, "No sensornumber" );
uint8_t num = request->arg( "number" ).toInt();
if ( num >= sensor.count() ) return request->send( 400, HEADER_HTML, "Invalid sensornumber" );
response = request->beginResponseStream( HEADER_HTML );
AsyncResponseStream *response = request->beginResponseStream( HEADER_HTML );
sensorName_t name;
sensorId_t id;
response->printf( "%s\n%.3f\n%s\n", sensor.getName( num, name ), sensor.temp( num ), sensor.getId( num, id ) );
Expand All @@ -272,7 +272,7 @@ void webServerTask ( void * pvParameters )
if ( !sensor.count() ) return request->send( 501, HEADER_HTML, NOT_PRESENT_ERROR_501 );
sensorName_t name;
sensorId_t id;
response = request->beginResponseStream( HEADER_HTML );
AsyncResponseStream *response = request->beginResponseStream( HEADER_HTML );
for ( uint8_t num = 0; num < sensor.count(); num++ )
response->printf( "%s,%.3f,%s\n", sensor.getName( num, name ), sensor.temp( num ), sensor.getId( num, id ) );

Expand Down Expand Up @@ -303,7 +303,7 @@ void webServerTask ( void * pvParameters )

else if ( request->hasArg( "status" ) )
{
response = request->beginResponseStream( HEADER_HTML );
AsyncResponseStream *response = request->beginResponseStream( HEADER_HTML );
for ( uint8_t channelNumber = 0; channelNumber < NUMBER_OF_CHANNELS; channelNumber++ )
{
char content[8];
Expand Down Expand Up @@ -333,7 +333,7 @@ void webServerTask ( void * pvParameters )
{
return request->send( 501, HEADER_HTML, NOT_PRESENT_ERROR_501 );
}
response = request->beginResponseStream( HEADER_HTML );
AsyncResponseStream *response = request->beginResponseStream( HEADER_HTML );
response->printf( "%.2f", tftBrightness );
return request->send( response );
}
Expand All @@ -349,7 +349,7 @@ void webServerTask ( void * pvParameters )

else if ( request->hasArg( "timezone" ) )
{
response = request->beginResponseStream( HEADER_HTML );
AsyncResponseStream *response = request->beginResponseStream( HEADER_HTML );
response->printf( "%s", getenv( "TZ" ) );
return request->send( response );
}
Expand Down Expand Up @@ -450,7 +450,6 @@ void webServerTask ( void * pvParameters )

server.on( "/api/setdevice", HTTP_POST, []( AsyncWebServerRequest * request )
{
AsyncResponseStream *response;
if ( !request->authenticate( WWW_USERNAME, preferences.getString( PASSWD_KEY_NVS, WWW_DEFAULT_PASSWD ).c_str() ) )
{
return request->requestAuthentication();
Expand Down Expand Up @@ -516,7 +515,7 @@ void webServerTask ( void * pvParameters )
oledContrast = contrast;
OLED.setContrast( contrast << 4 );
preferences.putUInt( "oledcontrast", oledContrast );
response = request->beginResponseStream( HEADER_HTML );
AsyncResponseStream *response = request->beginResponseStream( HEADER_HTML );
response->printf( "%i", contrast );
return request->send( response );
}
Expand Down Expand Up @@ -567,7 +566,7 @@ void webServerTask ( void * pvParameters )
setupDimmerPWMfrequency( LEDC_MAXIMUM_FREQ, newPWMDepth );
preferences.putUInt( "pwmdepth" , ledcNumberOfBits );
}
response = request->beginResponseStream( HEADER_HTML );
AsyncResponseStream *response = request->beginResponseStream( HEADER_HTML );
response->printf( "%i", ledcNumberOfBits );
return request->send( response );
}
Expand All @@ -584,7 +583,7 @@ void webServerTask ( void * pvParameters )
setupDimmerPWMfrequency( tempPWMfrequency, ledcNumberOfBits );
preferences.putDouble( "pwmfrequency", ledcActualFrequency );
}
response = request->beginResponseStream( HEADER_HTML );
AsyncResponseStream *response = request->beginResponseStream( HEADER_HTML );
response->printf( "%.0f", ledcActualFrequency );
return request->send( response );
}
Expand Down Expand Up @@ -669,7 +668,7 @@ void webServerTask ( void * pvParameters )
tft.setRotation( tftOrientation );
tftClearScreen = true;
preferences.putString( "tftorientation", ( tftOrientation == TFT_ORIENTATION_NORMAL ) ? "normal" : "upsidedown" );
response = request->beginResponseStream( HEADER_HTML );
AsyncResponseStream *response = request->beginResponseStream( HEADER_HTML );
response->printf( "%s", preferences.getString( "tftorientation", "" ).c_str() );
return request->send( response );
}
Expand All @@ -683,7 +682,7 @@ void webServerTask ( void * pvParameters )
}
tftBrightness = brightness;
preferences.putFloat( "tftbrightness", brightness );
response = request->beginResponseStream( HEADER_HTML );
AsyncResponseStream *response = request->beginResponseStream( HEADER_HTML );
response->printf( "%.2f", tftBrightness );
return request->send( response );
}
Expand All @@ -698,7 +697,7 @@ void webServerTask ( void * pvParameters )
{
return request->send( 400, HEADER_HTML, "Error setting timezone." );
}
response = request->beginResponseStream( HEADER_HTML );
AsyncResponseStream *response = request->beginResponseStream( HEADER_HTML );
response->printf( "%s", getenv( "TZ" ) );
return request->send( response );
}
Expand Down

0 comments on commit 1016ca8

Please sign in to comment.