|
|
@ -1,4 +1,6 @@ |
|
|
|
/*
|
|
|
|
/*
|
|
|
|
|
|
|
|
* Based on an example project for ESP-HTTPD. |
|
|
|
|
|
|
|
* |
|
|
|
* ---------------------------------------------------------------------------- |
|
|
|
* ---------------------------------------------------------------------------- |
|
|
|
* "THE BEER-WARE LICENSE" (Revision 42): |
|
|
|
* "THE BEER-WARE LICENSE" (Revision 42): |
|
|
|
* Jeroen Domburg <jeroen@spritesmods.com> wrote this file. As long as you retain |
|
|
|
* Jeroen Domburg <jeroen@spritesmods.com> wrote this file. As long as you retain |
|
|
@ -10,33 +12,25 @@ |
|
|
|
// library headers
|
|
|
|
// library headers
|
|
|
|
#include <esp8266.h> |
|
|
|
#include <esp8266.h> |
|
|
|
#include "httpd.h" |
|
|
|
#include "httpd.h" |
|
|
|
#include "httpdespfs.h" |
|
|
|
|
|
|
|
#include "cgiwifi.h" |
|
|
|
|
|
|
|
#include "cgiflash.h" |
|
|
|
|
|
|
|
#include "auth.h" |
|
|
|
|
|
|
|
#include "espfs.h" |
|
|
|
#include "espfs.h" |
|
|
|
#include "captdns.h" |
|
|
|
|
|
|
|
#include "webpages-espfs.h" |
|
|
|
#include "webpages-espfs.h" |
|
|
|
#include "cgiwebsocket.h" |
|
|
|
#include "captdns.h" |
|
|
|
|
|
|
|
|
|
|
|
// user files
|
|
|
|
|
|
|
|
#include "cgi.h" |
|
|
|
|
|
|
|
#include "serial.h" |
|
|
|
#include "serial.h" |
|
|
|
#include "io.h" |
|
|
|
#include "io.h" |
|
|
|
#include "datalink.h" |
|
|
|
#include "datalink.h" |
|
|
|
#include "uart_driver.h" |
|
|
|
|
|
|
|
#include "uptime.h" |
|
|
|
#include "uptime.h" |
|
|
|
|
|
|
|
#include "routes.h" |
|
|
|
|
|
|
|
|
|
|
|
#include "page_home.h" |
|
|
|
extern HttpdBuiltInUrl builtInUrls[]; |
|
|
|
#include "sampling.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "sbmp.h" |
|
|
|
static ETSTimer prSecondTimer; |
|
|
|
|
|
|
|
|
|
|
|
static ETSTimer prHeapTimer; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Timer called each second */ |
|
|
|
/** Timer called each second */ |
|
|
|
static void ICACHE_FLASH_ATTR prHeapTimerCb(void *arg) |
|
|
|
static void ICACHE_FLASH_ATTR prSecondTimerCb(void *arg) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
(void)arg; |
|
|
|
|
|
|
|
|
|
|
|
static u8 cnt = 0; |
|
|
|
static u8 cnt = 0; |
|
|
|
static u32 last = 0; |
|
|
|
static u32 last = 0; |
|
|
|
|
|
|
|
|
|
|
@ -54,41 +48,6 @@ static void ICACHE_FLASH_ATTR prHeapTimerCb(void *arg) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @brief BasicAuth name/password checking function. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* It's invoked by the authBasic() built-in route handler |
|
|
|
|
|
|
|
* until it returns 0. Each time it populates the provided |
|
|
|
|
|
|
|
* name and password buffer. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param connData : connection context |
|
|
|
|
|
|
|
* @param no : user number (incremented each time it's called) |
|
|
|
|
|
|
|
* @param user : user buffer |
|
|
|
|
|
|
|
* @param userLen : user buffer size |
|
|
|
|
|
|
|
* @param pass : password buffer |
|
|
|
|
|
|
|
* @param passLen : password buffer size |
|
|
|
|
|
|
|
* @return 0 to end, 1 if more users are available. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
int FLASH_FN myPassFn(HttpdConnData *connData, int no, char *user, int userLen, char *pass, int passLen) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
(void)connData; |
|
|
|
|
|
|
|
(void)userLen; |
|
|
|
|
|
|
|
(void)passLen; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (no == 0) { |
|
|
|
|
|
|
|
os_strcpy(user, "admin"); |
|
|
|
|
|
|
|
os_strcpy(pass, "s3cr3t"); |
|
|
|
|
|
|
|
return 1; |
|
|
|
|
|
|
|
//Add more users this way. Check against incrementing no for each user added.
|
|
|
|
|
|
|
|
// } else if (no==1) {
|
|
|
|
|
|
|
|
// os_strcpy(user, "user1");
|
|
|
|
|
|
|
|
// os_strcpy(pass, "something");
|
|
|
|
|
|
|
|
// return 1;
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Some stuff for alternative ESPFS storage methods
|
|
|
|
// Some stuff for alternative ESPFS storage methods
|
|
|
|
#ifdef ESPFS_POS |
|
|
|
#ifdef ESPFS_POS |
|
|
|
CgiUploadFlashDef uploadParams = { |
|
|
|
CgiUploadFlashDef uploadParams = { |
|
|
@ -99,6 +58,7 @@ CgiUploadFlashDef uploadParams = { |
|
|
|
}; |
|
|
|
}; |
|
|
|
#define INCLUDE_FLASH_FNS |
|
|
|
#define INCLUDE_FLASH_FNS |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
#ifdef OTA_FLASH_SIZE_K |
|
|
|
#ifdef OTA_FLASH_SIZE_K |
|
|
|
CgiUploadFlashDef uploadParams = { |
|
|
|
CgiUploadFlashDef uploadParams = { |
|
|
|
.type = CGIFLASH_TYPE_FW, |
|
|
|
.type = CGIFLASH_TYPE_FW, |
|
|
@ -111,56 +71,6 @@ CgiUploadFlashDef uploadParams = { |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* This is the main url->function dispatching data struct. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* In short, it's a struct with various URLs plus their handlers. The handlers can |
|
|
|
|
|
|
|
* be 'standard' CGI functions you wrote, or 'special' CGIs requiring an argument. |
|
|
|
|
|
|
|
* They can also be auth-functions. An asterisk will match any url starting with |
|
|
|
|
|
|
|
* everything before the asterisks; "*" matches everything. The list will be |
|
|
|
|
|
|
|
* handled top-down, so make sure to put more specific rules above the more |
|
|
|
|
|
|
|
* general ones. Authorization things (like authBasic) act as a 'barrier' and |
|
|
|
|
|
|
|
* should be placed above the URLs they protect. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static HttpdBuiltInUrl builtInUrls[] = { |
|
|
|
|
|
|
|
ROUTE_CGI_ARG("*", cgiRedirectApClientToHostname, "esp8266.nonet"), // redirect func for the captive portal
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ROUTE_TPL_FILE("/", tplHome, "/pages/home.tpl"), |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ROUTE_CGI("/acquire.cgi", cgiReadSamples), |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ROUTE_TPL_FILE("/multipart", tplMultipart, "/multipart.tpl"), |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Enable the line below to protect the WiFi configuration with an username/password combo.
|
|
|
|
|
|
|
|
// ROUTE_AUTH("/wifi/*", myPassFn),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ROUTE_REDIRECT("/wifi/", "/wifi"), |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ROUTE_TPL_FILE("/wifi", tplWlan, "/pages/wifi.tpl"), |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ROUTE_CGI("/wifi/scan.cgi", cgiWiFiScan), |
|
|
|
|
|
|
|
ROUTE_CGI("/wifi/connect.cgi", cgiWiFiConnect), |
|
|
|
|
|
|
|
ROUTE_CGI("/wifi/connstatus.cgi", cgiWiFiConnStatus), |
|
|
|
|
|
|
|
ROUTE_CGI("/wifi/setmode.cgi", cgiWiFiSetMode), |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ROUTE_FS("*"), //Catch-all cgi function for the filesystem
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ROUTE_END() |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//static ETSTimer prTestTimer;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//static void ICACHE_FLASH_ATTR test_timer_task(void *arg) {
|
|
|
|
|
|
|
|
// const char * t = "Test\r\n";
|
|
|
|
|
|
|
|
// UART_WriteBuffer(0, (uint8_t*)t, strlen(t), 1000);
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define STR_HELPER(x) #x |
|
|
|
|
|
|
|
#define STR(x) STR_HELPER(x) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Main routine. Initialize stdout, the I/O, filesystem and the webserver and we're done. |
|
|
|
* Main routine. Initialize stdout, the I/O, filesystem and the webserver and we're done. |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -170,10 +80,10 @@ void user_init(void) |
|
|
|
serialInit(); |
|
|
|
serialInit(); |
|
|
|
uptime_timer_init(); |
|
|
|
uptime_timer_init(); |
|
|
|
|
|
|
|
|
|
|
|
banner("\n*** ESP8266 starting, " |
|
|
|
banner("*** ESP8266 starting ***"); |
|
|
|
"HTTPD v."HTTPDVER", " |
|
|
|
info("HTTPD v."HTTPDVER", SBMP v."SBMP_VER", IoT SDK v."STR(ESP_SDK_VERSION)); |
|
|
|
"SBMP v."SBMP_VER", " |
|
|
|
printf(LOG_EOL); |
|
|
|
"IoT SDK v." STR(ESP_SDK_VERSION)" ***\n"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// reset button etc
|
|
|
|
// reset button etc
|
|
|
|
ioInit(); |
|
|
|
ioInit(); |
|
|
@ -196,15 +106,11 @@ void user_init(void) |
|
|
|
|
|
|
|
|
|
|
|
httpdInit(builtInUrls, 80); |
|
|
|
httpdInit(builtInUrls, 80); |
|
|
|
|
|
|
|
|
|
|
|
info("\nReady\n"); |
|
|
|
printf(LOG_EOL); |
|
|
|
|
|
|
|
info("Ready"); |
|
|
|
os_timer_disarm(&prHeapTimer); |
|
|
|
printf(LOG_EOL); |
|
|
|
os_timer_setfn(&prHeapTimer, prHeapTimerCb, NULL); |
|
|
|
|
|
|
|
os_timer_arm(&prHeapTimer, 1000, 1); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
os_timer_disarm(&prSecondTimer); |
|
|
|
void user_rf_pre_init() |
|
|
|
os_timer_setfn(&prSecondTimer, prSecondTimerCb, NULL); |
|
|
|
{ |
|
|
|
os_timer_arm(&prSecondTimer, 1000, 1); |
|
|
|
//Not needed, but some SDK versions want this defined.
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|