mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-21 10:26:06 +03:00
Merge commit '7e7632378490ae766e71b05cdf6d1ea500dbd6ce' into esp8266
This commit is contained in:
commit
24b919a8c6
@ -188,7 +188,7 @@ See attached example and library README file for details.
|
|||||||
Libraries that don't rely on low-level access to AVR registers should work well. Here are a few libraries that were verified to work:
|
Libraries that don't rely on low-level access to AVR registers should work well. Here are a few libraries that were verified to work:
|
||||||
|
|
||||||
- [aREST](https://github.com/marcoschwartz/aREST) REST API handler library.
|
- [aREST](https://github.com/marcoschwartz/aREST) REST API handler library.
|
||||||
- [PubSubClient](https://github.com/knolleary/pubsubclient) MQTT library. Use this [sample](https://gist.github.com/igrr/7f7e7973366fc01d6393) to get started.
|
- [PubSubClient](https://github.com/Imroy/pubsubclient) MQTT library by @Imroy.
|
||||||
- [DHT11](https://github.com/adafruit/DHT-sensor-library) - initialize DHT as follows: ```DHT dht(DHTPIN, DHTTYPE, 15);```
|
- [DHT11](https://github.com/adafruit/DHT-sensor-library) - initialize DHT as follows: ```DHT dht(DHTPIN, DHTTYPE, 15);```
|
||||||
- [DallasTemperature](https://github.com/milesburton/Arduino-Temperature-Control-Library.git)
|
- [DallasTemperature](https://github.com/milesburton/Arduino-Temperature-Control-Library.git)
|
||||||
- [NeoPixelBus](https://github.com/Makuna/NeoPixelBus) - Arduino NeoPixel library compatible with esp8266.
|
- [NeoPixelBus](https://github.com/Makuna/NeoPixelBus) - Arduino NeoPixel library compatible with esp8266.
|
||||||
|
16
changes.md
16
changes.md
@ -1,5 +1,21 @@
|
|||||||
# Change log
|
# Change log
|
||||||
|
|
||||||
|
## Current version
|
||||||
|
|
||||||
|
### Core
|
||||||
|
|
||||||
|
- Updated I2C library to better handle repeated start for certain devices.
|
||||||
|
|
||||||
|
### Libraries
|
||||||
|
|
||||||
|
- ESP8266WebServer: add gzip streaming, fix sendContent behaviour,
|
||||||
|
add setContentSize method.
|
||||||
|
- ESP8266WiFi: add BSSID, channel, isHidden methods, fix AP/STA mode
|
||||||
|
selection (#28).
|
||||||
|
|
||||||
|
### Tools
|
||||||
|
|
||||||
|
|
||||||
## 1.6.4-673-g8cd3697
|
## 1.6.4-673-g8cd3697
|
||||||
May 22, 2015
|
May 22, 2015
|
||||||
|
|
||||||
|
@ -106,36 +106,54 @@ void handleFileUpdate(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void handleFileDelete(){
|
void handleFileDelete(){
|
||||||
if(server.args() == 0) return server.send(500, "text/plain", "BAD ARGS");
|
if(server.args() == 0) {
|
||||||
|
server.send(500, "text/plain", "BAD ARGS");
|
||||||
|
return;
|
||||||
|
}
|
||||||
String path = server.arg(0);
|
String path = server.arg(0);
|
||||||
if(path == "/")
|
if(path == "/") {
|
||||||
return server.send(500, "text/plain", "BAD PATH");
|
server.send(500, "text/plain", "BAD PATH");
|
||||||
if(!FS.exists((char *)(path.c_str())))
|
return;
|
||||||
return server.send(404, "text/plain", "FileNotFound");
|
}
|
||||||
|
if(!FS.exists((char *)(path.c_str()))) {
|
||||||
|
server.send(404, "text/plain", "FileNotFound");
|
||||||
|
return;
|
||||||
|
}
|
||||||
FS.remove((char *)path.c_str());
|
FS.remove((char *)path.c_str());
|
||||||
server.send(200, "text/plain", "");
|
server.send(200, "text/plain", "");
|
||||||
path = String();
|
path = String();
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleFileCreate(){
|
void handleFileCreate(){
|
||||||
if(server.args() == 0)
|
if(server.args() == 0) {
|
||||||
return server.send(500, "text/plain", "BAD ARGS");
|
server.send(500, "text/plain", "BAD ARGS");
|
||||||
|
return;
|
||||||
|
}
|
||||||
String path = server.arg(0);
|
String path = server.arg(0);
|
||||||
if(path == "/")
|
if(path == "/") {
|
||||||
return server.send(500, "text/plain", "BAD PATH");
|
server.send(500, "text/plain", "BAD PATH");
|
||||||
if(FS.exists((char *)path.c_str()))
|
return;
|
||||||
return server.send(500, "text/plain", "FILE EXISTS");
|
}
|
||||||
|
if(FS.exists((char *)path.c_str())) {
|
||||||
|
server.send(500, "text/plain", "FILE EXISTS");
|
||||||
|
return;
|
||||||
|
}
|
||||||
FSFile file = FS.open((char *)path.c_str(), FSFILE_OVERWRITE);
|
FSFile file = FS.open((char *)path.c_str(), FSFILE_OVERWRITE);
|
||||||
if(file)
|
if(file)
|
||||||
file.close();
|
file.close();
|
||||||
else
|
else {
|
||||||
return server.send(500, "text/plain", "CREATE FAILED");
|
server.send(500, "text/plain", "CREATE FAILED");
|
||||||
|
return;
|
||||||
|
}
|
||||||
server.send(200, "text/plain", "");
|
server.send(200, "text/plain", "");
|
||||||
path = String();
|
path = String();
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleFileList() {
|
void handleFileList() {
|
||||||
if(!server.hasArg("dir")) return server.send(500, "text/plain", "BAD ARGS");
|
if(!server.hasArg("dir")) {
|
||||||
|
server.send(500, "text/plain", "BAD ARGS");
|
||||||
|
return;
|
||||||
|
}
|
||||||
String path = server.arg("dir");
|
String path = server.arg("dir");
|
||||||
|
|
||||||
FSFile entry;
|
FSFile entry;
|
||||||
@ -148,19 +166,21 @@ void handleFileList() {
|
|||||||
}
|
}
|
||||||
dir.rewindDirectory();
|
dir.rewindDirectory();
|
||||||
|
|
||||||
WiFiClient client = server.client();
|
|
||||||
client.print("HTTP/1.1 200 OK\r\nContent-Type: text/json\r\nConnection: close\r\n\r\n");
|
|
||||||
String output = "[";
|
String output = "[";
|
||||||
while(true){
|
while(true){
|
||||||
entry = dir.openNextFile();
|
entry = dir.openNextFile();
|
||||||
if (!entry) break;
|
if (!entry)
|
||||||
|
break;
|
||||||
|
|
||||||
if(!FS.exists(entry.name())){
|
if(!FS.exists(entry.name())){
|
||||||
os_printf("Entry[%s] Not Exists!\n", entry.name());
|
os_printf("Entry[%s] Not Exists!\n", entry.name());
|
||||||
entry.remove();
|
entry.remove();
|
||||||
entry.close();
|
entry.close();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(output != "[") output += ',';
|
|
||||||
|
if(output != "[")
|
||||||
|
output += ',';
|
||||||
output += "{\"type\":\"";
|
output += "{\"type\":\"";
|
||||||
output += (entry.isDirectory())?"dir":"file";
|
output += (entry.isDirectory())?"dir":"file";
|
||||||
output += "\",\"name\":\"";
|
output += "\",\"name\":\"";
|
||||||
@ -171,12 +191,7 @@ void handleFileList() {
|
|||||||
dir.close();
|
dir.close();
|
||||||
|
|
||||||
output += "]";
|
output += "]";
|
||||||
client.write(output.c_str(), output.length());
|
server.send(200, "text/json", output);
|
||||||
output = String();
|
|
||||||
uint16_t maxWait = HTTP_MAX_CLOSE_WAIT;
|
|
||||||
while(client.connected() && maxWait--) {
|
|
||||||
delay(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup(void){
|
void setup(void){
|
||||||
|
@ -85,16 +85,9 @@ bool loadFromSdCard(String path){
|
|||||||
if (!dataFile)
|
if (!dataFile)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(server.hasArg("download")) dataType = "application/octet-stream";
|
if (server.hasArg("download")) dataType = "application/octet-stream";
|
||||||
|
|
||||||
server.sendHeader("Content-Length", String(dataFile.size()));
|
if (server.streamFile(dataFile, dataType) != dataFile.size()) {
|
||||||
server.sendHeader("Connection", "close");
|
|
||||||
server.sendHeader("Access-Control-Allow-Origin", "*");
|
|
||||||
server.send(200, dataType.c_str(), "");
|
|
||||||
|
|
||||||
WiFiClient client = server.client();
|
|
||||||
size_t totalSize = dataFile.size();
|
|
||||||
if (client.write(dataFile, HTTP_DOWNLOAD_UNIT_SIZE) != totalSize) {
|
|
||||||
DBG_OUTPUT_PORT.println("Sent less data than expected!");
|
DBG_OUTPUT_PORT.println("Sent less data than expected!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,7 +180,7 @@ void printDirectory() {
|
|||||||
return returnFail("NOT DIR");
|
return returnFail("NOT DIR");
|
||||||
}
|
}
|
||||||
dir.rewindDirectory();
|
dir.rewindDirectory();
|
||||||
|
server.setContentLength(CONTENT_LENGTH_UNKNOWN);
|
||||||
server.send(200, "text/json", "");
|
server.send(200, "text/json", "");
|
||||||
WiFiClient client = server.client();
|
WiFiClient client = server.client();
|
||||||
|
|
||||||
|
@ -111,6 +111,7 @@ void ESP8266WebServer::handleClient()
|
|||||||
}
|
}
|
||||||
|
|
||||||
_currentClient = client;
|
_currentClient = client;
|
||||||
|
_contentLength = CONTENT_LENGTH_NOT_SET;
|
||||||
_handleRequest();
|
_handleRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,9 +139,13 @@ void ESP8266WebServer::send(int code, const char* content_type, String content)
|
|||||||
if (!content_type)
|
if (!content_type)
|
||||||
content_type = "text/html";
|
content_type = "text/html";
|
||||||
|
|
||||||
String len(content.length());
|
|
||||||
sendHeader("Content-Type", content_type, true);
|
sendHeader("Content-Type", content_type, true);
|
||||||
sendHeader("Content-Length", len.c_str());
|
if (_contentLength != CONTENT_LENGTH_UNKNOWN) {
|
||||||
|
size_t length = (_contentLength == CONTENT_LENGTH_NOT_SET) ?
|
||||||
|
content.length() : _contentLength;
|
||||||
|
String lengthStr(length);
|
||||||
|
sendHeader("Content-Length", lengthStr.c_str());
|
||||||
|
}
|
||||||
sendHeader("Connection", "close");
|
sendHeader("Connection", "close");
|
||||||
sendHeader("Access-Control-Allow-Origin", "*");
|
sendHeader("Access-Control-Allow-Origin", "*");
|
||||||
|
|
||||||
@ -172,10 +177,6 @@ void ESP8266WebServer::sendContent(String content) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
uint16_t maxWait = HTTP_MAX_CLOSE_WAIT;
|
|
||||||
while(_currentClient.connected() && maxWait--) {
|
|
||||||
delay(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String ESP8266WebServer::arg(const char* name) {
|
String ESP8266WebServer::arg(const char* name) {
|
||||||
@ -245,6 +246,10 @@ void ESP8266WebServer::_handleRequest() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint16_t maxWait = HTTP_MAX_CLOSE_WAIT;
|
||||||
|
while(_currentClient.connected() && maxWait--) {
|
||||||
|
delay(1);
|
||||||
|
}
|
||||||
_currentClient = WiFiClient();
|
_currentClient = WiFiClient();
|
||||||
_currentUri = String();
|
_currentUri = String();
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,9 @@ enum HTTPUploadStatus { UPLOAD_FILE_START, UPLOAD_FILE_WRITE, UPLOAD_FILE_END };
|
|||||||
#define HTTP_MAX_DATA_WAIT 1000 //ms to wait for the client to send the request
|
#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
|
#define HTTP_MAX_CLOSE_WAIT 2000 //ms to wait for the client to close the connection
|
||||||
|
|
||||||
|
#define CONTENT_LENGTH_UNKNOWN ((size_t) -1)
|
||||||
|
#define CONTENT_LENGTH_NOT_SET ((size_t) -2)
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
HTTPUploadStatus status;
|
HTTPUploadStatus status;
|
||||||
String filename;
|
String filename;
|
||||||
@ -78,32 +81,19 @@ public:
|
|||||||
void send(int code, char* content_type, String content);
|
void send(int code, char* content_type, String content);
|
||||||
void send(int code, String content_type, String content);
|
void send(int code, String content_type, String content);
|
||||||
|
|
||||||
|
void setContentLength(size_t contentLength) { _contentLength = contentLength; }
|
||||||
void sendHeader(String name, String value, bool first = false);
|
void sendHeader(String name, String value, bool first = false);
|
||||||
void sendContent(String content);
|
void sendContent(String content);
|
||||||
|
|
||||||
template<typename T> size_t streamFile(T &file, String contentType){
|
template<typename T> size_t streamFile(T &file, String contentType){
|
||||||
String head = "HTTP/1.1 200 OK\r\nContent-Type: ";
|
setContentLength(file.size());
|
||||||
head += contentType;
|
if (String(file.name()).endsWith(".gz") &&
|
||||||
head += "\r\nContent-Length: ";
|
contentType != "application/x-gzip" &&
|
||||||
head += file.size();
|
contentType != "application/octet-stream"){
|
||||||
head += "\r\nConnection: close";
|
sendHeader("Content-Encoding", "gzip");
|
||||||
head += "\r\nAccess-Control-Allow-Origin: *";
|
|
||||||
if(
|
|
||||||
String(file.name()).endsWith(".gz") &&
|
|
||||||
contentType != "application/x-gzip" &&
|
|
||||||
contentType != "application/octet-stream"
|
|
||||||
){
|
|
||||||
head += "\r\nContent-Encoding: gzip";
|
|
||||||
}
|
}
|
||||||
head += "\r\n\r\n";
|
send(200, contentType, "");
|
||||||
_currentClient.print(head);
|
return _currentClient.write(file, HTTP_DOWNLOAD_UNIT_SIZE);
|
||||||
head = String();
|
|
||||||
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:
|
protected:
|
||||||
@ -131,6 +121,7 @@ protected:
|
|||||||
RequestArgument* _currentArgs;
|
RequestArgument* _currentArgs;
|
||||||
HTTPUpload _currentUpload;
|
HTTPUpload _currentUpload;
|
||||||
|
|
||||||
|
size_t _contentLength;
|
||||||
String _responseHeaders;
|
String _responseHeaders;
|
||||||
|
|
||||||
RequestHandler* _firstHandler;
|
RequestHandler* _firstHandler;
|
||||||
|
@ -251,7 +251,7 @@ uint8_t* ESP8266WiFiClass::BSSID(void)
|
|||||||
return reinterpret_cast<uint8_t*>(conf.bssid);
|
return reinterpret_cast<uint8_t*>(conf.bssid);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t ESP8266WiFiClass::Channel(void) {
|
int32_t ESP8266WiFiClass::channel(void) {
|
||||||
return wifi_get_channel();
|
return wifi_get_channel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -353,7 +353,7 @@ uint8_t * ESP8266WiFiClass::BSSID(uint8_t i)
|
|||||||
return it->bssid;
|
return it->bssid;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t ESP8266WiFiClass::Channel(uint8_t i)
|
int32_t ESP8266WiFiClass::channel(uint8_t i)
|
||||||
{
|
{
|
||||||
struct bss_info* it = reinterpret_cast<struct bss_info*>(_getScanInfoByIndex(i));
|
struct bss_info* it = reinterpret_cast<struct bss_info*>(_getScanInfoByIndex(i));
|
||||||
if (!it)
|
if (!it)
|
||||||
|
@ -160,7 +160,7 @@ public:
|
|||||||
*
|
*
|
||||||
* return: channel
|
* return: channel
|
||||||
*/
|
*/
|
||||||
int32_t Channel(void);
|
int32_t channel(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return the current network RSSI. Note: this is just a stub, there is no way to
|
* Return the current network RSSI. Note: this is just a stub, there is no way to
|
||||||
@ -214,11 +214,11 @@ public:
|
|||||||
uint8_t * BSSID(uint8_t networkItem);
|
uint8_t * BSSID(uint8_t networkItem);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return Channel of scanned wifi
|
* return channel of scanned wifi
|
||||||
* @param networkItem specify from which network item want to get the information
|
* @param networkItem specify from which network item want to get the information
|
||||||
* @return uint32_t Channel of scanned wifi
|
* @return uint32_t channel of scanned wifi
|
||||||
*/
|
*/
|
||||||
int32_t Channel(uint8_t networkItem);
|
int32_t channel(uint8_t networkItem);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return if the scanned wifi is Hidden (no SSID)
|
* return if the scanned wifi is Hidden (no SSID)
|
||||||
|
@ -123,7 +123,7 @@ wl_status_t ESP8266WiFiMulti::run(void) {
|
|||||||
DEBUG_WIFI_MULTI("[WIFI] SSID: %s\n", WiFi.SSID());
|
DEBUG_WIFI_MULTI("[WIFI] SSID: %s\n", WiFi.SSID());
|
||||||
DEBUG_WIFI_MULTI("[WIFI] IP: %d.%d.%d.%d\n", ip[0], ip[1], ip[2], ip[3]);
|
DEBUG_WIFI_MULTI("[WIFI] IP: %d.%d.%d.%d\n", ip[0], ip[1], ip[2], ip[3]);
|
||||||
DEBUG_WIFI_MULTI("[WIFI] MAC: %02X:%02X:%02X:%02X:%02X:%02X\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
DEBUG_WIFI_MULTI("[WIFI] MAC: %02X:%02X:%02X:%02X:%02X:%02X\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||||
DEBUG_WIFI_MULTI("[WIFI] Channel: %d\n", WiFi.Channel());
|
DEBUG_WIFI_MULTI("[WIFI] Channel: %d\n", WiFi.channel());
|
||||||
break;
|
break;
|
||||||
case WL_NO_SSID_AVAIL:
|
case WL_NO_SSID_AVAIL:
|
||||||
DEBUG_WIFI_MULTI("[WIFI] Connecting Faild AP not found.\n");
|
DEBUG_WIFI_MULTI("[WIFI] Connecting Faild AP not found.\n");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user