Websocket demo

This commit is contained in:
Jeroen Domburg
2015-09-30 12:15:06 +08:00
parent 05d75a9fd1
commit b52d0cfba0
+16
View File
@@ -25,6 +25,7 @@ some pictures of cats.
#include "espfs.h" #include "espfs.h"
#include "captdns.h" #include "captdns.h"
#include "webpages-espfs.h" #include "webpages-espfs.h"
#include "cgiwebsocket.h"
//The example can print out the heap use every 3 seconds. You can use this to catch memory leaks. //The example can print out the heap use every 3 seconds. You can use this to catch memory leaks.
//#define SHOW_HEAP_USE //#define SHOW_HEAP_USE
@@ -46,6 +47,19 @@ int myPassFn(HttpdConnData *connData, int no, char *user, int userLen, char *pas
return 0; return 0;
} }
void myWebsocketRecv(Websock *ws, char *data, int len, int flags) {
int i;
os_printf("Websocket: Received data: ");
for (i=0; i<len; i++) os_printf("%c", data[i]);
os_printf("\n");
}
void myWebsocketConnect(Websock *ws) {
ws->recvCb=myWebsocketRecv;
cgiWebsocketSend(ws, "Hi, Websocket!", 14, WEBSOCK_FLAG_NONE);
}
#ifdef ESPFS_POS #ifdef ESPFS_POS
CgiUploadFlashDef uploadParams={ CgiUploadFlashDef uploadParams={
.type=CGIFLASH_TYPE_ESPFS, .type=CGIFLASH_TYPE_ESPFS,
@@ -102,6 +116,8 @@ HttpdBuiltInUrl builtInUrls[]={
{"/wifi/connstatus.cgi", cgiWiFiConnStatus, NULL}, {"/wifi/connstatus.cgi", cgiWiFiConnStatus, NULL},
{"/wifi/setmode.cgi", cgiWiFiSetMode, NULL}, {"/wifi/setmode.cgi", cgiWiFiSetMode, NULL},
{"/websocket/ws.cgi", cgiWebsocket, myWebsocketConnect},
{"*", cgiEspFsHook, NULL}, //Catch-all cgi function for the filesystem {"*", cgiEspFsHook, NULL}, //Catch-all cgi function for the filesystem
{NULL, NULL, NULL} {NULL, NULL, NULL}
}; };