Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ $product_id = '0x2303'

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
VM_DISPLAY_NAME = "ESP8266-DEV"
VM_HOSTNAME = "esp8266-dev"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

config.vm.hostname = VM_HOSTNAME
config.vm.box = "hashicorp/precise32"
config.vm.provision :shell, path: "vm-bootstrap.sh", privileged: false

config.vm.provider :virtualbox do |vb|
vb.customize ['modifyvm', :id, '--usb', 'on']
vb.customize ["modifyvm", :id, "--name", VM_DISPLAY_NAME]
vb.name = VM_DISPLAY_NAME
vb.customize ['usbfilter', 'add', '0', '--target', :id, '--name', 'USB_to_TTL_converter', '--vendorid', $vendor_id, '--productid', $product_id]
end

Expand Down
33 changes: 20 additions & 13 deletions esphttpd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,39 @@ XTENSA_TOOLS_ROOT ?= /opt/Espressif/crosstool-NG/builds/xtensa-lx106-elf/bin

#Extra Tensilica includes from the ESS VM
SDK_EXTRA_INCLUDES ?= /opt/Espressif/include
SDK_EXTRA_LIBS ?= /opt/Espressif/arch/lib

# base directory of the ESP8266 SDK package, absolute
SDK_BASE ?= /opt/Espressif/ESP8266_SDK

#Esptool.py path and port
ESPTOOL ?= ../esptool.py
ESPTOOL ?= esptool
ESPPORT ?= /dev/ttyUSB0
#ESPDELAY indicates seconds to wait between flashing the two binary images
ESPDELAY ?= 3
ESPBAUD ?= 115200

# name for the target project
TARGET = httpd

# which modules (subdirectories) of the project to include in compiling
#MODULES = driver user lwip/api lwip/app lwip/core lwip/core/ipv4 lwip/netif
MODULES = driver user
EXTRA_INCDIR = include \
. \
lib/heatshrink/ \
$(SDK_EXTRA_INCLUDES)

# libraries used in this project, mainly provided by the SDK
LIBS = c gcc hal phy net80211 lwip wpa main
LIBS = c gcc hal phy pp net80211 wpa main lwip

# compiler flags using during compilation of source files
CFLAGS = -Os -ggdb -std=c99 -Werror -Wpointer-arith -Wundef -Wall -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH
CFLAGS = -Os -ggdb -std=c99 -Werror -Wpointer-arith -Wundef -Wall -Wl,-EL -fno-inline-functions \
-nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH \
-Wno-address

# linker flags used to generate the main object file
LDFLAGS = -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static
LDFLAGS = -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static -L$(SDK_EXTRA_LIBS)

# linker script used for the above linkier step
LD_SCRIPT = eagle.app.v6.ld
Expand All @@ -68,7 +75,6 @@ LD := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-gcc
####
#### no user configurable options below here
####
FW_TOOL ?= /usr/bin/esptool
SRC_DIR := $(MODULES)
BUILD_DIR := $(addprefix $(BUILD_BASE)/,$(MODULES))

Expand Down Expand Up @@ -113,11 +119,11 @@ all: checkdirs $(TARGET_OUT) $(FW_FILE_1) $(FW_FILE_2)

$(FW_FILE_1): $(TARGET_OUT) firmware
$(vecho) "FW $@"
$(Q) $(FW_TOOL) -eo $(TARGET_OUT) $(FW_FILE_1_ARGS)
$(Q) $(ESPTOOL) -eo $(TARGET_OUT) $(FW_FILE_1_ARGS)

$(FW_FILE_2): $(TARGET_OUT) firmware
$(vecho) "FW $@"
$(Q) $(FW_TOOL) -eo $(TARGET_OUT) $(FW_FILE_2_ARGS)
$(Q) $(ESPTOOL) -eo $(TARGET_OUT) $(FW_FILE_2_ARGS)

