diff --git a/.gitignore b/.gitignore index 3c8c0fe5c..d88f1f2da 100644 --- a/.gitignore +++ b/.gitignore @@ -72,3 +72,4 @@ nbproject build/macosx/esptool-*-osx.zip build/macosx/dist/osx-xtensa-lx106-elf.tgz +/hardware/esp8266com/esp8266/tools diff --git a/cores/esp8266/core_esp8266_wiring_analog.c b/cores/esp8266/core_esp8266_wiring_analog.c index bb5151018..53451b713 100644 --- a/cores/esp8266/core_esp8266_wiring_analog.c +++ b/cores/esp8266/core_esp8266_wiring_analog.c @@ -21,34 +21,13 @@ #include "wiring_private.h" #include "pins_arduino.h" +extern uint16_t readvdd33(void); + void analogReference(uint8_t mode) {} extern int __analogRead(uint8_t pin) { if(pin == 17){ - //return system_adc_read(); - uint8_t i; - uint16_t data[8]; - - rom_i2c_writeReg_Mask(0x6C,2,0,5,5,1); - - ESP8266_REG(0xD5C) |= (1 << 21); - while ((ESP8266_REG(0xD50) & (7 << 24)) > 0); - ESP8266_REG(0xD50) &= ~(1 << 1); - ESP8266_REG(0xD50) |= (1 << 1); - delayMicroseconds(2); - while ((ESP8266_REG(0xD50) & (7 << 24)) > 0); - - read_sar_dout(data); - rom_i2c_writeReg_Mask(0x6C,2,0,5,5,1); - - while ((ESP8266_REG(0xD50) & (7 << 24)) > 0); - ESP8266_REG(0xD5C) &= ~(1 << 21); - ESP8266_REG(0xD60) |= (1 << 0); - ESP8266_REG(0xD60) &= ~(1 << 0); - - uint16_t tout = 0; - for (i = 0; i < 8; i++) tout += data[i]; - return tout >> 4;//tout is 10 bits fraction + return readvdd33() >> 2; // readvdd33 is 12 bit } return digitalRead(pin) * 1023; } diff --git a/cores/esp8266/debug.cpp b/cores/esp8266/debug.cpp index 5e280122e..68d3a6b82 100644 --- a/cores/esp8266/debug.cpp +++ b/cores/esp8266/debug.cpp @@ -26,6 +26,7 @@ void ICACHE_RAM_ATTR hexdump(uint8_t *mem, uint32_t len, uint8_t cols) { for(uint32_t i = 0; i < len; i++) { if(i % cols == 0) { os_printf("\n[0x%08X] 0x%08X: ", mem, i); + yield(); } os_printf("%02X ", *mem); mem++; diff --git a/libraries/ESP8266WebServer/src/ESP8266WebServer.cpp b/libraries/ESP8266WebServer/src/ESP8266WebServer.cpp index 391cc556c..054929971 100644 --- a/libraries/ESP8266WebServer/src/ESP8266WebServer.cpp +++ b/libraries/ESP8266WebServer/src/ESP8266WebServer.cpp @@ -101,7 +101,8 @@ void ESP8266WebServer::handleClient() #endif // Wait for data from client to become available - while(client.connected() && !client.available()){ + uint16_t maxWait = HTTP_MAX_DATA_WAIT; + while(client.connected() && !client.available() && maxWait--){ delay(1); } @@ -136,7 +137,12 @@ void ESP8266WebServer::send(int code, const char* content_type, String content) if (!content_type) content_type = "text/html"; + + String len(content.length()); sendHeader("Content-Type", content_type, true); + sendHeader("Content-Length", len.c_str()); + sendHeader("Connection", "close"); + sendHeader("Access-Control-Allow-Origin", "*"); response += _responseHeaders; response += "\r\n"; @@ -145,6 +151,14 @@ void ESP8266WebServer::send(int code, const char* content_type, String content) sendContent(response); } +void ESP8266WebServer::send(int code, char* content_type, String content) { + send(code, (const char*)content_type, content); +} + +void ESP8266WebServer::send(int code, String content_type, String content) { + send(code, (const char*)content_type.c_str(), content); +} + void ESP8266WebServer::sendContent(String content) { size_t size_to_send = content.length(); size_t size_sent = 0; @@ -158,6 +172,10 @@ void ESP8266WebServer::sendContent(String content) { break; } } + uint16_t maxWait = HTTP_MAX_CLOSE_WAIT; + while(_currentClient.connected() && maxWait--) { + delay(1); + } } String ESP8266WebServer::arg(const char* name) { diff --git a/libraries/ESP8266WebServer/src/ESP8266WebServer.h b/libraries/ESP8266WebServer/src/ESP8266WebServer.h index d957e15ba..9f2b16480 100644 --- a/libraries/ESP8266WebServer/src/ESP8266WebServer.h +++ b/libraries/ESP8266WebServer/src/ESP8266WebServer.h @@ -31,6 +31,8 @@ enum HTTPUploadStatus { UPLOAD_FILE_START, UPLOAD_FILE_WRITE, UPLOAD_FILE_END }; #define HTTP_DOWNLOAD_UNIT_SIZE 1460 #define HTTP_UPLOAD_BUFLEN 2048 +#define HTTP_MAX_DATA_WAIT 1000 //ms to wait for the client to send the request +#define HTTP_MAX_CLOSE_WAIT 2000 //ms to wait for the client to close the connection typedef struct { HTTPUploadStatus status; @@ -73,6 +75,8 @@ public: // content_type - HTTP content type, like "text/plain" or "image/png" // content - actual content body void send(int code, const char* content_type = NULL, String content = String("")); + void send(int code, char* content_type, String content); + void send(int code, String content_type, String content); void sendHeader(String name, String value, bool first = false); void sendContent(String content); @@ -87,7 +91,12 @@ template size_t streamFile(T &file, String contentType){ head += "\r\n\r\n"; _currentClient.print(head); head = String(); - return _currentClient.write(file, HTTP_DOWNLOAD_UNIT_SIZE); + size_t res = _currentClient.write(file, HTTP_DOWNLOAD_UNIT_SIZE); + uint16_t maxWait = HTTP_MAX_CLOSE_WAIT; + while(_currentClient.connected() && maxWait--) { + delay(1); + } + return res; } protected: