Compare commits

..

No commits in common. "d9cb8bf6bccf85b542ebfbb07c255bfedd9a1104" and "f44b7486b8e0ecf61ac8da8e9e1031e7afbe78cc" have entirely different histories.

3 changed files with 10 additions and 12 deletions

View File

@ -86,7 +86,7 @@ boolean HttpClient::connectByHostOrIp()
return _connectionStatus == SUCCESSFUL; return _connectionStatus == SUCCESSFUL;
} }
HttpClient::HttpQueryStatus HttpClient::sendHttpQuery(const char *resource, HttpRequestMethod method, Dictionary<DictionaryHelper::StringEntity> *getData, Dictionary<DictionaryHelper::StringEntity> *postData, Dictionary<DictionaryHelper::StringEntity> *headerData) int HttpClient::sendHttpQuery(const char *resource, HttpRequestMethod method, Dictionary<DictionaryHelper::StringEntity> *getData, Dictionary<DictionaryHelper::StringEntity> *postData, Dictionary<DictionaryHelper::StringEntity> *headerData)
{ {
if(resource != NULL) //We overwrite the resource if it has been already defined if(resource != NULL) //We overwrite the resource if it has been already defined
{ {
@ -101,7 +101,7 @@ HttpClient::HttpQueryStatus HttpClient::sendHttpQuery(const char *resource, Http
return sendHttpQuery(method, getData, postData, headerData); return sendHttpQuery(method, getData, postData, headerData);
} }
HttpClient::HttpQueryStatus HttpClient::sendHttpQuery(HttpRequestMethod method, Dictionary<DictionaryHelper::StringEntity> *getData, Dictionary<DictionaryHelper::StringEntity> *postData, Dictionary<DictionaryHelper::StringEntity> *headerData) int HttpClient::sendHttpQuery(HttpRequestMethod method, Dictionary<DictionaryHelper::StringEntity> *getData, Dictionary<DictionaryHelper::StringEntity> *postData, Dictionary<DictionaryHelper::StringEntity> *headerData)
{ {
//We reset this two flags //We reset this two flags
_httpCode = HTTP_CODE::UNDEFINED_CODE; _httpCode = HTTP_CODE::UNDEFINED_CODE;
@ -117,7 +117,7 @@ HttpClient::HttpQueryStatus HttpClient::sendHttpQuery(HttpRequestMethod method,
if(!connected() || _connectionStatus == FAILED) if(!connected() || _connectionStatus == FAILED)
{ {
if(_retries == _maxRetries) return HttpQueryStatus::ERR_CONN_MAX_RETRY; if(_retries == _maxRetries) return -__LINE__;
if(_connectionStatus == FAILED) if(_connectionStatus == FAILED)
{ {
@ -138,7 +138,7 @@ HttpClient::HttpQueryStatus HttpClient::sendHttpQuery(HttpRequestMethod method,
Serial.printf("Failed to reconnect\n"); Serial.printf("Failed to reconnect\n");
#endif #endif
stop(); stop();
return HttpQueryStatus::ERR_CONN; return -__LINE__;
} }
else else
_retries = 0; _retries = 0;
@ -174,12 +174,12 @@ HttpClient::HttpQueryStatus HttpClient::sendHttpQuery(HttpRequestMethod method,
Serial.printf("Http verb unspecified\n"); Serial.printf("Http verb unspecified\n");
#endif #endif
if(!_keepAlive)stop(); if(!_keepAlive)stop();
return HttpQueryStatus::UNKNOWN_HTTP_METHOD; return -__LINE__;
break; break;
} }
} }
return HttpQueryStatus::SUCCESS; return 0;
} }
HttpClient::HTTP_CODE HttpClient::isReplyAvailable(uint16_t timeout) HttpClient::HTTP_CODE HttpClient::isReplyAvailable(uint16_t timeout)

View File

@ -17,7 +17,7 @@ namespace HttpClientHelper
class HttpClient : public WiFiClient, public HttpConstants class HttpClient : public WiFiClient, public HttpConstants
{ {
public: public:
enum HttpQueryStatus { SUCCESS = 0, ERR_CONN, ERR_CONN_MAX_RETRY, UNKNOWN_HTTP_METHOD }; enum ConnectionStatus { NO_ATTEMPT = 0, SUCCESSFUL, FAILED };
HttpClient(const char *address, uint16_t port = 80, uint32_t timeout = 5000); HttpClient(const char *address, uint16_t port = 80, uint32_t timeout = 5000);
HttpClient(const char *address, const char *resource, uint16_t port = 80, uint32_t timeout = 5000); HttpClient(const char *address, const char *resource, uint16_t port = 80, uint32_t timeout = 5000);
@ -25,13 +25,13 @@ class HttpClient : public WiFiClient, public HttpConstants
HttpClient(const HttpClient &object); HttpClient(const HttpClient &object);
virtual ~HttpClient(); virtual ~HttpClient();
HttpQueryStatus sendHttpQuery(const char *resource, int sendHttpQuery(const char *resource,
HttpRequestMethod method = HttpRequestMethod::GET, HttpRequestMethod method = HttpRequestMethod::GET,
Dictionary<DictionaryHelper::StringEntity> *getData = NULL, Dictionary<DictionaryHelper::StringEntity> *getData = NULL,
Dictionary<DictionaryHelper::StringEntity> *postData = NULL, Dictionary<DictionaryHelper::StringEntity> *postData = NULL,
Dictionary<DictionaryHelper::StringEntity> *headerData = NULL); Dictionary<DictionaryHelper::StringEntity> *headerData = NULL);
HttpQueryStatus sendHttpQuery(HttpRequestMethod method = HttpRequestMethod::GET, int sendHttpQuery(HttpRequestMethod method = HttpRequestMethod::GET,
Dictionary<DictionaryHelper::StringEntity> *getData = NULL, Dictionary<DictionaryHelper::StringEntity> *getData = NULL,
Dictionary<DictionaryHelper::StringEntity> *postData = NULL, Dictionary<DictionaryHelper::StringEntity> *postData = NULL,
Dictionary<DictionaryHelper::StringEntity> *headerData = NULL); Dictionary<DictionaryHelper::StringEntity> *headerData = NULL);
@ -46,8 +46,6 @@ class HttpClient : public WiFiClient, public HttpConstants
uint16_t readHttpBody(uint8_t *buffer, uint32_t size); uint16_t readHttpBody(uint8_t *buffer, uint32_t size);
protected: protected:
private: private:
enum ConnectionStatus { NO_ATTEMPT = 0, SUCCESSFUL, FAILED };
boolean connectByHostOrIp(); boolean connectByHostOrIp();
void sendUriWithGetParams(Dictionary<DictionaryHelper::StringEntity> *data); void sendUriWithGetParams(Dictionary<DictionaryHelper::StringEntity> *data);
void sendPostData(Dictionary<DictionaryHelper::StringEntity> *data); void sendPostData(Dictionary<DictionaryHelper::StringEntity> *data);

View File

@ -127,7 +127,7 @@ OTAUpdater::UpdateInfo OTAUpdater::fetchUpdateInfo(const char *softwareVersion,
headerData.add("x-ESP8266-STA-MAC",DictionaryHelper::StringEntity(WiFi.macAddress().c_str())); headerData.add("x-ESP8266-STA-MAC",DictionaryHelper::StringEntity(WiFi.macAddress().c_str()));
headerData.add("User-Agent",DictionaryHelper::StringEntity("ESP8266-http-Update")); headerData.add("User-Agent",DictionaryHelper::StringEntity("ESP8266-http-Update"));
if(httpClient.sendHttpQuery(HttpClient::HttpRequestMethod::GET, &getData, NULL, &headerData) == HttpClient::HttpQueryStatus::SUCCESS) if(httpClient.sendHttpQuery(HttpClient::HttpRequestMethod::GET, &getData, NULL, &headerData) == 0)
{ {
HttpConstants::HTTP_CODE result = httpClient.isReplyAvailable(1000); HttpConstants::HTTP_CODE result = httpClient.isReplyAvailable(1000);
switch(result) switch(result)