$(TARGET_OUT): $(APP_AR)
$(vecho) "LD $@"
Expand All @@ -136,19 +142,20 @@ firmware:
$(Q) mkdir -p $@

flash: $(FW_FILE_1) $(FW_FILE_2)
-$(ESPTOOL) --port $(ESPPORT) write_flash 0x00000 firmware/0x00000.bin
sleep 3
-$(ESPTOOL) --port $(ESPPORT) write_flash 0x40000 firmware/0x40000.bin
$(Q) $(ESPTOOL) -cp $(ESPPORT) -cb $(ESPBAUD) -ca 0x00000 -cf firmware/0x00000.bin -v
$(Q) [ $(ESPDELAY) -ne 0 ] && echo "Please put the ESP in bootloader mode..." || true
$(Q) sleep $(ESPDELAY) || true
$(Q) $(ESPTOOL) -cp $(ESPPORT) -cb $(ESPBAUD) -ca 0x40000 -cf firmware/0x40000.bin -v

webpages.espfs: html/ mkespfsimage/mkespfsimage
cd html; find | ../mkespfsimage/mkespfsimage > ../webpages.espfs; cd ..
webpages.espfs: html/ html/wifi/ mkespfsimage/mkespfsimage
cd html; find | ../mkespfsimage/mkespfsimage > ../webpages.espfs; cd ..

mkespfsimage/mkespfsimage: mkespfsimage/
make -C mkespfsimage

htmlflash: webpages.espfs
if [ $$(stat -c '%s' webpages.espfs) -gt $$(( 0x2E000 )) ]; then echo "webpages.espfs too big!"; false; fi
-$(ESPTOOL) --port $(ESPPORT) write_flash 0x12000 webpages.espfs
$(ESPTOOL) -cp $(ESPPORT) -cb $(ESPBAUD) -ca 0x12000 -cf webpages.espfs -v

clean:
$(Q) rm -f $(APP_AR)
Expand Down
17 changes: 13 additions & 4 deletions esphttpd/README
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ 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 authentication or https.
- No support for https.

The Ugly (aka: bugs, misbehaviour)
- Possible buffer overflows (usually not remotely exploitable) due to no os_snprintf
Expand All @@ -35,14 +35,14 @@ 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 a crosstool-ng gcc setup combined with the libs & includes
from the ESP SDK and ESP VM. You probably also need an UNIX-slike system; I'm working on
from the ESP SDK and ESP VM. 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}/crosstool-NG/builds/xtensa-lx106-elf/bin:$PATH
export XTENSA_TOOLS_ROOT=${PWD}/crosstool-NG/builds/xtensa-lx106-elf/bin
export SDK_BASE=${PWD}/esp_iot_sdk_v0.9.2/
export SDK_BASE=${PWD}/esp_iot_sdk_v0.9.5/
export SDK_EXTRA_INCLUDES=${PWD}/esp_iot_sdk_novm_unpacked/usr/xtensa/XtDevTools/install/builds/RC-2010.1-win32/lx106/xtensa-elf/include/
export ESPTOOL=${PWD}/esptool/esptool.py
export ESPPORT=/dev/ttyUSB0
Expand All @@ -57,7 +57,6 @@ cd esphttpd
git submodule init
git submodule update


Now, build the code:
make

Expand All @@ -76,3 +75,13 @@ WRITING CODE FOR THE WEBSERVER
the SDK works, this shouldn't be too hard :P


CHANGE FROM SDK 0.9.3 (and earlier) TO SDK 0.9.4:
Change all occurences of
espconn_sent(connData->conn, (uint8 *)buff, len);
to
httpdSend(connData, buff, len)
please. The reason for this is that you can't do multiple espconn_sent calls serially anymore, so
httpd needs to buffer the writes now. This is only needed in your own code; the code that comes
with httpd already has this changed.


1 change: 1 addition & 0 deletions esphttpd/html/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ body {
margin: 0 auto;
padding: 20px
}

