mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-12 01:53:07 +03:00
Merge remote-tracking branch 'esp8266/master'
This commit is contained in:
@ -50,6 +50,7 @@ HTTPClient::HTTPClient() {
|
||||
_returnCode = 0;
|
||||
_size = -1;
|
||||
_canReuse = false;
|
||||
_tcpTimeout = HTTPCLIENT_DEFAULT_TCP_TIMEOUT;
|
||||
|
||||
}
|
||||
|
||||
@ -252,6 +253,17 @@ void HTTPClient::setAuthorization(const char * auth) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* set the timeout for the TCP connection
|
||||
* @param timeout unsigned int
|
||||
*/
|
||||
void HTTPClient::setTimeout(uint16_t timeout) {
|
||||
_tcpTimeout = timeout;
|
||||
if(connected()) {
|
||||
_tcp->setTimeout(timeout);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* send a GET request
|
||||
* @return http code
|
||||
@ -354,16 +366,25 @@ int HTTPClient::sendRequest(const char * type, Stream * stream, size_t size) {
|
||||
|
||||
if(buff) {
|
||||
// read all data from stream and send it to server
|
||||
while(connected() && stream->available() && (len > 0 || len == -1)) {
|
||||
while(connected() && (stream->available() > -1) && (len > 0 || len == -1)) {
|
||||
|
||||
// get available data size
|
||||
size_t s = stream->available();
|
||||
|
||||
if(len) {
|
||||
s = ((s > len) ? len : s);
|
||||
}
|
||||
|
||||
if(s) {
|
||||
int c = stream->readBytes(buff, ((s > buff_size) ? buff_size : s));
|
||||
|
||||
// write it to Stream
|
||||
bytesWritten += _tcp->write((const uint8_t *) buff, c);
|
||||
int w = _tcp->write((const uint8_t *) buff, c);
|
||||
bytesWritten += w;
|
||||
if(w != c) {
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client][sendRequest] short write asked for %d but got %d\n", c, w);
|
||||
break;
|
||||
}
|
||||
|
||||
if(len > 0) {
|
||||
len -= c;
|
||||
@ -378,7 +399,7 @@ int HTTPClient::sendRequest(const char * type, Stream * stream, size_t size) {
|
||||
free(buff);
|
||||
|
||||
if(size && (int) size != bytesWritten) {
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client][sendRequest] Stream payload bytesWritten %d and size %d mismatch!.\n", bytesWritten, _size);
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client][sendRequest] Stream payload bytesWritten %d and size %d mismatch!.\n", bytesWritten, size);
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client][sendRequest] ERROR SEND PAYLOAD FAILED!");
|
||||
return HTTPC_ERROR_SEND_PAYLOAD_FAILED;
|
||||
} else {
|
||||
@ -386,7 +407,7 @@ int HTTPClient::sendRequest(const char * type, Stream * stream, size_t size) {
|
||||
}
|
||||
|
||||
} else {
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client][writeToStream] too less ram! need " HTTP_TCP_BUFFER_SIZE);
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client][sendRequest] too less ram! need %d\n", HTTP_TCP_BUFFER_SIZE);
|
||||
return HTTPC_ERROR_TOO_LESS_RAM;
|
||||
}
|
||||
|
||||
@ -470,7 +491,12 @@ int HTTPClient::writeToStream(Stream * stream) {
|
||||
int c = _tcp->readBytes(buff, ((size > buff_size) ? buff_size : size));
|
||||
|
||||
// write it to Stream
|
||||
bytesWritten += stream->write(buff, c);
|
||||
int w = stream->write(buff, c);
|
||||
bytesWritten += w;
|
||||
if(w != c) {
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client][writeToStream] short write asked for %d but got %d\n", c, w);
|
||||
break;
|
||||
}
|
||||
|
||||
if(len > 0) {
|
||||
len -= c;
|
||||
@ -491,7 +517,7 @@ int HTTPClient::writeToStream(Stream * stream) {
|
||||
}
|
||||
|
||||
} else {
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client][writeToStream] too less ram! need " HTTP_TCP_BUFFER_SIZE);
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client][writeToStream] too less ram! need %d\n", HTTP_TCP_BUFFER_SIZE);
|
||||
return HTTPC_ERROR_TOO_LESS_RAM;
|
||||
}
|
||||
|
||||
@ -659,7 +685,7 @@ bool HTTPClient::connect(void) {
|
||||
}
|
||||
|
||||
// set Timeout for readBytesUntil and readStringUntil
|
||||
_tcp->setTimeout(HTTPCLIENT_TCP_TIMEOUT);
|
||||
_tcp->setTimeout(_tcpTimeout);
|
||||
|
||||
#ifdef ESP8266
|
||||
_tcp->setNoDelay(true);
|
||||
|
@ -31,7 +31,7 @@
|
||||
#define DEBUG_HTTPCLIENT(...)
|
||||
#endif
|
||||
|
||||
#define HTTPCLIENT_TCP_TIMEOUT (1000)
|
||||
#define HTTPCLIENT_DEFAULT_TCP_TIMEOUT (1000)
|
||||
|
||||
/// HTTP client errors
|
||||
#define HTTPC_ERROR_CONNECTION_REFUSED (-1)
|
||||
@ -127,6 +127,7 @@ class HTTPClient {
|
||||
void setUserAgent(const char * userAgent);
|
||||
void setAuthorization(const char * user, const char * password);
|
||||
void setAuthorization(const char * auth);
|
||||
void setTimeout(uint16_t timeout);
|
||||
|
||||
/// request handling
|
||||
int GET();
|
||||
@ -170,7 +171,7 @@ class HTTPClient {
|
||||
String _host;
|
||||
uint16_t _port;
|
||||
bool _reuse;
|
||||
|
||||
uint16_t _tcpTimeout;
|
||||
|
||||
String _url;
|
||||
bool _https;
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
class RequestHandler {
|
||||
public:
|
||||
virtual ~RequestHandler() { }
|
||||
virtual bool canHandle(HTTPMethod method, String uri) { return false; }
|
||||
virtual bool canUpload(String uri) { return false; }
|
||||
virtual bool handle(ESP8266WebServer& server, HTTPMethod requestMethod, String requestUri) { return false; }
|
||||
|
@ -897,6 +897,43 @@ void ESP8266WiFiClass::_smartConfigCallback(uint32_t st, void* result)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* set Sleep mode
|
||||
* @param type sleep_type_t
|
||||
* @return bool
|
||||
*/
|
||||
bool ESP8266WiFiClass::setSleepMode(WiFiSleepType_t type) {
|
||||
return wifi_set_sleep_type((sleep_type_t)type);
|
||||
}
|
||||
|
||||
/**
|
||||
* get Sleep mode
|
||||
* @return sleep_type_t
|
||||
*/
|
||||
WiFiSleepType_t ESP8266WiFiClass::getSleepMode() {
|
||||
return (WiFiSleepType_t)wifi_get_sleep_type();
|
||||
}
|
||||
|
||||
/**
|
||||
* set phy Mode
|
||||
* @param mode phy_mode_t
|
||||
* @return bool
|
||||
*/
|
||||
bool ESP8266WiFiClass::setPhyMode(WiFiPhyMode_t mode) {
|
||||
return wifi_set_phy_mode((phy_mode_t)mode);
|
||||
}
|
||||
|
||||
/**
|
||||
* get phy Mode
|
||||
* @return phy_mode_t
|
||||
*/
|
||||
WiFiPhyMode_t ESP8266WiFiClass::getPhyMode() {
|
||||
return (WiFiPhyMode_t)wifi_get_phy_mode();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
|
||||
void ESP8266WiFiClass::_eventCallback(void* arg)
|
||||
|
@ -36,8 +36,21 @@ extern "C" {
|
||||
#define WIFI_SCAN_RUNNING (-1)
|
||||
#define WIFI_SCAN_FAILED (-2)
|
||||
|
||||
|
||||
// Note:
|
||||
// this enums need to be in sync with the SDK!
|
||||
|
||||
enum WiFiMode { WIFI_OFF = 0, WIFI_STA = 1, WIFI_AP = 2, WIFI_AP_STA = 3 };
|
||||
|
||||
typedef enum {
|
||||
WIFI_PHY_MODE_11B = 1, WIFI_PHY_MODE_11G = 2, WIFI_PHY_MODE_11N = 3
|
||||
} WiFiPhyMode_t;
|
||||
|
||||
typedef enum {
|
||||
WIFI_NONE_SLEEP = 0, WIFI_LIGHT_SLEEP = 2, WIFI_MODEM_SLEEP = 3
|
||||
} WiFiSleepType_t;
|
||||
|
||||
|
||||
class ESP8266WiFiClass
|
||||
{
|
||||
public:
|
||||
@ -375,6 +388,32 @@ public:
|
||||
friend class WiFiClient;
|
||||
friend class WiFiServer;
|
||||
|
||||
/**
|
||||
* set Sleep mode
|
||||
* @param type WiFiPhyMode_t
|
||||
* @return bool
|
||||
*/
|
||||
bool setSleepMode(WiFiSleepType_t type);
|
||||
|
||||
/**
|
||||
* get Sleep mode
|
||||
* @return sleep_type_t
|
||||
*/
|
||||
WiFiSleepType_t getSleepMode();
|
||||
|
||||
/**
|
||||
* set phy Mode
|
||||
* @param mode phy_mode_t
|
||||
* @return bool
|
||||
*/
|
||||
bool setPhyMode(WiFiPhyMode_t mode);
|
||||
|
||||
/**
|
||||
* get phy Mode
|
||||
* @return phy_mode_t
|
||||
*/
|
||||
WiFiPhyMode_t getPhyMode();
|
||||
|
||||
protected:
|
||||
void _mode(WiFiMode);
|
||||
static void _scanDone(void* result, int status);
|
||||
|
@ -493,8 +493,9 @@ extern "C" void* ax_port_malloc(size_t size, const char* file, int line) {
|
||||
DEBUG_TLS_MEM_PRINT("%s:%d malloc %d failed, left %d\r\n", file, line, size, ESP.getFreeHeap());
|
||||
panic();
|
||||
}
|
||||
if (size >= 1024)
|
||||
if (size >= 1024) {
|
||||
DEBUG_TLS_MEM_PRINT("%s:%d malloc %d, left %d\r\n", file, line, size, ESP.getFreeHeap());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -510,8 +511,9 @@ extern "C" void* ax_port_realloc(void* ptr, size_t size, const char* file, int l
|
||||
DEBUG_TLS_MEM_PRINT("%s:%d realloc %d failed, left %d\r\n", file, line, size, ESP.getFreeHeap());
|
||||
panic();
|
||||
}
|
||||
if (size >= 1024)
|
||||
if (size >= 1024) {
|
||||
DEBUG_TLS_MEM_PRINT("%s:%d realloc %d, left %d\r\n", file, line, size, ESP.getFreeHeap());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -519,6 +521,7 @@ extern "C" void ax_port_free(void* ptr) {
|
||||
free(ptr);
|
||||
uint32_t *p = (uint32_t*) ptr;
|
||||
size_t size = p[-3];
|
||||
if (size >= 1024)
|
||||
if (size >= 1024) {
|
||||
DEBUG_TLS_MEM_PRINT("free %d, left %d\r\n", p[-3], ESP.getFreeHeap());
|
||||
}
|
||||
}
|
||||
|
@ -299,7 +299,7 @@ static void ATTR_GDBFN sendReason() {
|
||||
} else if (gdbstub_savedRegs.reason&0x80) {
|
||||
//We stopped because of an exception. Convert exception code to a signal number and send it.
|
||||
i=gdbstub_savedRegs.reason&0x7f;
|
||||
if (i<sizeof(exceptionSignal)) return gdbPacketHex(exceptionSignal[i], 8); else gdbPacketHex(11, 8);
|
||||
if (i<sizeof(exceptionSignal)) gdbPacketHex(exceptionSignal[i], 8); else gdbPacketHex(11, 8);
|
||||
} else {
|
||||
//We stopped because of a debugging exception.
|
||||
gdbPacketHex(5, 8); //sigtrap
|
||||
|
Reference in New Issue
Block a user