1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-21 10:26:06 +03:00

Merge pull request #11 from esp8266/esp8266

Esp8266
This commit is contained in:
Me No Dev 2015-06-27 01:14:36 +03:00
commit 466b56641c
50 changed files with 708 additions and 149 deletions

5
.gitignore vendored
View File

@ -13,7 +13,7 @@ hardware/arduino/bootloaders/caterina_LUFA/Caterina.lss
hardware/arduino/bootloaders/caterina_LUFA/Caterina.elf
hardware/arduino/bootloaders/caterina_LUFA/Caterina.eep
hardware/arduino/bootloaders/caterina_LUFA/.dep/
build/libastylej-*.zip
build/*.zip
build/windows/work/
build/windows/*.zip
build/windows/*.tgz
@ -56,6 +56,9 @@ avr-toolchain-*.zip
/hardware/tools/esp8266/utils/
/hardware/tools/esp8266/xtensa-lx106-elf
/hardware/tools/esp8266/esptool.exe
/hardware/esp8266com/esp8266/tools/xtensa*
/hardware/esp8266com/esp8266/tools/esptool*
/hardware/esp8266com/esp8266/tools/utils
/hardware/tools/avr/
/hardware/tools/gcc-arm-none-eabi-4.8.3-2014q1/
/hardware/tools/bossac.exe

View File

@ -21,13 +21,7 @@ generic.build.board=ESP8266_ESP01
generic.build.core=esp8266
generic.build.variant=generic
generic.build.flash_mode=qio
generic.build.flash_size=512K
generic.build.flash_freq=40
generic.build.flash_ld=eagle.flash.512k.ld
generic.build.spiffs_start=0x6B000
generic.build.spiffs_end=0x7B000
generic.build.spiffs_pagesize=256
generic.build.spiffs_blocksize=4096
generic.menu.CpuFrequency.80=80 MHz
generic.menu.CpuFrequency.80.build.f_cpu=80000000L
@ -123,10 +117,10 @@ generic.menu.FlashSize.4M.upload.maximum_size=1044464
# generic.menu.FlashSize.16M.build.spiffs_end=0x1000000
# generic.menu.FlashSize.16M.build.spiffs_blocksize=8192
# generic.menu.FlashFreq.40=40MHz
# generic.menu.FlashFreq.40.build.flash_freq=40
# generic.menu.FlashFreq.80=80MHz
# generic.menu.FlashFreq.80.build.flash_freq=80
generic.menu.FlashFreq.40=40MHz
generic.menu.FlashFreq.40.build.flash_freq=40
generic.menu.FlashFreq.80=80MHz
generic.menu.FlashFreq.80.build.flash_freq=80
##############################################################
modwifi.name=Olimex MOD-WIFI-ESP8266(-DEV)

View File

@ -143,13 +143,13 @@ void ets_intr_unlock();
// level 15 will disable ALL interrupts,
// level 0 will disable most software interrupts
//
#define xt_disable_interrupts(state, level) __asm__ __volatile__("rsil %0," __STRINGIFY(level) "; esync; isync; dsync" : "=a" (state))
#define xt_enable_interrupts(state) __asm__ __volatile__("wsr %0,ps; esync" :: "a" (state) : "memory")
#define xt_disable_interrupts(state, level) __asm__ __volatile__("rsil %0," __STRINGIFY(level) : "=a" (state))
#define xt_enable_interrupts(state) __asm__ __volatile__("wsr %0,ps; isync" :: "a" (state) : "memory")
extern uint32_t interruptsState;
#define interrupts() xt_enable_interrupts(interruptsState)
#define noInterrupts() __asm__ __volatile__("rsil %0,15; esync; isync; dsync" : "=a" (interruptsState))
#define noInterrupts() __asm__ __volatile__("rsil %0,15" : "=a" (interruptsState))
#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() )
@ -195,6 +195,7 @@ unsigned long micros(void);
void delay(unsigned long);
void delayMicroseconds(unsigned int us);
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout);
unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout);
void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val);
uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder);
@ -236,6 +237,8 @@ void loop(void);
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define _min(a,b) ((a)<(b)?(a):(b))
#define _max(a,b) ((a)>(b)?(a):(b))
uint16_t makeWord(uint16_t w);
uint16_t makeWord(byte h, byte l);
@ -243,6 +246,7 @@ uint16_t makeWord(byte h, byte l);
#define word(...) makeWord(__VA_ARGS__)
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L);
unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L);
void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0);
void noTone(uint8_t _pin);
@ -250,7 +254,7 @@ void noTone(uint8_t _pin);
// WMath prototypes
long random(long);
long random(long, long);
void randomSeed(unsigned int);
void randomSeed(unsigned long);
long map(long, long, long, long, long);

View File

@ -97,8 +97,8 @@ void EspClass::wdtFeed(void)
void EspClass::deepSleep(uint32_t time_us, WakeMode mode)
{
system_deep_sleep_set_option(static_cast<int>(mode));
system_deep_sleep(time_us);
system_deep_sleep_set_option(static_cast<int>(mode));
system_deep_sleep(time_us);
}
extern "C" void esp_yield();
@ -280,8 +280,8 @@ uint32_t EspClass::getFlashChipSizeByChipId(void) {
String EspClass::getResetInfo(void) {
if(resetInfo.reason != 0) {
char buff[150];
sprintf(&buff[0], "Fatal exception:%d flag:%d epc1:0x%08x epc2:0x%08x epc3:0x%08x excvaddr:0x%08x depc:0x%08x", resetInfo.exccause, resetInfo.reason, resetInfo.epc1, resetInfo.epc2, resetInfo.epc3, resetInfo.excvaddr, resetInfo.depc);
char buff[200];
sprintf(&buff[0], "Fatal exception:%d flag:%d (%s) epc1:0x%08x epc2:0x%08x epc3:0x%08x excvaddr:0x%08x depc:0x%08x", resetInfo.exccause, resetInfo.reason, (resetInfo.reason == 0 ? "DEFAULT" : resetInfo.reason == 1 ? "WDT" : resetInfo.reason == 2 ? "EXCEPTION" : resetInfo.reason == 3 ? "SOFT_WDT" : resetInfo.reason == 4 ? "SOFT_RESTART" : resetInfo.reason == 5 ? "DEEP_SLEEP_AWAKE" : "???"), resetInfo.epc1, resetInfo.epc2, resetInfo.epc3, resetInfo.excvaddr, resetInfo.depc);
return String(buff);
}
return String("flag: 0");
@ -400,6 +400,13 @@ bool EspClass::updateSketch(Stream& in, uint32_t size) {
return false;
}
if(addr == freeSpaceStart) {
// check for valid first magic byte
if(*((uint8 *) buffer.get()) != 0xE9) {
return false;
}
}
noInterrupts();
rc = SPIWrite(addr, buffer.get(), willRead);
interrupts();

View File

@ -129,7 +129,7 @@ class EspClass {
uint32_t EspClass::getCycleCount()
{
uint32_t ccount;
__asm__ __volatile__("rsr %0,ccount":"=a" (ccount));
__asm__ __volatile__("esync; rsr %0,ccount":"=a" (ccount));
return ccount;
}

View File

@ -620,6 +620,7 @@ size_t HardwareSerial::write(uint8_t c) {
while(_tx_buffer->room() == 0) {
yield();
uart_arm_tx_interrupt(_uart);
}
_tx_buffer->write(c);

View File

@ -127,8 +127,7 @@ size_t ICACHE_FLASH_ATTR Print::print(const Printable& x) {
}
size_t ICACHE_FLASH_ATTR Print::println(void) {
size_t n = print("\r\n");
return n;
return print("\r\n");
}
size_t ICACHE_FLASH_ATTR Print::println(const String &s) {

View File

@ -69,6 +69,8 @@ class Stream: public Print {
}
// returns true if target string is found, false if timed out
bool find(char target) { return find (&target, 1); }
bool findUntil(const char *target, const char *terminator); // as find but search ends if the terminator string is found
bool findUntil(const uint8_t *target, const char *terminator) {
return findUntil((char *) target, terminator);

View File

@ -27,7 +27,7 @@ extern "C" {
#include <stdlib.h>
}
void randomSeed(unsigned int seed) {
void randomSeed(unsigned long seed) {
if(seed != 0) {
srand(seed);
}

View File

@ -39,8 +39,12 @@ class cbuf {
}
size_t room() const {
if(_end >= _begin) return _size - (_end - _begin) - 1;
if(_end >= _begin) {
return _size - (_end - _begin) - 1;
}
if(_begin == _end) {
return _size;
}
return _begin - _end - 1;
}

View File

@ -121,9 +121,10 @@ void init_done() {
extern "C" {
void user_init(void) {
system_rtc_mem_read(0, &resetInfo, sizeof(struct rst_info));
struct rst_info info = { 0 };
system_rtc_mem_write(0, &info, sizeof(struct rst_info));
struct rst_info *rtc_info_ptr = system_get_rst_info();
memcpy((void *) &resetInfo, (void *) rtc_info_ptr, sizeof(resetInfo));
uart_div_modify(0, UART_CLK_FREQ / (115200));

View File

@ -201,6 +201,17 @@ static uint8_t phy_init_data[128] =
// 18<=x<=36: use input voltage,
// the value is voltage*10, 33 is 3.3V, 30 is 3.0V,
// x<18 or x>36: default voltage is 3.3V
//
// the value of this byte depend from the TOUT pin usage (1 or 2):
// 1)
// analogRead function (system_adc_read()):
// is only available when wire TOUT pin17 to external circuitry, Input Voltage Range restricted to 0 ~ 1.0V.
// For this function the vdd33_const must be set as real power voltage of VDD3P3 pin 3 and 4
// The range of operating voltage of ESP8266 is 1.8V~3.6Vthe unit of vdd33_const is 0.1Vso effective value range of vdd33_const is [18,36]
// 2)
// getVcc function (system_get_vdd33):
// is only available when TOUT pin17 is suspended (floating), this function measure the power voltage of VDD3P3 pin 3 and 4
// For this function the vdd33_const must be set to 255 (0xFF).
[107] = 33,
// disable RF calibration for certain number of times

View File

@ -30,3 +30,7 @@ unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout) {
while(digitalRead(pin) == state && (micros() - start) < timeout);
return micros() - start;
}
unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout) {
return pulseIn(pin, state, timeout);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

38
doc/eclipse/eclipse.md Normal file
View File

@ -0,0 +1,38 @@
using Eclipse with Arduino ESP8266
===========================================
### What to Download ###
- [arduino IDE](https://www.arduino.cc/en/Main/Software)
- [Eclipse IDE for C/C++ Developers](http://www.eclipse.org/downloads/packages/eclipse-ide-cc-developers/marsr)
- [Java](http://www.java.com/)
### Setup Arduino ###
see the [Readme](https://github.com/esp8266/Arduino#installing-with-boards-manager)
### Setup Eclipse ###
- [step 1](http://www.baeyens.it/eclipse/how_to.shtml#/c)
- [step 2](http://www.baeyens.it/eclipse/how_to.shtml#/e)
- go to Window --> preferences --> Arduino
- add as private hardware path the Part to the ESP8266
###### example private hardware path
Windows: C:\Users\[username]\AppData\Roaming\Arduino15\packages\esp8266\hardware
Linux: /home/[username]/.arduino15/packages/esp8266/hardware
### Eclipse wont build ###
if eclipse dont find the path to the Compiler add to the platform.txt
after:
```
version=1.6.4
```
this:
```
runtime.tools.xtensa-lx106-elf-gcc.path={runtime.platform.path}/../../../tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9
runtime.tools.esptool.path={runtime.platform.path}/../../../tools/esptool/0.4.4
```
Note:
- the path may changed, check the current version.
- each update over the Arduino IDE will remove the fix
- may not needed in future if Eclipse Plugin get an Update

View File

@ -0,0 +1,34 @@
#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
const byte DNS_PORT = 53;
IPAddress apIP(192, 168, 1, 1);
DNSServer dnsServer;
ESP8266WebServer webServer(80);
String responseHTML = ""
"<!DOCTYPE html><html><head><title>CaptivePortal</title></head><body>"
"<h1>Hello World!</h1><p>This is a captive portal example. All requests will "
"be redirected here.</p></body></html>";
void setup() {
WiFi.mode(WIFI_AP);
WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
WiFi.softAP("DNSServer CaptivePortal example");
// if DNSServer is started with "*" for domain name, it will reply with
// provided IP to all DNS request
dnsServer.start(DNS_PORT, "*", apIP);
// replay to all requests with same HTML
webServer.onNotFound([]() {
webServer.send(200, "text/html", responseHTML);
});
webServer.begin();
}
void loop() {
dnsServer.processNextRequest();
webServer.handleClient();
}

View File

@ -1,9 +1,11 @@
#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
const byte DNS_PORT = 53;
IPAddress apIP(192, 168, 1, 1);
DNSServer dnsServer;
ESP8266WebServer webServer(80);
void setup() {
WiFi.mode(WIFI_AP);
@ -19,10 +21,21 @@ void setup() {
// default is DNSReplyCode::NonExistentDomain
dnsServer.setErrorReplyCode(DNSReplyCode::ServerFailure);
//start DNS server for a specific domain name
// start DNS server for a specific domain name
dnsServer.start(DNS_PORT, "www.example.com", apIP);
// simple HTTP server to see that DNS server is working
webServer.onNotFound([]() {
String message = "Hello World!\n\n";
message += "URI: ";
message += webServer.uri();
webServer.send(200, "text/plain", message);
});
webServer.begin();
}
void loop() {
dnsServer.processNextRequest();
webServer.handleClient();
}

View File

@ -1,5 +1,5 @@
name=DNSServer
version=1.0.0
version=1.1.0
author=Kristijan Novoselić
maintainer=Kristijan Novoselić, <kristijan.novoselic@gmail.com>
sentence=A simple DNS server for ESP8266.

View File

@ -54,7 +54,8 @@ void DNSServer::processNextRequest()
if (_dnsHeader->QR == DNS_QR_QUERY &&
_dnsHeader->OPCode == DNS_OPCODE_QUERY &&
requestIncludesOnlyOneQuestion() &&
getDomainNameWithoutWwwPrefix() == _domainName)
(_domainName == "*" || getDomainNameWithoutWwwPrefix() == _domainName)
)
{
replyWithIP();
}

View File

@ -27,7 +27,7 @@ struct DNSHeader
unsigned char AA : 1; // authoritive answer
unsigned char OPCode : 4; // message_type
unsigned char QR : 1; // query/response flag
unsigned char RCode : 4; // response code
unsigned char RCode : 4; // response code
unsigned char Z : 3; // its z! reserved
unsigned char RA : 1; // recursion available
uint16_t QDCount; // number of question entries
@ -62,7 +62,6 @@ class DNSServer
uint32_t _ttl;
DNSReplyCode _errorReplyCode;
void downcaseAndRemoveWwwPrefix(String &domainName);
String getDomainNameWithoutWwwPrefix();
bool requestIncludesOnlyOneQuestion();

View File

@ -40,7 +40,9 @@ extern "C" void esp_schedule();
extern "C" void esp_yield();
ESP8266WiFiClass::ESP8266WiFiClass()
: _useApMode(false)
: _smartConfigStarted(false)
, _smartConfigDone(false)
, _useApMode(false)
, _useClientMode(false)
, _useStaticIp(false)
{
@ -121,7 +123,7 @@ uint8_t ESP8266WiFiClass::waitForConnectResult(){
}
// You will have to set the DNS-Server manually later since this will not enable DHCP
// You will have to set the DNS-Server manually later since this will not enable DHCP2
void ESP8266WiFiClass::config(IPAddress local_ip, IPAddress gateway, IPAddress subnet)
{
struct ip_info info;
@ -358,12 +360,47 @@ void ESP8266WiFiClass::_scanDone(void* result, int status)
}
}
esp_schedule();
ESP8266WiFiClass::_scanStarted = false;
ESP8266WiFiClass::_scanComplete = true;
if(!ESP8266WiFiClass::_scanAsync) {
esp_schedule();
}
}
int8_t ESP8266WiFiClass::scanComplete() {
int8_t ESP8266WiFiClass::scanNetworks()
if(_scanStarted) {
return WIFI_SCAN_RUNNING;
}
if(_scanComplete) {
return ESP8266WiFiClass::_scanCount;
}
return WIFI_SCAN_FAILD;
}
void ESP8266WiFiClass::scanDelete()
{
if (ESP8266WiFiClass::_scanResult)
{
delete[] reinterpret_cast<bss_info*>(ESP8266WiFiClass::_scanResult);
ESP8266WiFiClass::_scanResult = 0;
ESP8266WiFiClass::_scanCount = 0;
}
_scanComplete = false;
}
int8_t ESP8266WiFiClass::scanNetworks(bool async)
{
if(ESP8266WiFiClass::_scanStarted) {
return WIFI_SCAN_RUNNING;
}
ESP8266WiFiClass::_scanAsync = async;
if(_useApMode) {
// turn on AP+STA mode
mode(WIFI_AP_STA);
@ -378,21 +415,28 @@ int8_t ESP8266WiFiClass::scanNetworks()
disconnect();
}
if (ESP8266WiFiClass::_scanResult)
{
delete[] reinterpret_cast<bss_info*>(ESP8266WiFiClass::_scanResult);
ESP8266WiFiClass::_scanResult = 0;
ESP8266WiFiClass::_scanCount = 0;
}
scanDelete();
struct scan_config config;
config.ssid = 0;
config.bssid = 0;
config.channel = 0;
config.show_hidden = 0;
wifi_station_scan(&config, reinterpret_cast<scan_done_cb_t>(&ESP8266WiFiClass::_scanDone));
esp_yield();
return ESP8266WiFiClass::_scanCount;
if(wifi_station_scan(&config, reinterpret_cast<scan_done_cb_t>(&ESP8266WiFiClass::_scanDone))) {
ESP8266WiFiClass::_scanComplete = false;
ESP8266WiFiClass::_scanStarted = true;
if(ESP8266WiFiClass::_scanAsync) {
delay(0); // time for the OS to trigger the scan
return WIFI_SCAN_RUNNING;
}
esp_yield();
return ESP8266WiFiClass::_scanCount;
} else {
return WIFI_SCAN_FAILD;
}
}
void * ESP8266WiFiClass::_getScanInfoByIndex(int i)
@ -645,6 +689,10 @@ void ESP8266WiFiClass::printDiag(Print& p)
}
bool ESP8266WiFiClass::_scanAsync = false;
bool ESP8266WiFiClass::_scanStarted = false;
bool ESP8266WiFiClass::_scanComplete = false;
size_t ESP8266WiFiClass::_scanCount = 0;
void* ESP8266WiFiClass::_scanResult = 0;

View File

@ -32,6 +32,9 @@ extern "C" {
#include "WiFiClient.h"
#include "WiFiServer.h"
#define WIFI_SCAN_RUNNING (-1)
#define WIFI_SCAN_FAILD (-2)
enum WiFiMode { WIFI_OFF = 0, WIFI_STA = 1, WIFI_AP = 2, WIFI_AP_STA = 3 };
class ESP8266WiFiClass
@ -189,12 +192,26 @@ public:
int32_t RSSI();
/*
* called to get the scan state in Async mode
*
* return -1 if scan not fin
* return -2 if scan not triggered
*/
int8_t scanComplete();
/*
* delete last scan result from RAM
*/
void scanDelete();
/*
* Start scan WiFi networks available
*
* return: Number of discovered networks
*/
int8_t scanNetworks();
int8_t scanNetworks(bool async = false);
/*
* Return the SSID discovered during the network scan.
@ -314,13 +331,17 @@ protected:
void * _getScanInfoByIndex(int i);
static void _smartConfigCallback(uint32_t status, void* result);
static void _eventCallback(void *event);
bool _smartConfigStarted = false;
bool _smartConfigDone = false;
bool _smartConfigStarted;
bool _smartConfigDone;
bool _useApMode;
bool _useClientMode;
bool _useStaticIp;
static bool _scanAsync;
static bool _scanStarted;
static bool _scanComplete;
static size_t _scanCount;
static void* _scanResult;

View File

@ -40,107 +40,119 @@ bool ESP8266WiFiMulti::addAP(const char* ssid, const char *passphrase) {
wl_status_t ESP8266WiFiMulti::run(void) {
int8_t scanResult;
wl_status_t status = WiFi.status();
if(status == WL_DISCONNECTED || status == WL_NO_SSID_AVAIL || status == WL_IDLE_STATUS || status == WL_CONNECT_FAILED) {
WifiAPlist_t bestNetwork { NULL, NULL };
int bestNetworkDb = INT_MIN;
uint8 bestBSSID[6];
int32_t bestChannel;
scanResult = WiFi.scanComplete();
if(scanResult == WIFI_SCAN_RUNNING) {
// scan is running
return WL_NO_SSID_AVAIL;
} else if(scanResult > 0) {
// scan done analyze
WifiAPlist_t bestNetwork { NULL, NULL };
int bestNetworkDb = INT_MIN;
uint8 bestBSSID[6];
int32_t bestChannel;
DEBUG_WIFI_MULTI("[WIFI] delete old wifi config...\n");
WiFi.disconnect();
DEBUG_WIFI_MULTI("[WIFI] scan done\n");
delay(0);
DEBUG_WIFI_MULTI("[WIFI] start scan\n");
// WiFi.scanNetworks will return the number of networks found
int8_t n = WiFi.scanNetworks();
if(scanResult <= 0) {
DEBUG_WIFI_MULTI("[WIFI] no networks found\n");
} else {
DEBUG_WIFI_MULTI("[WIFI] %d networks found\n", scanResult);
for(int8_t i = 0; i < scanResult; ++i) {
DEBUG_WIFI_MULTI("[WIFI] scan done\n");
delay(0);
String ssid_scan;
int32_t rssi_scan;
uint8_t sec_scan;
uint8_t* BSSID_scan;
int32_t chan_scan;
bool hidden_scan;
if(n <= 0) {
DEBUG_WIFI_MULTI("[WIFI] no networks found\n");
} else {
DEBUG_WIFI_MULTI("[WIFI] %d networks found\n", n);
for(int8_t i = 0; i < n; ++i) {
WiFi.getNetworkInfo(i, ssid_scan, sec_scan, rssi_scan, BSSID_scan, chan_scan, hidden_scan);
String ssid_scan;
int32_t rssi_scan;
uint8_t sec_scan;
uint8_t* BSSID_scan;
int32_t chan_scan;
bool hidden_scan;
bool known = false;
for(uint32_t x = 0; x < APlist.size(); x++) {
WifiAPlist_t entry = APlist[x];
WiFi.getNetworkInfo(i, ssid_scan, sec_scan, rssi_scan, BSSID_scan, chan_scan, hidden_scan);
bool known = false;
for(uint32_t x = 0; x < APlist.size(); x++) {
WifiAPlist_t entry = APlist[x];
if(ssid_scan == entry.ssid) { // SSID match
known = true;
if(rssi_scan > bestNetworkDb) { // best network
if(sec_scan == ENC_TYPE_NONE || entry.passphrase) { // check for passphrase if not open wlan
bestNetworkDb = rssi_scan;
bestChannel = chan_scan;
memcpy((void*) &bestNetwork, (void*) &entry, sizeof(bestNetwork));
memcpy((void*) &bestBSSID, (void*) BSSID_scan, sizeof(bestBSSID));
if(ssid_scan == entry.ssid) { // SSID match
known = true;
if(rssi_scan > bestNetworkDb) { // best network
if(sec_scan == ENC_TYPE_NONE || entry.passphrase) { // check for passphrase if not open wlan
bestNetworkDb = rssi_scan;
bestChannel = chan_scan;
memcpy((void*) &bestNetwork, (void*) &entry, sizeof(bestNetwork));
memcpy((void*) &bestBSSID, (void*) BSSID_scan, sizeof(bestBSSID));
}
}
break;
}
break;
}
}
if(known) {
DEBUG_WIFI_MULTI(" ---> ");
} else {
DEBUG_WIFI_MULTI(" ");
}
if(known) {
DEBUG_WIFI_MULTI(" ---> ");
} else {
DEBUG_WIFI_MULTI(" ");
}
DEBUG_WIFI_MULTI(" %d: [%d][%02X:%02X:%02X:%02X:%02X:%02X] %s (%d) %c\n", i, chan_scan, BSSID_scan[0], BSSID_scan[1], BSSID_scan[2], BSSID_scan[3], BSSID_scan[4], BSSID_scan[5], ssid_scan.c_str(), rssi_scan, (sec_scan == ENC_TYPE_NONE) ? ' ' : '*');
delay(0);
DEBUG_WIFI_MULTI(" %d: [%d][%02X:%02X:%02X:%02X:%02X:%02X] %s (%d) %c\n", i, chan_scan, BSSID_scan[0], BSSID_scan[1], BSSID_scan[2], BSSID_scan[3], BSSID_scan[4], BSSID_scan[5], ssid_scan.c_str(), rssi_scan, (sec_scan == ENC_TYPE_NONE) ? ' ' : '*');
delay(0);
}
}
}
DEBUG_WIFI_MULTI("\n\n");
delay(0);
// clean up ram
WiFi.scanDelete();
if(bestNetwork.ssid) {
DEBUG_WIFI_MULTI("[WIFI] Connecting BSSID: %02X:%02X:%02X:%02X:%02X:%02X SSID: %s Channal: %d (%d)\n", bestBSSID[0], bestBSSID[1], bestBSSID[2], bestBSSID[3], bestBSSID[4], bestBSSID[5], bestNetwork.ssid, bestChannel, bestNetworkDb);
DEBUG_WIFI_MULTI("\n\n");
delay(0);
WiFi.begin(bestNetwork.ssid, bestNetwork.passphrase, bestChannel, bestBSSID);
status = WiFi.status();
if(bestNetwork.ssid) {
DEBUG_WIFI_MULTI("[WIFI] Connecting BSSID: %02X:%02X:%02X:%02X:%02X:%02X SSID: %s Channal: %d (%d)\n", bestBSSID[0], bestBSSID[1], bestBSSID[2], bestBSSID[3], bestBSSID[4], bestBSSID[5], bestNetwork.ssid, bestChannel, bestNetworkDb);
// wait for connection or fail
while(status != WL_CONNECTED && status != WL_NO_SSID_AVAIL && status != WL_CONNECT_FAILED) {
delay(10);
WiFi.begin(bestNetwork.ssid, bestNetwork.passphrase, bestChannel, bestBSSID);
status = WiFi.status();
}
IPAddress ip;
uint8_t * mac;
switch(status) {
case WL_CONNECTED:
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] 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());
break;
case WL_NO_SSID_AVAIL:
DEBUG_WIFI_MULTI("[WIFI] Connecting Faild AP not found.\n");
break;
case WL_CONNECT_FAILED:
DEBUG_WIFI_MULTI("[WIFI] Connecting Faild.\n");
break;
default:
DEBUG_WIFI_MULTI("[WIFI] Connecting Faild (%d).\n", status);
break;
// wait for connection or fail
while(status != WL_CONNECTED && status != WL_NO_SSID_AVAIL && status != WL_CONNECT_FAILED) {
delay(10);
status = WiFi.status();
}
IPAddress ip;
uint8_t * mac;
switch(status) {
case WL_CONNECTED:
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] 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());
break;
case WL_NO_SSID_AVAIL:
DEBUG_WIFI_MULTI("[WIFI] Connecting Faild AP not found.\n");
break;
case WL_CONNECT_FAILED:
DEBUG_WIFI_MULTI("[WIFI] Connecting Faild.\n");
break;
default:
DEBUG_WIFI_MULTI("[WIFI] Connecting Faild (%d).\n", status);
break;
}
} else {
DEBUG_WIFI_MULTI("[WIFI] no matching wifi found!\n");
}
} else {
DEBUG_WIFI_MULTI("[WIFI] no matching wifi found!\n");
// start scan
DEBUG_WIFI_MULTI("[WIFI] delete old wifi config...\n");
WiFi.disconnect();
DEBUG_WIFI_MULTI("[WIFI] start scan\n");
// scan wifi async mode
WiFi.scanNetworks(true);
}
}
return status;

View File

@ -90,12 +90,15 @@ class ClientContext {
}
void unref() {
DEBUGV(":ur %d\r\n", _refcnt);
if(--_refcnt == 0) {
flush();
close();
if(_discard_cb) _discard_cb(_discard_cb_arg, this);
delete this;
if(this != 0) {
DEBUGV(":ur %d\r\n", _refcnt);
if(--_refcnt == 0) {
flush();
close();
if(_discard_cb)
_discard_cb(_discard_cb_arg, this);
delete this;
}
}
}

View File

@ -77,10 +77,11 @@ public:
void unref()
{
DEBUGV(":ur %d\r\n", _refcnt);
if (--_refcnt == 0)
{
delete this;
if(this != 0) {
DEBUGV(":ur %d\r\n", _refcnt);
if(--_refcnt == 0) {
delete this;
}
}
}

View File

@ -98,7 +98,7 @@ bool ESP8266WiFiMesh::exchangeInfo(String message, WiFiClient curr_client)
* @message The string to send to the node.
*
*/
void WiFiMesh::connectToNode(String target_ssid, String message)
void ESP8266WiFiMesh::connectToNode(String target_ssid, String message)
{
WiFiClient curr_client;
WiFi.begin( target_ssid.c_str() );

View File

@ -0,0 +1,8 @@
name=ESP8266httpUpdate
version=1.0
author=Markus Sattler
maintainer=Markus Sattler
sentence=Http Update for ESP8266
paragraph=
url=https://github.com/Links2004/Arduino/tree/esp8266/hardware/esp8266com/esp8266/libraries/ESP8266httpUpdate
architectures=ESP8266

View File

@ -0,0 +1,165 @@
/**
*
* @file ESP8266HTTPUpdate.cpp
* @date 21.06.2015
* @author Markus Sattler
*
* Copyright (c) 2015 Markus Sattler. All rights reserved.
* This file is part of the ESP8266 Http Updater.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include "ESP8266HTTPUpdate.h"
ESP8266HTTPUpdate::ESP8266HTTPUpdate(void) {
}
ESP8266HTTPUpdate::~ESP8266HTTPUpdate(void) {
}
t_httpUpdate_return ESP8266HTTPUpdate::update(const char * host, uint16_t port, const char * url, const char * current_version) {
t_httpUpdate_return ret = HTTP_UPDATE_FAILD;
WiFiClient tcp;
DEBUG_HTTP_UPDATE("[httpUpdate] connected to %s:%u %s .... ", host, port, url);
if(!tcp.connect(host, port)) {
DEBUG_HTTP_UPDATE("faild.\n");
return ret;
}
DEBUG_HTTP_UPDATE("ok.\n");
// set Timeout for readBytesUntil and readStringUntil
tcp.setTimeout(2000);
tcp.setNoDelay(true);
String req = "GET ";
req += url;
req += " HTTP/1.1\r\n"
"Host: ";
req += host;
req += "\r\n"
"Connection: close\r\n"
"User-Agent: ESP8266-http-Update\r\n"
"x-ESP8266-STA-MAC: ";
req += WiFi.macAddress();
req += "\r\n"
"x-ESP8266-AP-MAC: ";
req += WiFi.softAPmacAddress();
req += "\r\n"
"x-ESP8266-free-space: ";
req += ESP.getFreeSketchSpace();
req += "\r\n"
"x-ESP8266-sketch-size: ";
req += ESP.getSketchSize();
req += "\r\n"
"x-ESP8266-chip-size: ";
req += ESP.getFlashChipRealSize();
req += "\r\n"
"x-ESP8266-sdk-version: ";
req += ESP.getSdkVersion();
if(current_version[0] != 0x00) {
req += "\r\n"
"x-ESP8266-version: ";
req += current_version;
}
req += "\r\n"
"\r\n";
tcp.write(req.c_str(), req.length());
uint32_t code = 0;
size_t len = 0;
while(true) {
String headerLine = tcp.readStringUntil('\n');
headerLine.trim(); // remove \r
if(headerLine.length() > 0) {
DEBUG_HTTP_UPDATE("[httpUpdate][Header] RX: %s\n", headerLine.c_str());
if(headerLine.startsWith("HTTP/1.")) {
// 9 = lenght of "HTTP/1.x "
code = headerLine.substring(9, headerLine.indexOf(' ', 9)).toInt();
} else if(headerLine.startsWith("Content-Length: ")) {
// 16 = lenght of "Content-Length: "
len = headerLine.substring(16).toInt();
}
} else {
break;
}
}
DEBUG_HTTP_UPDATE("[httpUpdate] Header read fin.\n");
DEBUG_HTTP_UPDATE("[httpUpdate] Server header:\n");
DEBUG_HTTP_UPDATE("[httpUpdate] - code: %d\n", code);
DEBUG_HTTP_UPDATE("[httpUpdate] - len: %d\n", len);
DEBUG_HTTP_UPDATE("[httpUpdate] ESP8266 info:\n");
DEBUG_HTTP_UPDATE("[httpUpdate] - free Space: %d\n", ESP.getFreeSketchSpace());
DEBUG_HTTP_UPDATE("[httpUpdate] - current Sketch Size: %d\n", ESP.getSketchSize());
if(current_version[0] != 0x00) {
DEBUG_HTTP_UPDATE("[httpUpdate] - current version: %s\n", current_version);
}
switch(code) {
case 200: ///< OK (Start Update)
if(len > 0) {
if(len > ESP.getFreeSketchSpace()) {
ret = HTTP_UPDATE_FAILD;
DEBUG_HTTP_UPDATE("[httpUpdate] FreeSketchSpace to low (%d) needed: %d\n", ESP.getFreeSketchSpace(), len);
} else {
if(ESP.updateSketch(tcp, len)) {
// may never reached!
ret = HTTP_UPDATE_OK;
DEBUG_HTTP_UPDATE("[httpUpdate] Update ok\n");
} else {
ret = HTTP_UPDATE_FAILD;
DEBUG_HTTP_UPDATE("[httpUpdate] Update failed\n");
}
}
} else {
ret = HTTP_UPDATE_FAILD;
DEBUG_HTTP_UPDATE("[httpUpdate]Content-Length is 0?!\n");
}
break;
case 304:
///< Not Modified (No updates)
ret = HTTP_UPDATE_NO_UPDATES;
break;
case 403:
///< Forbidden
// todo handle login
default:
ret = HTTP_UPDATE_FAILD;
DEBUG_HTTP_UPDATE("[httpUpdate] Code is (%d)\n", code);
break;
}
return ret;
}
t_httpUpdate_return ESP8266HTTPUpdate::update(String host, uint16_t port, String url, String current_version) {
return update(host.c_str(), port, url.c_str(), current_version.c_str());
}
ESP8266HTTPUpdate ESPhttpUpdate;

View File

@ -0,0 +1,55 @@
/**
*
* @file ESP8266HTTPUpdate.h
* @date 21.06.2015
* @author Markus Sattler
*
* Copyright (c) 2015 Markus Sattler. All rights reserved.
* This file is part of the ESP8266 Http Updater.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifndef ESP8266HTTPUPDATE_H_
#define ESP8266HTTPUPDATE_H_
#include <Arduino.h>
#include <ESP8266WiFi.h>
#define DEBUG_HTTP_UPDATE(...) Serial1.printf( __VA_ARGS__ )
#ifndef DEBUG_HTTP_UPDATE
#define DEBUG_HTTP_UPDATE(...)
#endif
typedef enum {
HTTP_UPDATE_FAILD,
HTTP_UPDATE_NO_UPDATES,
HTTP_UPDATE_OK
} t_httpUpdate_return;
class ESP8266HTTPUpdate {
public:
ESP8266HTTPUpdate(void);
~ESP8266HTTPUpdate(void);
t_httpUpdate_return update(const char * host, uint16_t port, const char * url = "/", const char * current_version = "");
t_httpUpdate_return update(String host, uint16_t port, String url = "/", String current_version = "");
};
extern ESP8266HTTPUpdate ESPhttpUpdate;
#endif /* ESP8266HTTPUPDATE_H_ */

View File

@ -117,9 +117,13 @@ sample code bearing this copyright.
#include "OneWire.h"
OneWire::OneWire(uint8_t pin)
OneWire::OneWire(uint8_t pin, bool pullup)
{
pinMode(pin, INPUT_PULLUP);
if(pullup) {
pinMode(pin, INPUT_PULLUP);
} else {
pinMode(pin, INPUT);
}
bitmask = PIN_TO_BITMASK(pin);
baseReg = PIN_TO_BASEREG(pin);
#if ONEWIRE_SEARCH

View File

@ -135,7 +135,7 @@ class OneWire
#endif
public:
OneWire( uint8_t pin);
OneWire(uint8_t pin, bool pullup = true);
// Perform a 1-Wire reset cycle. Returns 1 if a device responds
// with a presence pulse. Returns 0 if there is no device or the

View File

@ -3,7 +3,7 @@
The SD library allows for reading from and writing to SD cards.
For more information about this library please visit us at
http://arduino.cc/en/Reference/SD
http://www.arduino.cc/en/Reference/SD
== License ==

View File

@ -1,9 +1,9 @@
name=SD
version=1.0.4
version=1.0.5
author=Arduino, SparkFun
maintainer=Arduino <info@arduino.cc>
sentence=Enables reading and writing on SD cards. For all Arduino boards.
paragraph=Once an SD memory card is connected to the SPI interfare of the Arduino board you are enabled to create files and read/write on them. You can also move through directories on the SD card.
category=Data Storage
url=http://arduino.cc/en/Reference/SD
url=http://www.arduino.cc/en/Reference/SD
architectures=*

View File

@ -93,18 +93,23 @@ public:
// write, etc). Returns a File object for interacting with the file.
// Note that currently only one file can be open at a time.
File open(const char *filename, uint8_t mode = FILE_READ);
File open(const String &filename, uint8_t mode = FILE_READ) { return open( filename.c_str(), mode ); }
// Methods to determine if the requested file path exists.
boolean exists(char *filepath);
boolean exists(const String &filepath) { return exists(filepath.c_str()); }
// Create the requested directory heirarchy--if intermediate directories
// do not exist they will be created.
boolean mkdir(char *filepath);
boolean mkdir(const String &filepath) { return mkdir(filepath.c_str()); }
// Delete the file.
boolean remove(char *filepath);
boolean remove(const String &filepath) { return remove(filepath.c_str()); }
boolean rmdir(char *filepath);
boolean rmdir(const String &filepath) { return rmdir(filepath.c_str()); }
uint8_t type(){ return card.type(); }
uint8_t fatType(){ return volume.fatType(); }

View File

@ -0,0 +1,24 @@
/*
ESP8266 Blink by Simon Peter
Blink the blue LED on the ESP-01 module
This example code is in the public domain
The blue LED on the ESP-01 module is connected to GPIO1
(which is also the TXD pin; so we cannot use Serial.print() at the same time)
Note that this sketch uses BUILTIN_LED to find the pin with the internal LED
*/
void setup() {
pinMode(BUILTIN_LED, OUTPUT); // Initialize the BUILTIN_LED pin as an output
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(BUILTIN_LED, LOW); // Turn the LED on (Note that LOW is the voltage level
// but actually the LED is on; this is because
// it is acive low on the ESP-01)
delay(1000); // Wait for a second
digitalWrite(BUILTIN_LED, HIGH); // Turn the LED off by making the voltage HIGH
delay(2000); // Wait for two seconds (to demonstrate the active low LED)
}

View File

@ -0,0 +1,33 @@
/*
ESP8266 BlinkWithoutDelay by Simon Peter
Blink the blue LED on the ESP-01 module
Based on the Arduino Blink without Delay example
This example code is in the public domain
The blue LED on the ESP-01 module is connected to GPIO1
(which is also the TXD pin; so we cannot use Serial.print() at the same time)
Note that this sketch uses BUILTIN_LED to find the pin with the internal LED
*/
int ledState = LOW;
unsigned long previousMillis = 0;
const long interval = 1000;
void setup() {
pinMode(BUILTIN_LED, OUTPUT);
}
void loop()
{
unsigned long currentMillis = millis();
if(currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
if (ledState == LOW)
ledState = HIGH; // Note that this switches the LED *off*
else
ledState = LOW; // Note that this switches the LED *on*
digitalWrite(BUILTIN_LED, ledState);
}
}

View File

@ -1,3 +1,35 @@
esp_iot_sdk_v1.1.2_15_06_16_p1 Release Note
-------------------------------------------
Here is a patch based on SDK_v1.1.2 resolved issue that "wifi_station_scan" cause loss of wireless connectivity.
Please replace them in esp_iot_sdk/lib folder.
Sorry for the inconvenience.
esp_iot_sdk_v1.1.2_15_06_12 Release Note
-------------------------------------------
Optimization:
1. support certificate issuer verification for SSL
2. Update SPI driver, support overlap mode
Add APIs:
1. wifi_station_set_hostname : set ESP8266 station DHCP hostname
2. wifi_station_get_hostname : get ESP8266 station DHCP hostname
3. spi_flash_set_read_func set user specified reading SPI function on overlap mode
4. espconn_secure_ca_disable : disable SSL CA verify
5. espconn_secure_ca_enable : enable SSL CA verify
Add Documentation:
1. SPI overlap introduction: \esp_iot_sdk\document, sorry that it has only Chinese version nowwe will add English version of this documentation ASAP.
2. SSL introduction: \esp_iot_sdk\document
esp_iot_sdk_v1.1.1_15_06_05 Release Note
-------------------------------------------

View File

@ -23,6 +23,9 @@ typedef void (* espconn_reconnect_callback)(void *arg, sint8 err);
#define ESPCONN_ARG -12 /* Illegal argument. */
#define ESPCONN_ISCONN -15 /* Already connected. */
#define ESPCONN_HANDSHAKE -28 /* ssl handshake failed */
#define ESPCONN_PROTO_MSG -61 /* ssl application invalid */
/** Protocol family and type of the espconn */
enum espconn_type {
ESPCONN_INVALID = 0,
@ -455,6 +458,28 @@ bool espconn_secure_set_size(uint8 level, uint16 size);
sint16 espconn_secure_get_size(uint8 level);
/******************************************************************************
* FunctionName : espconn_secure_ca_enable
* Description : enable the certificate authenticate and set the flash sector
* as client or server
* Parameters : level -- set for client or server
* 1: client,2:server,3:client and server
* flash_sector -- flash sector for save certificate
* Returns : result true or false
*******************************************************************************/
bool espconn_secure_ca_enable(uint8 level, uint8 flash_sector );
/******************************************************************************
* FunctionName : espconn_secure_ca_disable
* Description : disable the certificate authenticate as client or server
* Parameters : level -- set for client or server
* 1: client,2:server,3:client and server
* Returns : result true or false
*******************************************************************************/
bool espconn_secure_ca_disable(uint8 level);
/******************************************************************************
* FunctionName : espconn_secure_accept
* Description : The function given as the listen

View File

@ -30,4 +30,12 @@ SpiFlashOpResult spi_flash_erase_sector(uint16 sec);
SpiFlashOpResult spi_flash_write(uint32 des_addr, uint32 *src_addr, uint32 size);
SpiFlashOpResult spi_flash_read(uint32 src_addr, uint32 *des_addr, uint32 size);
typedef SpiFlashOpResult (* user_spi_flash_read)(
SpiFlashChip *spi,
uint32 src_addr,
uint32 *des_addr,
uint32 size);
void spi_flash_set_read_func(user_spi_flash_read read);
#endif

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1 +1 @@
1.1.1_15_06_05
1.1.2_15_06_16_p1