most of the wifi functionality working, + new style

This commit is contained in:
2017-01-26 04:38:19 +01:00
parent c9b03ebca1
commit 1a33084041
144 changed files with 10475 additions and 459 deletions
+4
View File
@@ -32,8 +32,12 @@ void ICACHE_FLASH_ATTR screen_notifyChange()
/** Socket received a message */
void ICACHE_FLASH_ATTR updateSockRx(Websock *ws, char *data, int len, int flags)
{
// Add terminator if missing (seems to randomly happen)
data[len] = 0;
dbg("Sock RX str: %s, len %d", data, len);
if (strstarts(data, "STR:")) {
// pass string verbatim
UART_WriteString(UART0, data+4, UART_TIMEOUT_US);
+11 -37
View File
@@ -12,24 +12,21 @@
#include "cgi_main.h"
#include "cgi_sockets.h"
#define WIFI_PROTECT 1
#define WIFI_AUTH_NAME "admin"
#define WIFI_AUTH_PASS "password"
#define WIFI_PROTECT 0
#define WIFI_AUTH_NAME "wifi"
#define WIFI_AUTH_PASS "nicitel"
#if WIFI_PROTECT
static int ICACHE_FLASH_ATTR wifiPassFn(HttpdConnData *connData, int no, char *user, int userLen, char *pass,
int passLen);
#endif
static int wifiPassFn(HttpdConnData *connData, int no, char *user, int userLen, char *pass, int passLen);
/**
* Application routes
*/
HttpdBuiltInUrl builtInUrls[] = {
HttpdBuiltInUrl routes[] = {
// redirect func for the captive portal
ROUTE_CGI_ARG("*", cgiRedirectApClientToHostname, "esp8266.nonet"),
ROUTE_CGI_ARG("*", cgiRedirectApClientToHostname, "esp-remote-term.ap"),
// --- Web pages ---
ROUTE_TPL_FILE("/", tplScreen, "term.tpl"),
ROUTE_TPL_FILE("/", tplScreen, "/term.tpl"),
// --- Sockets ---
ROUTE_WS(URL_WS_UPDATE, updateSockConnect),
@@ -42,15 +39,15 @@ HttpdBuiltInUrl builtInUrls[] = {
#if WIFI_PROTECT
ROUTE_AUTH("/wifi*", wifiPassFn),
#endif
// TODO add those pages
// ROUTE_REDIRECT("/wifi/", "/wifi"),
// ROUTE_TPL_FILE("/wifi", tplWlan, "/pages/wifi.tpl"),
ROUTE_REDIRECT("/wifi/", "/wifi"),
ROUTE_TPL_FILE("/wifi", tplWlan, "/wifi.tpl"),
ROUTE_CGI("/wifi/scan", cgiWiFiScan),
ROUTE_CGI("/wifi/connect", cgiWiFiConnect),
ROUTE_CGI("/wifi/connstatus", cgiWiFiConnStatus),
ROUTE_CGI("/wifi/setmode", cgiWiFiSetMode),
ROUTE_CGI("/wifi/setchannel", cgiWiFiSetChannel),
ROUTE_CGI("/wifi/setname", cgiWiFiSetSSID),
ROUTE_FILESYSTEM(),
ROUTE_END(),
@@ -58,38 +55,15 @@ HttpdBuiltInUrl builtInUrls[] = {
// --- Wifi password protection ---
#if WIFI_PROTECT
/**
* @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.
* Password for WiFi config
*/
static int ICACHE_FLASH_ATTR wifiPassFn(HttpdConnData *connData, int no, char *user, int userLen, char *pass, int passLen)
{
(void)connData;
(void)userLen;
(void)passLen;
if (no == 0) {
os_strcpy(user, WIFI_AUTH_NAME);
os_strcpy(pass, WIFI_AUTH_PASS);
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;
}
#endif
+1 -1
View File
@@ -4,7 +4,7 @@
#include <esp8266.h>
#include <httpd.h>
extern HttpdBuiltInUrl builtInUrls[];
extern HttpdBuiltInUrl routes[];
/** Broadcast screen state to sockets */
void screen_notifyChange();
+7 -4
View File
@@ -23,7 +23,7 @@
#include "screen.h"
#include "routes.h"
#define FIRMWARE_VERSION "0.1"
#define FIRMWARE_VERSION "0.2"
#ifdef ESPFS_POS
CgiUploadFlashDef uploadParams={
@@ -50,11 +50,14 @@ static ETSTimer prHeapTimer;
/** Periodically show heap usage */
static void ICACHE_FLASH_ATTR prHeapTimerCb(void *arg)
{
static unsigned int cnt = 0;
static uint32_t cnt = 0;
static uint32_t last = 0;
if (cnt == 5) {
dbg("HEAP: %ld bytes free", (unsigned long) system_get_free_heap_size());
uint32_t heap = system_get_free_heap_size();
dbg("Free heap: %d bytes (~ %d)", heap, (heap-last));
cnt = 0;
last = heap;
}
cnt++;
@@ -89,7 +92,7 @@ void ICACHE_FLASH_ATTR user_init(void)
captdnsInit();
// Server
httpdInit(builtInUrls, 80);
httpdInit(routes, 80);
// Heap use timer & blink
os_timer_disarm(&prHeapTimer);