diff --git a/src/app/CFGFileParser.cpp b/src/app/CFGFileParser.cpp
index 6171622..8fb51f5 100644
--- a/src/app/CFGFileParser.cpp
+++ b/src/app/CFGFileParser.cpp
@@ -17,6 +17,7 @@ void *CFGFileParser::parseFile()
if(!file)
{
delete dictioRef;
+ file.close();
return NULL;
}
@@ -201,4 +202,3 @@ char *CFGFileParser::addChar(char *pointer, const char character)
return pointer;
}
-
diff --git a/src/app/WEBServerManager.cpp b/src/app/WEBServerManager.cpp
index 2c747c3..bd59b9f 100644
--- a/src/app/WEBServerManager.cpp
+++ b/src/app/WEBServerManager.cpp
@@ -137,18 +137,11 @@ boolean WEBServerManager::parseQuery(WiFiClient *wifiClient)
free(_httpRequestData.httpResource);_httpRequestData.httpResource = NULL;
_httpRequestData.httpResource = parseBuffer;parseBuffer = NULL;
- _httpParserState = HTTP_RESOURCE_PARAM_SECTION;
+ _httpParserState = HTTP_RESOURCE_PARAM_SECTION;
}
- else if(readChar != ' ')
+ else if(readChar == ' ')
{
- //if(readChar != '/' && readChar != '\\') slashesOrantiSlashesOnly = false;
-
- parseBuffer = addChar(parseBuffer, readChar);
- _httpParserState = HTTP_RESOURCE_SECTION;
- }
- else
- {
- free(_httpRequestData.httpResource);_httpRequestData.httpResource = NULL;
+ free(_httpRequestData.httpResource);_httpRequestData.httpResource = NULL;
if(slashesOrantiSlashesOnly)
{
free(parseBuffer);parseBuffer = NULL;
@@ -157,8 +150,15 @@ boolean WEBServerManager::parseQuery(WiFiClient *wifiClient)
}
else
_httpRequestData.httpResource = parseBuffer;parseBuffer = NULL;
-
+
_httpParserState = HTTP_VER_SECTION;
+ }
+ else
+ {
+ if(readChar != '/' && readChar != '\\') slashesOrantiSlashesOnly = false;
+
+ parseBuffer = addChar(parseBuffer, readChar);
+ _httpParserState = HTTP_RESOURCE_SECTION;
}
break;
case HTTP_RESOURCE_PARAM_SECTION:
@@ -291,7 +291,7 @@ boolean WEBServerManager::sendPageToClientFromSdCard(WiFiClient *wifiClient)
if(_sdCardManager != NULL)
{
File pageToSend;
- char readChar(0), *filePath(NULL), *header(NULL);
+ char readChar(0), *filePath(NULL), *header(NULL), sendBuffer[2048];
//We check what kind of http verb it is
switch(_httpRequestData.HRM)
@@ -324,6 +324,7 @@ boolean WEBServerManager::sendPageToClientFromSdCard(WiFiClient *wifiClient)
sprintf(response, "HTTP/1.1 404 Not Found\r\nContent-Type: text/html\r\n\r\n\r\n\r\n
Page not found for :
\r\n%s
\r\n", _httpRequestData.httpResource);
wifiClient->print(response);
free(response);response = NULL;
+ pageToSend.close();
return false;
}
@@ -349,8 +350,13 @@ boolean WEBServerManager::sendPageToClientFromSdCard(WiFiClient *wifiClient)
while(pageToSend.available())
{
- readChar = (char) pageToSend.read();
+
+ if(wifiClient->write(sendBuffer, pageToSend.read(sendBuffer,2048)) == 0)
+ break;
+
+ /*readChar = (char) pageToSend.read();
wifiClient->write(readChar);
+ Serial.print(readChar);*/
}
pageToSend.close();
@@ -397,7 +403,8 @@ WEBServerManager::HttpMIMEType WEBServerManager::getMIMETypeByExtension(const ch
else if(strcmp(extension,"css") == 0) return TEXT_CSS;
else if(strcmp(extension,"js") == 0) return TEXT_JAVASCRIPT;
else if(strcmp(extension,"png") == 0) return IMAGE_PNG;
- else return TEXT_PLAIN;
+ else if(strcmp(extension, "mp3") == 0) return AUDIO_MPEG;
+ else return UNKNOWN_MIME;
}
char *WEBServerManager::getHTTPHeader(HttpMIMEType httpMIMEType, unsigned long size)
@@ -421,7 +428,15 @@ char *WEBServerManager::getHTTPHeader(HttpMIMEType httpMIMEType, unsigned long s
case TEXT_PLAIN:
sprintf(header,"HTTP/1.1 200 OK\r\nContent-Type: %s\r\nContent-Length: %lu\r\n\r\n","text/plain",size);
break;
+ case AUDIO_MPEG:
+ sprintf(header,"HTTP/1.1 200 OK\r\nContent-Type: %s\r\nContent-Length: %lu\r\n\r\n","audio/mpeg",size);
+ break;
+ case APPLICATION_OCTET_STREAM:
+ sprintf(header,"HTTP/1.1 200 OK\r\nContent-Type: %s\r\nContent-Length: %lu\r\n\r\n","application/octet-stream",size);
+ break;
default:
+ sprintf(header,"HTTP/1.1 200 OK\r\nContent-Type: %s\r\nContent-Length: %lu\r\n\r\n","application/octet-stream",size);
+ break;
break;
}
diff --git a/src/app/WEBServerManager.h b/src/app/WEBServerManager.h
index a5ab83a..7109332 100644
--- a/src/app/WEBServerManager.h
+++ b/src/app/WEBServerManager.h
@@ -16,7 +16,7 @@ class WEBServerManager
enum HttpRequestMethod {UNDEFINED, GET, HEAD, POST, PUT, DELETE, CONNECT, OPTIONS, TRACE, PATCH};
enum HttpVersion {UNKNOWN, HTTP_0_9, HTTP_1_1, HTTP_1_0, HTTP_2_0};
enum HttpParserStatus {INIT, LINE_BREAK, HTTP_VERB_SECTION, HTTP_RESOURCE_SECTION, HTTP_RESOURCE_PARAM_SECTION, HTTP_VER_SECTION, PARAMETER_SECTION, BODY_SECTION, IGNORED, ERROR};
- enum HttpMIMEType{UNKNOWN_MIME, TEXT_PLAIN, TEXT_CSS, TEXT_HTML, TEXT_JAVASCRIPT, APPLICATION_JSON, APPLICATION_X_WWW_FORM_URLENCODED, IMAGE_PNG};
+ enum HttpMIMEType{UNKNOWN_MIME, TEXT_PLAIN, TEXT_CSS, TEXT_HTML, TEXT_JAVASCRIPT, APPLICATION_JSON, APPLICATION_X_WWW_FORM_URLENCODED, IMAGE_PNG, AUDIO_MPEG, APPLICATION_OCTET_STREAM};
struct HttpRequestData{
HttpRequestMethod HRM;
HttpVersion HV;
diff --git a/src/app/app.ino b/src/app/app.ino
index 1881e7b..768b6a0 100644
--- a/src/app/app.ino
+++ b/src/app/app.ino
@@ -22,7 +22,10 @@ void setup()
CFGFileParser cfgFileParser(sab.getSdCardManager(), AP_CFG_FILE);
CFGDictionary *cfgDictionary = (CFGDictionary *) cfgFileParser.parseFile();
- Serial.print("AP PASSWORD : ");if((*cfgDictionary)("PASSWORD") != NULL)Serial.println((*cfgDictionary)("PASSWORD")->stringValue());
+ if(cfgDictionary != NULL)
+ {
+ Serial.print("AP PASSWORD : ");if((*cfgDictionary)("PASSWORD") != NULL)Serial.println((*cfgDictionary)("PASSWORD")->stringValue());
+ }
delete cfgDictionary;
sab.getScreenManager().addView(&(view_1), &v1p, 0);
@@ -38,6 +41,8 @@ void setup()
sab.getWebServerManager().addApiRoutine("/helloServer", &(helloServerApi), NULL);
sab.getWebServerManager().addApiRoutine("/view/next", &(nextViewApi), &sab, WEBServerManager::GET);
sab.getWebServerManager().addApiRoutine("/rtc/get/time", &(rtcTimeApi), &sab, WEBServerManager::GET);
+ sab.getWebServerManager().addApiRoutine("/sdcard/eject", &(sdCardEjectApi), &sab, WEBServerManager::GET);
+ sab.getWebServerManager().addApiRoutine("/sdcard/insert", &(sdCardInsertApi), &sab, WEBServerManager::GET);
Serial.println("End setup");
}
diff --git a/src/app/webApi.cpp b/src/app/webApi.cpp
index b4e3adc..1330dec 100644
--- a/src/app/webApi.cpp
+++ b/src/app/webApi.cpp
@@ -27,3 +27,26 @@ boolean rtcTimeApi(WEBServerManager::HttpRequestData &HRD, WiFiClient *wc, void
return true;
}
+boolean sdCardEjectApi(WEBServerManager::HttpRequestData &HRD, WiFiClient *wc, void *pData)
+{
+ SAB *p = (SAB *)pData;
+ char buffer[200];
+ p->getSdCardManager().end();
+ sprintf(buffer,"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{ \"status\" : \"ok\", \"card\" : \"ejected\" }");
+ wc->print(buffer);
+ return true;
+}
+
+boolean sdCardInsertApi(WEBServerManager::HttpRequestData &HRD, WiFiClient *wc, void *pData)
+{
+ SAB *p = (SAB *)pData;
+ char buffer[200];
+
+ if(p->getSdCardManager().begin(p->getSdCardConfig().getSPISpeed(), p->getPinConfig().getSPI_sdCard_cs()))
+ sprintf(buffer,"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{ \"status\" : \"ok\", \"card\" : \"inserted\" }");
+ else
+ sprintf(buffer,"HTTP/1.1 500 OK\r\nContent-Type: application/json\r\n\r\n{ \"status\" : \"error\", \"message\" : \"begin failed\" }");
+
+ wc->print(buffer);
+ return true;
+}
diff --git a/src/app/webApi.h b/src/app/webApi.h
index 73dea7f..0ff9434 100644
--- a/src/app/webApi.h
+++ b/src/app/webApi.h
@@ -5,5 +5,7 @@
boolean helloServerApi(WEBServerManager::HttpRequestData&, WiFiClient*, void*);
boolean nextViewApi(WEBServerManager::HttpRequestData&, WiFiClient*, void*);
boolean rtcTimeApi(WEBServerManager::HttpRequestData&, WiFiClient*, void*);
+boolean sdCardEjectApi(WEBServerManager::HttpRequestData&, WiFiClient*, void*);
+boolean sdCardInsertApi(WEBServerManager::HttpRequestData&, WiFiClient*, void*);
#endif