1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-27 18:02:17 +03:00

Merge branch 'master' into my_changes_on_2.1.0-rc1

This commit is contained in:
Joost Jager
2016-01-12 21:26:09 +01:00
44 changed files with 421 additions and 85 deletions

View File

@ -107,7 +107,7 @@ void HTTPClient::begin(String url, String httpsFingerprint) {
int index = url.indexOf(':');
//int index2;
bool hasPort = false;
if(index) {
if(index >= 0) {
protocol = url.substring(0, index);
url.remove(0, (index + 3)); // remove http:// or https://

View File

@ -51,23 +51,23 @@ extern "C" {
#define SSDP_METHOD_SIZE 10
#define SSDP_URI_SIZE 2
#define SSDP_BUFFER_SIZE 64
#define SSDP_MULTICAST_TTL 1
#define SSDP_MULTICAST_TTL 2
static const IPAddress SSDP_MULTICAST_ADDR(239, 255, 255, 250);
static const char* _ssdp_response_template =
static const char* _ssdp_response_template =
"HTTP/1.1 200 OK\r\n"
"EXT:\r\n"
"ST: upnp:rootdevice\r\n";
static const char* _ssdp_notify_template =
static const char* _ssdp_notify_template =
"NOTIFY * HTTP/1.1\r\n"
"HOST: 239.255.255.250:1900\r\n"
"NT: upnp:rootdevice\r\n"
"NTS: ssdp:alive\r\n";
static const char* _ssdp_packet_template =
static const char* _ssdp_packet_template =
"%s" // _ssdp_response_template / _ssdp_notify_template
"CACHE-CONTROL: max-age=%u\r\n" // SSDP_INTERVAL
"SERVER: Arduino/1.0 UPNP/1.1 %s/%s\r\n" // _modelName, _modelNumber
@ -75,7 +75,7 @@ static const char* _ssdp_packet_template =
"LOCATION: http://%u.%u.%u.%u:%u/%s\r\n" // WiFi.localIP(), _port, _schemaURL
"\r\n";
static const char* _ssdp_schema_template =
static const char* _ssdp_schema_template =
"HTTP/1.1 200 OK\r\n"
"Content-Type: text/xml\r\n"
"Connection: close\r\n"
@ -89,7 +89,7 @@ static const char* _ssdp_schema_template =
"</specVersion>"
"<URLBase>http://%u.%u.%u.%u:%u/</URLBase>" // WiFi.localIP(), _port
"<device>"
"<deviceType>urn:schemas-upnp-org:device:Basic:1</deviceType>"
"<deviceType>%s</deviceType>"
"<friendlyName>%s</friendlyName>"
"<presentationURL>%s</presentationURL>"
"<serialNumber>%s</serialNumber>"
@ -128,6 +128,7 @@ SSDPClass::SSDPClass() :
_server(0),
_timer(new SSDPTimer),
_port(80),
_ttl(SSDP_MULTICAST_TTL),
_respondToPort(0),
_pending(false),
_delay(0),
@ -136,6 +137,7 @@ _notify_time(0)
{
_uuid[0] = '\0';
_modelNumber[0] = '\0';
sprintf(_deviceType, "urn:schemas-upnp-org:device:Basic:1");
_friendlyName[0] = '\0';
_presentationURL[0] = '\0';
_serialNumber[0] = '\0';
@ -152,11 +154,11 @@ SSDPClass::~SSDPClass(){
bool SSDPClass::begin(){
_pending = false;
uint32_t chipId = ESP.getChipId();
sprintf(_uuid, "38323636-4558-4dda-9188-cda0e6%02x%02x%02x",
(uint16_t) ((chipId >> 16) & 0xff),
(uint16_t) ((chipId >> 8) & 0xff),
(uint16_t) ((chipId >> 8) & 0xff),
(uint16_t) chipId & 0xff );
#ifdef DEBUG_SSDP
@ -179,13 +181,13 @@ bool SSDPClass::begin(){
DEBUGV("SSDP failed to join igmp group");
return false;
}
if (!_server->listen(*IP_ADDR_ANY, SSDP_PORT)) {
return false;
}
_server->setMulticastInterface(ifaddr);
_server->setMulticastTTL(SSDP_MULTICAST_TTL);
_server->setMulticastTTL(_ttl);
_server->onRx(std::bind(&SSDPClass::_update, this));
if (!_server->connect(multicast_addr, SSDP_PORT)) {
return false;
@ -199,8 +201,8 @@ bool SSDPClass::begin(){
void SSDPClass::_send(ssdp_method_t method){
char buffer[1460];
uint32_t ip = WiFi.localIP();
int len = snprintf(buffer, sizeof(buffer),
int len = snprintf(buffer, sizeof(buffer),
_ssdp_packet_template,
(method == NONE)?_ssdp_response_template:_ssdp_notify_template,
SSDP_INTERVAL,
@ -239,6 +241,7 @@ void SSDPClass::schema(WiFiClient client){
uint32_t ip = WiFi.localIP();
client.printf(_ssdp_schema_template,
IP2STR(&ip), _port,
_deviceType,
_friendlyName,
_presentationURL,
_serialNumber,
@ -268,7 +271,7 @@ void SSDPClass::_update(){
uint8_t cr = 0;
char buffer[SSDP_BUFFER_SIZE] = {0};
while(_server->getSize() > 0){
char c = _server->read();
@ -279,9 +282,9 @@ void SSDPClass::_update(){
if(c == ' '){
if(strcmp(buffer, "M-SEARCH") == 0) method = SEARCH;
else if(strcmp(buffer, "NOTIFY") == 0) method = NOTIFY;
if(method == NONE) state = ABORT;
else state = URI;
else state = URI;
cursor = 0;
} else if(cursor < SSDP_METHOD_SIZE - 1){ buffer[cursor++] = c; buffer[cursor] = '\0'; }
@ -289,8 +292,8 @@ void SSDPClass::_update(){
case URI:
if(c == ' '){
if(strcmp(buffer, "*")) state = ABORT;
else state = PROTO;
cursor = 0;
else state = PROTO;
cursor = 0;
} else if(cursor < SSDP_URI_SIZE - 1){ buffer[cursor++] = c; buffer[cursor] = '\0'; }
break;
case PROTO:
@ -304,8 +307,8 @@ void SSDPClass::_update(){
case VALUE:
if(cr == 2){
switch(header){
case START:
break;
case START:
break;
case MAN:
#ifdef DEBUG_SSDP
DEBUG_SSDP.printf("MAN: %s\n", (char *)buffer);
@ -318,6 +321,12 @@ void SSDPClass::_update(){
DEBUG_SSDP.printf("REJECT: %s\n", (char *)buffer);
#endif
}
// if the search type matches our type, we should respond instead of ABORT
if(strcmp(buffer, _deviceType) == 0){
_pending = true;
_process_time = millis();
state = KEY;
}
break;
case MX:
_delay = random(0, atoi(buffer)) * 1000L;
@ -331,7 +340,7 @@ void SSDPClass::_update(){
else if(strcmp(buffer, "ST") == 0) header = ST;
else if(strcmp(buffer, "MX") == 0) header = MX;
}
if(cursor < SSDP_BUFFER_SIZE - 1){ buffer[cursor++] = c; buffer[cursor] = '\0'; }
}
break;
@ -365,6 +374,10 @@ void SSDPClass::setHTTPPort(uint16_t port){
_port = port;
}
void SSDPClass::setDeviceType(const char *deviceType){
strlcpy(_deviceType, deviceType, sizeof(_deviceType));
}
void SSDPClass::setName(const char *name){
strlcpy(_friendlyName, name, sizeof(_friendlyName));
}
@ -377,6 +390,10 @@ void SSDPClass::setSerialNumber(const char *serialNumber){
strlcpy(_serialNumber, serialNumber, sizeof(_serialNumber));
}
void SSDPClass::setSerialNumber(const uint32_t serialNumber){
snprintf(_serialNumber, sizeof(uint32_t)*2+1, "%08X", serialNumber);
}
void SSDPClass::setModelName(const char *name){
strlcpy(_modelName, name, sizeof(_modelName));
}
@ -397,6 +414,10 @@ void SSDPClass::setManufacturerURL(const char *url){
strlcpy(_manufacturerURL, url, sizeof(_manufacturerURL));
}
void SSDPClass::setTTL(const uint8_t ttl){
_ttl = ttl;
}
void SSDPClass::_onTimerStatic(SSDPClass* self) {
self->_update();
}

View File

@ -37,6 +37,7 @@ class UdpContext;
#define SSDP_UUID_SIZE 37
#define SSDP_SCHEMA_URL_SIZE 64
#define SSDP_DEVICE_TYPE_SIZE 64
#define SSDP_FRIENDLY_NAME_SIZE 64
#define SSDP_SERIAL_NUMBER_SIZE 32
#define SSDP_PRESENTATION_URL_SIZE 128
@ -64,6 +65,8 @@ class SSDPClass{
void schema(WiFiClient client);
void setDeviceType(const String& deviceType) { setDeviceType(deviceType.c_str()); }
void setDeviceType(const char *deviceType);
void setName(const String& name) { setName(name.c_str()); }
void setName(const char *name);
void setURL(const String& url) { setURL(url.c_str()); }
@ -72,6 +75,7 @@ class SSDPClass{
void setSchemaURL(const char *url);
void setSerialNumber(const String& serialNumber) { setSerialNumber(serialNumber.c_str()); }
void setSerialNumber(const char *serialNumber);
void setSerialNumber(const uint32_t serialNumber);
void setModelName(const String& name) { setModelName(name.c_str()); }
void setModelName(const char *name);
void setModelNumber(const String& num) { setModelNumber(num.c_str()); }
@ -83,6 +87,7 @@ class SSDPClass{
void setManufacturerURL(const String& url) { setManufacturerURL(url.c_str()); }
void setManufacturerURL(const char *url);
void setHTTPPort(uint16_t port);
void setTTL(uint8_t ttl);
protected:
void _send(ssdp_method_t method);
@ -93,6 +98,7 @@ class SSDPClass{
UdpContext* _server;
SSDPTimer* _timer;
uint16_t _port;
uint8_t _ttl;
IPAddress _respondToAddr;
uint16_t _respondToPort;
@ -101,9 +107,10 @@ class SSDPClass{
unsigned short _delay;
unsigned long _process_time;
unsigned long _notify_time;
char _schemaURL[SSDP_SCHEMA_URL_SIZE];
char _uuid[SSDP_UUID_SIZE];
char _deviceType[SSDP_DEVICE_TYPE_SIZE];
char _friendlyName[SSDP_FRIENDLY_NAME_SIZE];
char _serialNumber[SSDP_SERIAL_NUMBER_SIZE];
char _presentationURL[SSDP_PRESENTATION_URL_SIZE];

View File

@ -213,11 +213,10 @@ void ESP8266WebServer::_prepareHeader(String& response, int code, const char* co
content_type = "text/html";
sendHeader("Content-Type", content_type, true);
if (_contentLength != CONTENT_LENGTH_UNKNOWN && _contentLength != CONTENT_LENGTH_NOT_SET) {
sendHeader("Content-Length", String(_contentLength));
}
else if (contentLength > 0){
if (_contentLength == CONTENT_LENGTH_NOT_SET) {
sendHeader("Content-Length", String(contentLength));
} else if (_contentLength != CONTENT_LENGTH_UNKNOWN) {
sendHeader("Content-Length", String(_contentLength));
}
sendHeader("Connection", "close");
sendHeader("Access-Control-Allow-Origin", "*");

View File

@ -40,6 +40,17 @@ extern "C" {
#include "WiFiServer.h"
#include "WiFiClientSecure.h"
#ifdef DEBUG_ESP_WIFI
#ifdef DEBUG_ESP_PORT
#define DEBUG_WIFI(...) DEBUG_ESP_PORT.printf( __VA_ARGS__ )
#endif
#endif
#ifndef DEBUG_WIFI
#define DEBUG_WIFI(...)
#endif
class ESP8266WiFiClass : public ESP8266WiFiGenericClass, public ESP8266WiFiSTAClass, public ESP8266WiFiScanClass, public ESP8266WiFiAPClass {
public:

View File

@ -85,19 +85,24 @@ bool ESP8266WiFiAPClass::softAP(const char* ssid, const char* passphrase, int ch
if(!WiFi.enableAP(true)) {
// enable AP failed
DEBUG_WIFI("[AP] enableAP failed!\n");
return false;
}
if(!ssid || *ssid == 0 || strlen(ssid) > 31) {
// fail SSID too long or missing!
DEBUG_WIFI("[AP] SSID too long or missing!\n");
return false;
}
if(passphrase && (strlen(passphrase) > 63 || strlen(passphrase) < 8)) {
// fail passphrase to long or short!
DEBUG_WIFI("[AP] fail passphrase to long or short!\n");
return false;
}
bool ret = true;
struct softap_config conf;
strcpy(reinterpret_cast<char*>(conf.ssid), ssid);
conf.channel = channel;
@ -116,20 +121,50 @@ bool ESP8266WiFiAPClass::softAP(const char* ssid, const char* passphrase, int ch
struct softap_config conf_current;
wifi_softap_get_config(&conf_current);
if(softap_config_equal(conf, conf_current)) {
DEBUGV("softap config unchanged");
return true;
}
if(!softap_config_equal(conf, conf_current)) {
bool ret;
ETS_UART_INTR_DISABLE();
if(WiFi._persistent) {
ret = wifi_softap_set_config(&conf);
} else {
ret = wifi_softap_set_config_current(&conf);
}
ETS_UART_INTR_ENABLE();
if(!ret) {
DEBUG_WIFI("[AP] set_config failed!\n");
return false;
}
ETS_UART_INTR_DISABLE();
if(WiFi._persistent) {
ret = wifi_softap_set_config(&conf);
} else {
ret = wifi_softap_set_config_current(&conf);
DEBUG_WIFI("[AP] softap config unchanged\n");
}
if(wifi_softap_dhcps_status() != DHCP_STARTED) {
DEBUG_WIFI("[AP] DHCP not started, starting...\n");
if(!wifi_softap_dhcps_start()) {
DEBUG_WIFI("[AP] wifi_softap_dhcps_start failed!\n");
ret = false;
}
}
// check IP config
struct ip_info ip;
if(wifi_get_ip_info(SOFTAP_IF, &ip)) {
if(ip.ip.addr == 0x00000000) {
// Invalid config
DEBUG_WIFI("[AP] IP config Invalid resetting...\n");
//192.168.244.1 , 192.168.244.1 , 255.255.255.0
ret = softAPConfig(0x01F4A8C0, 0x01F4A8C0, 0x00FFFFFF);
if(!ret) {
DEBUG_WIFI("[AP] softAPConfig failed!\n");
ret = false;
}
}
} else {
DEBUG_WIFI("[AP] wifi_get_ip_info failed!\n");
ret = false;
}
ETS_UART_INTR_ENABLE();
return ret;
}
@ -142,21 +177,76 @@ bool ESP8266WiFiAPClass::softAP(const char* ssid, const char* passphrase, int ch
* @param subnet subnet mask
*/
bool ESP8266WiFiAPClass::softAPConfig(IPAddress local_ip, IPAddress gateway, IPAddress subnet) {
DEBUG_WIFI("[APConfig] local_ip: %s gateway: %s subnet: %s\n", local_ip.toString().c_str(), gateway.toString().c_str(), subnet.toString().c_str());
if(!WiFi.enableAP(true)) {
// enable AP failed
DEBUG_WIFI("[APConfig] enableAP failed!\n");
return false;
}
bool ret = true;
struct ip_info info;
info.ip.addr = static_cast<uint32_t>(local_ip);
info.gw.addr = static_cast<uint32_t>(gateway);
info.netmask.addr = static_cast<uint32_t>(subnet);
wifi_softap_dhcps_stop();
if(wifi_set_ip_info(SOFTAP_IF, &info)) {
return wifi_softap_dhcps_start();
if(!wifi_softap_dhcps_stop()) {
DEBUG_WIFI("[APConfig] wifi_softap_dhcps_stop failed!\n");
}
return false;
if(!wifi_set_ip_info(SOFTAP_IF, &info)) {
DEBUG_WIFI("[APConfig] wifi_set_ip_info failed!\n");
ret = false;
}
struct dhcps_lease dhcp_lease;
IPAddress ip = local_ip;
ip[3] += 99;
dhcp_lease.start_ip.addr = static_cast<uint32_t>(ip);
DEBUG_WIFI("[APConfig] DHCP IP start: %s\n", ip.toString().c_str());
ip[3] += 100;
dhcp_lease.end_ip.addr = static_cast<uint32_t>(ip);
DEBUG_WIFI("[APConfig] DHCP IP end: %s\n", ip.toString().c_str());
if(!wifi_softap_set_dhcps_lease(&dhcp_lease)) {
DEBUG_WIFI("[APConfig] wifi_set_ip_info failed!\n");
ret = false;
}
// set lease time to 720min --> 12h
if(!wifi_softap_set_dhcps_lease_time(720)) {
DEBUG_WIFI("[APConfig] wifi_softap_set_dhcps_lease_time failed!\n");
ret = false;
}
uint8 mode = 1;
if(!wifi_softap_set_dhcps_offer_option(OFFER_ROUTER, &mode)) {
DEBUG_WIFI("[APConfig] wifi_softap_set_dhcps_offer_option failed!\n");
ret = false;
}
if(!wifi_softap_dhcps_start()) {
DEBUG_WIFI("[APConfig] wifi_softap_dhcps_start failed!\n");
ret = false;
}
// check config
if(wifi_get_ip_info(SOFTAP_IF, &info)) {
if(info.ip.addr == 0x00000000) {
DEBUG_WIFI("[APConfig] IP config Invalid?!\n");
ret = false;
} else if(local_ip != info.ip.addr) {
ip = info.ip.addr;
DEBUG_WIFI("[APConfig] IP config not set correct?! new IP: %s\n", ip.toString().c_str());
ret = false;
}
} else {
DEBUG_WIFI("[APConfig] wifi_get_ip_info failed!\n");
ret = false;
}
return ret;
}
@ -179,6 +269,10 @@ bool ESP8266WiFiAPClass::softAPdisconnect(bool wifioff) {
}
ETS_UART_INTR_ENABLE();
if(!ret) {
DEBUG_WIFI("[APdisconnect] set_config failed!\n");
}
if(wifioff) {
ret = WiFi.enableAP(false);
}

View File

@ -103,10 +103,10 @@ void ESP8266WiFiGenericClass::removeEvent(WiFiEventCb cbEvent, WiFiEvent_t event
*/
void ESP8266WiFiGenericClass::_eventCallback(void* arg) {
System_Event_t* event = reinterpret_cast<System_Event_t*>(arg);
DEBUGV("wifi evt: %d\n", event->event);
DEBUG_WIFI("wifi evt: %d\n", event->event);
if(event->event == EVENT_STAMODE_DISCONNECTED) {
DEBUGV("STA disconnect: %d\n", event->event_info.disconnected.reason);
DEBUG_WIFI("STA disconnect: %d\n", event->event_info.disconnected.reason);
WiFiClient::stopAll();
}

View File

@ -127,7 +127,7 @@ wl_status_t ESP8266WiFiMulti::run(void) {
ip = WiFi.localIP();
mac = WiFi.BSSID();
DEBUG_WIFI_MULTI("[WIFI] Connecting done.\n");
DEBUG_WIFI_MULTI("[WIFI] SSID: %s\n", WiFi.SSID());
DEBUG_WIFI_MULTI("[WIFI] SSID: %s\n", WiFi.SSID().c_str());
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] Channel: %d\n", WiFi.channel());

View File

@ -3,7 +3,7 @@
#include "c_types.h"
/*------------------------<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>------------------------*/
/*------------------------<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>------------------------*/
#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE
#ifndef IOT_SIP_MODE
@ -61,7 +61,7 @@ static const unsigned short heapSTRUCT_SIZE = ( sizeof( xBlockLink ) + portBYTE_
//static size_t xFreeBytesRemaining = ( ( size_t ) configADJUSTED_HEAP_SIZE ) & ( ( size_t ) ~portBYTE_ALIGNMENT_MASK );
/*------------------------<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-----------------------------------*/
/*------------------------<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-----------------------------------*/
//static void prvInsertBlockIntoFreeList( xBlockLink *pxBlockToInsert ) ;//ICACHE_FLASH_ATTR;
@ -69,9 +69,9 @@ static const unsigned short heapSTRUCT_SIZE = ( sizeof( xBlockLink ) + portBYTE_
void vApplicationMallocFailedHook( void ) ;//ICACHE_FLASH_ATTR;
void *pvPortMalloc( size_t xWantedSize ) ;//ICACHE_FLASH_ATTR;
void *pvPortMalloc( size_t xWantedSize, const char* file, int line ) __attribute__((malloc, alloc_size(1)));//ICACHE_FLASH_ATTR;
void vPortFree( void *pv ) ;//ICACHE_FLASH_ATTR;
void vPortFree( void *pv, const char* file, int line ) ;//ICACHE_FLASH_ATTR;
size_t xPortGetFreeHeapSize( void ) ;//ICACHE_FLASH_ATTR;

View File

@ -1,4 +1,4 @@
name=Ethernet
name=Ethernet(esp8266)
version=1.0.4
author=Arduino
maintainer=Arduino <info@arduino.cc>

View File

@ -0,0 +1,10 @@
name=OneWire(esp8266)
version=2.2
author=Jim Studt, Tom Pollard, Robin James, Glenn Trewitt, Jason Dangel, Guillermo Lovato, Paul Stoffregen, Scott Roberts, Bertrik Sikken, Mark Tillotson, Ken Butcher, Roger Clark, Love Nystrom
maintainer=
sentence=Access 1-wire temperature sensors, memory and other chips. ESP8266 compatible version.
paragraph=
category=Communication
url=
architectures=esp8266

View File

@ -1,4 +1,4 @@
name=SD
name=SD(esp8266)
version=1.0.5
author=Arduino, SparkFun
maintainer=Arduino <info@arduino.cc>

View File

@ -1,4 +1,4 @@
name=Servo
name=Servo(esp8266)
version=1.0.2
author=Michael C. Miller
maintainer=GitHub/esp8266/arduino