Compare commits
2 Commits
f44b7486b8
...
d9cb8bf6bc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d9cb8bf6bc | ||
|
|
9d4edfc0f0 |
@ -86,7 +86,7 @@ boolean HttpClient::connectByHostOrIp()
|
|||||||
return _connectionStatus == SUCCESSFUL;
|
return _connectionStatus == SUCCESSFUL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int HttpClient::sendHttpQuery(const char *resource, HttpRequestMethod method, Dictionary<DictionaryHelper::StringEntity> *getData, Dictionary<DictionaryHelper::StringEntity> *postData, Dictionary<DictionaryHelper::StringEntity> *headerData)
|
HttpClient::HttpQueryStatus 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 @@ int HttpClient::sendHttpQuery(const char *resource, HttpRequestMethod method, Di
|
|||||||
return sendHttpQuery(method, getData, postData, headerData);
|
return sendHttpQuery(method, getData, postData, headerData);
|
||||||
}
|
}
|
||||||
|
|
||||||
int HttpClient::sendHttpQuery(HttpRequestMethod method, Dictionary<DictionaryHelper::StringEntity> *getData, Dictionary<DictionaryHelper::StringEntity> *postData, Dictionary<DictionaryHelper::StringEntity> *headerData)
|
HttpClient::HttpQueryStatus 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 @@ int HttpClient::sendHttpQuery(HttpRequestMethod method, Dictionary<DictionaryHel
|
|||||||
|
|
||||||
if(!connected() || _connectionStatus == FAILED)
|
if(!connected() || _connectionStatus == FAILED)
|
||||||
{
|
{
|
||||||
if(_retries == _maxRetries) return -__LINE__;
|
if(_retries == _maxRetries) return HttpQueryStatus::ERR_CONN_MAX_RETRY;
|
||||||
|
|
||||||
if(_connectionStatus == FAILED)
|
if(_connectionStatus == FAILED)
|
||||||
{
|
{
|
||||||
@ -138,7 +138,7 @@ int HttpClient::sendHttpQuery(HttpRequestMethod method, Dictionary<DictionaryHel
|
|||||||
Serial.printf("Failed to reconnect\n");
|
Serial.printf("Failed to reconnect\n");
|
||||||
#endif
|
#endif
|
||||||
stop();
|
stop();
|
||||||
return -__LINE__;
|
return HttpQueryStatus::ERR_CONN;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
_retries = 0;
|
_retries = 0;
|
||||||
@ -174,12 +174,12 @@ int HttpClient::sendHttpQuery(HttpRequestMethod method, Dictionary<DictionaryHel
|
|||||||
Serial.printf("Http verb unspecified\n");
|
Serial.printf("Http verb unspecified\n");
|
||||||
#endif
|
#endif
|
||||||
if(!_keepAlive)stop();
|
if(!_keepAlive)stop();
|
||||||
return -__LINE__;
|
return HttpQueryStatus::UNKNOWN_HTTP_METHOD;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return HttpQueryStatus::SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpClient::HTTP_CODE HttpClient::isReplyAvailable(uint16_t timeout)
|
HttpClient::HTTP_CODE HttpClient::isReplyAvailable(uint16_t timeout)
|
||||||
|
|||||||
@ -17,7 +17,7 @@ namespace HttpClientHelper
|
|||||||
class HttpClient : public WiFiClient, public HttpConstants
|
class HttpClient : public WiFiClient, public HttpConstants
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum ConnectionStatus { NO_ATTEMPT = 0, SUCCESSFUL, FAILED };
|
enum HttpQueryStatus { SUCCESS = 0, ERR_CONN, ERR_CONN_MAX_RETRY, UNKNOWN_HTTP_METHOD };
|
||||||
|
|
||||||
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();
|
||||||
|
|
||||||
int sendHttpQuery(const char *resource,
|
HttpQueryStatus 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);
|
||||||
|
|
||||||
int sendHttpQuery(HttpRequestMethod method = HttpRequestMethod::GET,
|
HttpQueryStatus 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,6 +46,8 @@ 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);
|
||||||
|
|||||||
@ -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) == 0)
|
if(httpClient.sendHttpQuery(HttpClient::HttpRequestMethod::GET, &getData, NULL, &headerData) == HttpClient::HttpQueryStatus::SUCCESS)
|
||||||
{
|
{
|
||||||
HttpConstants::HTTP_CODE result = httpClient.isReplyAvailable(1000);
|
HttpConstants::HTTP_CODE result = httpClient.isReplyAvailable(1000);
|
||||||
switch(result)
|
switch(result)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user