Skip to content

Commit a26ea74

Browse files
author
Marcos Kirsch
committed
Updated with newer notes on memory and firmware
1 parent a86f2d6 commit a26ea74

File tree

1 file changed

+29
-32
lines changed

1 file changed

+29
-32
lines changed

README.md

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# nodemcu-httpserver
2-
A (very) simple web server written in Lua for the ESP8266 firmware NodeMCU.
1+
# (nodemcu-httpserver)[https://github.com/marcoskirsch/nodemcu-httpserver]
2+
A (very) simple web server written in Lua for the ESP8266 running the NodeMCU firmware.
33

44
## Features
55

@@ -12,11 +12,13 @@ A (very) simple web server written in Lua for the ESP8266 firmware NodeMCU.
1212

1313
## How to use
1414

15-
1. Upload server files using [nodemcu-uploader](https://github.com/kmpm/nodemcu-uploader) or similar.
16-
Or, even better, use GNU Make with the bundled makefile. Type the following to upload
17-
server code, init.lua (which you may want to modify), and some example files:
15+
1. Upload server files using [nodemcu-uploader](https://github.com/kmpm/nodemcu-uploader).
16+
The easiest is to use GNU Make with the bundled Makefile. Open the Makefile and modify the
17+
user configuration to point to your nodemcu-uploader script and your serial port.
18+
Type the following to upload the server code, init.lua (which you may want to modify),
19+
and some example files:
1820

19-
make upload
21+
make upload_all
2022

2123
If you only want to upload the server code, then type:
2224

@@ -31,7 +33,7 @@ A (very) simple web server written in Lua for the ESP8266 firmware NodeMCU.
3133

3234
dofile("httpserver.lc")(80)
3335

34-
In this example, 80 is the port your server is listening at but you can change it.
36+
In this example, 80 is the port your server is listening at, but you can change it.
3537

3638
2. Want to upload your own files? Move them to the http/ folder. Be careful though,
3739
the flash memory seems to fill up quickly and get corrupted.
@@ -62,24 +64,22 @@ A (very) simple web server written in Lua for the ESP8266 firmware NodeMCU.
6264
The _args_ parameter is a Lua table that contains any arguments sent by the client in the GET request.
6365

6466
For example, if the client requests _http://2.2.2.2/foo.lua?color=red_ then the server will execute the function
65-
in your Lua script _foo.lua_ and pass in _connection_ and _args_, where _args.color == "red"_.
67+
in your Lua script _foo.lua_ and pass in _connection_ and _args_, where _args.color = "red"_.
6668

67-
If you are going to be sending lots (as in over a KB) of data, you should yield the thread/coroutine every now and then
68-
in order to avoid overflowing the buffer in the microcontroller. Use:
69+
If you are going to be sending lots (as in over a KB) of data in your script, you should yield the thread/coroutine
70+
every now and then in order to avoid overflowing the send buffer in the microcontroller. Use:
6971

7072
coroutine.yield()
7173

72-
The easiest is to check out the included example scripts for more ideas.
74+
Look at the included example scripts for more ideas.
7375

7476
### Example: Garage door opener
7577

7678
#### Purpose
7779

7880
This is a bundled example that shows how to use nodemcu-httpserver
7981
together with server-side scripting to control something with the
80-
ESP8266. In this example, we will pretend to open a garage door.
81-
This is a very simple example that doesn't even use arguments passed
82-
in the request (see example args.lua for that).
82+
ESP8266. In this example, we will pretend to open one of two garage doors.
8383

8484
Your typical [garage door opener](http://en.wikipedia.org/wiki/Garage_door_opener)
8585
has a wired remote with a single button. The button simply connects to
@@ -88,11 +88,10 @@ A (very) simple web server written in Lua for the ESP8266 firmware NodeMCU.
8888

8989
#### Hardware description
9090

91-
This example assumes that GPIO2 on the ESP8266 is connected to a relay
92-
that can be controlled. How to wire such thing is outside of the scope
93-
of this document [but information is easily found online]
94-
(https://www.google.com/search?q=opening+a+garage+door+with+a+microcontroller).
95-
The relay is controlled by the microcontroller and acts as the button,
91+
This example assumes that GPIO0 and GPIO2 on the ESP8266 are connected each to a relay
92+
that can be controlled. How to wire such thing is outside of the scope of this document
93+
[but information is easily found online](https://www.google.com/search?q=opening+a+garage+door+with+a+microcontroller).
94+
The relays are controlled by the microcontroller and act as the push button,
9695
and can actually be connected in parallel with the existing mechanical button.
9796

9897
#### Software description
@@ -108,13 +107,13 @@ A (very) simple web server written in Lua for the ESP8266 firmware NodeMCU.
108107
and then toggles the GPIO2 line for a short amount of time (roughly equivalent to
109108
the typical button press for opening a garage door) and then toggles it back.
110109
* **apple-touch-icon.png**: This is optional. Provides an icon that
111-
will be used if you "Add to Home Screen" the demo. Now it looks like an app!`
110+
will be used if you "Add to Home Screen" the demo on an iPhone. Now it looks like an app!
112111

113112
#### Security implications
114113

115114
Be careful permanently installing something like this in your home. The
116115
scripts use no authentication and no encryption. Your only layer of
117-
security is your wifi network and anyone with access to it could open
116+
security is the wifi network and anyone with access to it could open
118117
or close your garage, enter your home, and steal your flatscreen TV.
119118

120119
This script is provided simply as an educational example and you should
@@ -128,19 +127,17 @@ A (very) simple web server written in Lua for the ESP8266 firmware NodeMCU.
128127

129128
## Notes on memory usage.
130129

131-
The chip is very, very memory constrained. You must use a build of nodemcu-firmware recent enough to support
132-
node.compile() since the server expects all server scripts to be compiled.
130+
The chip is very, very memory constrained.
133131

134-
* It is recommended you use a firmware build without support for floating point.
135-
In the (nodemcu-firmware releases page)[https://github.com/nodemcu/nodemcu-firmware/releases] these would be the ones
136-
with the term "integer" in them. If you want to build your own, then edit file nodemcu-firmware/app/lua/luaconf.h right
137-
around line 572 (line number may change) by adding
132+
* Use nodemcu-firmware dev096 or newer with as few optional modules as possible.
133+
Older versions have very little free RAM.
138134

139-
#define LUA_NUMBER_INTEGRAL
135+
* Use a firmware build without floating point support. This takes up a good chunk of RAM as well.
136+
In the (nodemcu-firmware releases page)[https://github.com/nodemcu/nodemcu-firmware/releases] these
137+
would be the ones with the term "integer" in them. If you are building it yourself then we'll assume
138+
you know what you're doing.
140139

141-
Then rebuild and re-flash the firmware.
140+
* Any help reducing the memory needs of the server without crippling its functionality is appreciated!
142141

143-
* Any help reducing the memory needs of the server without crippling its features are appreciated!
144-
145-
* You can compile your Lua scripts in order to reduce their memory usage. The server knows to treat
142+
* Compile your Lua scripts in order to reduce their memory usage. The server knows to serve and treat
146143
both .lua and .lc files as scripts.

0 commit comments

Comments
 (0)