Refactored web-server

pull/193/head
Karai Csaba 9 years ago committed by Thorsten von Eicken
parent 89a9ff0d24
commit f6f1fbb926
  1. 2
      cmd/cmd.h
  2. 2
      cmd/handlers.c
  3. 2
      esp-link/cgi.c
  4. 2
      esp-link/cgiwebserver.c
  5. 4
      esp-link/main.c
  6. 2
      examples/arduino/EspLinkSample/EspLink.h
  7. 14
      web-server/web-server.c
  8. 8
      web-server/web-server.h

@ -49,7 +49,7 @@ typedef enum {
CMD_REST_REQUEST, CMD_REST_REQUEST,
CMD_REST_SETHEADER, CMD_REST_SETHEADER,
CMD_WEB_DATA = 30, CMD_WEB_JSON_DATA = 30,
CMD_WEB_REQ_CB, CMD_WEB_REQ_CB,
} CmdName; } CmdName;

@ -12,6 +12,7 @@
#ifdef REST #ifdef REST
#include <rest.h> #include <rest.h>
#endif #endif
#include <web-server.h>
#ifdef CMD_DBG #ifdef CMD_DBG
#define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__); } while(0) #define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__); } while(0)
@ -47,6 +48,7 @@ const CmdList commands[] = {
{CMD_REST_REQUEST, "REST_REQ", REST_Request}, {CMD_REST_REQUEST, "REST_REQ", REST_Request},
{CMD_REST_SETHEADER, "REST_SETHDR", REST_SetHeader}, {CMD_REST_SETHEADER, "REST_SETHDR", REST_SetHeader},
#endif #endif
{CMD_WEB_JSON_DATA, "WEB_JSON_DATA", WEB_JsonData},
}; };
//===== List of registered callbacks (to uC) //===== List of registered callbacks (to uC)

@ -222,7 +222,7 @@ int ICACHE_FLASH_ATTR cgiMenu(HttpdConnData *connData) {
"\"version\": \"%s\", " "\"version\": \"%s\", "
"\"name\": \"%s\"" "\"name\": \"%s\""
" }", " }",
webServerUserPages(), esp_link_version, name); WEB_UserPages(), esp_link_version, name);
httpdSend(connData, buff, -1); httpdSend(connData, buff, -1);
return HTTPD_CGI_DONE; return HTTPD_CGI_DONE;

@ -60,7 +60,7 @@ int ICACHE_FLASH_ATTR webServerMultipartCallback(MultipartCmd cmd, char *data, i
{ {
uint32_t magic = ESPFS_MAGIC; uint32_t magic = ESPFS_MAGIC;
spi_flash_write( (int)getUserPageSectionStart(), (uint32_t *)&magic, sizeof(uint32_t) ); spi_flash_write( (int)getUserPageSectionStart(), (uint32_t *)&magic, sizeof(uint32_t) );
webServerInit(); WEB_Init();
} }
break; break;
} }

@ -100,7 +100,7 @@ HttpdBuiltInUrl builtInUrls[] = {
{ "/mqtt", cgiMqtt, NULL }, { "/mqtt", cgiMqtt, NULL },
#endif #endif
{ "/web-server/upload", cgiWebServerUpload, NULL }, { "/web-server/upload", cgiWebServerUpload, NULL },
{ "*.json", cgiJsonHook, NULL }, //Catch-all cgi JSON queries { "*.json", WEB_CgiJsonHook, NULL }, //Catch-all cgi JSON queries
{ "*", cgiEspFsHook, NULL }, //Catch-all cgi function for the filesystem { "*", cgiEspFsHook, NULL }, //Catch-all cgi function for the filesystem
{ NULL, NULL, NULL } { NULL, NULL, NULL }
}; };
@ -159,7 +159,7 @@ void user_init(void) {
//os_printf("espFsInit %s\n", res?"ERR":"ok"); //os_printf("espFsInit %s\n", res?"ERR":"ok");
// mount the http handlers // mount the http handlers
httpdInit(builtInUrls, 80); httpdInit(builtInUrls, 80);
webServerInit(); WEB_Init();
// init the wifi-serial transparent bridge (port 23) // init the wifi-serial transparent bridge (port 23)
serbridgeInit(23, 2323); serbridgeInit(23, 2323);

@ -43,7 +43,7 @@ typedef enum {
CMD_REST_REQUEST, CMD_REST_REQUEST,
CMD_REST_SETHEADER, CMD_REST_SETHEADER,
CMD_WEB_DATA = 30, CMD_WEB_JSON_DATA = 30,
CMD_WEB_REQ_CB, CMD_WEB_REQ_CB,
} CmdName; } CmdName;

@ -16,12 +16,12 @@ static char* web_server_reasons[] = {
char * webServerPages = NULL; char * webServerPages = NULL;
char * ICACHE_FLASH_ATTR webServerUserPages() char * ICACHE_FLASH_ATTR WEB_UserPages()
{ {
return webServerPages; return webServerPages;
} }
void ICACHE_FLASH_ATTR webServerBrowseFiles() void ICACHE_FLASH_ATTR WEB_BrowseFiles()
{ {
char buffer[1024]; char buffer[1024];
buffer[0] = 0; buffer[0] = 0;
@ -74,17 +74,17 @@ void ICACHE_FLASH_ATTR webServerBrowseFiles()
os_memcpy( webServerPages, buffer, len ); os_memcpy( webServerPages, buffer, len );
} }
void ICACHE_FLASH_ATTR webServerInit() void ICACHE_FLASH_ATTR WEB_Init()
{ {
espFsInit(userPageCtx, (void *)getUserPageSectionStart(), ESPFS_FLASH); espFsInit(userPageCtx, (void *)getUserPageSectionStart(), ESPFS_FLASH);
if( espFsIsValid( userPageCtx ) ) if( espFsIsValid( userPageCtx ) )
os_printf("Valid user file system found!\n"); os_printf("Valid user file system found!\n");
else else
os_printf("No user file system found!\n"); os_printf("No user file system found!\n");
webServerBrowseFiles(); WEB_BrowseFiles();
} }
int ICACHE_FLASH_ATTR cgiJsonHook(HttpdConnData *connData) int ICACHE_FLASH_ATTR WEB_CgiJsonHook(HttpdConnData *connData)
{ {
if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up. if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up.
@ -180,3 +180,7 @@ int ICACHE_FLASH_ATTR cgiJsonHook(HttpdConnData *connData)
// TODO // TODO
return HTTPD_CGI_MORE; return HTTPD_CGI_MORE;
} }
void ICACHE_FLASH_ATTR WEB_JsonData(CmdPacket *cmd)
{
}

@ -4,6 +4,7 @@
#include <esp8266.h> #include <esp8266.h>
#include "httpd.h" #include "httpd.h"
#include "cmd.h"
typedef enum typedef enum
{ {
@ -15,11 +16,12 @@ typedef enum
INVALID=-1, INVALID=-1,
} RequestReason; } RequestReason;
void webServerInit(); void WEB_Init();
char * webServerUserPages(); char * WEB_UserPages();
int ICACHE_FLASH_ATTR cgiJsonHook(HttpdConnData *connData); int WEB_CgiJsonHook(HttpdConnData *connData);
void WEB_JsonData(CmdPacket *cmd);
#endif /* WEB_SERVER_H */ #endif /* WEB_SERVER_H */

Loading…
Cancel
Save