Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
cotestatnt committed Nov 20, 2024
1 parent a9a4b6c commit b36dd3d
Show file tree
Hide file tree
Showing 7 changed files with 229 additions and 182 deletions.
6 changes: 3 additions & 3 deletions examples/csvLogger/.vscode/arduino.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"configuration": "JTAGAdapter=default,PSRAM=disabled,FlashMode=qio,FlashSize=4M,LoopCore=1,EventsCore=1,USBMode=hwcdc,CDCOnBoot=default,MSCOnBoot=default,DFUOnBoot=default,UploadMode=default,PartitionScheme=default,CPUFreq=240,UploadSpeed=921600,DebugLevel=none,EraseFlash=none",
"board": "esp32:esp32:esp32s3",
"port": "COM3",
"configuration": "USBMode=hwcdc,JTAGAdapter=default,CDCOnBoot=default,PartitionScheme=default,CPUFreq=160,FlashMode=qio,FlashFreq=80,UploadSpeed=921600,DebugLevel=error,EraseFlash=none",
"board": "esp32:esp32:nologo_esp32c3_super_mini",
"port": "COM26",
"sketch": "csvLogger.ino"
}
249 changes: 147 additions & 102 deletions examples/csvLogger/.vscode/c_cpp_properties.json

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions examples/csvLogger/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"files.associations": {
"functional": "cpp"
}
}
15 changes: 2 additions & 13 deletions examples/csvLogger/csvLogger.ino
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ struct tm ntpTime;
const char* basePath = "/csv";



// This script will set page favicon using a base_64 encoded 32x32 pixel icon
static const char base64_favicon[] PROGMEM = R"string_literal(
var favIcon = "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAACXBIWXMAAA7EAAAOxAGVKw4bAAABv0lEQVRYw+3XvWsUURTG4ScYsVEUJUtEEOxiYxTF0i6bSlBSaCXi32B" +
Expand Down Expand Up @@ -58,20 +57,10 @@ void getFsInfo(fsInfo_t* fsInfo) {
}
#endif

//////////////////////////////// NTP Time /////////////////////////////////////////
void getUpdatedtime(const uint32_t timeout) {
uint32_t start = millis();
do {
time_t now = time(nullptr);
ntpTime = *localtime(&now);
delay(1);
} while (millis() - start < timeout && ntpTime.tm_year <= (1970 - 1900));
}


//////////////////////////// Append a row to csv file ///////////////////////////////////
bool appendRow() {
getUpdatedtime(10);
getLocalTime(&ntpTime, 10);

char filename[32];
snprintf(filename, sizeof(filename),
Expand Down Expand Up @@ -149,7 +138,7 @@ void setup() {
#elif defined(ESP32)
configTzTime(MYTZ, "time.google.com", "time.windows.com", "pool.ntp.org");
#endif
getUpdatedtime(5000); // Wait for NTP sync
getLocalTime(&ntpTime, 5000); // Wait for NTP sync

// Configure /setup page and start Web Server
myWebServer.addJavascript(base64_favicon, "favicon");
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=esp-fs-webserver
version=2.0.7
version=2.0.8
author=Tolentino Cotesta <cotestatnt@yahoo.com>
maintainer=Tolentino Cotesta <cotestatnt@yahoo.com>
sentence=From FSBrowser.ino example to library
Expand Down
126 changes: 67 additions & 59 deletions src/esp-fs-webserver.cpp
Original file line number Diff line number Diff line change
@@ -1,65 +1,73 @@
#include "esp-fs-webserver.h"
#include "detail/RequestHandlersImpl.h"

// // Override default handleClient() method to increase connection speed
// #if defined(ESP32)
// void FSWebServer::handleClient()
// {
// if (_currentStatus == HC_NONE) {
// _currentClient = _server.available();
// if (!_currentClient) {
// if (_nullDelay) {
// delay(1);
// }
// return;
// }
// log_v("New client: client.localIP()=%s", _currentClient.localIP().toString().c_str());
// _currentStatus = HC_WAIT_READ;
// _statusChange = millis();
// }

// bool keepCurrentClient = false;

// if (_currentClient.connected()) {
// switch (_currentStatus) {
// // No-op to avoid C++ compiler warning
// case HC_NONE:
// break;

// // Wait for data from client to become available
// case HC_WAIT_READ:
// if (_currentClient.available()) {
// if (_parseRequest(_currentClient)) {
// _currentClient.setTimeout(HTTP_MAX_SEND_WAIT / 1000);
// _contentLength = CONTENT_LENGTH_NOT_SET;
// _handleRequest();
// }
// }
// else {
// if (millis() - _statusChange <= 100) {
// keepCurrentClient = true;
// }
// yield();
// }
// break;

// // Wait for client to close the connection
// case HC_WAIT_CLOSE:
// if (millis() - _statusChange <= HTTP_MAX_CLOSE_WAIT) {
// keepCurrentClient = true;
// yield();
// }
// break;
// }
// }

// if (!keepCurrentClient) {
// _currentClient = WiFiClient();
// _currentStatus = HC_NONE;
// _currentUpload.reset();
// }
// }
// #endif
// Override default handleClient() method to increase connection speed
#if defined(ESP32)
void FSWebServer::handleClient()
{
if (_currentStatus == HC_NONE) {
_currentClient = _server.available();
if (!_currentClient) {
if (_nullDelay) {
delay(1);
}
return;
}
log_v("New client: client.localIP()=%s", _currentClient.localIP().toString().c_str());
_currentStatus = HC_WAIT_READ;
_statusChange = millis();
}

bool keepCurrentClient = false;

if (_currentClient.connected()) {
switch (_currentStatus) {
// No-op to avoid C++ compiler warning
case HC_NONE:
break;

// Wait for data from client to become available
case HC_WAIT_READ:
if (_currentClient.available()) {
if (_parseRequest(_currentClient)) {
_currentClient.setTimeout(HTTP_MAX_SEND_WAIT / 1000);
_contentLength = CONTENT_LENGTH_NOT_SET;
_handleRequest();

if (_currentClient.isSSE()) {
_currentStatus = HC_WAIT_CLOSE;
_statusChange = millis();
keepCurrentClient = true;
}
}
}
else { // !_currentClient.available()
// if (millis() - _statusChange <= HTTP_MAX_DATA_WAIT) {

if (millis() - _statusChange <= 100) {
keepCurrentClient = true;
}
yield();
}
break;

// Wait for client to close the connection
case HC_WAIT_CLOSE:
if (millis() - _statusChange <= HTTP_MAX_CLOSE_WAIT) {
keepCurrentClient = true;
yield();
}
break;
}
}

if (!keepCurrentClient) {
_currentClient = WiFiClient();
_currentStatus = HC_NONE;
_currentUpload.reset();
}
}
#endif

#define MDNS_INSTANCE "esp-fs-webserver"

Expand Down
8 changes: 4 additions & 4 deletions src/esp-fs-webserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,10 @@ class FSWebServer : public WebServerClass
IPAddress m_captiveIp = IPAddress(192, 168, 4, 1);
ServerWebSocket* m_websocket;

// #if defined(ESP32)
// // Override default handleClient() method to increase connection speed
// void handleClient() override;
// #endif
#if defined(ESP32)
// Override default handleClient() method to increase connection speed
void handleClient() override;
#endif

// Default handler for all URIs not defined above, use it to read files from filesystem
bool captivePortal();
Expand Down

0 comments on commit b36dd3d

Please sign in to comment.