Updated with newer notes on memory and firmware
This commit is contained in:
parent
a86f2d6384
commit
a26ea74609
61
README.md
61
README.md
@ -1,5 +1,5 @@
|
|||||||
# nodemcu-httpserver
|
# (nodemcu-httpserver)[https://github.com/marcoskirsch/nodemcu-httpserver]
|
||||||
A (very) simple web server written in Lua for the ESP8266 firmware NodeMCU.
|
A (very) simple web server written in Lua for the ESP8266 running the NodeMCU firmware.
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
@ -12,11 +12,13 @@ A (very) simple web server written in Lua for the ESP8266 firmware NodeMCU.
|
|||||||
|
|
||||||
## How to use
|
## How to use
|
||||||
|
|
||||||
1. Upload server files using [nodemcu-uploader](https://github.com/kmpm/nodemcu-uploader) or similar.
|
1. Upload server files using [nodemcu-uploader](https://github.com/kmpm/nodemcu-uploader).
|
||||||
Or, even better, use GNU Make with the bundled makefile. Type the following to upload
|
The easiest is to use GNU Make with the bundled Makefile. Open the Makefile and modify the
|
||||||
server code, init.lua (which you may want to modify), and some example files:
|
user configuration to point to your nodemcu-uploader script and your serial port.
|
||||||
|
Type the following to upload the server code, init.lua (which you may want to modify),
|
||||||
|
and some example files:
|
||||||
|
|
||||||
make upload
|
make upload_all
|
||||||
|
|
||||||
If you only want to upload the server code, then type:
|
If you only want to upload the server code, then type:
|
||||||
|
|
||||||
@ -31,7 +33,7 @@ A (very) simple web server written in Lua for the ESP8266 firmware NodeMCU.
|
|||||||
|
|
||||||
dofile("httpserver.lc")(80)
|
dofile("httpserver.lc")(80)
|
||||||
|
|
||||||
In this example, 80 is the port your server is listening at but you can change it.
|
In this example, 80 is the port your server is listening at, but you can change it.
|
||||||
|
|
||||||
2. Want to upload your own files? Move them to the http/ folder. Be careful though,
|
2. Want to upload your own files? Move them to the http/ folder. Be careful though,
|
||||||
the flash memory seems to fill up quickly and get corrupted.
|
the flash memory seems to fill up quickly and get corrupted.
|
||||||
@ -62,14 +64,14 @@ A (very) simple web server written in Lua for the ESP8266 firmware NodeMCU.
|
|||||||
The _args_ parameter is a Lua table that contains any arguments sent by the client in the GET request.
|
The _args_ parameter is a Lua table that contains any arguments sent by the client in the GET request.
|
||||||
|
|
||||||
For example, if the client requests _http://2.2.2.2/foo.lua?color=red_ then the server will execute the function
|
For example, if the client requests _http://2.2.2.2/foo.lua?color=red_ then the server will execute the function
|
||||||
in your Lua script _foo.lua_ and pass in _connection_ and _args_, where _args.color == "red"_.
|
in your Lua script _foo.lua_ and pass in _connection_ and _args_, where _args.color = "red"_.
|
||||||
|
|
||||||
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
|
If you are going to be sending lots (as in over a KB) of data in your script, you should yield the thread/coroutine
|
||||||
in order to avoid overflowing the buffer in the microcontroller. Use:
|
every now and then in order to avoid overflowing the send buffer in the microcontroller. Use:
|
||||||
|
|
||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
|
|
||||||
The easiest is to check out the included example scripts for more ideas.
|
Look at the included example scripts for more ideas.
|
||||||
|
|
||||||
### Example: Garage door opener
|
### Example: Garage door opener
|
||||||
|
|
||||||
@ -77,9 +79,7 @@ A (very) simple web server written in Lua for the ESP8266 firmware NodeMCU.
|
|||||||
|
|
||||||
This is a bundled example that shows how to use nodemcu-httpserver
|
This is a bundled example that shows how to use nodemcu-httpserver
|
||||||
together with server-side scripting to control something with the
|
together with server-side scripting to control something with the
|
||||||
ESP8266. In this example, we will pretend to open a garage door.
|
ESP8266. In this example, we will pretend to open one of two garage doors.
|
||||||
This is a very simple example that doesn't even use arguments passed
|
|
||||||
in the request (see example args.lua for that).
|
|
||||||
|
|
||||||
Your typical [garage door opener](http://en.wikipedia.org/wiki/Garage_door_opener)
|
Your typical [garage door opener](http://en.wikipedia.org/wiki/Garage_door_opener)
|
||||||
has a wired remote with a single button. The button simply connects to
|
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.
|
|||||||
|
|
||||||
#### Hardware description
|
#### Hardware description
|
||||||
|
|
||||||
This example assumes that GPIO2 on the ESP8266 is connected to a relay
|
This example assumes that GPIO0 and GPIO2 on the ESP8266 are connected each to a relay
|
||||||
that can be controlled. How to wire such thing is outside of the scope
|
that can be controlled. How to wire such thing is outside of the scope of this document
|
||||||
of this document [but information is easily found online]
|
[but information is easily found online](https://www.google.com/search?q=opening+a+garage+door+with+a+microcontroller).
|
||||||
(https://www.google.com/search?q=opening+a+garage+door+with+a+microcontroller).
|
The relays are controlled by the microcontroller and act as the push button,
|
||||||
The relay is controlled by the microcontroller and acts as the button,
|
|
||||||
and can actually be connected in parallel with the existing mechanical button.
|
and can actually be connected in parallel with the existing mechanical button.
|
||||||
|
|
||||||
#### Software description
|
#### Software description
|
||||||
@ -108,13 +107,13 @@ A (very) simple web server written in Lua for the ESP8266 firmware NodeMCU.
|
|||||||
and then toggles the GPIO2 line for a short amount of time (roughly equivalent to
|
and then toggles the GPIO2 line for a short amount of time (roughly equivalent to
|
||||||
the typical button press for opening a garage door) and then toggles it back.
|
the typical button press for opening a garage door) and then toggles it back.
|
||||||
* **apple-touch-icon.png**: This is optional. Provides an icon that
|
* **apple-touch-icon.png**: This is optional. Provides an icon that
|
||||||
will be used if you "Add to Home Screen" the demo. Now it looks like an app!`
|
will be used if you "Add to Home Screen" the demo on an iPhone. Now it looks like an app!
|
||||||
|
|
||||||
#### Security implications
|
#### Security implications
|
||||||
|
|
||||||
Be careful permanently installing something like this in your home. The
|
Be careful permanently installing something like this in your home. The
|
||||||
scripts use no authentication and no encryption. Your only layer of
|
scripts use no authentication and no encryption. Your only layer of
|
||||||
security is your wifi network and anyone with access to it could open
|
security is the wifi network and anyone with access to it could open
|
||||||
or close your garage, enter your home, and steal your flatscreen TV.
|
or close your garage, enter your home, and steal your flatscreen TV.
|
||||||
|
|
||||||
This script is provided simply as an educational example and you should
|
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.
|
|||||||
|
|
||||||
## Notes on memory usage.
|
## Notes on memory usage.
|
||||||
|
|
||||||
The chip is very, very memory constrained. You must use a build of nodemcu-firmware recent enough to support
|
The chip is very, very memory constrained.
|
||||||
node.compile() since the server expects all server scripts to be compiled.
|
|
||||||
|
|
||||||
* It is recommended you use a firmware build without support for floating point.
|
* Use nodemcu-firmware dev096 or newer with as few optional modules as possible.
|
||||||
In the (nodemcu-firmware releases page)[https://github.com/nodemcu/nodemcu-firmware/releases] these would be the ones
|
Older versions have very little free RAM.
|
||||||
with the term "integer" in them. If you want to build your own, then edit file nodemcu-firmware/app/lua/luaconf.h right
|
|
||||||
around line 572 (line number may change) by adding
|
|
||||||
|
|
||||||
#define LUA_NUMBER_INTEGRAL
|
* Use a firmware build without floating point support. This takes up a good chunk of RAM as well.
|
||||||
|
In the (nodemcu-firmware releases page)[https://github.com/nodemcu/nodemcu-firmware/releases] these
|
||||||
|
would be the ones with the term "integer" in them. If you are building it yourself then we'll assume
|
||||||
|
you know what you're doing.
|
||||||
|
|
||||||
Then rebuild and re-flash the firmware.
|
* Any help reducing the memory needs of the server without crippling its functionality is appreciated!
|
||||||
|
|
||||||
* Any help reducing the memory needs of the server without crippling its features are appreciated!
|
* Compile your Lua scripts in order to reduce their memory usage. The server knows to serve and treat
|
||||||
|
|
||||||
* You can compile your Lua scripts in order to reduce their memory usage. The server knows to treat
|
|
||||||
both .lua and .lc files as scripts.
|
both .lua and .lc files as scripts.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user