Binary file added esphttpd/html/wifi/icons.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions esphttpd/html/wifi/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,11 @@ body {
margin: 0 auto;
padding: 20px
}

.icon {
background-image: url("icons.png");
background-color: transparent;
width: 32px;
height: 32px;
display: inline-block;
}
17 changes: 16 additions & 1 deletion esphttpd/html/wifi/wifi.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ function createInputForAp(ap) {
if (ap.essid=="" && ap.rssi==0) return;
var div=document.createElement("div");
div.id="apdiv";
var rssi=document.createElement("div");
var rssiVal=-Math.floor(ap.rssi/51)*32;
rssi.className="icon";
rssi.style.backgroundPosition="0px "+rssiVal+"px";
var encrypt=document.createElement("div");
var encVal="-64"; //assume wpa/wpa2
if (ap.enc=="0") encVal="0"; //open
if (ap.enc=="1") encVal="-32"; //wep
encrypt.className="icon";
encrypt.style.backgroundPosition="-32px "+encVal+"px";
var input=document.createElement("input");
input.type="radio";
input.name="essid";
Expand All @@ -18,8 +28,10 @@ function createInputForAp(ap) {
input.id="opt-"+ap.essid;
var label=document.createElement("label");
label.htmlFor="opt-"+ap.essid;
label.textContent=ap.essid+" (rssi "+ap.rssi+")";
label.textContent=ap.essid;
div.appendChild(input);
div.appendChild(rssi);
div.appendChild(encrypt);
div.appendChild(label);
return div;
}
Expand Down Expand Up @@ -65,6 +77,9 @@ window.onload=function(e) {
<p>
Current WiFi mode: %WiFiMode%
</p>
<p>
Note: %WiFiapwarn%
</p>
<form name="wifiform" action="connect.cgi" method="post">
<p>
To connect to a WiFi network, please select one of the detected networks...<br>
Expand Down
14 changes: 12 additions & 2 deletions esphttpd/include/espmissingincludes.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#ifndef ESPMISSINGINCLUIDES_H
#define ESPMISSINGINCLUIDES_H
#ifndef ESPMISSINGINCLUDES_H
#define ESPMISSINGINCLUDES_H

#include <ets_sys.h>
#include <stdint.h>

//Missing function prototypes in include folders. Gcc will warn on these if we don't define 'em anywhere.
//MOST OF THESE ARE GUESSED! but they seem to swork and shut up the compiler.
typedef struct espconn espconn;

int atoi(const char *nptr);
void ets_install_putc1(void *routine);
Expand All @@ -25,12 +27,20 @@ char *ets_strstr(const char *haystack, const char *needle);
void ets_timer_arm_new(ETSTimer *a, int b, int c, int isMstimer);
void ets_timer_disarm(ETSTimer *a);
void ets_timer_setfn(ETSTimer *t, ETSTimerFunc *fn, void *parg);
void ets_update_cpu_frequency(int freqmhz);
int os_printf(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
int os_snprintf(char *str, size_t size, const char *format, ...) __attribute__ ((format (printf, 3, 4)));
int os_printf_plus(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
void pvPortFree(void *ptr);
void *pvPortMalloc(size_t xWantedSize);
void *pvPortZalloc(size_t);
void uart_div_modify(int no, unsigned int freq);
void vPortFree(void *ptr);
void *vPortMalloc(size_t xWantedSize);
uint8 wifi_get_opmode(void);
uint32 system_get_time();
int os_random();
int rand(void);
void ets_bzero(void *s, size_t n);
void ets_delay_us(int ms);
#endif
3 changes: 3 additions & 0 deletions esphttpd/include/httpdconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@

//Pos of esp fs in flash
#define ESPFS_POS 0x12000

//If you want, you can define a realm for the authentication system.
//#define HTTP_AUTH_REALM "MyRealm"
Loading