1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-23 19:21:59 +03:00

Merge pull request #438 from Links2004/esp8266

update SDK to esp_iot_sdk_v1.1.2_15_06_16_p1
This commit is contained in:
Ivan Grokhotkov
2015-06-26 20:33:02 +03:00
424 changed files with 6081 additions and 12705 deletions

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

@ -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

@ -32,7 +32,7 @@ extern struct rst_info resetInfo;
// #define DEBUG_SERIAL Serial
/**
* User-defined Literals
* usage:
@ -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();
@ -426,7 +433,7 @@ bool EspClass::updateSketch(Stream& in, uint32_t size) {
ebcmd.args[1] = 0x00000;
ebcmd.args[2] = size;
eboot_command_write(&ebcmd);
ESP.restart();
return true; // never happens
}

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

@ -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);
}

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);
@ -377,22 +414,29 @@ 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

@ -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

@ -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

View File

@ -1 +1 @@
1.1.1_15_06_05
1.1.2_15_06_16_p1