diff --git a/Makefile b/Makefile index 4923b20..b101aae 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,7 @@ 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 @@ -28,6 +29,7 @@ ESPPORT ?= /dev/ttyUSB0 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 \ . \ @@ -35,13 +37,15 @@ EXTRA_INCDIR = include \ $(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 \ + -DLWIP_OPEN_SRC -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 @@ -141,7 +145,7 @@ flash: $(FW_FILE_1) $(FW_FILE_2) -$(ESPTOOL) --port $(ESPPORT) write_flash 0x40000 firmware/0x40000.bin webpages.espfs: html/ mkespfsimage/mkespfsimage - cd html; find | ../mkespfsimage/mkespfsimage > ../webpages.espfs; cd .. + cd html; find | ../mkespfsimage/mkespfsimage > ../webpages.espfs; cd .. mkespfsimage/mkespfsimage: mkespfsimage/ make -C mkespfsimage diff --git a/include/espmissingincludes.h b/include/espmissingincludes.h index c8a0f24..2f12772 100644 --- a/include/espmissingincludes.h +++ b/include/espmissingincludes.h @@ -1,10 +1,12 @@ -#ifndef ESPMISSINGINCLUIDES_H -#define ESPMISSINGINCLUIDES_H +#ifndef ESPMISSINGINCLUDES_H +#define ESPMISSINGINCLUDES_H #include +#include //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); @@ -33,4 +35,9 @@ 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); #endif diff --git a/mkespfsimage/main.c b/mkespfsimage/main.c index b636ef4..e2e210d 100644 --- a/mkespfsimage/main.c +++ b/mkespfsimage/main.c @@ -36,7 +36,7 @@ int htoxl(int in) { size_t compressHeatshrink(char *in, int insize, char *out, int outsize, int level) { char *inp=in; char *outp=out; - int len; + size_t len; int ws[]={5, 6, 8, 11, 13}; int ls[]={3, 3, 4, 4, 4}; HSE_poll_res pres; diff --git a/user/cgi.c b/user/cgi.c index 384bde4..c489408 100644 --- a/user/cgi.c +++ b/user/cgi.c @@ -20,6 +20,7 @@ Some random cgi routines. #include "cgi.h" #include "io.h" #include "espmissingincludes.h" +#include //cause I can't be bothered to write an ioGetLed() static char currLedState=0; diff --git a/user/cgiwifi.c b/user/cgiwifi.c index a6bba43..2cf8418 100644 --- a/user/cgiwifi.c +++ b/user/cgiwifi.c @@ -28,9 +28,9 @@ typedef struct { char enc; } ApData; -//Scan resolt +//Scan result typedef struct { - char scanInProgress; + char scanInProgress; //if 1, don't access the underlying stuff from the webpage. ApData **apData; int noAps; } ScanResultData; @@ -46,7 +46,6 @@ void ICACHE_FLASH_ATTR wifiScanDoneCb(void *arg, STATUS status) { os_printf("wifiScanDoneCb %d\n", status); if (status!=OK) { cgiWifiAps.scanInProgress=0; - wifi_station_disconnect(); //test HACK return; } @@ -65,11 +64,16 @@ void ICACHE_FLASH_ATTR wifiScanDoneCb(void *arg, STATUS status) { //Allocate memory for access point data cgiWifiAps.apData=(ApData **)os_malloc(sizeof(ApData *)*n); cgiWifiAps.noAps=n; + os_printf("Scan done: found %d APs\n", n); //Copy access point data to the static struct n=0; bss_link = (struct bss_info *)arg; while (bss_link != NULL) { + if (n>=cgiWifiAps.noAps) { + os_printf("Huh? I have more than the allocated %d aps!\n", cgiWifiAps.noAps); + break; + } cgiWifiAps.apData[n]=(ApData *)os_malloc(sizeof(ApData)); cgiWifiAps.apData[n]->rssi=bss_link->rssi; cgiWifiAps.apData[n]->enc=bss_link->authmode; @@ -78,7 +82,6 @@ void ICACHE_FLASH_ATTR wifiScanDoneCb(void *arg, STATUS status) { bss_link = bss_link->next.stqe_next; n++; } - os_printf("Scan done: found %d APs\n", n); //We're done. cgiWifiAps.scanInProgress=0; } @@ -86,14 +89,17 @@ void ICACHE_FLASH_ATTR wifiScanDoneCb(void *arg, STATUS status) { //Routine to start a WiFi access point scan. static void ICACHE_FLASH_ATTR wifiStartScan() { - int x; +// int x; + if (cgiWifiAps.scanInProgress) return; cgiWifiAps.scanInProgress=1; +/* x=wifi_station_get_connect_status(); if (x!=STATION_GOT_IP) { //Unit probably is trying to connect to a bogus AP. This messes up scanning. Stop that. os_printf("STA status = %d. Disconnecting STA...\n", x); wifi_station_disconnect(); } +*/ wifi_station_scan(NULL, wifiScanDoneCb); } @@ -137,6 +143,7 @@ static void ICACHE_FLASH_ATTR resetTimerCb(void *arg) { int x=wifi_station_get_connect_status(); if (x==STATION_GOT_IP) { //Go to STA mode. This needs a reset, so do that. + os_printf("Got IP. Going into STA mode..\n"); wifi_set_opmode(1); system_restart(); } else { @@ -150,6 +157,7 @@ static void ICACHE_FLASH_ATTR resetTimerCb(void *arg) { static void ICACHE_FLASH_ATTR reassTimerCb(void *arg) { int x; static ETSTimer resetTimer; + os_printf("Try to connect to AP....\n"); wifi_station_disconnect(); wifi_station_set_config(&stconf); wifi_station_connect(); @@ -180,11 +188,12 @@ int ICACHE_FLASH_ATTR cgiWiFiConnect(HttpdConnData *connData) { os_strncpy((char*)stconf.ssid, essid, 32); os_strncpy((char*)stconf.password, passwd, 64); + os_printf("Try to connect to AP %s pw %s\n", essid, passwd); //Schedule disconnect/connect os_timer_disarm(&reassTimer); os_timer_setfn(&reassTimer, reassTimerCb, NULL); -#if 0 +#if 1 os_timer_arm(&reassTimer, 1000, 0); httpdRedirect(connData, "connecting.html"); diff --git a/user/espfs.c b/user/espfs.c index 59f8643..81828e0 100644 --- a/user/espfs.c +++ b/user/espfs.c @@ -131,6 +131,7 @@ EspFsFile ICACHE_FLASH_ATTR *espFsOpen(char *fileName) { //Yay, this is the file we need! p+=h.nameLen; //Skip to content. r=(EspFsFile *)os_malloc(sizeof(EspFsFile)); //Alloc file desc mem +// os_printf("Alloc %p\n", r); if (r==NULL) return NULL; r->header=(EspFsHeader *)hpos; r->decompressor=h.compression; @@ -186,6 +187,7 @@ int ICACHE_FLASH_ATTR espFsRead(EspFsFile *fh, char *buff, int len) { unsigned int elen, rlen; char ebuff[16]; heatshrink_decoder *dec=(heatshrink_decoder *)fh->decompData; +// os_printf("Alloc %p\n", dec); while(decodeddecompressor==COMPRESS_HEATSHRINK) { - heatshrink_decoder_free((heatshrink_decoder*)fh->decompData); + heatshrink_decoder *dec=(heatshrink_decoder *)fh->decompData; + heatshrink_decoder_free(dec); +// os_printf("Freed %p\n", dec); } #endif +// os_printf("Freed %p\n", fh); os_free(fh); } diff --git a/user/heatshrink_decoder.c b/user/heatshrink_decoder.c index 763a318..51e0852 100644 --- a/user/heatshrink_decoder.c +++ b/user/heatshrink_decoder.c @@ -13,7 +13,6 @@ #include "mem.h" #include "osapi.h" #include "heatshrink_config_httpd.h" -#define malloc(x) os_malloc(x) #define memset(x,y,z) os_memset(x,y,z) #define memcpy(x,y,z) os_memcpy(x,y,z) #include "../lib/heatshrink/heatshrink_decoder.c" diff --git a/user/httpd.h b/user/httpd.h index cea277d..e9505c9 100644 --- a/user/httpd.h +++ b/user/httpd.h @@ -1,7 +1,7 @@ #ifndef HTTPD_H #define HTTPD_H -#include #include +#include "lwip/ip_addr.h" #include #define HTTPD_CGI_MORE 0 diff --git a/user/user_main.c b/user/user_main.c index abb9476..b5b414b 100644 --- a/user/user_main.c +++ b/user/user_main.c @@ -41,6 +41,7 @@ HttpdBuiltInUrl builtInUrls[]={ void user_init(void) { stdoutInit(); + os_printf("HTTPD EXAMPLE START\n"); ioInit(); httpdInit(builtInUrls, 80); os_printf("\nReady\n");