Compare commits
No commits in common. "db1873b714b7cdb2d01ce145f2f7c0fa5795f8d4" and "e68ab0419573fc04fc636a1d92a346a5a346ee69" have entirely different histories.
db1873b714
...
e68ab04195
@ -17,7 +17,6 @@ class HttpConstants
|
|||||||
APPLICATION_X_WWW_FORM_URLENCODED,
|
APPLICATION_X_WWW_FORM_URLENCODED,
|
||||||
IMAGE_PNG,
|
IMAGE_PNG,
|
||||||
IMAGE_JPEG,
|
IMAGE_JPEG,
|
||||||
IMAGE_X_ICO,
|
|
||||||
AUDIO_MPEG,
|
AUDIO_MPEG,
|
||||||
APPLICATION_OCTET_STREAM};
|
APPLICATION_OCTET_STREAM};
|
||||||
enum HTTP_CODE {
|
enum HTTP_CODE {
|
||||||
@ -129,9 +128,6 @@ class HttpConstants
|
|||||||
case HttpMIMEType::IMAGE_JPEG:
|
case HttpMIMEType::IMAGE_JPEG:
|
||||||
return HTTPCONSTANTS_STRING("image/jpeg");
|
return HTTPCONSTANTS_STRING("image/jpeg");
|
||||||
break;
|
break;
|
||||||
case HttpMIMEType::IMAGE_X_ICO:
|
|
||||||
return HTTPCONSTANTS_STRING("image/x-icon");
|
|
||||||
break;
|
|
||||||
case HttpMIMEType::AUDIO_MPEG:
|
case HttpMIMEType::AUDIO_MPEG:
|
||||||
return HTTPCONSTANTS_STRING("audio/mpeg");
|
return HTTPCONSTANTS_STRING("audio/mpeg");
|
||||||
break;
|
break;
|
||||||
|
@ -295,13 +295,13 @@ boolean ScreenManager::displayView(const uint8_t UID)
|
|||||||
return _error == OK;
|
return _error == OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean ScreenManager::displayNextView()
|
void ScreenManager::displayNextView()
|
||||||
{
|
{
|
||||||
_autoOFFDelayRef = millis();
|
_autoOFFDelayRef = millis();
|
||||||
if(!_enabled) return false;
|
if(!_enabled) return;
|
||||||
_forceRefresh = true;
|
_forceRefresh = true;
|
||||||
_error = OK;
|
_error = OK;
|
||||||
if(isListEmpty(_viewLinkedList))return false;
|
if(isListEmpty(_viewLinkedList))return;
|
||||||
|
|
||||||
if(_currentView == NO_CURRENT_VIEW)
|
if(_currentView == NO_CURRENT_VIEW)
|
||||||
{
|
{
|
||||||
@ -328,16 +328,15 @@ boolean ScreenManager::displayNextView()
|
|||||||
}
|
}
|
||||||
|
|
||||||
run();
|
run();
|
||||||
return _error == OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean ScreenManager::displayPreviousView()
|
void ScreenManager::displayPreviousView()
|
||||||
{
|
{
|
||||||
_autoOFFDelayRef = millis();
|
_autoOFFDelayRef = millis();
|
||||||
if(!_enabled) return false;
|
if(!_enabled) return;
|
||||||
_forceRefresh = true;
|
_forceRefresh = true;
|
||||||
_error = OK;
|
_error = OK;
|
||||||
if(isListEmpty(_tail))return false;
|
if(isListEmpty(_tail))return;
|
||||||
|
|
||||||
if(_currentView == NO_CURRENT_VIEW)
|
if(_currentView == NO_CURRENT_VIEW)
|
||||||
{
|
{
|
||||||
@ -364,7 +363,6 @@ boolean ScreenManager::displayPreviousView()
|
|||||||
}
|
}
|
||||||
|
|
||||||
run();
|
run();
|
||||||
return _error == OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenManager::invertDisplayColor(const boolean inverted)
|
void ScreenManager::invertDisplayColor(const boolean inverted)
|
||||||
|
@ -26,8 +26,8 @@ class ScreenManager
|
|||||||
boolean addView(boolean (*viewLogicFunction)(Adafruit_SSD1306&, void*), void *pData, const unsigned char UID);
|
boolean addView(boolean (*viewLogicFunction)(Adafruit_SSD1306&, void*), void *pData, const unsigned char UID);
|
||||||
boolean removeView(const unsigned char UID);
|
boolean removeView(const unsigned char UID);
|
||||||
boolean displayView(const uint8_t UID);
|
boolean displayView(const uint8_t UID);
|
||||||
boolean displayNextView();
|
void displayNextView();
|
||||||
boolean displayPreviousView();
|
void displayPreviousView();
|
||||||
void forceRefresh();
|
void forceRefresh();
|
||||||
boolean applyCfgFromSD();
|
boolean applyCfgFromSD();
|
||||||
void invertDisplayColor(const boolean inverted);
|
void invertDisplayColor(const boolean inverted);
|
||||||
|
@ -55,19 +55,11 @@ class WEBServer : public TCPServer<T>, public HttpConstants
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Helper function used for the webApi
|
//Helper function used for the webApi
|
||||||
static void sendHTTPHeader(WiFiClient *client, const char *contentType, const size_t contentLength = 0, HttpVersion version = HttpVersion::HTTP_1_1, HTTP_CODE HTTPCode = HTTP_CODE::HTTP_CODE_OK)
|
static void sendHTTPHeader(WiFiClient *client, const char *contentType, const size_t contentLength, HttpVersion version = HttpVersion::HTTP_1_1, HTTP_CODE HTTPCode = HTTP_CODE::HTTP_CODE_OK)
|
||||||
{
|
{
|
||||||
if(!client) return;
|
if(!client) return;
|
||||||
(void)HTTPCode;
|
(void)HTTPCode;
|
||||||
|
client->printf("%s 200 OK\r\nContent-Type: %s\r\nContent-Length: %d\r\n\r\n", httpVersionToString(version), contentType, contentLength);
|
||||||
client->printf("%s 200 OK\r\nContent-Type: %s", httpVersionToString(version), contentType);
|
|
||||||
|
|
||||||
if(contentLength)
|
|
||||||
{
|
|
||||||
client->printf("\r\nContent-Length: %d", contentLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
client->print("\r\n\r\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setWWWDir(const char *WWWDir)
|
void setWWWDir(const char *WWWDir)
|
||||||
@ -609,9 +601,8 @@ class WEBServer : public TCPServer<T>, public HttpConstants
|
|||||||
Serial.println(pageToSend.name());
|
Serial.println(pageToSend.name());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(pageToSend.isDirectory()) //TODO : List the files present in the directory
|
if(pageToSend.isDirectory()) //To DO : List the files present in the directory
|
||||||
{
|
{
|
||||||
//sendDirectoryListing(client, pageToSend); //Sends the content of the directory like what apache does by default. CRASHING FOR NOW, needs to be checked further.
|
|
||||||
pageToSend.close();
|
pageToSend.close();
|
||||||
|
|
||||||
sendInfoResponse(HTTP_CODE::HTTP_CODE_FORBIDDEN, client, "The file you want to access is a folder");
|
sendInfoResponse(HTTP_CODE::HTTP_CODE_FORBIDDEN, client, "The file you want to access is a folder");
|
||||||
@ -700,47 +691,8 @@ class WEBServer : public TCPServer<T>, public HttpConstants
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendDirectoryListing(T *client, File& pageToSend)
|
|
||||||
{
|
|
||||||
/*sendHTTPHeader(&client->_client, HttpConstants::httpMIMETypeToString(HttpConstants::TEXT_HTML));
|
|
||||||
client->_client.printf_P(PSTR( "<!DOCTYPE HTML>\r\n\
|
|
||||||
<html>\r\n\
|
|
||||||
<head>\r\n\
|
|
||||||
<title>Index of %s</title>\r\n\
|
|
||||||
</head>\r\n\
|
|
||||||
<body>\r\n\
|
|
||||||
<h1>Index of %s</h1>\r\n\
|
|
||||||
<table>\r\n\
|
|
||||||
<tr><th>Name</th><th>Created</th><th>Last modified</th><th>Size</th></tr>\r\n\
|
|
||||||
<tr><th colspan=\"4\"><hr></th></tr>\r\n")
|
|
||||||
, client->_httpRequestData.httpResource, client->_httpRequestData.httpResource);*/
|
|
||||||
//File nextFile;
|
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
//if(!(nextFile = pageToSend.openNextFile()))break;
|
|
||||||
File nextFile = pageToSend.openNextFile();
|
|
||||||
if (!nextFile) //No more files in the directory
|
|
||||||
break;
|
|
||||||
//time_t creationTime = nextFile.getCreationTime(), lastModified = nextFile.getLastWrite();
|
|
||||||
|
|
||||||
/*client->_client.printf_P(PSTR("<tr><td><a href=\"%s\">%s</a></td><td align=\"right\">2021-07-09 15:37 </td><td align=\"right\">2021-07-09 15:37 </td><td align=\"right\"> %u</td></tr>\r\n"),
|
|
||||||
nextFile.name(),
|
|
||||||
nextFile.name(),
|
|
||||||
nextFile.size()
|
|
||||||
);*/
|
|
||||||
Serial.printf("%s %u\r\n", nextFile.name(), nextFile.size());
|
|
||||||
nextFile.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*client->_client.printf_P(PSTR( "<tr><th colspan=\"4\"><hr></th></tr>\r\n\
|
|
||||||
</table>\r\n\
|
|
||||||
<address>SAB WEBServer, Version %s at %s Port %u</address>\r\n\
|
|
||||||
</body>\r\n\
|
|
||||||
</html>"), "1.0.0", "", TCPServer<T>::getPort()); //TODO get IP*/
|
|
||||||
}
|
|
||||||
|
|
||||||
/*Static helper methods*/
|
/*Static helper methods*/
|
||||||
|
|
||||||
static void sendInfoResponse(HTTP_CODE http_code, T *client, const char *message)
|
static void sendInfoResponse(HTTP_CODE http_code, T *client, const char *message)
|
||||||
{
|
{
|
||||||
char codeLiteral[100];
|
char codeLiteral[100];
|
||||||
@ -800,7 +752,6 @@ class WEBServer : public TCPServer<T>, public HttpConstants
|
|||||||
else if(strcmp(extension, "js") == 0) return TEXT_JAVASCRIPT;
|
else if(strcmp(extension, "js") == 0) return TEXT_JAVASCRIPT;
|
||||||
else if(strcmp(extension, "png") == 0) return IMAGE_PNG;
|
else if(strcmp(extension, "png") == 0) return IMAGE_PNG;
|
||||||
else if(strcmp(extension, "jpg") == 0) return IMAGE_JPEG;
|
else if(strcmp(extension, "jpg") == 0) return IMAGE_JPEG;
|
||||||
else if(strcmp(extension, "ico") == 0) return IMAGE_X_ICO;
|
|
||||||
else if(strcmp(extension, "mp3") == 0) return AUDIO_MPEG;
|
else if(strcmp(extension, "mp3") == 0) return AUDIO_MPEG;
|
||||||
else return UNKNOWN_MIME;
|
else return UNKNOWN_MIME;
|
||||||
}
|
}
|
||||||
|
@ -88,6 +88,7 @@ void setup()
|
|||||||
sab.getWebServer().addApiRoutine("/sab/wifi/scanner", &(apScannerApi), NULL, WEBServer<WEBClient>::GET);
|
sab.getWebServer().addApiRoutine("/sab/wifi/scanner", &(apScannerApi), NULL, WEBServer<WEBClient>::GET);
|
||||||
sab.getWebServer().addApiRoutine("/sab/systeminfo", &(systemInfoApi), &sab, WEBServer<WEBClient>::GET);
|
sab.getWebServer().addApiRoutine("/sab/systeminfo", &(systemInfoApi), &sab, WEBServer<WEBClient>::GET);
|
||||||
sab.getWebServer().addApiRoutine("/sab/power/info", &(powerInfoApi), &sab, WEBServer<WEBClient>::GET);
|
sab.getWebServer().addApiRoutine("/sab/power/info", &(powerInfoApi), &sab, WEBServer<WEBClient>::GET);
|
||||||
|
sab.getWebServer().addApiRoutine("/sab/power/set/freq", &(powerSettingsApi), &sab, WEBServer<WEBClient>::GET);
|
||||||
sab.getWebServer().addApiRoutine("/sab/io/get/level", &(ioGetLevelApi), vio.ioState, WEBServer<WEBClient>::GET);
|
sab.getWebServer().addApiRoutine("/sab/io/get/level", &(ioGetLevelApi), vio.ioState, WEBServer<WEBClient>::GET);
|
||||||
sab.getWebServer().addApiRoutine("/sab/io/set/level", &(ioSetLevelApi), &sab, WEBServer<WEBClient>::GET);
|
sab.getWebServer().addApiRoutine("/sab/io/set/level", &(ioSetLevelApi), &sab, WEBServer<WEBClient>::GET);
|
||||||
sab.getWebServer().addApiRoutine("/sab/io/get/mode", &(ioGetModeApi), &sab, WEBServer<WEBClient>::GET);
|
sab.getWebServer().addApiRoutine("/sab/io/get/mode", &(ioGetModeApi), &sab, WEBServer<WEBClient>::GET);
|
||||||
|
@ -21,19 +21,17 @@ boolean viewByUIDApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc,
|
|||||||
|
|
||||||
if(pSE == NULL)
|
if(pSE == NULL)
|
||||||
{
|
{
|
||||||
strcpy(buffer, "{\"status\":\"failed\",\"message\":\"expected UID parameter\"}");
|
sprintf(buffer, "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{\"status\":\"failed\",\"message\":\"expected UID parameter\"}");
|
||||||
}
|
}
|
||||||
else if(strlen(pSE->getString()) > 0)
|
else if(strlen(pSE->getString()) > 0)
|
||||||
{
|
{
|
||||||
if(p->getScreenManager().displayView(atoi(pSE->getString())))
|
if(p->getScreenManager().displayView(atoi(pSE->getString())))
|
||||||
sprintf(buffer, "{\"status\":\"ok\",\"ViewUID\":\"%d\"}", p->getScreenManager().getCurrentViewUID());
|
sprintf(buffer, "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{\"status\":\"ok\",\"ViewUID\":\"%d\"}", p->getScreenManager().getCurrentViewUID());
|
||||||
else
|
else
|
||||||
sprintf(buffer, "{\"status\":\"failed\",\"message\":\"%s\"}", p->getScreenManager().getErrorMessage());
|
sprintf(buffer, "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{\"status\":\"failed\",\"message\":\"%s\"}", p->getScreenManager().getErrorMessage());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
strcpy(buffer, "{\"status\":\"failed\",\"message\":\"UID parameter empty\"}");
|
sprintf(buffer, "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{\"status\":\"failed\",\"message\":\"UID parameter empty\"}");
|
||||||
|
|
||||||
WEBServer<WEBClient>::sendHTTPHeader(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer));
|
|
||||||
wc->print(buffer);
|
wc->print(buffer);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -44,12 +42,12 @@ boolean nextViewApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc,
|
|||||||
SAB *p = (SAB *)pData;
|
SAB *p = (SAB *)pData;
|
||||||
char buffer[200];
|
char buffer[200];
|
||||||
|
|
||||||
if(p->getScreenManager().displayNextView())
|
p->getScreenManager().displayNextView();
|
||||||
sprintf(buffer, "{\"status\":\"ok\",\"ViewUID\":\"%d\"}", p->getScreenManager().getCurrentViewUID());
|
|
||||||
else
|
|
||||||
sprintf(buffer, "{\"status\":\"failed\",\"message\":\"%s\"}", p->getScreenManager().getErrorMessage());
|
|
||||||
|
|
||||||
WEBServer<WEBClient>::sendHTTPHeader(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer));
|
if(p->getScreenManager().getError() == ScreenManager::OK)
|
||||||
|
sprintf(buffer, "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{\"status\":\"ok\",\"ViewUID\":\"%d\"}", p->getScreenManager().getCurrentViewUID());
|
||||||
|
else
|
||||||
|
sprintf(buffer, "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{\"status\":\"failed\",\"message\":\"%s\"}", p->getScreenManager().getErrorMessage());
|
||||||
wc->print(buffer);
|
wc->print(buffer);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -61,11 +59,10 @@ boolean reloadViewApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc
|
|||||||
char buffer[200];
|
char buffer[200];
|
||||||
|
|
||||||
if(p->getScreenManager().init())
|
if(p->getScreenManager().init())
|
||||||
strcpy(buffer, "{\"status\":\"ok\",\"message\":\"config reloaded\"}");
|
strcpy(buffer, "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{\"status\":\"ok\",\"message\":\"config reloaded\"}");
|
||||||
else
|
else
|
||||||
strcpy(buffer, "{\"status\":\"failed\",\"message\":\"unable to reload config\"}");
|
strcpy(buffer, "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{\"status\":\"failed\",\"message\":\"unable to reload config\"}");
|
||||||
|
|
||||||
WEBServer<WEBClient>::sendHTTPHeader(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer));
|
|
||||||
wc->print(buffer);
|
wc->print(buffer);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -91,20 +88,22 @@ boolean rtcSetTimeApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc
|
|||||||
DictionaryHelper::StringEntity *pSE = HRD.getParams("datetime");
|
DictionaryHelper::StringEntity *pSE = HRD.getParams("datetime");
|
||||||
if(pSE == NULL)
|
if(pSE == NULL)
|
||||||
{
|
{
|
||||||
strcpy(buffer,"{\"status\":\"failed\",\"message\":\"expected datetime parameter\"}");
|
sprintf(buffer,"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{\"status\":\"failed\",\"message\":\"expected datetime parameter\"}");
|
||||||
}
|
}
|
||||||
else if(strlen(pSE->getString()) > 0)
|
else if(strlen(pSE->getString()) > 0)
|
||||||
{
|
{
|
||||||
Dictionary<DictionaryHelper::StringEntity> *dictio = pSE->split('_');
|
Dictionary<DictionaryHelper::StringEntity> *dictio = pSE->split('_');
|
||||||
if(dictio == NULL)
|
if(dictio == NULL)
|
||||||
{
|
{
|
||||||
strcpy(buffer,"{\"status\":\"failed\",\"message\":\"datetime format error\"}");
|
sprintf(buffer,"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{\"status\":\"failed\",\"message\":\"datetime format error\"}");
|
||||||
|
wc->print(buffer);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(dictio->count() != 6)
|
if(dictio->count() != 6)
|
||||||
{
|
{
|
||||||
strcpy(buffer,"{\"status\":\"error\",\"message\":\"datetime format error\"}");
|
sprintf(buffer,"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{\"status\":\"error\",\"message\":\"datetime format error\"}");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -117,16 +116,15 @@ boolean rtcSetTimeApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc
|
|||||||
atoi(dictio->getAt(5)->getString())
|
atoi(dictio->getAt(5)->getString())
|
||||||
));
|
));
|
||||||
DateTime d = p->getRtcManager().getDateTime();
|
DateTime d = p->getRtcManager().getDateTime();
|
||||||
sprintf(buffer,"{\"status\":\"ok\",\"date\":\"%d/%d/%d\",\"time\":\"%d:%d:%d\"}", d.day(), d.month(), d.year(), d.hour(), d.minute(), d.second());
|
sprintf(buffer,"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{\"status\":\"ok\",\"date\":\"%d/%d/%d\",\"time\":\"%d:%d:%d\"}", d.day(), d.month(), d.year(), d.hour(), d.minute(), d.second());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wc->print(buffer);
|
||||||
delete dictio;
|
delete dictio;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
strcpy(buffer,"{\"status\":\"failed\",\"message\":\"datetime parameter is empty\"}");
|
|
||||||
}
|
|
||||||
WEBServer<WEBClient>::sendHTTPHeader(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer));
|
|
||||||
wc->print(buffer);
|
wc->print(buffer);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -185,8 +183,7 @@ boolean espRestartApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc
|
|||||||
SAB *sab = (SAB*)pData;
|
SAB *sab = (SAB*)pData;
|
||||||
char buffer[200];
|
char buffer[200];
|
||||||
|
|
||||||
sprintf(buffer,"{\"status\":\"ok\",\"message\":\"module %s in 10 seconds\"}",strstr(HRD.httpResource,"reset") == NULL ? "restarting" : "resetting");
|
sprintf(buffer,"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{\"status\":\"ok\",\"message\":\"module %s in 10 seconds\"}",strstr(HRD.httpResource,"reset") == NULL ? "restarting" : "resetting");
|
||||||
WEBServer<WEBClient>::sendHTTPHeader(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer));
|
|
||||||
wc->print(buffer);
|
wc->print(buffer);
|
||||||
|
|
||||||
sab->getTaskSchedulerManager().addTask(sab->getTaskSchedulerManager().findFreeTaskId(), TaskSchedulerManagerHelper::Schedule::scheduleBuilder()
|
sab->getTaskSchedulerManager().addTask(sab->getTaskSchedulerManager().findFreeTaskId(), TaskSchedulerManagerHelper::Schedule::scheduleBuilder()
|
||||||
@ -209,11 +206,10 @@ boolean sdCardSizeApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc
|
|||||||
char buffer[200];
|
char buffer[200];
|
||||||
double size = p->getSdCardManager().getSize(GBYTE);
|
double size = p->getSdCardManager().getSize(GBYTE);
|
||||||
if(size == 0.0)
|
if(size == 0.0)
|
||||||
strcpy(buffer,"{\"status\":\"ok\",\"card\":\"not present\",\"size\":\"0\"}");
|
sprintf(buffer,"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{\"status\":\"ok\",\"card\":\"not present\",\"size\":\"0\"}");
|
||||||
else
|
else
|
||||||
sprintf(buffer,"{\"status\":\"ok\",\"card\":\"present\",\"size\":\"%.2f\",\"unit\":\"GByte\"}",size);
|
sprintf(buffer,"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{\"status\":\"ok\",\"card\":\"present\",\"size\":\"%.2f\",\"unit\":\"GByte\"}",size);
|
||||||
|
|
||||||
WEBServer<WEBClient>::sendHTTPHeader(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer));
|
|
||||||
wc->print(buffer);
|
wc->print(buffer);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -226,8 +222,8 @@ boolean staWifiInfoApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *w
|
|||||||
IPAddress IP = p->getConnectivityManager().localIP();
|
IPAddress IP = p->getConnectivityManager().localIP();
|
||||||
|
|
||||||
sprintf(buffer,"{\"status\":\"ok\",\"RSSI\":%d,\"RSSI2\":%d,\"local IP\":\"%u.%u.%u.%u\",\"mac\":\"%s\"}", p->getConnectivityManager().RSSI(), p->getConnectivityManager().RSSIPercent(), IP[0], IP[1], IP[2], IP[3], p->getConnectivityManager().macAddress().c_str());
|
sprintf(buffer,"{\"status\":\"ok\",\"RSSI\":%d,\"RSSI2\":%d,\"local IP\":\"%u.%u.%u.%u\",\"mac\":\"%s\"}", p->getConnectivityManager().RSSI(), p->getConnectivityManager().RSSIPercent(), IP[0], IP[1], IP[2], IP[3], p->getConnectivityManager().macAddress().c_str());
|
||||||
|
|
||||||
WEBServer<WEBClient>::sendHTTPHeader(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer));
|
WEBServer<WEBClient>::sendHTTPHeader(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer));
|
||||||
|
|
||||||
wc->print(buffer);
|
wc->print(buffer);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -251,8 +247,7 @@ boolean apScannerApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc,
|
|||||||
(void)HRD;
|
(void)HRD;
|
||||||
(void)pData;
|
(void)pData;
|
||||||
uint8_t number = WiFi.scanNetworks();
|
uint8_t number = WiFi.scanNetworks();
|
||||||
WEBServer<WEBClient>::sendHTTPHeader(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON));
|
wc->print("HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n[");
|
||||||
wc->print("[");
|
|
||||||
|
|
||||||
for(uint8_t i(0); i < number; i++)
|
for(uint8_t i(0); i < number; i++)
|
||||||
{
|
{
|
||||||
@ -288,13 +283,12 @@ boolean powerInfoApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc,
|
|||||||
char buffer[300];
|
char buffer[300];
|
||||||
PowerManager::PowerInfo pi = p->getPowerManager().getPowerInfo();
|
PowerManager::PowerInfo pi = p->getPowerManager().getPowerInfo();
|
||||||
|
|
||||||
sprintf(buffer,"{\"status\":\"ok\",\"power type\":\"%s\",\"level\":\"%u\",\"unit\":\"%%\"}", pi.powerType == PowerManager::USB ? "USB" : "BAT", pi.level);
|
sprintf(buffer,"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{\"status\":\"ok\",\"power type\":\"%s\",\"level\":\"%u\",\"unit\":\"%%\"}", pi.powerType == PowerManager::USB ? "USB" : "BAT", pi.level);
|
||||||
|
|
||||||
WEBServer<WEBClient>::sendHTTPHeader(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer));
|
|
||||||
wc->print(buffer);
|
wc->print(buffer);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
/* Changing the MCU frequency on the fly isn"t supported anymore by the SDK.
|
|
||||||
boolean powerSettingsApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData)
|
boolean powerSettingsApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData)
|
||||||
{
|
{
|
||||||
SAB *p = (SAB *)pData;
|
SAB *p = (SAB *)pData;
|
||||||
@ -327,7 +321,6 @@ boolean powerSettingsApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient
|
|||||||
wc->print(buffer);
|
wc->print(buffer);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
boolean ioGetLevelApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData)
|
boolean ioGetLevelApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData)
|
||||||
{
|
{
|
||||||
@ -337,11 +330,11 @@ boolean ioGetLevelApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc
|
|||||||
|
|
||||||
if(HRD.getParams.count() == 0)//We send every IO state
|
if(HRD.getParams.count() == 0)//We send every IO state
|
||||||
{
|
{
|
||||||
sprintf(buffer,"{\"status\":\"ok\",\"P0\":\"%d\",\"P1\":\"%d\",\"P2\":\"%d\",\"P3\":\"%d\",\"P4\":\"%d\",\"P5\":\"%d\",\"P6\":\"%d\",\"P7\":\"%d\"}",ioState[0],ioState[1],ioState[2],ioState[3],ioState[4],ioState[5],ioState[6],ioState[7]);
|
sprintf(buffer,"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{\"status\":\"ok\",\"P0\":\"%d\",\"P1\":\"%d\",\"P2\":\"%d\",\"P3\":\"%d\",\"P4\":\"%d\",\"P5\":\"%d\",\"P6\":\"%d\",\"P7\":\"%d\"}",ioState[0],ioState[1],ioState[2],ioState[3],ioState[4],ioState[5],ioState[6],ioState[7]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
strcpy(buffer,"{\"status\":\"ok\"");
|
strcpy(buffer,"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{\"status\":\"ok\"");
|
||||||
if(HRD.getParams("P0") != NULL)
|
if(HRD.getParams("P0") != NULL)
|
||||||
{
|
{
|
||||||
sprintf(helperBuffer,",\"P0\":\"%d\"",ioState[0]);
|
sprintf(helperBuffer,",\"P0\":\"%d\"",ioState[0]);
|
||||||
@ -385,7 +378,6 @@ boolean ioGetLevelApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc
|
|||||||
strcat(buffer,"}");
|
strcat(buffer,"}");
|
||||||
}
|
}
|
||||||
|
|
||||||
WEBServer<WEBClient>::sendHTTPHeader(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer));
|
|
||||||
wc->print(buffer);
|
wc->print(buffer);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -430,9 +422,8 @@ boolean ioSetLevelApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc
|
|||||||
}
|
}
|
||||||
|
|
||||||
p->getIoManager().getPcf().digitalReadAll(ioState);//We retrieve the IO state
|
p->getIoManager().getPcf().digitalReadAll(ioState);//We retrieve the IO state
|
||||||
sprintf(buffer,"{\"status\":\"ok\",\"P0\":\"%d\",\"P1\":\"%d\",\"P2\":\"%d\",\"P3\":\"%d\",\"P4\":\"%d\",\"P5\":\"%d\",\"P6\":\"%d\",\"P7\":\"%d\"}",ioState[0],ioState[1],ioState[2],ioState[3],ioState[4],ioState[5],ioState[6],ioState[7]);
|
sprintf(buffer,"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{\"status\":\"ok\",\"P0\":\"%d\",\"P1\":\"%d\",\"P2\":\"%d\",\"P3\":\"%d\",\"P4\":\"%d\",\"P5\":\"%d\",\"P6\":\"%d\",\"P7\":\"%d\"}",ioState[0],ioState[1],ioState[2],ioState[3],ioState[4],ioState[5],ioState[6],ioState[7]);
|
||||||
|
|
||||||
WEBServer<WEBClient>::sendHTTPHeader(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer));
|
|
||||||
wc->print(buffer);
|
wc->print(buffer);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -449,19 +440,11 @@ boolean ioGetModeApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc,
|
|||||||
|
|
||||||
if(HRD.getParams.count() == 0)//We send every IO mode
|
if(HRD.getParams.count() == 0)//We send every IO mode
|
||||||
{
|
{
|
||||||
sprintf(buffer,"{\"status\":\"ok\",\"P0\":\"%s\",\"P1\":\"%s\",\"P2\":\"%s\",\"P3\":\"%s\",\"P4\":\"%s\",\"P5\":\"%s\",\"P6\":\"%s\",\"P7\":\"%s\"}",
|
sprintf(buffer,"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{\"status\":\"ok\",\"P0\":\"%s\",\"P1\":\"%s\",\"P2\":\"%s\",\"P3\":\"%s\",\"P4\":\"%s\",\"P5\":\"%s\",\"P6\":\"%s\",\"P7\":\"%s\"}",ioMode[0] ? OUT:IN,ioMode[1] ? OUT:IN,ioMode[2] ? OUT:IN,ioMode[3] ? OUT:IN,ioMode[4] ? OUT:IN,ioMode[5] ? OUT:IN,ioMode[6] ? OUT:IN,ioMode[7] ? OUT:IN);
|
||||||
ioMode[0] ? OUT:IN,
|
|
||||||
ioMode[1] ? OUT:IN,
|
|
||||||
ioMode[2] ? OUT:IN,
|
|
||||||
ioMode[3] ? OUT:IN,
|
|
||||||
ioMode[4] ? OUT:IN,
|
|
||||||
ioMode[5] ? OUT:IN,
|
|
||||||
ioMode[6] ? OUT:IN,
|
|
||||||
ioMode[7] ? OUT:IN);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
strcpy(buffer,"{\"status\":\"ok\"");
|
strcpy(buffer,"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{\"status\":\"ok\"");
|
||||||
if(HRD.getParams("P0") != NULL)
|
if(HRD.getParams("P0") != NULL)
|
||||||
{
|
{
|
||||||
sprintf(helperBuffer,",\"P0\":\"%s\"",ioMode[0] ? OUT:IN);
|
sprintf(helperBuffer,",\"P0\":\"%s\"",ioMode[0] ? OUT:IN);
|
||||||
@ -505,7 +488,6 @@ boolean ioGetModeApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc,
|
|||||||
strcat(buffer," }");
|
strcat(buffer," }");
|
||||||
}
|
}
|
||||||
|
|
||||||
WEBServer<WEBClient>::sendHTTPHeader(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer));
|
|
||||||
wc->print(buffer);
|
wc->print(buffer);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -551,9 +533,8 @@ boolean ioSetModeApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc,
|
|||||||
}
|
}
|
||||||
|
|
||||||
p->getIoManager().getPcf().getPinModeAll(ioMode);//We retrieve the IO modes aka INPUT or OUTPUT
|
p->getIoManager().getPcf().getPinModeAll(ioMode);//We retrieve the IO modes aka INPUT or OUTPUT
|
||||||
sprintf(buffer,"{\"status\":\"ok\",\"P0\":\"%s\",\"P1\":\"%s\",\"P2\":\"%s\",\"P3\":\"%s\",\"P4\":\"%s\",\"P5\":\"%s\",\"P6\":\"%s\",\"P7\":\"%s\"}",ioMode[0] ? OUT:IN,ioMode[1] ? OUT:IN,ioMode[2] ? OUT:IN,ioMode[3] ? OUT:IN,ioMode[4] ? OUT:IN,ioMode[5] ? OUT:IN,ioMode[6] ? OUT:IN,ioMode[7] ? OUT:IN);
|
sprintf(buffer,"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{\"status\":\"ok\",\"P0\":\"%s\",\"P1\":\"%s\",\"P2\":\"%s\",\"P3\":\"%s\",\"P4\":\"%s\",\"P5\":\"%s\",\"P6\":\"%s\",\"P7\":\"%s\"}",ioMode[0] ? OUT:IN,ioMode[1] ? OUT:IN,ioMode[2] ? OUT:IN,ioMode[3] ? OUT:IN,ioMode[4] ? OUT:IN,ioMode[5] ? OUT:IN,ioMode[6] ? OUT:IN,ioMode[7] ? OUT:IN);
|
||||||
|
|
||||||
WEBServer<WEBClient>::sendHTTPHeader(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer));
|
|
||||||
wc->print(buffer);
|
wc->print(buffer);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user