mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
commit
20f372aefe
@ -14,6 +14,10 @@ Starting with 1.6.4, Arduino allows installation of third-party platform package
|
||||
- Enter ```http://arduino.esp8266.com/stable/package_esp8266com_index.json``` into *Additional Board Manager URLs* field. You can add multiple URLs, separating them with commas.
|
||||
- Open Boards Manager from Tools > Board menu and install *esp8266* platform (and don't forget to select your ESP8266 board from Tools > Board menu after installation).
|
||||
|
||||
The best place to ask questions related to this core is ESP8266 community forum: http://www.esp8266.com/arduino.
|
||||
If you find this ESP8266 board manager useful, please consider supporting it with a donation. The ESP8266 Community Forum and IGRR have made this wonderful port available.
|
||||
[](https://www.paypal.com/webscr?cmd=_s-xclick&hosted_button_id=4M56YCWV6PX66)
|
||||
|
||||
#### Available versions
|
||||
|
||||
##### Stable version 
|
||||
@ -26,7 +30,6 @@ Boards manager link: `http://arduino.esp8266.com/staging/package_esp8266com_inde
|
||||
|
||||
Documentation: [Reference](http://arduino.esp8266.com/staging/doc/reference.html)
|
||||
|
||||
|
||||
### Using git version [](https://travis-ci.org/esp8266/Arduino)
|
||||
|
||||
- Install Arduino 1.6.5
|
||||
@ -54,10 +57,6 @@ Documentation for latest development version:
|
||||
|
||||
### Issues and support ###
|
||||
|
||||
The best place to ask questions related to this core is ESP8266 community forum: http://www.esp8266.com/arduino.
|
||||
If you find the forum useful, please consider supporting it with a donation.
|
||||
[](https://www.paypal.com/webscr?cmd=_s-xclick&hosted_button_id=4M56YCWV6PX66)
|
||||
|
||||
If you encounter an issue, you are welcome to submit it here on Github: https://github.com/esp8266/Arduino/issues.
|
||||
Please provide as much context as possible: version which you are using (you can check it in Boards Manager), your sketch code, serial output, board model, IDE settings (board selection, flash size, etc).
|
||||
|
||||
|
10
boards.txt
10
boards.txt
@ -584,6 +584,8 @@ d1.menu.UploadTool.esptool.upload.verbose=-vv
|
||||
d1.menu.UploadTool.espota=OTA
|
||||
d1.menu.UploadTool.espota.upload.tool=espota
|
||||
|
||||
d1.menu.UploadSpeed.921600=921600
|
||||
d1.menu.UploadSpeed.921600.upload.speed=921600
|
||||
d1.menu.UploadSpeed.115200=115200
|
||||
d1.menu.UploadSpeed.115200.upload.speed=115200
|
||||
d1.menu.UploadSpeed.9600=9600
|
||||
@ -601,8 +603,7 @@ d1.menu.UploadSpeed.460800.macosx=460800
|
||||
d1.menu.UploadSpeed.460800.upload.speed=460800
|
||||
d1.menu.UploadSpeed.512000.windows=512000
|
||||
d1.menu.UploadSpeed.512000.upload.speed=512000
|
||||
d1.menu.UploadSpeed.921600=921600
|
||||
d1.menu.UploadSpeed.921600.upload.speed=921600
|
||||
|
||||
|
||||
d1.menu.FlashSize.4M3M=4M (3M SPIFFS)
|
||||
d1.menu.FlashSize.4M3M.build.flash_size=4M
|
||||
@ -654,6 +655,8 @@ d1_mini.menu.UploadTool.esptool.upload.verbose=-vv
|
||||
d1_mini.menu.UploadTool.espota=OTA
|
||||
d1_mini.menu.UploadTool.espota.upload.tool=espota
|
||||
|
||||
d1_mini.menu.UploadSpeed.921600=921600
|
||||
d1_mini.menu.UploadSpeed.921600.upload.speed=921600
|
||||
d1_mini.menu.UploadSpeed.115200=115200
|
||||
d1_mini.menu.UploadSpeed.115200.upload.speed=115200
|
||||
d1_mini.menu.UploadSpeed.9600=9600
|
||||
@ -671,8 +674,7 @@ d1_mini.menu.UploadSpeed.460800.macosx=460800
|
||||
d1_mini.menu.UploadSpeed.460800.upload.speed=460800
|
||||
d1_mini.menu.UploadSpeed.512000.windows=512000
|
||||
d1_mini.menu.UploadSpeed.512000.upload.speed=512000
|
||||
d1_mini.menu.UploadSpeed.921600=921600
|
||||
d1_mini.menu.UploadSpeed.921600.upload.speed=921600
|
||||
|
||||
|
||||
d1_mini.menu.FlashSize.4M3M=4M (3M SPIFFS)
|
||||
d1_mini.menu.FlashSize.4M3M.build.flash_size=4M
|
||||
|
@ -37,6 +37,11 @@ static void uart1_write_char_d(char c);
|
||||
static void print_stack(uint32_t start, uint32_t end);
|
||||
//static void print_pcs(uint32_t start, uint32_t end);
|
||||
|
||||
extern void __custom_crash_callback( struct rst_info * rst_info, uint32_t stack, uint32_t stack_end ) {
|
||||
}
|
||||
|
||||
extern void custom_crash_callback( struct rst_info * rst_info, uint32_t stack, uint32_t stack_end ) __attribute__ ((weak, alias("__custom_crash_callback")));
|
||||
|
||||
void __wrap_system_restart_local() {
|
||||
register uint32_t sp asm("a1");
|
||||
|
||||
@ -92,6 +97,9 @@ void __wrap_system_restart_local() {
|
||||
|
||||
// print_pcs(sp + offset, stack_end);
|
||||
print_stack(sp + offset, stack_end);
|
||||
|
||||
custom_crash_callback( &rst_info, sp + offset, stack_end );
|
||||
|
||||
delayMicroseconds(10000);
|
||||
__real_system_restart_local();
|
||||
}
|
||||
|
@ -10,6 +10,8 @@ title: Supported Hardware
|
||||
- [SparkFun ESP8266 Thing](#sparkfun-esp8266-thing)
|
||||
- [SweetPea ESP-210](#sweetpea-esp-210)
|
||||
- [Generic ESP8266 modules](#generic-esp8266-modules)
|
||||
- [WeMos D1](#wemos-d1)
|
||||
- [WeMos D1 mini](#wemos-d1-mini)
|
||||
|
||||
### Adafruit HUZZAH ESP8266 (ESP-12)
|
||||
|
||||
@ -162,3 +164,57 @@ ESPxx Hardware
|
||||
|
||||
### Improved Stability
|
||||

|
||||
|
||||
### Boot Messages and Modes
|
||||
|
||||
The ESP module checks at every boot the Pins 0, 2 and 15.
|
||||
based on them its boots in different modes:
|
||||
|
||||
| GPIO15 | GPIO0 | GPIO2 | Mode |
|
||||
| ------ | ----- | ----- | -------------------------------- |
|
||||
| 0V | 0V | 3.3V | Uart Bootloader |
|
||||
| 0V | 3.3V | 3.3V | Boot sketch (SPI flash) |
|
||||
| 3.3V | x | x | SDIO mode (not used for Arduino) |
|
||||
|
||||
|
||||
at startup the ESP prints out the current boot mode example:
|
||||
```
|
||||
rst cause:2, boot mode:(3,6)
|
||||
```
|
||||
|
||||
note:
|
||||
- GPIO2 is used as TX output and the internal Pullup is enabled on boot.
|
||||
|
||||
#### rst cause
|
||||
|
||||
| Number | Description |
|
||||
| ------ | ---------------------- |
|
||||
| 0 | unknown |
|
||||
| 1 | normal boot |
|
||||
| 2 | reset pin |
|
||||
| 3 | software reset |
|
||||
| 4 | watchdog reset |
|
||||
|
||||
|
||||
#### boot mode
|
||||
|
||||
the first value respects the pin setup of the Pins 0, 2 and 15.
|
||||
|
||||
| Number | GPIO15 | GPIO0 | GPIO2 | Mode |
|
||||
| ------ | ------ | ----- | ----- | ---------- |
|
||||
| 0 | 0V | 0V | 0V | Not valid |
|
||||
| 1 | 0V | 0V | 3.3V | Uart |
|
||||
| 2 | 0V | 3.3V | 0V | Not valid |
|
||||
| 3 | 0V | 3.3V | 3.3V | Flash |
|
||||
| 4 | 3.3V | 0V | 0V | SDIO |
|
||||
| 5 | 3.3V | 0V | 3.3V | SDIO |
|
||||
| 6 | 3.3V | 3.3V | 0V | SDIO |
|
||||
| 7 | 3.3V | 3.3V | 3.3V | SDIO |
|
||||
|
||||
note:
|
||||
- number = ((GPIO15 << 2) | (GPIO0 << 1) | GPIO2);
|
||||
|
||||
### WeMos D1
|
||||
Product page: http://wemos.cc
|
||||
### WeMos D1 mini
|
||||
Product page: http://wemos.cc
|
||||
|
@ -10,7 +10,7 @@ title: OTA Update
|
||||
|
||||
## Introduction
|
||||
|
||||
OTA (Over the Air) update is the process of loading the firmware to ESP module using WiFi connection rather that a serial port. Such functionality became extremely useful in case of limited or no physical access to the module. There is no imposed protection on OTA update process. Such protection should be implemented by developer to ensure that updates are allowed only from legitimate / trusted source.
|
||||
OTA (Over the Air) update is the process of loading the firmware to ESP module using WiFi connection rather that a serial port. Such functionality became extremely useful in case of limited or no physical access to the module.
|
||||
|
||||
OTA may be done from:
|
||||
- [Arduino IDE](#arduino-ide)
|
||||
@ -18,13 +18,42 @@ OTA may be done from:
|
||||
|
||||
In any case first firmware upload have to be done over a serial port. If OTA routines are correctly implemented in sketch, then all subsequent uploads may be done over the air.
|
||||
|
||||
The following chapters provide more details and both methods of doing OTA.
|
||||
There is no imposed security on OTA process from being hacked. It is up to developer to ensure that updates are allowed only from legitimate / trusted source. Once update is complete module restarts and new code is executed. Developer should ensure that application running on module is shut down and restarted in safe manner. Chapters below provide additinal information regarding security and safety of OTA process.
|
||||
|
||||
### Security
|
||||
|
||||
Module has to be exposed wirelessly to get it updated with a new code. That poses chances of module being violently hacked and loaded with some other firmware. To reduce likelihood of being hacked consider protecting your uploads with a password, selecting certain OTA port, etc.
|
||||
|
||||
Check functionality provided with [ArduinoOTA](https://github.com/esp8266/Arduino/tree/master/libraries/ArduinoOTA) library that may improve security:
|
||||
```cpp
|
||||
void setPort(uint16_t port);
|
||||
void setHostname(const char *hostname);
|
||||
void setPassword(const char *password);
|
||||
```
|
||||
If possible implement other means of protection from being hacked, e.g. exposing module for uploads only according to specific schedule, trigger OTA only be user pressing dedicated “Update” button, etc.
|
||||
|
||||
### Safety
|
||||
|
||||
OTA process takes ESP’s resources and bandwidth during upload. Then module is restarted and a new sketch executed. Analyse and test how it affects functionality of your existing and new sketch.
|
||||
|
||||
If ESP is placed in remote location and controlling some equipment, you should put additional attention what happens if operation of this equipment is suddenly interrupted by update process. Therefore decide how to put this equipment into safe state before starting the update. For instance your module may be controlling a garden watering system in a sequence. If this sequence is not properly shut down and a water valve left open, your garden may be flooded if this valve is not closed after OTA is finished and module restarts.
|
||||
|
||||
The following functions are provided with [ArduinoOTA](https://github.com/esp8266/Arduino/tree/master/libraries/ArduinoOTA) library and intended to handle functionality of your application during specific stages of OTA on or on an OTA error:
|
||||
```cpp
|
||||
void onStart(OTA_CALLBACK(fn));
|
||||
void onEnd(OTA_CALLBACK(fn));
|
||||
void onProgress(OTA_CALLBACK_PROGRESS(fn));
|
||||
void onError(OTA_CALLBACK_ERROR (fn));
|
||||
```
|
||||
|
||||
The following chapters provide more details and specific methods of doing OTA.
|
||||
|
||||
|
||||
## Basic Requirements
|
||||
|
||||
- Flash chip size is 2x the size of the sketch.
|
||||
|
||||
|
||||
## Arduino IDE
|
||||
|
||||
Uploading modules wirelessly from Arduino IDE is intended for the following typical scenarios:
|
||||
@ -37,17 +66,19 @@ Uploading modules wirelessly from Arduino IDE is intended for the following typi
|
||||
|
||||
#### Let's Do It
|
||||
|
||||
OTA process will be demonstrated using:
|
||||
- DNS_SD_Arduino_OTA.ino sketch available from Arduino IDE
|
||||
- NodeMCU 1.0 board with ESP-12E module
|
||||
Currently there are two software configurations that support OTA updates
|
||||
- [Classic OTA](#classic-ota-configuration): Arduino IDE 1.6.5 and [stable](https://github.com/esp8266/Arduino#staging-version-) (July 23, 2015) or [staging](https://github.com/esp8266/Arduino#staging-version-) (Sep 30, 2015) platform package that provides first OTA implementation, yet without support for [ArduinoOTA](https://github.com/esp8266/Arduino/tree/master/libraries/ArduinoOTA) library. This particular configuration is intended for less experienced users. It soon will be depreciated once implementation below is fully released.
|
||||
- [ArduinoOTA](#arduinoota-configuration): Arduino-PR-4107-BUILD-421 and latest git version of platform package that includes [ArduinoOTA](https://github.com/esp8266/Arduino/tree/master/libraries/ArduinoOTA) library. This configuration features preliminary build of Arduino IDE and is intended for more experienced users. Please mid your step.
|
||||
|
||||
Instructions below demonstrate how to configure both [Classic OTA](#classic-ota-configuration) and [ArduinoOTA](#arduinoota-configuration) using NodeMCU 1.0 board with ESP-12E.
|
||||
|
||||
##### Classic OTA Configuration
|
||||
|
||||
1. Before you begin, please make sure that you have the following installed:
|
||||
- Arduino IDE and ESP8266 board support as described under https://github.com/esp8266/Arduino#installing-with-boards-manager
|
||||
- Python 2.7.10 (do not install Python 3.5.0 that is not supported):
|
||||
1. Upload Python from https://www.python.org/
|
||||
2. Start installer
|
||||
3. Select “Add python.exe to Path” (see below – that option is not selected by default)
|
||||
4. Complete remaining steps of installation
|
||||
- [Python](https://www.python.org/) 2.7.10 (do not install Python 3.5.0 that is not supported):
|
||||
|
||||
**Note:** Windows users should select “Add python.exe to Path” (see below – this option is not selected by default)
|
||||
|
||||

|
||||
|
||||
@ -57,6 +88,8 @@ OTA process will be demonstrated using:
|
||||
|
||||

|
||||
|
||||
**Note:** This sketch is available only for stable (July 23, 2015) and staging (Sep 30, 2015) releases installed in Arduino IDE using https://github.com/esp8266/Arduino#installing-with-boards-manager. It was removed in [#980](https://github.com/esp8266/Arduino/pull/980) from Github repository.
|
||||
|
||||
- Update ssid and pass in the sketch so the module can join your WiFi network
|
||||
|
||||

|
||||
@ -69,7 +102,7 @@ OTA process will be demonstrated using:
|
||||
|
||||

|
||||
|
||||
4. Only if module is connected, after a dozen (or two dozens) of seconds the esp8266-ota port will show up in Arduino IDE:
|
||||
4. Only if module is connected to network, after a couple of seconds, the esp8266-ota port will show up in Arduino IDE:
|
||||
|
||||

|
||||
|
||||
@ -77,12 +110,25 @@ OTA process will be demonstrated using:
|
||||
|
||||

|
||||
|
||||
**Note:** If you do not see “Upload Using: OTA” option available for “NodeMCU 1.0 (ESP-12E Module)” board, please upload the latest [boards.txt](https://github.com/esp8266/Arduino/blob/master/boards.txt) file from Github repository, replace existing file and restart Arduino IDE.
|
||||
|
||||
6. If you have successfully completed all the above steps, you can upload (Ctrl+U) the same (or any other) sketch over OTA:
|
||||
|
||||

|
||||
|
||||
**Note** To be able to upload your sketch over and over again using OTA, you need to embed OTA routines inside. Please use DNS_SD_Arduino_OTA.ino as an example.
|
||||
|
||||
##### ArduinoOTA Configuration
|
||||
|
||||
1. Get the following software:
|
||||
- Arduino-PR-4107-BUILD-421 - https://github.com/esp8266/Arduino/pull/984#issuecomment-155905800
|
||||
- Latest git version of pacakge - https://github.com/esp8266/Arduino#using-git-version-
|
||||
- Python 2.7.10
|
||||
|
||||
2. Proceed to step 2 under [Classic OTA Configuration](#classic-ota-configuration) using BasicOTA.ino or OTALeds.ino skech instead.
|
||||
|
||||
3. Carry on with remaining steps.
|
||||
|
||||
|
||||
## HTTP Server
|
||||
|
||||
|
@ -167,6 +167,7 @@ NodeMCU 1.0 | 4M | 1M, 3M
|
||||
Olimex MOD-WIFI-ESP8266(-DEV)| 2M | 1M
|
||||
SparkFun Thing | 512k | 64k
|
||||
SweetPea ESP-210 | 4M | 1M, 3M
|
||||
WeMos D1 & D1 mini | 4M | 1M, 3M
|
||||
|
||||
**Note:** to use any of file system functions in the sketch, add the following include to the sketch:
|
||||
|
||||
|
@ -31,14 +31,25 @@
|
||||
#define DEBUG_OUTPUT Serial
|
||||
|
||||
|
||||
ESP8266WebServer::ESP8266WebServer(IPAddress addr, int port)
|
||||
: _server(addr, port)
|
||||
, _firstHandler(0)
|
||||
, _lastHandler(0)
|
||||
, _currentArgCount(0)
|
||||
, _currentArgs(0)
|
||||
, _headerKeysCount(0)
|
||||
, _currentHeaders(0)
|
||||
{
|
||||
}
|
||||
|
||||
ESP8266WebServer::ESP8266WebServer(int port)
|
||||
: _server(port)
|
||||
, _firstHandler(0)
|
||||
, _lastHandler(0)
|
||||
, _currentArgCount(0)
|
||||
, _currentArgs(0)
|
||||
,_headerKeysCount(0)
|
||||
,_currentHeaders(0)
|
||||
, _headerKeysCount(0)
|
||||
, _currentHeaders(0)
|
||||
{
|
||||
}
|
||||
|
||||
@ -46,8 +57,6 @@ ESP8266WebServer::~ESP8266WebServer() {
|
||||
if (_currentHeaders)
|
||||
delete[]_currentHeaders;
|
||||
_headerKeysCount = 0;
|
||||
if (!_firstHandler)
|
||||
return;
|
||||
RequestHandler* handler = _firstHandler;
|
||||
while (handler) {
|
||||
RequestHandler* next = handler->next();
|
||||
|
@ -59,6 +59,7 @@ typedef struct {
|
||||
class ESP8266WebServer
|
||||
{
|
||||
public:
|
||||
ESP8266WebServer(IPAddress addr, int port = 80);
|
||||
ESP8266WebServer(int port = 80);
|
||||
~ESP8266WebServer();
|
||||
|
||||
|
@ -31,6 +31,7 @@ extern "C" {
|
||||
#include "IPAddress.h"
|
||||
#include "WiFiClient.h"
|
||||
#include "WiFiServer.h"
|
||||
#include "WiFiClientSecure.h"
|
||||
|
||||
#define WIFI_SCAN_RUNNING (-1)
|
||||
#define WIFI_SCAN_FAILED (-2)
|
||||
|
@ -50,7 +50,6 @@ extern "C"
|
||||
#define SSL_DEBUG_OPTS 0
|
||||
#endif
|
||||
|
||||
#define SSL_RX_BUF_SIZE 1536
|
||||
|
||||
class SSLContext {
|
||||
public:
|
||||
@ -59,8 +58,6 @@ public:
|
||||
_ssl_ctx = ssl_ctx_new(SSL_SERVER_VERIFY_LATER | SSL_DEBUG_OPTS, 0);
|
||||
}
|
||||
++_ssl_ctx_refcnt;
|
||||
|
||||
_rxbuf = new cbuf(SSL_RX_BUF_SIZE);
|
||||
}
|
||||
|
||||
~SSLContext() {
|
||||
@ -73,8 +70,6 @@ public:
|
||||
if (_ssl_ctx_refcnt == 0) {
|
||||
ssl_ctx_free(_ssl_ctx);
|
||||
}
|
||||
|
||||
delete _rxbuf;
|
||||
}
|
||||
|
||||
void ref() {
|
||||
@ -92,36 +87,50 @@ public:
|
||||
}
|
||||
|
||||
int read(uint8_t* dst, size_t size) {
|
||||
if (size > _rxbuf->getSize()) {
|
||||
_readAll();
|
||||
if (!_available) {
|
||||
if (!_readAll())
|
||||
return 0;
|
||||
}
|
||||
return _rxbuf->read(reinterpret_cast<char*>(dst), size);
|
||||
size_t will_copy = (_available < size) ? _available : size;
|
||||
memcpy(dst, _read_ptr, will_copy);
|
||||
_read_ptr += will_copy;
|
||||
_available -= will_copy;
|
||||
if (_available == 0) {
|
||||
_read_ptr = nullptr;
|
||||
}
|
||||
return will_copy;
|
||||
}
|
||||
|
||||
int read() {
|
||||
optimistic_yield(100);
|
||||
if (!_rxbuf->getSize()) {
|
||||
_readAll();
|
||||
if (!_available) {
|
||||
if (!_readAll())
|
||||
return -1;
|
||||
}
|
||||
return _rxbuf->read();
|
||||
int result = _read_ptr[0];
|
||||
++_read_ptr;
|
||||
--_available;
|
||||
if (_available == 0) {
|
||||
_read_ptr = nullptr;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int peek() {
|
||||
if (!_rxbuf->getSize()) {
|
||||
_readAll();
|
||||
if (!_available) {
|
||||
if (!_readAll())
|
||||
return -1;
|
||||
}
|
||||
return _rxbuf->peek();
|
||||
return _read_ptr[0];
|
||||
}
|
||||
|
||||
int available() {
|
||||
auto rc = _rxbuf->getSize();
|
||||
if (rc == 0) {
|
||||
_readAll();
|
||||
rc = _rxbuf->getSize();
|
||||
auto cb = _available;
|
||||
if (cb == 0) {
|
||||
cb = _readAll();
|
||||
} else {
|
||||
optimistic_yield(100);
|
||||
}
|
||||
return rc;
|
||||
return cb;
|
||||
}
|
||||
|
||||
operator SSL*() {
|
||||
@ -133,6 +142,8 @@ protected:
|
||||
if (!_ssl)
|
||||
return 0;
|
||||
|
||||
optimistic_yield(100);
|
||||
|
||||
uint8_t* data;
|
||||
int rc = ssl_read(_ssl, &data);
|
||||
if (rc <= 0) {
|
||||
@ -142,25 +153,18 @@ protected:
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
if (rc > _rxbuf->room()) {
|
||||
DEBUGV("WiFiClientSecure rx overflow");
|
||||
rc = _rxbuf->room();
|
||||
}
|
||||
int result = 0;
|
||||
size_t sizeBefore = _rxbuf->getSize();
|
||||
if (rc)
|
||||
result = _rxbuf->write(reinterpret_cast<const char*>(data), rc);
|
||||
DEBUGV("*** rb: %d + %d = %d\r\n", sizeBefore, rc, _rxbuf->getSize());
|
||||
return result;
|
||||
DEBUGV(":wcs ra %d", rc);
|
||||
_read_ptr = data;
|
||||
_available = rc;
|
||||
return _available;
|
||||
}
|
||||
|
||||
static SSL_CTX* _ssl_ctx;
|
||||
static int _ssl_ctx_refcnt;
|
||||
SSL* _ssl = nullptr;
|
||||
int _refcnt = 0;
|
||||
cbuf* _rxbuf;
|
||||
const uint8_t* _read_ptr = nullptr;
|
||||
size_t _available = 0;
|
||||
};
|
||||
|
||||
SSL_CTX* SSLContext::_ssl_ctx = nullptr;
|
||||
@ -311,14 +315,13 @@ bool WiFiClientSecure::verify(const char* fp, const char* url) {
|
||||
while (pos < len && fp[pos] == ' ') {
|
||||
++pos;
|
||||
}
|
||||
DEBUGV("pos:%d ", pos);
|
||||
if (pos > len - 2) {
|
||||
DEBUGV("fingerprint too short\r\n");
|
||||
DEBUGV("pos:%d len:%d fingerprint too short\r\n", pos, len);
|
||||
return false;
|
||||
}
|
||||
uint8_t high, low;
|
||||
if (!parseHexNibble(fp[pos], &high) || !parseHexNibble(fp[pos+1], &low)) {
|
||||
DEBUGV("invalid hex sequence: %c%c\r\n", fp[pos], fp[pos+1]);
|
||||
DEBUGV("pos:%d len:%d invalid hex sequence: %c%c\r\n", pos, len, fp[pos], fp[pos+1]);
|
||||
return false;
|
||||
}
|
||||
pos += 2;
|
||||
|
@ -38,33 +38,41 @@ extern "C" {
|
||||
#include "cbuf.h"
|
||||
#include "include/ClientContext.h"
|
||||
|
||||
WiFiServer::WiFiServer(uint16_t port)
|
||||
WiFiServer::WiFiServer(IPAddress addr, uint16_t port)
|
||||
: _port(port)
|
||||
, _addr(addr)
|
||||
, _pcb(nullptr)
|
||||
, _unclaimed(nullptr)
|
||||
, _discarded(nullptr)
|
||||
{
|
||||
_port = port;
|
||||
_pcb = 0;
|
||||
_unclaimed = 0;
|
||||
_discarded = 0;
|
||||
}
|
||||
|
||||
void WiFiServer::begin()
|
||||
WiFiServer::WiFiServer(uint16_t port)
|
||||
: _port(port)
|
||||
, _addr((uint32_t) IPADDR_ANY)
|
||||
, _pcb(nullptr)
|
||||
, _unclaimed(nullptr)
|
||||
, _discarded(nullptr)
|
||||
{
|
||||
err_t err;
|
||||
}
|
||||
|
||||
void WiFiServer::begin() {
|
||||
err_t err;
|
||||
tcp_pcb* pcb = tcp_new();
|
||||
if (!pcb)
|
||||
return;
|
||||
|
||||
err = tcp_bind(pcb, INADDR_ANY, _port);
|
||||
ip_addr_t local_addr;
|
||||
local_addr.addr = (uint32_t) _addr;
|
||||
err = tcp_bind(pcb, &local_addr, _port);
|
||||
|
||||
if (err != ERR_OK)
|
||||
{
|
||||
if (err != ERR_OK) {
|
||||
tcp_close(pcb);
|
||||
return;
|
||||
}
|
||||
|
||||
tcp_pcb* listen_pcb = tcp_listen(pcb);
|
||||
if (!listen_pcb)
|
||||
{
|
||||
if (!listen_pcb) {
|
||||
tcp_close(pcb);
|
||||
return;
|
||||
}
|
||||
@ -73,26 +81,30 @@ void WiFiServer::begin()
|
||||
tcp_arg(listen_pcb, (void*) this);
|
||||
}
|
||||
|
||||
void WiFiServer::setNoDelay(bool nodelay){
|
||||
if(!_pcb) return;
|
||||
if(nodelay) tcp_nagle_disable(_pcb);
|
||||
else tcp_nagle_enable(_pcb);
|
||||
void WiFiServer::setNoDelay(bool nodelay) {
|
||||
if (!_pcb)
|
||||
return;
|
||||
|
||||
if (nodelay)
|
||||
tcp_nagle_disable(_pcb);
|
||||
else
|
||||
tcp_nagle_enable(_pcb);
|
||||
}
|
||||
|
||||
bool WiFiServer::getNoDelay(){
|
||||
if(!_pcb) return false;
|
||||
bool WiFiServer::getNoDelay() {
|
||||
if (!_pcb)
|
||||
return false;
|
||||
return tcp_nagle_disabled(_pcb);
|
||||
}
|
||||
|
||||
bool WiFiServer::hasClient(){
|
||||
if (_unclaimed) return true;
|
||||
bool WiFiServer::hasClient() {
|
||||
if (_unclaimed)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
WiFiClient WiFiServer::available(byte* status)
|
||||
{
|
||||
if (_unclaimed)
|
||||
{
|
||||
WiFiClient WiFiServer::available(byte* status) {
|
||||
if (_unclaimed) {
|
||||
WiFiClient result(_unclaimed);
|
||||
_unclaimed = _unclaimed->next();
|
||||
DEBUGV("WS:av\r\n");
|
||||
@ -100,7 +112,6 @@ WiFiClient WiFiServer::available(byte* status)
|
||||
}
|
||||
|
||||
optimistic_yield(1000);
|
||||
|
||||
return WiFiClient();
|
||||
}
|
||||
|
||||
@ -111,21 +122,18 @@ uint8_t WiFiServer::status() {
|
||||
}
|
||||
|
||||
|
||||
size_t WiFiServer::write(uint8_t b)
|
||||
{
|
||||
size_t WiFiServer::write(uint8_t b) {
|
||||
return write(&b, 1);
|
||||
}
|
||||
|
||||
size_t WiFiServer::write(const uint8_t *buffer, size_t size)
|
||||
{
|
||||
size_t WiFiServer::write(const uint8_t *buffer, size_t size) {
|
||||
// write to all clients
|
||||
// not implemented
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T* slist_append_tail(T* head, T* item)
|
||||
{
|
||||
T* slist_append_tail(T* head, T* item) {
|
||||
if (!head)
|
||||
return item;
|
||||
T* last = head;
|
||||
@ -135,29 +143,23 @@ T* slist_append_tail(T* head, T* item)
|
||||
return head;
|
||||
}
|
||||
|
||||
int8_t WiFiServer::_accept(tcp_pcb* apcb, int8_t err)
|
||||
{
|
||||
int8_t WiFiServer::_accept(tcp_pcb* apcb, int8_t err) {
|
||||
DEBUGV("WS:ac\r\n");
|
||||
ClientContext* client = new ClientContext(apcb, &WiFiServer::_s_discard, this);
|
||||
_unclaimed = slist_append_tail(_unclaimed, client);
|
||||
tcp_accepted(_pcb);
|
||||
// printf("WiFiServer::_accept\r\n");
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
void WiFiServer::_discard(ClientContext* client)
|
||||
{
|
||||
void WiFiServer::_discard(ClientContext* client) {
|
||||
// _discarded = slist_append_tail(_discarded, client);
|
||||
DEBUGV("WS:dis\r\n");
|
||||
// printf("WiFiServer::_discard\r\n");
|
||||
}
|
||||
|
||||
int8_t WiFiServer::_s_accept(void *arg, tcp_pcb* newpcb, int8_t err)
|
||||
{
|
||||
int8_t WiFiServer::_s_accept(void *arg, tcp_pcb* newpcb, int8_t err) {
|
||||
return reinterpret_cast<WiFiServer*>(arg)->_accept(newpcb, err);
|
||||
}
|
||||
|
||||
void WiFiServer::_s_discard(void* server, ClientContext* ctx)
|
||||
{
|
||||
void WiFiServer::_s_discard(void* server, ClientContext* ctx) {
|
||||
reinterpret_cast<WiFiServer*>(server)->_discard(ctx);
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ extern "C" {
|
||||
}
|
||||
|
||||
#include "Server.h"
|
||||
#include "IPAddress.h"
|
||||
|
||||
class ClientContext;
|
||||
class WiFiClient;
|
||||
@ -36,12 +37,14 @@ class WiFiClient;
|
||||
class WiFiServer : public Server {
|
||||
private:
|
||||
uint16_t _port;
|
||||
IPAddress _addr;
|
||||
tcp_pcb* _pcb;
|
||||
|
||||
ClientContext* _unclaimed;
|
||||
ClientContext* _discarded;
|
||||
|
||||
public:
|
||||
WiFiServer(IPAddress addr, uint16_t port);
|
||||
WiFiServer(uint16_t port);
|
||||
WiFiClient available(uint8_t* status = NULL);
|
||||
bool hasClient();
|
||||
|
@ -34,17 +34,19 @@ 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_FAILED;
|
||||
WiFiClient tcp;
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] connected to %s:%u %s .... ", host, port, url);
|
||||
|
||||
if(!tcp.connect(host, port)) {
|
||||
DEBUG_HTTP_UPDATE("failed.\n");
|
||||
return ret;
|
||||
return HTTP_UPDATE_FAILED;
|
||||
}
|
||||
DEBUG_HTTP_UPDATE("ok.\n");
|
||||
return update(tcp, host, url, current_version);
|
||||
}
|
||||
|
||||
t_httpUpdate_return ESP8266HTTPUpdate::update(WiFiClient& tcp, const char* host, const char* url, const char * current_version) {
|
||||
t_httpUpdate_return ret = HTTP_UPDATE_FAILED;
|
||||
// set Timeout for readBytesUntil and readStringUntil
|
||||
tcp.setTimeout(2000);
|
||||
tcp.setNoDelay(true);
|
||||
|
@ -50,6 +50,7 @@ class ESP8266HTTPUpdate {
|
||||
|
||||
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 = "");
|
||||
t_httpUpdate_return update(WiFiClient& client, const char* host, const char* url = "/", const char * current_version = "");
|
||||
};
|
||||
|
||||
extern ESP8266HTTPUpdate ESPhttpUpdate;
|
||||
|
9
libraries/esp8266/library.properties
Normal file
9
libraries/esp8266/library.properties
Normal file
@ -0,0 +1,9 @@
|
||||
name=ESP8266
|
||||
version=1.0
|
||||
author=Simon Peter,Markus Sattler,Ivan Grokhotkov
|
||||
maintainer=Ivan Grokhtkov <ivan@esp8266.com>
|
||||
sentence=ESP8266 sketches examples
|
||||
paragraph=
|
||||
category=Other
|
||||
url=
|
||||
architectures=esp8266
|
2
libraries/esp8266/src/dummy.h
Normal file
2
libraries/esp8266/src/dummy.h
Normal file
@ -0,0 +1,2 @@
|
||||
// This file is here only to silence warnings from Arduino IDE
|
||||
// Currently IDE doesn't support no-code libraries, like this collection of example sketches.
|
@ -1,6 +1,12 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
|
||||
# Figure out how will the package be called
|
||||
ver=`git describe --tags --always`
|
||||
package_name=esp8266-$ver
|
||||
echo "Version: $ver"
|
||||
echo "Package name: $package_name"
|
||||
|
||||
# Set REMOTE_URL environment variable to the address where the package will be
|
||||
# available for download. This gets written into package json file.
|
||||
if [ -z "$REMOTE_URL" ]; then
|
||||
@ -8,13 +14,17 @@ if [ -z "$REMOTE_URL" ]; then
|
||||
echo "REMOTE_URL not defined, using default"
|
||||
fi
|
||||
echo "Remote: $REMOTE_URL"
|
||||
pushd ..
|
||||
# Figure out how will the package be called
|
||||
ver=`git describe --tags --always`
|
||||
package_name=esp8266-$ver
|
||||
echo "Version: $ver"
|
||||
echo "Package name: $package_name"
|
||||
|
||||
if [ -z "$PKG_URL" ]; then
|
||||
PKG_URL="$REMOTE_URL/versions/$ver/$package_name.zip"
|
||||
fi
|
||||
echo "Package: $PKG_URL"
|
||||
|
||||
if [ -z "$DOC_URL" ]; then
|
||||
DOC_URL="$REMOTE_URL/versions/$ver/doc/reference.html"
|
||||
fi
|
||||
echo "Docs: $DOC_URL"
|
||||
pushd ..
|
||||
# Create directory for the package
|
||||
outdir=package/versions/$ver/$package_name
|
||||
srcdir=$PWD
|
||||
@ -72,11 +82,11 @@ echo SHA-256: $sha
|
||||
echo "Making package_esp8266com_index.json"
|
||||
cat $srcdir/package/package_esp8266com_index.template.json | \
|
||||
jq ".packages[0].platforms[0].version = \"$ver\" | \
|
||||
.packages[0].platforms[0].url = \"$REMOTE_URL/versions/$ver/$package_name.zip\" |\
|
||||
.packages[0].platforms[0].url = \"$PKG_URL\" |\
|
||||
.packages[0].platforms[0].archiveFileName = \"$package_name.zip\" |\
|
||||
.packages[0].platforms[0].checksum = \"SHA-256:$sha\" |\
|
||||
.packages[0].platforms[0].size = \"$size\" |\
|
||||
.packages[0].platforms[0].help.online = \"$REMOTE_URL/versions/$ver/doc/reference.html\"" \
|
||||
.packages[0].platforms[0].help.online = \"$DOC_URL\"" \
|
||||
> package_esp8266com_index.json
|
||||
|
||||
popd
|
||||
|
60
package/merge_packages.py
Executable file
60
package/merge_packages.py
Executable file
@ -0,0 +1,60 @@
|
||||
#!/usr/bin/env python
|
||||
# This script merges two Arduino Board Manager package json files.
|
||||
# Usage:
|
||||
# python merge_packages.py package_esp8266com_index.json version/new/package_esp8266com_index.json
|
||||
# Written by Ivan Grokhotkov, 2015
|
||||
#
|
||||
from __future__ import print_function
|
||||
import json
|
||||
import sys
|
||||
|
||||
def load_package(filename):
|
||||
pkg = json.load(open(filename))['packages'][0]
|
||||
print("Loaded package {0} from {1}".format(pkg['name'], filename), file=sys.stderr)
|
||||
print("{0} platform(s), {1} tools".format(len(pkg['platforms']), len(pkg['tools'])), file=sys.stderr)
|
||||
return pkg
|
||||
|
||||
def merge_objects(versions, obj):
|
||||
for o in obj:
|
||||
name = o['name'].encode('ascii')
|
||||
ver = o['version'].encode('ascii')
|
||||
if not name in versions:
|
||||
print("found new object, {0}".format(name), file=sys.stderr)
|
||||
versions[name] = {}
|
||||
if not ver in versions[name]:
|
||||
print("found new version {0} for object {1}".format(ver, name), file=sys.stderr)
|
||||
versions[name][ver] = o
|
||||
return versions
|
||||
|
||||
|
||||
def main(args):
|
||||
if len(args) < 3:
|
||||
print("Usage: {0} <package1> <package2>".format(args[0]), file=sys.stderr)
|
||||
return 1
|
||||
|
||||
tools = {}
|
||||
platforms = {}
|
||||
pkg1 = load_package(args[1])
|
||||
tools = merge_objects(tools, pkg1['tools']);
|
||||
platforms = merge_objects(platforms, pkg1['platforms']);
|
||||
pkg2 = load_package(args[2])
|
||||
tools = merge_objects(tools, pkg2['tools']);
|
||||
platforms = merge_objects(platforms, pkg2['platforms']);
|
||||
|
||||
pkg1['tools'] = []
|
||||
pkg1['platforms'] = []
|
||||
|
||||
for name in tools:
|
||||
for version in tools[name]:
|
||||
print("Adding tool {0}-{1}".format(name, version), file=sys.stderr)
|
||||
pkg1['tools'].append(tools[name][version])
|
||||
|
||||
for name in platforms:
|
||||
for version in platforms[name]:
|
||||
print("Adding platform {0}-{1}".format(name, version), file=sys.stderr)
|
||||
pkg1['platforms'].append(platforms[name][version])
|
||||
|
||||
json.dump({'packages':[pkg1]}, sys.stdout, indent=2)
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main(sys.argv))
|
@ -42,6 +42,12 @@
|
||||
},
|
||||
{
|
||||
"name": "SweetPea ESP-210"
|
||||
},
|
||||
{
|
||||
"name": "WeMos D1"
|
||||
},
|
||||
{
|
||||
"name": "WeMos D1 mini"
|
||||
}
|
||||
],
|
||||
"toolsDependencies": [
|
||||
|
@ -64,10 +64,10 @@ recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpreprocessor
|
||||
recipe.S.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.cpreprocessor.flags} {compiler.S.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"
|
||||
|
||||
## Create archives
|
||||
recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{build.path}/core.a" "{object_file}"
|
||||
recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{build.path}/arduino.ar" "{object_file}"
|
||||
|
||||
## Combine gc-sections, archives, and objects
|
||||
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" -Wl,--start-group {object_files} "{build.path}/core.a" {compiler.c.elf.libs} -Wl,--end-group "-L{build.path}"
|
||||
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" -Wl,--start-group {object_files} "{build.path}/arduino.ar" {compiler.c.elf.libs} -Wl,--end-group "-L{build.path}"
|
||||
|
||||
## Create eeprom
|
||||
recipe.objcopy.eep.pattern=
|
||||
|
@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python
|
||||
# This script will download and extract required tools into the current directory
|
||||
# Tools list is obtained from tools.json file
|
||||
# Written by Ivan Grokhotkov, 2015
|
||||
# This script will download and extract required tools into the current directory.
|
||||
# Tools list is obtained from package/package_esp8266com_index.template.json file.
|
||||
# Written by Ivan Grokhotkov, 2015.
|
||||
#
|
||||
from __future__ import print_function
|
||||
import urllib
|
||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user