Refactored web-server

pull/183/head
Karai Csaba 9 years ago committed by cskarai
parent c14c214f49
commit 86c5614446
  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_SETHEADER,
CMD_WEB_DATA = 30,
CMD_WEB_JSON_DATA = 30,
CMD_WEB_REQ_CB,
} CmdName;

@ -12,6 +12,7 @@
#ifdef REST
#include <rest.h>
#endif
#include <web-server.h>
#ifdef CMD_DBG
#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_SETHEADER, "REST_SETHDR", REST_SetHeader},
#endif
{CMD_WEB_JSON_DATA, "WEB_JSON_DATA", WEB_JsonData},
};
//===== List of registered callbacks (to uC)

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

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

@ -99,7 +99,7 @@ HttpdBuiltInUrl builtInUrls[] = {
{ "/mqtt", cgiMqtt, NULL },
#endif
{ "/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
{ NULL, NULL, NULL }
};
@ -157,7 +157,7 @@ void user_init(void) {
//os_printf("espFsInit %s\n", res?"ERR":"ok");
// mount the http handlers
httpdInit(builtInUrls, 80);
webServerInit();
WEB_Init();
// init the wifi-serial transparent bridge (port 23)
serbridgeInit(23, 2323);

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

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

@ -4,6 +4,7 @@
#include <esp8266.h>
#include "httpd.h"
#include "cmd.h"
typedef enum
{
@ -15,11 +16,12 @@ typedef enum
INVALID=-1,
} 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 */

Loading…
Cancel
Save