/*! restCallback(void *res) @brief Function called by esp-link when data is sent, received or an error occured. @details The function is called by esp-link when data is sent or received from the remote server. @note Internal library function @param res Pointer to ELClientResponse structure @warning The content of the response structure is overwritten when the next package arrives! */ void ELClientRest::restCallback(void *res) { if (!res) return; ELClientResponse *resp = (ELClientResponse *)res; resp->popArg(&_status, sizeof(_status)); if (_elc->_debugEn) { _elc->_debug->print("REST code "); _elc->_debug->println(_status); } _len = resp->popArgPtr(&_data); }
void httpCbHandler(void *response) { ELClientResponse *resp = (ELClientResponse *)response; char requestType[20]; // GET or POST char url[128]; // URL without the query string char vars[128]; // query string after the "?" in the url char post[128]; // post data int ret; Serial.print("Argc: "); Serial.println(resp->argc()); if (resp->argc() != 4) { http.sendResponse(400, "Malformed request"); return; } resp->popArg(requestType, sizeof(requestType)); resp->popArg(url, sizeof(url)); resp->popArg(vars, sizeof(vars)); resp->popArg(post, sizeof(post)); Serial.print("HTTP "); Serial.print(requestType); Serial.println(" request"); Serial.print(" URL: "); Serial.println(url); Serial.print(" VARS: "); Serial.println(vars); Serial.print(" POST: "); Serial.println(post); #ifdef INTERNAL_PAGE if (strcmp(requestType, "GET") == 0) ret = http.sendResponse(200, webpage1); else #endif if (strcmp(requestType, "POST") == 0) { const char *p; if ((p = strstr(post, "gto=")) != NULL) { if (myRobot.processButton(p[4])) ret = http.sendResponse(200, "Robot operation completed."); else ret = http.sendResponse(400, "Unknown robot operation."); } else ret = http.sendResponse(400, "Unknown request."); } Serial.print("sendResponse returned "); Serial.println(ret); }