Compare commits
6 Commits
e68ab04195
...
db1873b714
Author | SHA1 | Date | |
---|---|---|---|
|
db1873b714 | ||
|
1c1992820d | ||
|
9d831f11d9 | ||
|
8c6dd39bd7 | ||
|
11f3f85dde | ||
|
2943ed5da6 |
@ -17,6 +17,7 @@ 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 {
|
||||||
@ -128,6 +129,9 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenManager::displayNextView()
|
boolean ScreenManager::displayNextView()
|
||||||
{
|
{
|
||||||
_autoOFFDelayRef = millis();
|
_autoOFFDelayRef = millis();
|
||||||
if(!_enabled) return;
|
if(!_enabled) return false;
|
||||||
_forceRefresh = true;
|
_forceRefresh = true;
|
||||||
_error = OK;
|
_error = OK;
|
||||||
if(isListEmpty(_viewLinkedList))return;
|
if(isListEmpty(_viewLinkedList))return false;
|
||||||
|
|
||||||
if(_currentView == NO_CURRENT_VIEW)
|
if(_currentView == NO_CURRENT_VIEW)
|
||||||
{
|
{
|
||||||
@ -328,15 +328,16 @@ void ScreenManager::displayNextView()
|
|||||||
}
|
}
|
||||||
|
|
||||||
run();
|
run();
|
||||||
|
return _error == OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenManager::displayPreviousView()
|
boolean ScreenManager::displayPreviousView()
|
||||||
{
|
{
|
||||||
_autoOFFDelayRef = millis();
|
_autoOFFDelayRef = millis();
|
||||||
if(!_enabled) return;
|
if(!_enabled) return false;
|
||||||
_forceRefresh = true;
|
_forceRefresh = true;
|
||||||
_error = OK;
|
_error = OK;
|
||||||
if(isListEmpty(_tail))return;
|
if(isListEmpty(_tail))return false;
|
||||||
|
|
||||||
if(_currentView == NO_CURRENT_VIEW)
|
if(_currentView == NO_CURRENT_VIEW)
|
||||||
{
|
{
|
||||||
@ -363,6 +364,7 @@ void 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);
|
||||||
void displayNextView();
|
boolean displayNextView();
|
||||||
void displayPreviousView();
|
boolean displayPreviousView();
|
||||||
void forceRefresh();
|
void forceRefresh();
|
||||||
boolean applyCfgFromSD();
|
boolean applyCfgFromSD();
|
||||||
void invertDisplayColor(const boolean inverted);
|
void invertDisplayColor(const boolean inverted);
|
||||||
|
@ -55,11 +55,19 @@ 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, 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 = 0, 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)
|
||||||
@ -601,8 +609,9 @@ class WEBServer : public TCPServer<T>, public HttpConstants
|
|||||||
Serial.println(pageToSend.name());
|
Serial.println(pageToSend.name());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(pageToSend.isDirectory()) //To DO : List the files present in the directory
|
if(pageToSend.isDirectory()) //TODO : 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");
|
||||||
@ -691,8 +700,47 @@ class WEBServer : public TCPServer<T>, public HttpConstants
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*Static helper methods*/
|
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 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];
|
||||||
@ -752,6 +800,7 @@ 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,7 +88,6 @@ 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,17 +21,19 @@ boolean viewByUIDApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc,
|
|||||||
|
|
||||||
if(pSE == NULL)
|
if(pSE == NULL)
|
||||||
{
|
{
|
||||||
sprintf(buffer, "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{\"status\":\"failed\",\"message\":\"expected UID parameter\"}");
|
strcpy(buffer, "{\"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, "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{\"status\":\"ok\",\"ViewUID\":\"%d\"}", p->getScreenManager().getCurrentViewUID());
|
sprintf(buffer, "{\"status\":\"ok\",\"ViewUID\":\"%d\"}", p->getScreenManager().getCurrentViewUID());
|
||||||
else
|
else
|
||||||
sprintf(buffer, "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{\"status\":\"failed\",\"message\":\"%s\"}", p->getScreenManager().getErrorMessage());
|
sprintf(buffer, "{\"status\":\"failed\",\"message\":\"%s\"}", p->getScreenManager().getErrorMessage());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
sprintf(buffer, "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{\"status\":\"failed\",\"message\":\"UID parameter empty\"}");
|
strcpy(buffer, "{\"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;
|
||||||
}
|
}
|
||||||
@ -42,12 +44,12 @@ boolean nextViewApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc,
|
|||||||
SAB *p = (SAB *)pData;
|
SAB *p = (SAB *)pData;
|
||||||
char buffer[200];
|
char buffer[200];
|
||||||
|
|
||||||
p->getScreenManager().displayNextView();
|
if(p->getScreenManager().displayNextView())
|
||||||
|
sprintf(buffer, "{\"status\":\"ok\",\"ViewUID\":\"%d\"}", p->getScreenManager().getCurrentViewUID());
|
||||||
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
|
else
|
||||||
sprintf(buffer, "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{\"status\":\"failed\",\"message\":\"%s\"}", p->getScreenManager().getErrorMessage());
|
sprintf(buffer, "{\"status\":\"failed\",\"message\":\"%s\"}", p->getScreenManager().getErrorMessage());
|
||||||
|
|
||||||
|
WEBServer<WEBClient>::sendHTTPHeader(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer));
|
||||||
wc->print(buffer);
|
wc->print(buffer);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -59,10 +61,11 @@ boolean reloadViewApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc
|
|||||||
char buffer[200];
|
char buffer[200];
|
||||||
|
|
||||||
if(p->getScreenManager().init())
|
if(p->getScreenManager().init())
|
||||||
strcpy(buffer, "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{\"status\":\"ok\",\"message\":\"config reloaded\"}");
|
strcpy(buffer, "{\"status\":\"ok\",\"message\":\"config reloaded\"}");
|
||||||
else
|
else
|
||||||
strcpy(buffer, "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{\"status\":\"failed\",\"message\":\"unable to reload config\"}");
|
strcpy(buffer, "{\"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;
|
||||||
}
|
}
|
||||||
@ -88,22 +91,20 @@ 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)
|
||||||
{
|
{
|
||||||
sprintf(buffer,"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{\"status\":\"failed\",\"message\":\"expected datetime parameter\"}");
|
strcpy(buffer,"{\"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)
|
||||||
{
|
{
|
||||||
sprintf(buffer,"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{\"status\":\"failed\",\"message\":\"datetime format error\"}");
|
strcpy(buffer,"{\"status\":\"failed\",\"message\":\"datetime format error\"}");
|
||||||
wc->print(buffer);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(dictio->count() != 6)
|
if(dictio->count() != 6)
|
||||||
{
|
{
|
||||||
sprintf(buffer,"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{\"status\":\"error\",\"message\":\"datetime format error\"}");
|
strcpy(buffer,"{\"status\":\"error\",\"message\":\"datetime format error\"}");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -116,15 +117,16 @@ 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,"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());
|
sprintf(buffer,"{\"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;
|
||||||
}
|
}
|
||||||
@ -183,7 +185,8 @@ boolean espRestartApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc
|
|||||||
SAB *sab = (SAB*)pData;
|
SAB *sab = (SAB*)pData;
|
||||||
char buffer[200];
|
char buffer[200];
|
||||||
|
|
||||||
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");
|
sprintf(buffer,"{\"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()
|
||||||
@ -206,10 +209,11 @@ 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)
|
||||||
sprintf(buffer,"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{\"status\":\"ok\",\"card\":\"not present\",\"size\":\"0\"}");
|
strcpy(buffer,"{\"status\":\"ok\",\"card\":\"not present\",\"size\":\"0\"}");
|
||||||
else
|
else
|
||||||
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);
|
sprintf(buffer,"{\"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;
|
||||||
}
|
}
|
||||||
@ -222,8 +226,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;
|
||||||
}
|
}
|
||||||
@ -247,7 +251,8 @@ 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();
|
||||||
wc->print("HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n[");
|
WEBServer<WEBClient>::sendHTTPHeader(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON));
|
||||||
|
wc->print("[");
|
||||||
|
|
||||||
for(uint8_t i(0); i < number; i++)
|
for(uint8_t i(0); i < number; i++)
|
||||||
{
|
{
|
||||||
@ -283,12 +288,13 @@ 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,"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);
|
sprintf(buffer,"{\"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;
|
||||||
@ -321,6 +327,7 @@ 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)
|
||||||
{
|
{
|
||||||
@ -330,11 +337,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,"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]);
|
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]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
strcpy(buffer,"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{\"status\":\"ok\"");
|
strcpy(buffer,"{\"status\":\"ok\"");
|
||||||
if(HRD.getParams("P0") != NULL)
|
if(HRD.getParams("P0") != NULL)
|
||||||
{
|
{
|
||||||
sprintf(helperBuffer,",\"P0\":\"%d\"",ioState[0]);
|
sprintf(helperBuffer,",\"P0\":\"%d\"",ioState[0]);
|
||||||
@ -378,6 +385,7 @@ 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;
|
||||||
}
|
}
|
||||||
@ -422,8 +430,9 @@ 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,"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]);
|
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]);
|
||||||
|
|
||||||
|
WEBServer<WEBClient>::sendHTTPHeader(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer));
|
||||||
wc->print(buffer);
|
wc->print(buffer);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -440,11 +449,19 @@ 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,"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);
|
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);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
strcpy(buffer,"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{\"status\":\"ok\"");
|
strcpy(buffer,"{\"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);
|
||||||
@ -488,6 +505,7 @@ 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;
|
||||||
}
|
}
|
||||||
@ -533,8 +551,9 @@ 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,"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);
|
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);
|
||||||
|
|
||||||
|
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