From 4568d9e42a28ffef200869eca0968ca9622d6a16 Mon Sep 17 00:00:00 2001 From: wemos <11569115@qq.com> Date: Sun, 8 Nov 2015 13:31:18 +0800 Subject: [PATCH 1/3] add wemos D1 & D1 mini boards --- boards.txt | 109 ++++++++++++++++++++++++++++++++ variants/d1/pins_arduino.h | 86 +++++++++++++++++++++++++ variants/d1_mini/pins_arduino.h | 83 ++++++++++++++++++++++++ 3 files changed, 278 insertions(+) create mode 100644 variants/d1/pins_arduino.h create mode 100644 variants/d1_mini/pins_arduino.h diff --git a/boards.txt b/boards.txt index d5ca569be..7ab4fd9cb 100644 --- a/boards.txt +++ b/boards.txt @@ -542,3 +542,112 @@ esp210.menu.FlashSize.4M1M.build.spiffs_pagesize=256 # # wifio.upload.tool=esptool # + +############################################################## +d1.name=WeMos D1 + +d1.upload.tool=esptool +d1.upload.speed=460800 +d1.upload.resetmethod=ck +d1.upload.maximum_size=1044464 +d1.upload.maximum_data_size=81920 +d1.upload.wait_for_upload_port=true +d1.serial.disableDTR=true +d1.serial.disableRTS=true + +d1.build.mcu=esp8266 +d1.build.f_cpu=80000000L +d1.build.board=ESP8266_ESP12 +d1.build.core=esp8266 +d1.build.variant=d1 +d1.build.flash_mode=dio +d1.build.flash_size=4M +d1.build.flash_freq=40 +d1.build.flash_ld=eagle.flash.4m.ld +d1.build.spiffs_start=0x100000 +d1.build.spiffs_end=0x3FB000 +d1.build.spiffs_pagesize=256 +d1.build.spiffs_blocksize=8192 + +d1.menu.UploadTool.esptool=Serial +d1.menu.UploadTool.esptool.upload.tool=esptool +d1.menu.UploadTool.espota=OTA +d1.menu.UploadTool.espota.upload.tool=espota + +d1.menu.CpuFrequency.80=80 MHz +d1.menu.CpuFrequency.80.build.f_cpu=80000000L +d1.menu.CpuFrequency.160=160 MHz +d1.menu.CpuFrequency.160.build.f_cpu=160000000L + +d1.menu.UploadSpeed.460800=460800 +d1.menu.UploadSpeed.460800.upload.speed=460800 +d1.menu.UploadSpeed.115200=115200 +d1.menu.UploadSpeed.115200.upload.speed=115200 +d1.menu.UploadSpeed.9600=9600 +d1.menu.UploadSpeed.9600.upload.speed=9600 +d1.menu.UploadSpeed.57600=57600 +d1.menu.UploadSpeed.57600.upload.speed=57600 +d1.menu.UploadSpeed.256000.windows=256000 +d1.menu.UploadSpeed.256000.upload.speed=256000 +d1.menu.UploadSpeed.230400.linux=230400 +d1.menu.UploadSpeed.230400.macosx=230400 +d1.menu.UploadSpeed.230400.macosx=230400 +d1.menu.UploadSpeed.230400.upload.speed=230400 +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 +############################################################## +d1mini.name=WeMos D1 mini + +d1mini.upload.tool=esptool +d1mini.upload.speed=460800 +d1mini.upload.resetmethod=ck +d1mini.upload.maximum_size=1044464 +d1mini.upload.maximum_data_size=81920 +d1mini.upload.wait_for_upload_port=true +d1mini.serial.disableDTR=true +d1mini.serial.disableRTS=true + +d1mini.build.mcu=esp8266 +d1mini.build.f_cpu=80000000L +d1mini.build.board=ESP8266_ESP12 +d1mini.build.core=esp8266 +d1mini.build.variant=d1_mini +d1mini.build.flash_mode=dio +d1mini.build.flash_size=4M +d1mini.build.flash_freq=40 +d1mini.build.flash_ld=eagle.flash.4m.ld +d1mini.build.spiffs_start=0x100000 +d1mini.build.spiffs_end=0x3FB000 +d1mini.build.spiffs_pagesize=256 +d1mini.build.spiffs_blocksize=8192 + +d1mini.menu.UploadTool.esptool=Serial +d1mini.menu.UploadTool.esptool.upload.tool=esptool +d1mini.menu.UploadTool.espota=OTA +d1mini.menu.UploadTool.espota.upload.tool=espota + +d1mini.menu.CpuFrequency.80=80 MHz +d1mini.menu.CpuFrequency.80.build.f_cpu=80000000L +d1mini.menu.CpuFrequency.160=160 MHz +d1mini.menu.CpuFrequency.160.build.f_cpu=160000000L + +d1mini.menu.UploadSpeed.460800=460800 +d1mini.menu.UploadSpeed.460800.upload.speed=460800 +d1mini.menu.UploadSpeed.115200=115200 +d1mini.menu.UploadSpeed.115200.upload.speed=115200 +d1mini.menu.UploadSpeed.9600=9600 +d1mini.menu.UploadSpeed.9600.upload.speed=9600 +d1mini.menu.UploadSpeed.57600=57600 +d1mini.menu.UploadSpeed.57600.upload.speed=57600 +d1mini.menu.UploadSpeed.256000.windows=256000 +d1mini.menu.UploadSpeed.256000.upload.speed=256000 +d1mini.menu.UploadSpeed.230400.linux=230400 +d1mini.menu.UploadSpeed.230400.macosx=230400 +d1mini.menu.UploadSpeed.230400.macosx=230400 +d1mini.menu.UploadSpeed.230400.upload.speed=230400 +d1mini.menu.UploadSpeed.512000.windows=512000 +d1mini.menu.UploadSpeed.512000.upload.speed=512000 +d1mini.menu.UploadSpeed.921600=921600 +d1mini.menu.UploadSpeed.921600.upload.speed=921600 diff --git a/variants/d1/pins_arduino.h b/variants/d1/pins_arduino.h new file mode 100644 index 000000000..ddab599ba --- /dev/null +++ b/variants/d1/pins_arduino.h @@ -0,0 +1,86 @@ +/* + pins_arduino.h - Pin definition functions for Arduino + Part of Arduino - http://www.arduino.cc/ + + Copyright (c) 2007 David A. Mellis + Modified for ESP8266 platform by Ivan Grokhotkov, 2014-2015. + + 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., 59 Temple Place, Suite 330, + Boston, MA 02111-1307 USA + + $Id: wiring.h 249 2007-02-03 16:52:51Z mellis $ +*/ + +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#define EXTERNAL_NUM_INTERRUPTS 16 +#define NUM_DIGITAL_PINS 17 +#define NUM_ANALOG_INPUTS 1 + +#define analogInputToDigitalPin(p) ((p > 0)?NOT_A_PIN:0) +#define digitalPinToInterrupt(p) (((p) < EXTERNAL_NUM_INTERRUPTS)?p:NOT_A_PIN) +#define digitalPinHasPWM(p) (((p) < NUM_DIGITAL_PINS)?p:NOT_A_PIN) + +static const uint8_t SDA = 4; +static const uint8_t SCL = 5; + +static const uint8_t SS = 15; +static const uint8_t MOSI = 13; +static const uint8_t MISO = 12; +static const uint8_t SCK = 14; + +static const uint8_t BUILTIN_LED = 2;//new ESP-12E GPIO2 + +static const uint8_t A0 = 17; + +static const uint8_t D0 = 3; +static const uint8_t D1 = 1; +static const uint8_t D2 = 16; +static const uint8_t D3 = 5; +static const uint8_t D4 = 4; +static const uint8_t D5 = 14; +static const uint8_t D6 = 12; +static const uint8_t D7 = 13; +static const uint8_t D8 = 0; +static const uint8_t D9 = 2; +static const uint8_t D10 = 15; +static const uint8_t D11 = 13; +static const uint8_t D12 = 12; +static const uint8_t D13 = 14; +static const uint8_t D14 = 4; +static const uint8_t D15 = 5; + +// These serial port names are intended to allow libraries and architecture-neutral +// sketches to automatically default to the correct port name for a particular type +// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN, +// the first hardware serial port whose RX/TX pins are not dedicated to another use. +// +// SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor +// +// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial +// +// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library +// +// SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins. +// +// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX +// pins are NOT connected to anything by default. +#define SERIAL_PORT_MONITOR Serial +#define SERIAL_PORT_USBVIRTUAL Serial +#define SERIAL_PORT_HARDWARE Serial +#define SERIAL_PORT_HARDWARE_OPEN Serial + +#endif /* Pins_Arduino_h */ diff --git a/variants/d1_mini/pins_arduino.h b/variants/d1_mini/pins_arduino.h new file mode 100644 index 000000000..160b9a442 --- /dev/null +++ b/variants/d1_mini/pins_arduino.h @@ -0,0 +1,83 @@ +/* + pins_arduino.h - Pin definition functions for Arduino + Part of Arduino - http://www.arduino.cc/ + + Copyright (c) 2007 David A. Mellis + Modified for ESP8266 platform by Ivan Grokhotkov, 2014-2015. + + 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., 59 Temple Place, Suite 330, + Boston, MA 02111-1307 USA + + $Id: wiring.h 249 2007-02-03 16:52:51Z mellis $ +*/ + +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#define EXTERNAL_NUM_INTERRUPTS 16 +#define NUM_DIGITAL_PINS 17 +#define NUM_ANALOG_INPUTS 1 + +#define analogInputToDigitalPin(p) ((p > 0)?NOT_A_PIN:0) +#define digitalPinToInterrupt(p) (((p) < EXTERNAL_NUM_INTERRUPTS)?p:NOT_A_PIN) +#define digitalPinHasPWM(p) (((p) < NUM_DIGITAL_PINS)?p:NOT_A_PIN) + +static const uint8_t SDA = 4; +static const uint8_t SCL = 5; + +static const uint8_t SS = 15; +static const uint8_t MOSI = 13; +static const uint8_t MISO = 12; +static const uint8_t SCK = 14; + +static const uint8_t BUILTIN_LED = 2; + +static const uint8_t A0 = 17; + +static const uint8_t D0 = 16; +static const uint8_t D1 = 5; +static const uint8_t D2 = 4; +static const uint8_t D3 = 0; +static const uint8_t D4 = 2; +static const uint8_t D5 = 14; +static const uint8_t D6 = 12; +static const uint8_t D7 = 13; +static const uint8_t D8 = 15; +static const uint8_t D9 = 3; +static const uint8_t D10 = 1; + +static const uint8_t D13 = 2; + +// These serial port names are intended to allow libraries and architecture-neutral +// sketches to automatically default to the correct port name for a particular type +// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN, +// the first hardware serial port whose RX/TX pins are not dedicated to another use. +// +// SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor +// +// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial +// +// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library +// +// SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins. +// +// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX +// pins are NOT connected to anything by default. +#define SERIAL_PORT_MONITOR Serial +#define SERIAL_PORT_USBVIRTUAL Serial +#define SERIAL_PORT_HARDWARE Serial +#define SERIAL_PORT_HARDWARE_OPEN Serial + +#endif /* Pins_Arduino_h */ From 3243b4ba0e6e52612b52f72ca5d327e552e00856 Mon Sep 17 00:00:00 2001 From: wemos <11569115@qq.com> Date: Mon, 9 Nov 2015 12:26:23 +0800 Subject: [PATCH 2/3] add wemos d1 boards.txt --- boards.txt | 152 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 91 insertions(+), 61 deletions(-) diff --git a/boards.txt b/boards.txt index 7ab4fd9cb..939f61ef6 100644 --- a/boards.txt +++ b/boards.txt @@ -548,7 +548,7 @@ d1.name=WeMos D1 d1.upload.tool=esptool d1.upload.speed=460800 -d1.upload.resetmethod=ck +d1.upload.resetmethod=nodemcu d1.upload.maximum_size=1044464 d1.upload.maximum_data_size=81920 d1.upload.wait_for_upload_port=true @@ -563,24 +563,19 @@ d1.build.variant=d1 d1.build.flash_mode=dio d1.build.flash_size=4M d1.build.flash_freq=40 -d1.build.flash_ld=eagle.flash.4m.ld -d1.build.spiffs_start=0x100000 -d1.build.spiffs_end=0x3FB000 -d1.build.spiffs_pagesize=256 -d1.build.spiffs_blocksize=8192 - -d1.menu.UploadTool.esptool=Serial -d1.menu.UploadTool.esptool.upload.tool=esptool -d1.menu.UploadTool.espota=OTA -d1.menu.UploadTool.espota.upload.tool=espota d1.menu.CpuFrequency.80=80 MHz d1.menu.CpuFrequency.80.build.f_cpu=80000000L d1.menu.CpuFrequency.160=160 MHz d1.menu.CpuFrequency.160.build.f_cpu=160000000L -d1.menu.UploadSpeed.460800=460800 -d1.menu.UploadSpeed.460800.upload.speed=460800 +d1.menu.UploadTool.esptool=Serial +d1.menu.UploadTool.esptool.upload.tool=esptool +d1.menu.UploadTool.esptool.upload.verbose=-vv + +d1.menu.UploadTool.espota=OTA +d1.menu.UploadTool.espota.upload.tool=espota + d1.menu.UploadSpeed.115200=115200 d1.menu.UploadSpeed.115200.upload.speed=115200 d1.menu.UploadSpeed.9600=9600 @@ -593,61 +588,96 @@ d1.menu.UploadSpeed.230400.linux=230400 d1.menu.UploadSpeed.230400.macosx=230400 d1.menu.UploadSpeed.230400.macosx=230400 d1.menu.UploadSpeed.230400.upload.speed=230400 +d1.menu.UploadSpeed.460800.linux=460800 +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 +d1.menu.FlashSize.4M3M.build.flash_ld=eagle.flash.4m.ld +d1.menu.FlashSize.4M3M.build.spiffs_start=0x100000 +d1.menu.FlashSize.4M3M.build.spiffs_end=0x3FB000 +d1.menu.FlashSize.4M3M.build.spiffs_blocksize=8192 +d1.menu.FlashSize.4M3M.build.spiffs_pagesize=256 + +d1.menu.FlashSize.4M1M=4M (1M SPIFFS) +d1.menu.FlashSize.4M1M.build.flash_size=4M +d1.menu.FlashSize.4M1M.build.flash_ld=eagle.flash.4m1m.ld +d1.menu.FlashSize.4M1M.build.spiffs_start=0x300000 +d1.menu.FlashSize.4M1M.build.spiffs_end=0x3FB000 +d1.menu.FlashSize.4M1M.build.spiffs_blocksize=8192 +d1.menu.FlashSize.4M1M.build.spiffs_pagesize=256 + + ############################################################## -d1mini.name=WeMos D1 mini +d1_mini.name=WeMos D1 mini -d1mini.upload.tool=esptool -d1mini.upload.speed=460800 -d1mini.upload.resetmethod=ck -d1mini.upload.maximum_size=1044464 -d1mini.upload.maximum_data_size=81920 -d1mini.upload.wait_for_upload_port=true -d1mini.serial.disableDTR=true -d1mini.serial.disableRTS=true +d1_mini.upload.tool=esptool +d1_mini.upload.speed=460800 +d1_mini.upload.resetmethod=nodemcu +d1_mini.upload.maximum_size=1044464 +d1_mini.upload.maximum_data_size=81920 +d1_mini.upload.wait_for_upload_port=true +d1_mini.serial.disableDTR=true +d1_mini.serial.disableRTS=true -d1mini.build.mcu=esp8266 -d1mini.build.f_cpu=80000000L -d1mini.build.board=ESP8266_ESP12 -d1mini.build.core=esp8266 -d1mini.build.variant=d1_mini -d1mini.build.flash_mode=dio -d1mini.build.flash_size=4M -d1mini.build.flash_freq=40 -d1mini.build.flash_ld=eagle.flash.4m.ld -d1mini.build.spiffs_start=0x100000 -d1mini.build.spiffs_end=0x3FB000 -d1mini.build.spiffs_pagesize=256 -d1mini.build.spiffs_blocksize=8192 +d1_mini.build.mcu=esp8266 +d1_mini.build.f_cpu=80000000L +d1_mini.build.board=ESP8266_ESP12 +d1_mini.build.core=esp8266 +d1_mini.build.variant=d1_mini +d1_mini.build.flash_mode=dio +d1_mini.build.flash_size=4M +d1_mini.build.flash_freq=40 -d1mini.menu.UploadTool.esptool=Serial -d1mini.menu.UploadTool.esptool.upload.tool=esptool -d1mini.menu.UploadTool.espota=OTA -d1mini.menu.UploadTool.espota.upload.tool=espota +d1_mini.menu.CpuFrequency.80=80 MHz +d1_mini.menu.CpuFrequency.80.build.f_cpu=80000000L +d1_mini.menu.CpuFrequency.160=160 MHz +d1_mini.menu.CpuFrequency.160.build.f_cpu=160000000L -d1mini.menu.CpuFrequency.80=80 MHz -d1mini.menu.CpuFrequency.80.build.f_cpu=80000000L -d1mini.menu.CpuFrequency.160=160 MHz -d1mini.menu.CpuFrequency.160.build.f_cpu=160000000L +d1_mini.menu.UploadTool.esptool=Serial +d1_mini.menu.UploadTool.esptool.upload.tool=esptool +d1_mini.menu.UploadTool.esptool.upload.verbose=-vv -d1mini.menu.UploadSpeed.460800=460800 -d1mini.menu.UploadSpeed.460800.upload.speed=460800 -d1mini.menu.UploadSpeed.115200=115200 -d1mini.menu.UploadSpeed.115200.upload.speed=115200 -d1mini.menu.UploadSpeed.9600=9600 -d1mini.menu.UploadSpeed.9600.upload.speed=9600 -d1mini.menu.UploadSpeed.57600=57600 -d1mini.menu.UploadSpeed.57600.upload.speed=57600 -d1mini.menu.UploadSpeed.256000.windows=256000 -d1mini.menu.UploadSpeed.256000.upload.speed=256000 -d1mini.menu.UploadSpeed.230400.linux=230400 -d1mini.menu.UploadSpeed.230400.macosx=230400 -d1mini.menu.UploadSpeed.230400.macosx=230400 -d1mini.menu.UploadSpeed.230400.upload.speed=230400 -d1mini.menu.UploadSpeed.512000.windows=512000 -d1mini.menu.UploadSpeed.512000.upload.speed=512000 -d1mini.menu.UploadSpeed.921600=921600 -d1mini.menu.UploadSpeed.921600.upload.speed=921600 +d1_mini.menu.UploadTool.espota=OTA +d1_mini.menu.UploadTool.espota.upload.tool=espota + +d1_mini.menu.UploadSpeed.115200=115200 +d1_mini.menu.UploadSpeed.115200.upload.speed=115200 +d1_mini.menu.UploadSpeed.9600=9600 +d1_mini.menu.UploadSpeed.9600.upload.speed=9600 +d1_mini.menu.UploadSpeed.57600=57600 +d1_mini.menu.UploadSpeed.57600.upload.speed=57600 +d1_mini.menu.UploadSpeed.256000.windows=256000 +d1_mini.menu.UploadSpeed.256000.upload.speed=256000 +d1_mini.menu.UploadSpeed.230400.linux=230400 +d1_mini.menu.UploadSpeed.230400.macosx=230400 +d1_mini.menu.UploadSpeed.230400.macosx=230400 +d1_mini.menu.UploadSpeed.230400.upload.speed=230400 +d1_mini.menu.UploadSpeed.460800.linux=460800 +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 +d1_mini.menu.FlashSize.4M3M.build.flash_ld=eagle.flash.4m.ld +d1_mini.menu.FlashSize.4M3M.build.spiffs_start=0x100000 +d1_mini.menu.FlashSize.4M3M.build.spiffs_end=0x3FB000 +d1_mini.menu.FlashSize.4M3M.build.spiffs_blocksize=8192 +d1_mini.menu.FlashSize.4M3M.build.spiffs_pagesize=256 + +d1_mini.menu.FlashSize.4M1M=4M (1M SPIFFS) +d1_mini.menu.FlashSize.4M1M.build.flash_size=4M +d1_mini.menu.FlashSize.4M1M.build.flash_ld=eagle.flash.4m1m.ld +d1_mini.menu.FlashSize.4M1M.build.spiffs_start=0x300000 +d1_mini.menu.FlashSize.4M1M.build.spiffs_end=0x3FB000 +d1_mini.menu.FlashSize.4M1M.build.spiffs_blocksize=8192 +d1_mini.menu.FlashSize.4M1M.build.spiffs_pagesize=256 From d1a0c53805b148759e4247215cf709fd7a60901d Mon Sep 17 00:00:00 2001 From: wemos <11569115@qq.com> Date: Mon, 9 Nov 2015 13:09:30 +0800 Subject: [PATCH 3/3] Squashed commit of the following: commit 810ab68ae5ad89d24a57ed8d18c8ff6acbb54349 Author: Ivan Grokhotkov Date: Mon Nov 9 01:37:22 2015 +0300 Fix WiFiClientSecure::connected (#43) thanks @whyameye commit 7384c3814b780e747940d9735fe08825a26f746c Merge: 46468d4 464d891 Author: Markus Date: Sun Nov 8 23:04:52 2015 +0100 Merge pull request #985 from Links2004/docu add missing exit in php sample commit 464d891877a3fb153844a0110ca865861815b063 Author: Markus Sattler Date: Sun Nov 8 22:48:48 2015 +0100 add missing exit in php sample commit 46468d4af7ace336c31029372368154ce3000b59 Author: Ivan Grokhotkov Date: Mon Nov 9 00:18:08 2015 +0300 I2C: generate STOP in case of NACK (fix #698, #254) thanks @petrd and @Yazzcat commit 4cf72e7ef4fcabde230de44ba1d1ab5d57cdeee0 Author: Ivan Grokhotkov Date: Sun Nov 8 23:44:25 2015 +0300 Add libc time functions Merging https://github.com/igrr/axtls-8266/pull/1 by @Juppit into the core commit 11340a5d7643bef60d9cf61ef27a72186ed4f44c Author: Ivan Grokhotkov Date: Sun Nov 8 15:01:17 2015 +0300 Fix some typos --- cores/esp8266/Arduino.h | 4 +- cores/esp8266/core_esp8266_si2c.c | 17 ++- cores/esp8266/libc_replacements.c | 18 --- cores/esp8266/time.c | 128 ++++++++++++++++++ doc/ota_updates.md | 65 ++++----- .../ESP8266WiFi/src/WiFiClientSecure.cpp | 3 + tests/Time/Time.ino | 35 +++++ 7 files changed, 211 insertions(+), 59 deletions(-) create mode 100644 cores/esp8266/time.c create mode 100644 tests/Time/Time.ino diff --git a/cores/esp8266/Arduino.h b/cores/esp8266/Arduino.h index 8f440f27b..6a7736634 100644 --- a/cores/esp8266/Arduino.h +++ b/cores/esp8266/Arduino.h @@ -153,7 +153,7 @@ void ets_intr_unlock(); // level (0-15), interrupts of the given level and above will be active // level 15 will disable ALL interrupts, // level 0 will enable ALL interrupts, -// +// #define xt_rsil(level) (__extension__({uint32_t state; __asm__ __volatile__("rsil %0," __STRINGIFY(level) : "=a" (state)); state;})) #define xt_wsr_ps(state) __asm__ __volatile__("wsr %0,ps; isync" :: "a" (state) : "memory") @@ -271,6 +271,8 @@ long random(long, long); void randomSeed(unsigned long); long map(long, long, long, long, long); +extern "C" void configTime(int timezone, int daylightOffset_sec, + const char* server1, const char* server2 = nullptr, const char* server3 = nullptr); #endif diff --git a/cores/esp8266/core_esp8266_si2c.c b/cores/esp8266/core_esp8266_si2c.c index 1db11bb87..4008c5c8f 100644 --- a/cores/esp8266/core_esp8266_si2c.c +++ b/cores/esp8266/core_esp8266_si2c.c @@ -150,9 +150,15 @@ static unsigned char twi_read_byte(bool nack) { unsigned char twi_writeTo(unsigned char address, unsigned char * buf, unsigned int len, unsigned char sendStop){ unsigned int i; if(!twi_write_start()) return 4;//line busy - if(!twi_write_byte(((address << 1) | 0) & 0xFF)) return 2;//received NACK on transmit of address - for(i=0; i +#include "sntp.h" + + +#ifndef _TIMEVAL_DEFINED +#define _TIMEVAL_DEFINED +struct timeval { + time_t tv_sec; + suseconds_t tv_usec; +}; +#endif + +extern char* sntp_asctime(const struct tm *t); +extern struct tm* sntp_localtime(const time_t *clock); + +// time gap in seconds from 01.01.1900 (NTP time) to 01.01.1970 (UNIX time) +#define DIFF1900TO1970 2208988800UL + +static int s_daylightOffset_sec = 0; +static int s_timezone_sec = 0; +static time_t s_bootTime = 0; + +// calculate offset used in gettimeofday +static void ensureBootTimeIsSet() +{ + if (!s_bootTime) + { + time_t now = sntp_get_current_timestamp(); + if (now) + { + s_bootTime = - millis() / 1000; + } + } +} + +static void setServer(int id, const char* name_or_ip) +{ + if (name_or_ip) + { + //TODO: check whether server is given by name or IP + sntp_setservername(0, (char*) name_or_ip); + } +} + +void configTime(int timezone, int daylightOffset_sec, const char* server1, const char* server2, const char* server3) +{ + sntp_stop(); + + setServer(0, server1); + setServer(1, server2); + setServer(2, server3); + + s_timezone_sec = timezone; + s_daylightOffset_sec = daylightOffset_sec; + sntp_set_timezone(timezone/3600); + sntp_init(); +} + +int clock_gettime(clockid_t unused, struct timespec *tp) +{ + tp->tv_sec = millis() / 1000; + tp->tv_nsec = micros() * 1000; + return 0; +} + +// seconds since 1970 +time_t mktime(struct tm *t) +{ + // system_mktime expects month in range 1..12 + #define START_MONTH 1 + return DIFF1900TO1970 + system_mktime(t->tm_year, t->tm_mon + START_MONTH, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec); +} + +time_t time(time_t * t) +{ + time_t seconds = sntp_get_current_timestamp(); + ensureBootTimeIsSet(); + if (t) + { + *t = seconds; + } + return seconds; +} + +char* asctime(const struct tm *t) +{ + return sntp_asctime(t); +} + +struct tm* localtime(const time_t *clock) +{ + return sntp_localtime(clock); +} + +char* ctime(const time_t *t) +{ + struct tm* p_tm = localtime(t); + char* result = asctime(p_tm); + return result; +} + +int gettimeofday(struct timeval *tp, void *tzp) +{ + if (tp) + { + ensureBootTimeIsSet(); + tp->tv_sec = (s_bootTime + millis()) / 1000; + tp->tv_usec = micros() * 1000; + } +} diff --git a/doc/ota_updates.md b/doc/ota_updates.md index d607c4e11..f6821391f 100644 --- a/doc/ota_updates.md +++ b/doc/ota_updates.md @@ -7,47 +7,45 @@ title: OTA Update * [Arduino IDE](#arduino-ide) * [HTTP Server](#http-server) * [Stream Interface](#stream-interface) - + ## Basic Requirements -- Flash chip size is 2x the size of the sketch - +- Flash chip size is 2x the size of the sketch. + ## Arduino IDE TODO describe Arduino IDE OTA process #### Requirements - - The ESP and the Computer must be connected to the Same network. - + - The ESP and the computer must be connected to the same network. ## HTTP Server -the ```ESPhttpUpdate``` class can check for updates and download a binary file form a HTTP web server. -It is possible to download updates from every IP or domain address on the Network or Internet. - +```ESPhttpUpdate``` class can check for updates and download a binary file from HTTP web server. +It is possible to download updates from every IP or domain address on the network or Internet. #### Requirements - web server - #### Arduino code -##### simple updater +##### Simple updater -the Simple Updater downloads the File every time the function is called. +Simple updater downloads the file every time the function is called. ```cpp ESPhttpUpdate.update("192.168.0.2", 80, "/arduino.bin"); ``` -##### advanced updater +##### Advanced updater -Its possible to point to a script at the server. -If a version String is delivered to the Function this String will be send to the server. -A Server side Update check is now possible. +Its possible to point update function to a script at the server. +If version string argument is given, it will be sent to the server. +Server side script can use this to check if update should be performed. -the Server can return a binary file for update (Header 200) -or it return header 304 to notify the ESP that no Update is needed. +Server side script can respond as follows: +- response code 200, and send the firmware image, +- or response code 304 to notify ESP that no update is required. ```cpp t_httpUpdate_return ret = ESPhttpUpdate.update("192.168.0.2", 80, "/esp/update/arduino.php", "optional current version string here"); @@ -59,23 +57,23 @@ switch(ret) { Serial.println("[update] Update no Update."); break; case HTTP_UPDATE_OK: - Serial.println("[update] Update ok."); // may not called we reboot the ESP + Serial.println("[update] Update ok."); // may not called we reboot the ESP break; } ``` #### Server request handling -##### simple updater +##### Simple updater -for the simple Updater the Server only needs to deliver the binary file for update. +For the simple updater the server only needs to deliver the binary file for update. -##### advanced updater +##### Advanced updater -for advanced update management a Script needs to run at the Server side, for example a PHP script. -at every Update request the the ESP sends some informations in the Header to the Server +For advanced update management a script needs to run at the server side, for example a PHP script. +At every update request the the ESP sends some information in HTTP headers to the server. -example Header data: +Example header data: ``` [HTTP_USER_AGENT] => ESP8266-http-Update [HTTP_X_ESP8266_STA_MAC] => 18:FE:AA:AA:AA:AA @@ -87,10 +85,9 @@ example Header data: [HTTP_X_ESP8266_VERSION] => DOOR-7-g14f53a19 ``` -with this information the script now can check if a update is needed. -It is also possible to deliver different binary´s based on the MAC address for example. +With this information the script now can check if a update is needed. It is also possible to deliver different binaries based on the MAC address for example. -script example: +Script example: ```php state() == ESTABLISHED) return 1; diff --git a/tests/Time/Time.ino b/tests/Time/Time.ino new file mode 100644 index 000000000..e4078534a --- /dev/null +++ b/tests/Time/Time.ino @@ -0,0 +1,35 @@ +#include +#include + +const char* ssid = ".........."; +const char* password = ".........."; + +int timezone = 3; +int dst = 0; + +void setup() { + Serial.begin(115200); + Serial.setDebugOutput(true); + + WiFi.mode(WIFI_STA); + WiFi.begin(ssid, password); + Serial.println("\nConnecting to WiFi"); + while (WiFi.status() != WL_CONNECTED) { + Serial.print("."); + delay(1000); + } + + configTime(3 * 3600, 0, "pool.ntp.org", "time.nist.gov"); + Serial.println("\nWaiting for time"); + while (!time(nullptr)) { + Serial.print("."); + delay(1000); + } + Serial.println(""); +} + +void loop() { + time_t now = time(nullptr); + Serial.println(ctime(&now)); + delay(1000); +}