Skip to content

Commit 74d789a

Browse files
Merge pull request #140 from konnected-io/nodemcu-3.0
Nodemcu 3.0 Update
2 parents 3ec892e + 34026b2 commit 74d789a

23 files changed

+931
-143
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ src/lfs/lfs.img
4242
*.x86_64
4343
*.hex
4444

45+
# Build Artifacts
46+
build
47+
firmware/builds
48+
4549
# Private files
4650
private
47-

README.md

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
# Konnected
66

77
**Konnected** integrates wired alarm system sensors and sirens to SmartThings, Home Assistant, OpenHAB, or Hubitat using a NodeMCU based ESP8266 development board and (optional) relay. This project consists of a few components:
8-
8+
99
1. [NodeMCU](http://nodemcu.com/index_en.html) based firmware for an ESP8266 development board in `firmware`
1010
1. Lua and HTML source code for the NodeMCU in `src`. All these files are built into a SPIFFS file system which runs on NodeMCU
1111
1. [SmartThings](https://www.smartthings.com/) platform code in `smartapps` and `devicetypes`
12-
12+
1313
![](http://docs.konnected.io/assets/images/konnected-alarm-panel.jpg)
1414

1515
## Skip this Installation!
@@ -26,7 +26,7 @@
2626
#### Note on Device Drivers
2727

2828
Windows and Mac users will need to download drivers so your computer can talk to the ESP8266 chip over USB. Depending
29-
on which board you have, there are different drivers:
29+
on which board you have, there are different drivers:
3030

3131
**[WeMos CH340 drivers](https://www.wemos.cc/en/latest/ch340_driver.html)** for boards that:
3232
* have the name _LoLin_ on the back or front
@@ -41,23 +41,19 @@ on which board you have, there are different drivers:
4141
Konnected leverages the [NodeMCU](https://github.com/nodemcu/nodemcu-firmware) codebase and [Docker builder](https://hub.docker.com/r/marcelstoer/nodemcu-build/) to create a base nodeMCU firmware image and a filesystem containing the Konnected application. Building only requires a few steps.
4242

4343
1. Download and install [Docker](https://www.docker.com/products/docker-desktop)
44-
1. Clone the Konnected and nodeMCU repos to the same level in your working directory
44+
1. Clone the Konnected repo
4545

4646
git clone https://github.com/konnected-io/konnected-security.git
47-
git clone https://github.com/nodemcu/nodemcu-firmware.git
48-
49-
1. Check out the 2.2.1 release of nodemcu
5047

51-
pushd nodemcu-firmware && git checkout 2.2.1-master_20190405 && popd
52-
53-
1. Use the build-firmware script to kick off the build - providing a semantic version command line argument as shown below. The build script will automatically pull down the nodeMCU docker builder, build the base firmware, create an LFS image, and build a SPIFFS file system containing the entire Konnected application.
48+
1. Use the build-firmware script to kick off the build - providing a semantic version command line argument as shown below. The build script will automatically pull down the correct nodeMCU image, and use this nodeMCU docker builder to create base firmware, an LFS image, and a SPIFFS file system containing the entire Konnected application.
5449

5550
cd konnected-security
5651
./scripts/build-firmware 2-2-99
5752

58-
1. Once the build completes a folder will be created in `firmware/builds` named after the version specified in the previous step. This folder will contain two files also reflecting the version.
53+
1. Once the build completes a folder will be created in `firmware/builds` named after the version specified in the previous step. This folder will contain three files also reflecting the version.
5954
1. konnected-filesystem-0x100000-2-2-99.img
6055
1. konnected-firmware-2-2-99.bin
56+
1. konnected-esp8266-2-2-99.bin
6157

6258
*Note: Each time you build it will remove any prior build outputs corresponding to the same version.*
6359
*Note: Versions in this project should always be formatted `<major>-<minor>-<patch>`.*
@@ -67,26 +63,26 @@ Flashing a build is simple with the [Konnected Flashing Tool](https://help.konne
6763

6864
Mac and Linux users can also easily flash from the command line using [scripts/flash](scripts/flash).
6965

70-
1. You must have Python installed with `pip` or `pip3`.
71-
* **Mac users**: I recommend using [Homebrew](https://brew.sh/) and `brew install python`
72-
66+
1. You must have Python installed with `pip` or `pip3`.
67+
* **Mac users**: I recommend using [Homebrew](https://brew.sh/) and `brew install python`
68+
7369
1. Open up a terminal and install `esptool` packages:
74-
70+
7571
pip3 install esptool
76-
72+
7773
1. Run the script in `scripts/flash` to flash the firmware and software to the device. You must pass in version and serial port args. The flash script will always attempt to flash a matching version in `firmware/builds` before falling back to `firmware/releases`
7874

7975
./scripts/flash 2-2-99 /dev/ttyS3
80-
76+
8177
*Note: You may also need to make the script executable by running `chmod 755 scripts/flash`.*
82-
78+
8379

8480
### Donations
8581

8682
We work hard on this project because we're passionate about making home automation accessible to everybody. Millions of
8783
homes in North America and worldwide are already wired with sensors and have the potential to become smart homes. We
8884
want to make this a reality.
89-
85+
9086
If you've used Konnected Security and it's improved your life and your home security, please consider [donating](http://docs.konnected.io/donate) to help us
9187
achieve that goal.
9288

firmware/nodemcu-firmware-overlay/app/include/user_config.h

Lines changed: 97 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,26 @@
2222
//#define BIT_RATE_AUTOBAUD
2323

2424

25+
// At start-up firmware details like:
26+
//
27+
// NodeMCU 3.0.1.0
28+
// branch:
29+
// commit:
30+
// release:
31+
// release DTS:
32+
// SSL: false
33+
// build type: integer
34+
// LFS: 0x0
35+
// modules: file,gpio,net,node,rtctime,sntp,tmr,uart,wifi
36+
// build 2020-01-27 17:39 powered by Lua 5.1.4 on SDK 3.0.2(824dc80)
37+
//
38+
// will be printed to serial console. While it's mandatory for bug reports
39+
// and good for development, it may be unwanted for non-interactive serial
40+
// devices.
41+
42+
//#define DISABLE_STARTUP_BANNER
43+
44+
2545
// Three separate build variants are now supported. The main difference is in the
2646
// processing of numeric data types. If LUA_NUMBER_INTEGRAL is defined, then
2747
// all numeric calculations are done in integer, with divide being an integer
@@ -41,12 +61,12 @@
4161

4262
// The Lua Flash Store (LFS) allows you to store Lua code in Flash memory and
4363
// the Lua VMS will execute this code directly from flash without needing any
44-
// RAM overhead. If you want to enable LFS then set the following define to
45-
// the size of the store that you need. This can be any multiple of 4kB up to
46-
// a maximum 256Kb.
47-
48-
#define LUA_FLASH_STORE 0x10000
64+
// RAM overhead. You can now configure LFS directly in the System Partition
65+
// Table insted of at compile time. However for backwards compatibility setting
66+
// LUA_FLASH_STORE defines the default partition size if the NodeMCU partition
67+
// tool is not used.
4968

69+
#define LUA_FLASH_STORE 0x40000
5070

5171
// By default Lua executes the file init.lua at start up. The following
5272
// define allows you to replace this with an alternative startup. Warning:
@@ -59,7 +79,7 @@
5979

6080

6181
// NodeMCU supports two file systems: SPIFFS and FATFS, the first is available
62-
// on all ESP8266 modules. The latter requires extra H/W so is less common.
82+
// on all ESP8266 modules. The latter requires extra H/W so it is less common.
6383
// If you use SPIFFS then there are a number of options which impact the
6484
// RAM overhead and performance of the file system.
6585

@@ -71,11 +91,15 @@
7191
// general, limiting the size of the FS only to what your application needs
7292
// gives the fastest start-up and imaging times.
7393

94+
// You can now configure SPIFFS size and position directly in the System
95+
// Partition Table. However backwards compatibility SPIFFS_MAX_FILESYSTEM_SIZE
96+
// can be set and this defines the default SPIFFS partition size if the NodeMCU
97+
// partition tool is not used. The value (~0x0) means the maximum size remaining.
98+
7499
#define BUILD_SPIFFS
75-
#define SPIFFS_FIXED_LOCATION 0x100000
76-
#define SPIFFS_MAX_FILESYSTEM_SIZE 128000
77-
//#define SPIFFS_SIZE_1M_BOUNDARY
78100
#define SPIFFS_CACHE 1 // Enable if you use you SPIFFS in R/W mode
101+
#define SPIFFS_MAX_FILESYSTEM_SIZE 0x100000
102+
#define SPIFFS_FIXED_LOCATION 0x100000
79103
#define SPIFFS_MAX_OPEN_FILES 4 // maximum number of open files for SPIFFS
80104
#define FS_OBJ_NAME_LEN 31 // maximum length of a filename
81105

@@ -84,26 +108,26 @@
84108

85109
// The HTTPS stack requires client SSL to be enabled. The SSL buffer size is
86110
// used only for espconn-layer secure connections, and is ignored otherwise.
87-
// Some HTTPS applications require a larger buffer size to work. See
111+
// Some HTTPS applications require a larger buffer size to work. See
88112
// https://github.com/nodemcu/nodemcu-firmware/issues/1457 for details.
89113
// The SHA2 and MD2 libraries are also optionally used by the crypto functions.
90114
// The SHA1 and MD5 function are implemented in the ROM BIOS. The MD2 and SHA2
91115
// are by firmware code, and can be enabled if you need this functionality.
92116

93117
#define CLIENT_SSL_ENABLE
94-
//#define MD2_ENABLE
95118
#define SHA2_ENABLE
96-
#define SSL_BUFFER_SIZE 5376
119+
#define SSL_BUFFER_SIZE 5380
120+
#define SSL_MAX_FRAGMENT_LENGTH_CODE MBEDTLS_SSL_MAX_FRAG_LEN_4096
97121

98122

99123
// GPIO_INTERRUPT_ENABLE needs to be defined if your application uses the
100124
// gpio.trig() or related GPIO interrupt service routine code. Likewise the
101-
// GPIO interrupt hook is requited for a few modules such as rotary. If you
102-
// don't require this functionality, then commenting out these options out
125+
// GPIO interrupt hook is required for a few modules such as rotary. If you
126+
// don't require this functionality, then commenting out these options
103127
// will remove any associated runtime overhead.
104128

105129
#define GPIO_INTERRUPT_ENABLE
106-
//#define GPIO_INTERRUPT_HOOK_ENABLE
130+
#define GPIO_INTERRUPT_HOOK_ENABLE
107131

108132

109133
// If your application uses the light sleep functions and you wish the
@@ -113,15 +137,18 @@
113137
//#define TIMER_SUSPEND_ENABLE
114138
//#define PMSLEEP_ENABLE
115139

140+
// The net module optionally offers net info functionnality. Uncomment the following
141+
// to enable the functionnality.
142+
#define NET_PING_ENABLE
116143

117144
// The WiFi module optionally offers an enhanced level of WiFi connection
118145
// management, using internal timer callbacks. Whilst many Lua developers
119146
// prefer to implement equivalent features in Lua, others will prefer the
120147
// Wifi module to do this for them. Uncomment the following to enable
121-
// this functionality. See the relevant WiFi module documentation for
148+
// this functionality. See the relevant WiFi module documentation for
122149
// further details, as the scope of these changes is not obvious.
123150

124-
// Enable the wifi.startsmart() and wifi.stopsmart()
151+
// Enable the wifi.startsmart() and wifi.stopsmart()
125152
//#define WIFI_SMART_ENABLE
126153

127154
// Enable wifi.sta.config() event callbacks
@@ -130,10 +157,6 @@
130157
// Enable creation on the wifi.eventmon.reason table
131158
#define WIFI_EVENT_MONITOR_DISCONNECT_REASON_LIST_ENABLE
132159

133-
// Enable use of the WiFi.monitor sub-module
134-
//#define LUA_USE_MODULES_WIFI_MONITOR
135-
136-
137160
// Whilst the DNS client details can be configured through the WiFi API,
138161
// the defaults can be exposed temporarily during start-up. The following
139162
// WIFI_STA options allow you to configure this in the firmware. If the
@@ -155,7 +178,23 @@
155178
#define ENDUSER_SETUP_AP_SSID "konnected"
156179

157180

158-
// The following sections are only relevent for those developers who are
181+
// I2C software driver partially supports use of GPIO16 (D0) pin for SCL line.
182+
// GPIO16 does not support open-drain mode and works in push-pull mode,
183+
// so clock stretching will not be possible, because circuit in slave device that
184+
// supposed to drive SCL low during stretching will not be capable to hold SCL low.
185+
// Also I2C speed will be limited to no more than 400000 Hz (FAST mode).
186+
// This define is does not have an effect on an old driver (see I2C_MASTER_OLD_VERSION).
187+
188+
//#define I2C_MASTER_GPIO16_ENABLE
189+
190+
// For compatibility reasons you can switch to old version of I2C software driver.
191+
// It does not support changing speed, have only one bus id = 0, does not support GPIO16
192+
// and works only in Standard(slow) mode with clock speed around 50kHz.
193+
194+
#define I2C_MASTER_OLD_VERSION
195+
196+
197+
// The following sections are only relevant for those developers who are
159198
// developing modules or core Lua changes and configure how extra diagnostics
160199
// are enabled in the firmware. These should only be configured if you are
161200
// building your own custom firmware and have full access to the firmware
@@ -189,24 +228,46 @@
189228
// change this if you have tracked the implications through the Firmware sources
190229
// and understand the these.
191230

231+
#define NODEMCU_EAGLEROM_PARTITION 1
232+
#define NODEMCU_IROM0TEXT_PARTITION 2
233+
#define NODEMCU_LFS0_PARTITION 3
234+
#define NODEMCU_LFS1_PARTITION 4
235+
#define NODEMCU_TLSCERT_PARTITION 5
236+
#define NODEMCU_SPIFFS0_PARTITION 6
237+
#define NODEMCU_SPIFFS1_PARTITION 7
238+
239+
#ifndef LUA_FLASH_STORE
240+
# define LUA_FLASH_STORE 0x0
241+
#endif
242+
243+
#ifndef SPIFFS_FIXED_LOCATION
244+
#define SPIFFS_FIXED_LOCATION 0x0
245+
// You'll rarely need to customize this, because nowadays
246+
// it's usually overruled by the partition table anyway.
247+
#endif
248+
#ifndef SPIFFS_MAX_FILESYSTEM_SIZE
249+
#define SPIFFS_MAX_FILESYSTEM_SIZE 0xFFFFFFFF
250+
#endif
251+
//#define SPIFFS_SIZE_1M_BOUNDARY
252+
192253
#define LUA_TASK_PRIO USER_TASK_PRIO_0
193254
#define LUA_PROCESS_LINE_SIG 2
194255
#define LUA_OPTIMIZE_DEBUG 2
195256
#define READLINE_INTERVAL 80
196257
#define STRBUF_DEFAULT_INCREMENT 3
197258
#define LUA_USE_BUILTIN_DEBUG_MINIMAL // for debug.getregistry() and debug.traceback()
198259

199-
#ifdef DEVELOPMENT_TOOLS
200-
#if defined(LUA_CROSS_COMPILER) || !defined(DEVELOPMENT_USE_GDB)
260+
#if defined(DEVELOPMENT_TOOLS) && defined(DEVELOPMENT_USE_GDB)
261+
extern void LUA_DEBUG_HOOK (void);
262+
#define lua_assert(x) ((x) ? (void) 0 : LUA_DEBUG_HOOK ())
263+
#elif defined(DEVELOPMENT_TOOLS) && defined(LUA_CROSS_COMPILER)
201264
extern void luaL_assertfail(const char *file, int line, const char *message);
202265
#define lua_assert(x) ((x) ? (void) 0 : luaL_assertfail(__FILE__, __LINE__, #x))
203266
#else
204-
extern void luaL_dbgbreak(void);
205-
#define lua_assert(x) ((x) ? (void) 0 : luaL_dbgbreak())
206-
#endif
267+
#define lua_assert(x) ((void) (x))
207268
#endif
208269

209-
#if !defined(LUA_NUMBER_INTEGRAL) && defined (LUA_DWORD_ALIGNED_TVALUES)
270+
#if !defined(LUA_NUMBER_INTEGRAL) && !defined (LUA_DWORD_ALIGNED_TVALUES)
210271
#define LUA_PACK_TVALUES
211272
#else
212273
#undef LUA_PACK_TVALUES
@@ -217,30 +278,30 @@ extern void luaL_dbgbreak(void);
217278
#define COAP_DEBUG
218279
#endif /* DEVELOP_VERSION */
219280

281+
282+
#if !defined(LUA_CROSS_COMPILER) && !defined(dbg_printf)
283+
extern void dbg_printf(const char *fmt, ...);
284+
#endif
285+
220286
#ifdef NODE_DEBUG
221287
#define NODE_DBG dbg_printf
222288
#else
223-
#define NODE_DBG
289+
#define NODE_DBG( ... )
224290
#endif /* NODE_DEBUG */
225291

226292
#define NODE_ERROR
227293
#ifdef NODE_ERROR
228294
#define NODE_ERR dbg_printf
229295
#else
230-
#define NODE_ERR
296+
#define NODE_ERR( ... )
231297
#endif /* NODE_ERROR */
232298

233299
// #define GPIO_SAFE_NO_INTR_ENABLE
234300
#define ICACHE_STORE_TYPEDEF_ATTR __attribute__((aligned(4),packed))
235301
#define ICACHE_STORE_ATTR __attribute__((aligned(4)))
236302
#define ICACHE_STRING(x) ICACHE_STRING2(x)
237303
#define ICACHE_STRING2(x) #x
238-
#define ICACHE_RAM_ATTR \
239-
__attribute__((section(".iram0.text." __FILE__ "." ICACHE_STRING(__LINE__))))
240-
#define ICACHE_FLASH_RESERVED_ATTR \
241-
__attribute__((section(".irom.reserved." __FILE__ "." ICACHE_STRING(__LINE__)),\
242-
used,unused,aligned(INTERNAL_FLASH_SECTOR_SIZE)))
243-
304+
#define ICACHE_RAM_ATTR __attribute__((section(".iram0.text." __FILE__ "." ICACHE_STRING(__LINE__))))
244305
#ifdef GPIO_SAFE_NO_INTR_ENABLE
245306
#define NO_INTR_CODE ICACHE_RAM_ATTR __attribute__ ((noinline))
246307
#else

0 commit comments

Comments
 (0)