Browse Source

removed junk, fixed license mess

master
Ondřej Hruška 6 years ago
parent
commit
5a0ee0ad4a
  1. 21
      LICENSE.txt
  2. 98
      README.md
  3. 9
      esphttpclient/LICENSE
  4. 90
      esphttpclient/test/httpclient_test.c
  5. 96
      libesphttpd/ESPHTTPD_README.md
  6. 11
      libesphttpd/LICENSE
  7. 9
      user/user_main.c

21
LICENSE.txt

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2016 Ondřej Hruška
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

98
README.md

@ -1,96 +1,12 @@
# esp-httpd README #
Appliance Health Monitor / Current Analyzer
===========================================
This is the demonstration project for the small but powerful libesphttpd webserver
for ESP8266(EX) chips. It is an example of how to make a module that can have
the AP it connects to configured over a webbrowser. It also illustrates multiple
flash layouts and some OTA update functionality.
Ondřej Hruška, 2016
## ABOUT THE WEBSERVER ##
Project based on ESP8266 IoT SDK, libesphttpd and esphttpclient.
The Good (aka: what's awesome)
- Supports multiple connections, for eg simultaneous html/css/js/images downloading
- Static files stored in flash, in an (optionally compressed) RO filesystem
- Pluggable using external cgi routines
- Simple template engine for mixed c and html things
- Usable as an embedded library - should be easy to drop into your existing projects
- Includes websocket support
The Bad (aka: what can be improved)
- Not built for speediness, although it's reasonable fast.
- Built according to what I remember of the HTTP protocol, not according to the
RFCs. Should work with most modern browsers, though.
- No support for https.
The Ugly (aka: bugs, misbehaviour)
- Possible buffer overflows (usually not remotely exploitable) due to no os_snprintf
This can be theoretically remedied by either Espressif including an os_snprintf in
their libs or by using some alternate printf lib, like elm-chans xprintf
## SOURCE OF THIS CODE ##
The official esphttpd repo lives at http://git.spritesserver.nl/esphttpd.git/ and
http://git.spritesserver.nl/libesphttpd.git/ . If you're a fan of Github, you can also
peruse the official mirror at https://github.com/Spritetm/esphttpd and https://github.com/Spritetm/libesphttpd . If
you want to discuss this code, there is a subforum at esp8266.com: http://www.esp8266.com/viewforum.php?f=34 .
## ABOUT THE EXAMPLE ##
When you flash the example into an ESP8266(EX) module, you get a small webserver with a few example
pages. If you've already connected your module to your WLAN before, it'll keep those settings. When
you haven't or the settings are wrong, keep GPIO0 for >5 seconds. The module will reboot into
its STA+AP mode. Connect a computer to the newly formed access point and browse to
http://192.168.4.1/wifi in order to connect the module to your WiFi network. The example also
allows you to control a LED that's connected to GPIO2.
## BUILDING EVERYTHING ##
For this, you need an environment that can compile ESP8266 firmware. Environments for this still
are in flux at the moment, but I'm using esp-open-sdk: https://github.com/pfalcon/esp-open-sdk .
You probably also need an UNIX-like system; I'm working on Debian Linux myself.
To manage the paths to all this, you can source a small shell fragment into your current session. For
example, I source a file with these contents:
export PATH=${PWD}/esp-open-sdk/xtensa-lx106-elf/bin:$PATH
export SDK_BASE=${PWD}/esp-open-sdk/sdk
export ESPTOOL=${PWD}/esptool/esptool.py
export ESPPORT=/dev/ttyUSB0
export ESPBAUD=460800
Actual setup of the SDK and toolchain is out of the scope of this document, so I hope this helps you
enough to set up your own if you haven't already.
If you have that, you can clone out the source code:
git clone http://git.spritesserver.nl/esphttpd.git/
This project makes use of heatshrink, which is a git submodule. To fetch the code:
cd esphttpd
git submodule init
git submodule update
Now, build the code:
make
Depending on the way you built it, esp-open-sdk sometimes patches Espressifs SDK, needing a slightly different
compiling process. If this is needed, you will get errors during compiling complaining about uint8_t being
undeclared. If this happens, try building like this:
make USE_OPENSDK=yes
You can also edit the Makefile to change this more permanently.
After the compile process, flash the code happens in 2 steps. First the code itself gets flashed. Reset the module into bootloader
mode and enter 'make flash'.
The 2nd step is to pack the static files the webserver will serve and flash that. Reset the module into
bootloader mode again and enter `make htmlflash`.
You should have a working webserver now.
## WRITING CODE FOR THE WEBSERVER ##
Please see the README.md of the libesphttpd project for the programming manual.
Website in `html_src/` is compiled to `html/` static files using the `web-build.sh` script.
You need Linux to work with this project.
Make sure you have **esp-open-sdk** installed and the Xtensa GCC is in your $PATH.

9
esphttpclient/LICENSE

@ -0,0 +1,9 @@
----------------------------------------------------------------------------
"THE BEER-WARE LICENSE" (Revision 42):
Martin d'Allens <martin.dallens@gmail.com> wrote this file. As long as you retain
this notice you can do whatever you want with this stuff. If we meet some day,
and you think this stuff is worth it, you can buy me a beer in return.
----------------------------------------------------------------------------
Upstream: https://github.com/Caerbannog/esphttpclient

90
esphttpclient/test/httpclient_test.c

@ -1,90 +0,0 @@
/*
* ----------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* Martin d'Allens <martin.dallens@gmail.com> wrote this file. As long as you retain
* this notice you can do whatever you want with this stuff. If we meet some day,
* and you think this stuff is worth it, you can buy me a beer in return.
* ----------------------------------------------------------------------------
*/
#include <esp8266.h>
#include "httpclient.h"
static int test_count = 0;
static ETSTimer test_timer;
static void ICACHE_FLASH_ATTR test_timer_cb()
{
dbg("\nTEST %d ", test_count);
switch(test_count) {
case 0:
dbg("=> IP address before network ready\n");
http_get("http://173.194.45.65", "", http_callback_example);
// This test will fail. The DHCP request returns directly, but the TCP connection hangs.
// FIXME: wait for network to be ready before connecting?
break;
case 1:
dbg("=> Simple GET\n");
http_get("http://wtfismyip.com/text", "", http_callback_example);
break;
case 2:
dbg("=> Response too long\n");
http_get("http://www.wikipedia.org/", "", http_callback_example);
break;
case 3:
dbg("=> Connection refused\n");
http_get("http://att.com:1234/", "", http_callback_example);
break;
case 4:
dbg("=> Empty response, wrong protocol\n");
http_get("http://google.com:443/", "", http_callback_example);
break;
case 5:
dbg("=> Invalid DNS\n");
http_get("http://invalid.dns/", "", http_callback_example);
break;
case 6:
dbg("=> Connection time out\n");
http_get("http://google.com:1234/", "", http_callback_example);
break;
case 7:
dbg("=> Simple POST\n");
http_post("http://httpbin.org/post", "first_word=hello&second_word=world", "Content-Type: application/x-www-form-urlencoded\r\n", http_callback_example);
break;
case 8:
dbg("=> Moved\n");
http_get("http://wikipedia.org/", "", http_callback_example);
break;
case 9:
dbg("=> IP address, 404\n");
http_get("http://54.200.182.206/", "", http_callback_example);
break;
case 10:
dbg("=> Concurrent requests\n");
http_get("http://wtfismyip.com/text", "", http_callback_example);
http_post("http://httpbin.org/post", "first_word=hello&second_word=world", "Content-Type: application/x-www-form-urlencoded\r\n", http_callback_example);
http_get("http://wtfismyip.com/text", "", http_callback_example);
http_post("http://httpbin.org/post", "first_word=hello&second_word=world", "Content-Type: application/x-www-form-urlencoded\r\n", http_callback_example);
http_get("http://wtfismyip.com/text", "", http_callback_example);
http_post("http://httpbin.org/post", "first_word=hello&second_word=world", "Content-Type: application/x-www-form-urlencoded\r\n", http_callback_example);
http_get("http://wtfismyip.com/text", "", http_callback_example);
// FIXME: this test sometimes fails with "DNS error code -1"
break;
default:
dbg("=> DONE\n");
return;
}
test_count++;
os_timer_arm(&test_timer, 3000, 0);
}
void ICACHE_FLASH_ATTR http_test()
{
// FIXME: what happens when no Wifi network is available?
os_timer_disarm(&test_timer);
os_timer_setfn(&test_timer, test_timer_cb, NULL);
os_timer_arm(&test_timer, 0, 0); // Start immediately.
}

96
libesphttpd/ESPHTTPD_README.md

@ -0,0 +1,96 @@
# esp-httpd README #
This is the demonstration project for the small but powerful libesphttpd webserver
for ESP8266(EX) chips. It is an example of how to make a module that can have
the AP it connects to configured over a webbrowser. It also illustrates multiple
flash layouts and some OTA update functionality.
## ABOUT THE WEBSERVER ##
The Good (aka: what's awesome)
- Supports multiple connections, for eg simultaneous html/css/js/images downloading
- Static files stored in flash, in an (optionally compressed) RO filesystem
- Pluggable using external cgi routines
- Simple template engine for mixed c and html things
- Usable as an embedded library - should be easy to drop into your existing projects
- Includes websocket support
The Bad (aka: what can be improved)
- Not built for speediness, although it's reasonable fast.
- Built according to what I remember of the HTTP protocol, not according to the
RFCs. Should work with most modern browsers, though.
- No support for https.
The Ugly (aka: bugs, misbehaviour)
- Possible buffer overflows (usually not remotely exploitable) due to no os_snprintf
This can be theoretically remedied by either Espressif including an os_snprintf in
their libs or by using some alternate printf lib, like elm-chans xprintf
## SOURCE OF THIS CODE ##
The official esphttpd repo lives at http://git.spritesserver.nl/esphttpd.git/ and
http://git.spritesserver.nl/libesphttpd.git/ . If you're a fan of Github, you can also
peruse the official mirror at https://github.com/Spritetm/esphttpd and https://github.com/Spritetm/libesphttpd . If
you want to discuss this code, there is a subforum at esp8266.com: http://www.esp8266.com/viewforum.php?f=34 .
## ABOUT THE EXAMPLE ##
When you flash the example into an ESP8266(EX) module, you get a small webserver with a few example
pages. If you've already connected your module to your WLAN before, it'll keep those settings. When
you haven't or the settings are wrong, keep GPIO0 for >5 seconds. The module will reboot into
its STA+AP mode. Connect a computer to the newly formed access point and browse to
http://192.168.4.1/wifi in order to connect the module to your WiFi network. The example also
allows you to control a LED that's connected to GPIO2.
## BUILDING EVERYTHING ##
For this, you need an environment that can compile ESP8266 firmware. Environments for this still
are in flux at the moment, but I'm using esp-open-sdk: https://github.com/pfalcon/esp-open-sdk .
You probably also need an UNIX-like system; I'm working on Debian Linux myself.
To manage the paths to all this, you can source a small shell fragment into your current session. For
example, I source a file with these contents:
export PATH=${PWD}/esp-open-sdk/xtensa-lx106-elf/bin:$PATH
export SDK_BASE=${PWD}/esp-open-sdk/sdk
export ESPTOOL=${PWD}/esptool/esptool.py
export ESPPORT=/dev/ttyUSB0
export ESPBAUD=460800
Actual setup of the SDK and toolchain is out of the scope of this document, so I hope this helps you
enough to set up your own if you haven't already.
If you have that, you can clone out the source code:
git clone http://git.spritesserver.nl/esphttpd.git/
This project makes use of heatshrink, which is a git submodule. To fetch the code:
cd esphttpd
git submodule init
git submodule update
Now, build the code:
make
Depending on the way you built it, esp-open-sdk sometimes patches Espressifs SDK, needing a slightly different
compiling process. If this is needed, you will get errors during compiling complaining about uint8_t being
undeclared. If this happens, try building like this:
make USE_OPENSDK=yes
You can also edit the Makefile to change this more permanently.
After the compile process, flash the code happens in 2 steps. First the code itself gets flashed. Reset the module into bootloader
mode and enter 'make flash'.
The 2nd step is to pack the static files the webserver will serve and flash that. Reset the module into
bootloader mode again and enter `make htmlflash`.
You should have a working webserver now.
## WRITING CODE FOR THE WEBSERVER ##
Please see the README.md of the libesphttpd project for the programming manual.

11
libesphttpd/LICENSE

@ -0,0 +1,11 @@
----------------------------------------------------------------------------
"THE BEER-WARE LICENSE" (Revision 42):
Jeroen Domburg <jeroen@spritesmods.com> wrote this file. As long as you retain
this notice you can do whatever you want with this stuff. If we meet some day,
and you think this stuff is worth it, you can buy me a beer in return.
----------------------------------------------------------------------------
Upstream: https://github.com/Spritetm/libesphttpd
Code heavily modified by Ondřej Hruška <ondra@ondrovo.com>.
Improvements will (possibly) be offered for merge later.

9
user/user_main.c

@ -46,15 +46,6 @@ static void ICACHE_FLASH_ATTR prSecondTimerCb(void *arg)
last = heap;
}
if (++cnt2 == 15) {
cnt2 = 0;
dbg("=> Simple GET");
//http_get("http://data.ondrovo.com/f/hello.txt", "", http_callback_example);
http_get("http://data.ondrovo.com/f/hello.txt", "", http_callback_example);
}
// we will also try to set up a SBMP connection
if (sbmp_ep_handshake_status(dlnk_ep) != SBMP_HSK_SUCCESS) {
sbmp_ep_start_handshake(dlnk_ep);

Loading…
Cancel
Save