Skip to content

Commit dacaf31

Browse files
committed
Get README.md is up to date.
1 parent 7b25c72 commit dacaf31

File tree

1 file changed

+47
-50
lines changed

1 file changed

+47
-50
lines changed

README.md

+47-50
Original file line numberDiff line numberDiff line change
@@ -7,53 +7,51 @@ A (very) simple web server written in Lua for the ESP8266 running the NodeMCU fi
77
> you are really abusing its intended purpose. When it comes to scoping your ESP8266
88
> applications, the adage Keep It Simple Stupid truly applies.
99
>
10-
> -- <cite>[Terry Ellison](https://github.com/TerryE)</cite>, nodemcu-firmware maintainer,
10+
> -- <cite>[Terry Ellison](https://github.com/TerryE)</cite>, nodemcu-firmware maintainer
1111
1212
Let the abuse begin.
1313

1414
## Features
1515

16-
* GET, POST, PUT and minor changes to support other methods
16+
* GET, POST, PUT (other methods can be supported with minor changes)
1717
* Multiple MIME types
1818
* Error pages (404 and others)
19-
* Server-side execution of Lua scripts
19+
* *Server-side execution of Lua scripts*
2020
* Query string argument parsing with decoding of arguments
2121
* Serving .gz compressed files
2222
* HTTP Basic Authentication
2323
* Decoding of request bodies in both application/x-www-form-urlencoded and application/json (if cjson is available)
2424

2525
## How to use
2626

27-
1. Upload server files using [nodemcu-uploader](https://github.com/kmpm/nodemcu-uploader).
27+
1. Modify your local copy of the configuration file httpserver-conf.lua.
28+
29+
2. Upload server files using [nodemcu-uploader](https://github.com/kmpm/nodemcu-uploader).
2830
The easiest is to use GNU Make with the bundled Makefile. Open the Makefile and modify the
2931
user configuration to point to your nodemcu-uploader script and your serial port.
3032
Type the following to upload the server code, init.lua (which you may want to modify),
3133
and some example files:
3234

3335
make upload_all
3436

35-
If you only want to upload the server code, then type:
37+
If you only want to upload just the server code, then type:
3638

3739
make upload_server
3840

39-
And if you only want to upload the server files:
41+
And if you only want to upload just the files that can be served:
4042

4143
make upload_http
4244

43-
Restart the server. This will execute init.lua which will compile the server code.
44-
Then, assuming init.lua doesn't have it, start the server yourself by typing:
45-
46-
dofile("httpserver.lc")(80)
47-
48-
In this example, 80 is the port your server is listening at, but you can change it.
45+
Restart the server. This will execute included init.lua which will compile the server code,
46+
configure WiFi, and start the server.
4947

50-
2. Want to upload your own files? Move them to the http/ folder. Be careful though,
51-
the flash memory seems to fill up quickly and get corrupted.
48+
3. Want to serve your own files? Put them under the http/ folder and upload to the chip.
49+
For example, assuming you want to serve myfile.html, upload by typing:
5250

53-
All the files you upload must be prefixed with "http/". Wait, what?
51+
make upload FILE:=http/myfile.html
5452

55-
Yes: NodeMCU's filesystem does not support folders, but filenames *can* contain slashes.
56-
Only files that begin with "http/" will be accessible through the server.
53+
Notice that while NodeMCU's filesystem does not support folders, filenames *can* contain slashes.
54+
We take advantage of that and only files that begin with "http/" will be accessible through the server.
5755

5856
3. Visit your server from a web browser.
5957

@@ -63,21 +61,19 @@ Let the abuse begin.
6361
then index.html is served. By the way, unlike most HTTP servers, nodemcu_httpserver treats the URLs in a
6462
case-sensitive manner.
6563

66-
4. How to use HTTP Basic Authentication.
64+
## HTTP Basic Authentication.
6765

68-
Modify variables in configuration file httpserver-conf.lua in order to enable and to configure usernames/passwords.
69-
See comments in that file for more details.
66+
It's supported. Turn it on in httpserver-conf.lua.
7067

71-
When enabled, HTTP Basic Authentication is global to every file served by the server.
68+
Use it with care and don't fall into a false sense of security: HTTP Basic Authentication should not be
69+
considered secure since the server is not using encryption. Username and passwords travel
70+
in the clear.
7271

73-
Remember that HTTP Basic Authentication is a very basic authentication protocol, and should not be
74-
considered as secure since the server is not using encryption. Username and passwords travel
75-
in plain text.
72+
## Server-side scripting using your own Lua scripts
7673

77-
## How to use server-side scripting using your own Lua scripts
78-
79-
Similar to static files, upload a Lua script called "http/[name].lua where you replace [name] with your script's name.
80-
The script should return a function that takes three parameters:
74+
Yes, you can upload your own Lua scripts! This is pretty powerful.
75+
Just put it under http/ and upload it. Make sure it has a .lua extension.
76+
Your script should return a function that takes three parameters:
8177

8278
return function (connection, req, args)
8379
-- code goes here
@@ -107,42 +103,40 @@ Let the abuse begin.
107103

108104
#### Hardware description
109105

110-
This example assumes that GPIO1 and GPIO2 on the ESP8266 are connected each to a relay
111-
that can be controlled. How to wire such thing is outside of the scope of this document
112-
[but information is easily found online](https://www.google.com/search?q=opening+a+garage+door+with+a+microcontroller).
106+
This example assumes that you are using a [Wemos D1 Pro](https://wiki.wemos.cc/products:d1:d1_mini_pro)
107+
with two relay shields and two reed switches.
113108
The relays are controlled by the microcontroller and act as the push button,
114109
and can actually be connected in parallel with the existing mechanical button.
110+
The switches are wired so that the ESP8266 can tell whether the doors are open
111+
or closed at any given time.
115112

116113
#### Software description
117114

118115
This example consists of the following files:
119116

120-
* **garage_door_opener.html**: Static HTML displays a button with a link
121-
to the garage_door_opener.lua script. That's it!
122-
* **garage_door_opener.css**: Provides styling for garage_door_opener.html
123-
just so it looks pretty.
124-
* **garage_door_opener.lua**: Does the actual work. The script first sends
125-
a little javascript snippet to redirect the client back to garage_door_opener.html
126-
and then toggles the GPIO2 line for a short amount of time (roughly equivalent to
127-
the typical button press for opening a garage door) and then toggles it back.
117+
* **garage_door.html**: Static HTML displays a form with all options for controlling the
118+
two garage doors.
119+
* **garage_door_control.html**: Looks like a garage door remote, how neat!
120+
* **garage_door_control.css**: Provides styling for garage_door_control.html.
121+
* **garage_door.lua**: Does the actual work. The script performs the desired action on
122+
the requested door and returns the results as JSON.
128123
* **apple-touch-icon.png**: This is optional. Provides an icon that
129-
will be used if you "Add to Home Screen" the demo on an iPhone. Now it looks like an app!
124+
will be used if you "Add to Home Screen" garage_door_control.html on an iPhone.
125+
Now it looks like an app!
130126

131127
#### Security implications
132128

133129
Be careful permanently installing something like this in your home. The server provides
134130
no encryption. Your only layers of security are the WiFi network's password and simple
135-
HTTP authentication which sends your password unencrypted.
131+
HTTP authentication (if you enable it) which sends your password unencrypted.
136132

137-
This script is provided simply as an educational example. You've been warned.
133+
This script is provided for educational purposes. You've been warned.
138134

139135
## Not supported
140136

141137
* Other methods: HEAD, DELETE, TRACE, OPTIONS, CONNECT, PATCH
142138
* Encryption / SSL
143-
* Multiple users (HTTP Basic Authentication)
144-
* Only protect certain directories (HTTP Basic Authentication)
145-
* nodemcu-firmware versions older 1.5.1 (January 2016) because that's what I tested on.
139+
* Old nodemcu-firmware versions prior to January 2017) because I don't bother to test them.
146140

147141
## Contributing
148142

@@ -151,7 +145,9 @@ Let the abuse begin.
151145
and that you add examples for new features. I won't test all your changes myself but I
152146
am very grateful of improvements and fixes. Open issues in GitHub too, that's useful.
153147

154-
Please follow the coding style as close as possible:
148+
Please keep your PRs focused on one thing. I don't mind lots of PRs. I mind PRs that fix multiple unrelated things.
149+
150+
Follow the coding style as closely as possible:
155151

156152
* No tabs, indent with 3 spaces
157153
* Unix (LF) line endings
@@ -163,8 +159,9 @@ Let the abuse begin.
163159

164160
The chip is very, very memory constrained.
165161

166-
* Use a recent nodemcu-firmware with as few optional modules as possible.
167-
* Use a firmware build without floating point support. This takes up a good chunk of RAM as well.
168-
* Any help reducing the memory needs of the server without crippling its functionality is appreciated!
169-
* Compile your Lua scripts in order to reduce their memory usage. The server knows to serve and treat
162+
* Use a recent nodemcu-firmware. They've really improved memory usage and fixed leaks.
163+
* Use only the modules you need.
164+
* Use a firmware build without floating point support if you can.
165+
* Any help reducing the memory needs of the server without crippling its functionality is much appreciated!
166+
* Compile your Lua scripts in order to reduce their memory usage. The server knows to serve
170167
both .lua and .lc files as scripts.

0 commit comments

Comments
 (0)