..;.and now with the changed files too.
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
* Modification history:
|
* Modification history:
|
||||||
* 2014/3/12, v1.0 create this file.
|
* 2014/3/12, v1.0 create this file.
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
#include "espmissingincludes.h"
|
||||||
#include "ets_sys.h"
|
#include "ets_sys.h"
|
||||||
#include "osapi.h"
|
#include "osapi.h"
|
||||||
#include "driver/uart.h"
|
#include "driver/uart.h"
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 3.2 KiB |
@@ -97,5 +97,7 @@ typedef struct {
|
|||||||
void uart_init(UartBautRate uart0_br, UartBautRate uart1_br);
|
void uart_init(UartBautRate uart0_br, UartBautRate uart1_br);
|
||||||
void uart0_sendStr(const char *str);
|
void uart0_sendStr(const char *str);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
+196
-11
@@ -4,9 +4,12 @@ Some random cgi routines.
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <osapi.h>
|
#include <osapi.h>
|
||||||
|
#include "user_interface.h"
|
||||||
|
#include "mem.h"
|
||||||
#include "httpd.h"
|
#include "httpd.h"
|
||||||
#include "cgi.h"
|
#include "cgi.h"
|
||||||
#include "io.h"
|
#include "io.h"
|
||||||
|
#include "espmissingincludes.h"
|
||||||
|
|
||||||
int ICACHE_FLASH_ATTR cgiLed(HttpdConnData *connData) {
|
int ICACHE_FLASH_ATTR cgiLed(HttpdConnData *connData) {
|
||||||
int len;
|
int len;
|
||||||
@@ -18,33 +21,215 @@ int ICACHE_FLASH_ATTR cgiLed(HttpdConnData *connData) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
len=httpdFindArg(connData->postBuff, "led", buff, sizeof(buff));
|
len=httpdFindArg(connData->postBuff, "led", buff, sizeof(buff));
|
||||||
ioLed(atoi(buff));
|
if (len!=0) ioLed(atoi(buff));
|
||||||
|
|
||||||
httpdRedirect(connData, "led.html");
|
httpdRedirect(connData, "led.html");
|
||||||
return HTTPD_CGI_DONE;
|
return HTTPD_CGI_DONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ICACHE_FLASH_ATTR cgiTest(HttpdConnData *connData) {
|
|
||||||
|
//WiFi access point data
|
||||||
|
typedef struct {
|
||||||
|
char ssid[32];
|
||||||
|
char rssi;
|
||||||
|
char enc;
|
||||||
|
} ApData;
|
||||||
|
|
||||||
|
//Scan resolt
|
||||||
|
typedef struct {
|
||||||
|
char scanInProgress;
|
||||||
|
ApData **apData;
|
||||||
|
int noAps;
|
||||||
|
} ScanResultData;
|
||||||
|
|
||||||
|
//Static scan status storage.
|
||||||
|
ScanResultData cgiWifiAps;
|
||||||
|
|
||||||
|
void ICACHE_FLASH_ATTR wifiScanDoneCb(void *arg, STATUS status) {
|
||||||
|
int n;
|
||||||
|
struct bss_info *bss_link = (struct bss_info *)arg;
|
||||||
|
os_printf("wifiScanDoneCb %d\n", status);
|
||||||
|
if (status!=OK) {
|
||||||
|
cgiWifiAps.scanInProgress=0;
|
||||||
|
wifi_station_disconnect(); //test HACK
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Clear prev ap data if needed.
|
||||||
|
if (cgiWifiAps.apData!=NULL) {
|
||||||
|
for (n=0; n<cgiWifiAps.noAps; n++) os_free(cgiWifiAps.apData[n]);
|
||||||
|
os_free(cgiWifiAps.apData);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Count amount of access points found.
|
||||||
|
n=0;
|
||||||
|
while (bss_link != NULL) {
|
||||||
|
bss_link = bss_link->next.stqe_next;
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
//Allocate memory for access point data
|
||||||
|
cgiWifiAps.apData=(ApData **)os_malloc(sizeof(ApData *)*n);
|
||||||
|
cgiWifiAps.noAps=n;
|
||||||
|
|
||||||
|
//Copy access point data to the static struct
|
||||||
|
n=0;
|
||||||
|
bss_link = (struct bss_info *)arg;
|
||||||
|
while (bss_link != NULL) {
|
||||||
|
cgiWifiAps.apData[n]=(ApData *)os_malloc(sizeof(ApData));
|
||||||
|
cgiWifiAps.apData[n]->rssi=bss_link->rssi;
|
||||||
|
cgiWifiAps.apData[n]->enc=bss_link->authmode;
|
||||||
|
strncpy(cgiWifiAps.apData[n]->ssid, (char*)bss_link->ssid, 32);
|
||||||
|
|
||||||
|
bss_link = bss_link->next.stqe_next;
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
os_printf("Scan done: found %d APs\n", n);
|
||||||
|
//We're done.
|
||||||
|
cgiWifiAps.scanInProgress=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ICACHE_FLASH_ATTR wifiStartScan() {
|
||||||
|
int x;
|
||||||
|
cgiWifiAps.scanInProgress=1;
|
||||||
|
x=wifi_station_get_connect_status();
|
||||||
|
if (x!=STATION_GOT_IP) {
|
||||||
|
//Unit probably is trying to connect to a bogus AP. This messes up scanning. Stop that.
|
||||||
|
os_printf("STA status = %d. Disconnecting STA...\n", x);
|
||||||
|
wifi_station_disconnect();
|
||||||
|
}
|
||||||
|
wifi_station_scan(NULL, wifiScanDoneCb);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int ICACHE_FLASH_ATTR cgiWiFiScan(HttpdConnData *connData) {
|
||||||
int len;
|
int len;
|
||||||
char val1[128];
|
int i;
|
||||||
char val2[128];
|
|
||||||
char buff[1024];
|
char buff[1024];
|
||||||
|
httpdStartResponse(connData, 200);
|
||||||
|
httpdHeader(connData, "Content-Type", "text/json");
|
||||||
|
httpdEndHeaders(connData);
|
||||||
|
|
||||||
|
if (cgiWifiAps.scanInProgress==1) {
|
||||||
|
len=os_sprintf(buff, "{\n \"result\": { \n\"inProgress\": \"1\"\n }\n}\n");
|
||||||
|
espconn_sent(connData->conn, (uint8 *)buff, len);
|
||||||
|
} else {
|
||||||
|
len=os_sprintf(buff, "{\n \"result\": { \n\"inProgress\": \"0\", \n\"APs\": [\n");
|
||||||
|
espconn_sent(connData->conn, (uint8 *)buff, len);
|
||||||
|
if (cgiWifiAps.apData==NULL) cgiWifiAps.noAps=0;
|
||||||
|
for (i=0; i<cgiWifiAps.noAps; i++) {
|
||||||
|
len=os_sprintf(buff, "{\"essid\": \"%s\", \"rssi\": \"%d\", \"enc\": \"%d\"}%s\n",
|
||||||
|
cgiWifiAps.apData[i]->ssid, cgiWifiAps.apData[i]->rssi,
|
||||||
|
cgiWifiAps.apData[i]->enc, (i==cgiWifiAps.noAps-1)?"":",");
|
||||||
|
espconn_sent(connData->conn, (uint8 *)buff, len);
|
||||||
|
}
|
||||||
|
len=os_sprintf(buff, "]\n}\n}\n");
|
||||||
|
espconn_sent(connData->conn, (uint8 *)buff, len);
|
||||||
|
wifiStartScan();
|
||||||
|
}
|
||||||
|
return HTTPD_CGI_DONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct station_config stconf;
|
||||||
|
|
||||||
|
|
||||||
|
static void ICACHE_FLASH_ATTR resetTimerCb(void *arg) {
|
||||||
|
int x=wifi_station_get_connect_status();
|
||||||
|
if (x==STATION_GOT_IP) {
|
||||||
|
//Go to STA mode. This needs a reset, so do that.
|
||||||
|
wifi_set_opmode(1);
|
||||||
|
system_restart();
|
||||||
|
} else {
|
||||||
|
os_printf("Connect fail. Not going into STA-only mode.\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void ICACHE_FLASH_ATTR reassTimerCb(void *arg) {
|
||||||
|
int x;
|
||||||
|
static ETSTimer resetTimer;
|
||||||
|
wifi_station_disconnect();
|
||||||
|
wifi_station_set_config(&stconf);
|
||||||
|
wifi_station_connect();
|
||||||
|
x=wifi_get_opmode();
|
||||||
|
if (x!=1) {
|
||||||
|
//Schedule disconnect/connect
|
||||||
|
os_timer_disarm(&resetTimer);
|
||||||
|
os_timer_setfn(&resetTimer, resetTimerCb, NULL);
|
||||||
|
os_timer_arm(&resetTimer, 4000, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int ICACHE_FLASH_ATTR cgiWiFiConnect(HttpdConnData *connData) {
|
||||||
|
char essid[128];
|
||||||
|
char passwd[128];
|
||||||
|
static ETSTimer reassTimer;
|
||||||
|
|
||||||
if (connData->conn==NULL) {
|
if (connData->conn==NULL) {
|
||||||
//Connection aborted. Clean up.
|
//Connection aborted. Clean up.
|
||||||
return HTTPD_CGI_DONE;
|
return HTTPD_CGI_DONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
httpdStartResponse(connData, 200);
|
httpdFindArg(connData->postBuff, "essid", essid, sizeof(essid));
|
||||||
httpdHeader(connData, "Content-Type", "text/plain");
|
httpdFindArg(connData->postBuff, "passwd", passwd, sizeof(passwd));
|
||||||
httpdEndHeaders(connData);
|
|
||||||
|
|
||||||
|
os_strncpy((char*)stconf.ssid, essid, 32);
|
||||||
|
os_strncpy((char*)stconf.password, passwd, 64);
|
||||||
|
|
||||||
httpdFindArg(connData->postBuff, "Test1", val1, sizeof(val1));
|
//Schedule disconnect/connect
|
||||||
httpdFindArg(connData->postBuff, "Test2", val2, sizeof(val2));
|
os_timer_disarm(&reassTimer);
|
||||||
len=os_sprintf(buff, "Field 1: %s\nField 2: %s\n", val1, val2);
|
os_timer_setfn(&reassTimer, reassTimerCb, NULL);
|
||||||
espconn_sent(connData->conn, (uint8 *)buff, len);
|
os_timer_arm(&reassTimer, 1000, 0);
|
||||||
|
|
||||||
|
httpdRedirect(connData, "connecting.html");
|
||||||
|
|
||||||
return HTTPD_CGI_DONE;
|
return HTTPD_CGI_DONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Cgi that reads the SPI flash. Assumes 512KByte flash.
|
||||||
|
int ICACHE_FLASH_ATTR cgiReadFlash(HttpdConnData *connData) {
|
||||||
|
int *pos=(int *)&connData->cgiData;
|
||||||
|
if (connData->conn==NULL) {
|
||||||
|
//Connection aborted. Clean up.
|
||||||
|
return HTTPD_CGI_DONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*pos==0) {
|
||||||
|
os_printf("Start flash download.\n");
|
||||||
|
httpdStartResponse(connData, 200);
|
||||||
|
httpdHeader(connData, "Content-Type", "application/bin");
|
||||||
|
httpdEndHeaders(connData);
|
||||||
|
*pos=0x40200000;
|
||||||
|
return HTTPD_CGI_MORE;
|
||||||
|
}
|
||||||
|
espconn_sent(connData->conn, (uint8 *)(*pos), 1024);
|
||||||
|
*pos+=1024;
|
||||||
|
if (*pos>=0x40200000+(512*1024)) return HTTPD_CGI_DONE; else return HTTPD_CGI_MORE;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ICACHE_FLASH_ATTR cgiTest(HttpdConnData *connData) {
|
||||||
|
return HTTPD_CGI_DONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ICACHE_FLASH_ATTR tplWlan(HttpdConnData *connData, char *token, void **arg) {
|
||||||
|
char buff[1024];
|
||||||
|
int x;
|
||||||
|
static struct station_config stconf;
|
||||||
|
if (token==NULL) return;
|
||||||
|
wifi_station_get_config(&stconf);
|
||||||
|
|
||||||
|
os_strcpy(buff, "Unknown");
|
||||||
|
if (os_strcmp(token, "WiFiMode")==0) {
|
||||||
|
x=wifi_get_opmode();
|
||||||
|
if (x==1) os_strcpy(buff, "Client");
|
||||||
|
if (x==2) os_strcpy(buff, "SoftAP");
|
||||||
|
if (x==3) os_strcpy(buff, "STA+AP");
|
||||||
|
} else if (os_strcmp(token, "currSsid")==0) {
|
||||||
|
os_strcpy(buff, (char*)stconf.ssid);
|
||||||
|
} else if (os_strcmp(token, "WiFiPasswd")==0) {
|
||||||
|
os_strcpy(buff, (char*)stconf.password);
|
||||||
|
}
|
||||||
|
espconn_sent(connData->conn, (uint8 *)buff, os_strlen(buff));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,11 @@
|
|||||||
#include "httpd.h"
|
#include "httpd.h"
|
||||||
|
|
||||||
int cgiLed(HttpdConnData *connData);
|
int cgiLed(HttpdConnData *connData);
|
||||||
|
int cgiReadFlash(HttpdConnData *connData);
|
||||||
int cgiTest(HttpdConnData *connData);
|
int cgiTest(HttpdConnData *connData);
|
||||||
|
int cgiWiFiScan(HttpdConnData *connData);
|
||||||
|
void ICACHE_FLASH_ATTR tplWlan(HttpdConnData *connData, char *token, void **arg);
|
||||||
|
int ICACHE_FLASH_ATTR cgiWiFi(HttpdConnData *connData);
|
||||||
|
int ICACHE_FLASH_ATTR cgiWiFiConnect(HttpdConnData *connData);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
+8
-5
@@ -12,6 +12,7 @@ It's written for use with httpd, but doesn't need to be used as such.
|
|||||||
#include "espconn.h"
|
#include "espconn.h"
|
||||||
#include "mem.h"
|
#include "mem.h"
|
||||||
#include "osapi.h"
|
#include "osapi.h"
|
||||||
|
#include "espmissingincludes.h"
|
||||||
#else
|
#else
|
||||||
//Test build
|
//Test build
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -109,7 +110,8 @@ EspFsFile ICACHE_FLASH_ATTR *espFsOpen(char *fileName) {
|
|||||||
}
|
}
|
||||||
p+=sizeof(EspFsHeader);
|
p+=sizeof(EspFsHeader);
|
||||||
os_memcpy(namebuf, p, sizeof(namebuf));
|
os_memcpy(namebuf, p, sizeof(namebuf));
|
||||||
os_printf("Found file '%s'. Namelen=%x fileLenComp=%x, compr=%d flags=%d\n", namebuf, h.nameLen,h.fileLenComp,h.compression,h.flags);
|
os_printf("Found file '%s'. Namelen=%x fileLenComp=%x, compr=%d flags=%d\n",
|
||||||
|
namebuf, (unsigned int)h.nameLen, (unsigned int)h.fileLenComp, h.compression, h.flags);
|
||||||
if (os_strcmp(namebuf, fileName)==0) {
|
if (os_strcmp(namebuf, fileName)==0) {
|
||||||
p+=h.nameLen;
|
p+=h.nameLen;
|
||||||
r=(EspFsFile *)os_malloc(sizeof(EspFsFile));
|
r=(EspFsFile *)os_malloc(sizeof(EspFsFile));
|
||||||
@@ -155,7 +157,7 @@ int ICACHE_FLASH_ATTR espFsRead(EspFsFile *fh, char *buff, int len) {
|
|||||||
int toRead;
|
int toRead;
|
||||||
toRead=flen-(fh->posComp-fh->posStart);
|
toRead=flen-(fh->posComp-fh->posStart);
|
||||||
if (len>toRead) len=toRead;
|
if (len>toRead) len=toRead;
|
||||||
os_printf("Reading %d bytes from %x\n", len, fh->posComp);
|
os_printf("Reading %d bytes from %x\n", len, (unsigned int)fh->posComp);
|
||||||
memcpyAligned(buff, fh->posComp, len);
|
memcpyAligned(buff, fh->posComp, len);
|
||||||
fh->posDecomp+=len;
|
fh->posDecomp+=len;
|
||||||
fh->posComp+=len;
|
fh->posComp+=len;
|
||||||
@@ -164,23 +166,24 @@ int ICACHE_FLASH_ATTR espFsRead(EspFsFile *fh, char *buff, int len) {
|
|||||||
#ifdef EFS_HEATSHRINK
|
#ifdef EFS_HEATSHRINK
|
||||||
} else if (fh->decompressor==COMPRESS_HEATSHRINK) {
|
} else if (fh->decompressor==COMPRESS_HEATSHRINK) {
|
||||||
int decoded=0;
|
int decoded=0;
|
||||||
int elen, rlen, r;
|
unsigned int elen, rlen;
|
||||||
char ebuff[16];
|
char ebuff[16];
|
||||||
heatshrink_decoder *dec=(heatshrink_decoder *)fh->decompData;
|
heatshrink_decoder *dec=(heatshrink_decoder *)fh->decompData;
|
||||||
while(decoded<len) {
|
while(decoded<len) {
|
||||||
//Feed data into the decompressor
|
//Feed data into the decompressor
|
||||||
|
//ToDo: Check ret val of heatshrink fns for errors
|
||||||
elen=flen-(fh->posComp - fh->posStart);
|
elen=flen-(fh->posComp - fh->posStart);
|
||||||
if (elen==0) return decoded; //file is read
|
if (elen==0) return decoded; //file is read
|
||||||
if (elen>0) {
|
if (elen>0) {
|
||||||
memcpyAligned(ebuff, fh->posComp, 16);
|
memcpyAligned(ebuff, fh->posComp, 16);
|
||||||
r=heatshrink_decoder_sink(dec, ebuff, (elen>16)?16:elen, &rlen);
|
heatshrink_decoder_sink(dec, (uint8_t *)ebuff, (elen>16)?16:elen, &rlen);
|
||||||
fh->posComp+=rlen;
|
fh->posComp+=rlen;
|
||||||
if (rlen==elen) {
|
if (rlen==elen) {
|
||||||
heatshrink_decoder_finish(dec);
|
heatshrink_decoder_finish(dec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Grab decompressed data and put into buff
|
//Grab decompressed data and put into buff
|
||||||
r=heatshrink_decoder_poll(dec, buff, len-decoded, &rlen);
|
heatshrink_decoder_poll(dec, (uint8_t *)buff, len-decoded, &rlen);
|
||||||
fh->posDecomp+=rlen;
|
fh->posDecomp+=rlen;
|
||||||
buff+=rlen;
|
buff+=rlen;
|
||||||
decoded+=rlen;
|
decoded+=rlen;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#define _STDDEF_H
|
#define _STDDEF_H
|
||||||
#define _STDINT_H
|
#define _STDINT_H
|
||||||
|
|
||||||
|
#include "espmissingincludes.h"
|
||||||
#include "c_types.h"
|
#include "c_types.h"
|
||||||
#include "mem.h"
|
#include "mem.h"
|
||||||
#include "osapi.h"
|
#include "osapi.h"
|
||||||
|
|||||||
+10
-12
@@ -1,3 +1,4 @@
|
|||||||
|
#include "espmissingincludes.h"
|
||||||
#include "driver/uart.h"
|
#include "driver/uart.h"
|
||||||
#include "c_types.h"
|
#include "c_types.h"
|
||||||
#include "user_interface.h"
|
#include "user_interface.h"
|
||||||
@@ -43,6 +44,7 @@ typedef struct {
|
|||||||
static const MimeMap mimeTypes[]={
|
static const MimeMap mimeTypes[]={
|
||||||
{"htm", "text/htm"},
|
{"htm", "text/htm"},
|
||||||
{"html", "text/html"},
|
{"html", "text/html"},
|
||||||
|
{"js", "text/javascript"},
|
||||||
{"txt", "text/plain"},
|
{"txt", "text/plain"},
|
||||||
{"jpg", "image/jpeg"},
|
{"jpg", "image/jpeg"},
|
||||||
{"jpeg", "image/jpeg"},
|
{"jpeg", "image/jpeg"},
|
||||||
@@ -83,6 +85,7 @@ static int httpdHexVal(char c) {
|
|||||||
if (c>='0' && c<='9') return c-'0';
|
if (c>='0' && c<='9') return c-'0';
|
||||||
if (c>='A' && c<='F') return c-'A'+10;
|
if (c>='A' && c<='F') return c-'A'+10;
|
||||||
if (c>='a' && c<='f') return c-'a'+10;
|
if (c>='a' && c<='f') return c-'a'+10;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Decode a percent-encoded value
|
//Decode a percent-encoded value
|
||||||
@@ -107,13 +110,13 @@ int httpdUrlDecode(char *val, int valLen, char *ret, int retLen) {
|
|||||||
s++;
|
s++;
|
||||||
}
|
}
|
||||||
if (d<retLen) ret[d]=0;
|
if (d<retLen) ret[d]=0;
|
||||||
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Find a specific arg in a string of get- or post-data.
|
//Find a specific arg in a string of get- or post-data.
|
||||||
//Returns len of arg or -1 if not found.
|
//Returns len of arg or -1 if not found.
|
||||||
int ICACHE_FLASH_ATTR httpdFindArg(char *line, char *arg, char *buff, int buffLen) {
|
int ICACHE_FLASH_ATTR httpdFindArg(char *line, char *arg, char *buff, int buffLen) {
|
||||||
char *p, *e;
|
char *p, *e;
|
||||||
int len;
|
|
||||||
if (line==NULL) return 0;
|
if (line==NULL) return 0;
|
||||||
p=line;
|
p=line;
|
||||||
while(p!=NULL && *p!='\n' && *p!='\r' && *p!=0) {
|
while(p!=NULL && *p!='\n' && *p!='\r' && *p!=0) {
|
||||||
@@ -138,7 +141,7 @@ void ICACHE_FLASH_ATTR httpdStartResponse(HttpdConnData *conn, int code) {
|
|||||||
char buff[128];
|
char buff[128];
|
||||||
int l;
|
int l;
|
||||||
l=os_sprintf(buff, "HTTP/1.0 %d OK\r\nServer: esp8266-httpd/0.1\r\n", code);
|
l=os_sprintf(buff, "HTTP/1.0 %d OK\r\nServer: esp8266-httpd/0.1\r\n", code);
|
||||||
espconn_sent(conn->conn, buff, l);
|
espconn_sent(conn->conn, (uint8 *)buff, l);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -146,11 +149,11 @@ void ICACHE_FLASH_ATTR httpdHeader(HttpdConnData *conn, const char *field, const
|
|||||||
char buff[256];
|
char buff[256];
|
||||||
int l;
|
int l;
|
||||||
l=os_sprintf(buff, "%s: %s\r\n", field, val);
|
l=os_sprintf(buff, "%s: %s\r\n", field, val);
|
||||||
espconn_sent(conn->conn, buff, l);
|
espconn_sent(conn->conn, (uint8 *)buff, l);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ICACHE_FLASH_ATTR httpdEndHeaders(HttpdConnData *conn) {
|
void ICACHE_FLASH_ATTR httpdEndHeaders(HttpdConnData *conn) {
|
||||||
espconn_sent(conn->conn, "\r\n", 2);
|
espconn_sent(conn->conn, (uint8 *)"\r\n", 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
//ToDo: sprintf->snprintf everywhere
|
//ToDo: sprintf->snprintf everywhere
|
||||||
@@ -158,13 +161,10 @@ void ICACHE_FLASH_ATTR httpdRedirect(HttpdConnData *conn, char *newUrl) {
|
|||||||
char buff[1024];
|
char buff[1024];
|
||||||
int l;
|
int l;
|
||||||
l=os_sprintf(buff, "HTTP/1.1 302 Found\r\nLocation: %s\r\n\r\nMoved to %s\r\n", newUrl, newUrl);
|
l=os_sprintf(buff, "HTTP/1.1 302 Found\r\nLocation: %s\r\n\r\nMoved to %s\r\n", newUrl, newUrl);
|
||||||
espconn_sent(conn->conn, buff, l);
|
espconn_sent(conn->conn, (uint8 *)buff, l);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ICACHE_FLASH_ATTR cgiRedirect(HttpdConnData *connData) {
|
int ICACHE_FLASH_ATTR cgiRedirect(HttpdConnData *connData) {
|
||||||
int len;
|
|
||||||
char buff[1024];
|
|
||||||
|
|
||||||
if (connData->conn==NULL) {
|
if (connData->conn==NULL) {
|
||||||
//Connection aborted. Clean up.
|
//Connection aborted. Clean up.
|
||||||
return HTTPD_CGI_DONE;
|
return HTTPD_CGI_DONE;
|
||||||
@@ -198,7 +198,7 @@ static void ICACHE_FLASH_ATTR httpdSendResp(HttpdConnData *conn) {
|
|||||||
int r;
|
int r;
|
||||||
//See if the url is somewhere in our internal url table.
|
//See if the url is somewhere in our internal url table.
|
||||||
while (builtInUrls[i].url!=NULL && conn->url!=NULL) {
|
while (builtInUrls[i].url!=NULL && conn->url!=NULL) {
|
||||||
os_printf("%s == %s?\n", builtInUrls[i].url, conn->url);
|
// os_printf("%s == %s?\n", builtInUrls[i].url, conn->url);
|
||||||
if (os_strcmp(builtInUrls[i].url, conn->url)==0 || builtInUrls[i].url[0]=='*') {
|
if (os_strcmp(builtInUrls[i].url, conn->url)==0 || builtInUrls[i].url[0]=='*') {
|
||||||
os_printf("Is url index %d\n", i);
|
os_printf("Is url index %d\n", i);
|
||||||
conn->cgiData=NULL;
|
conn->cgiData=NULL;
|
||||||
@@ -237,7 +237,6 @@ static void ICACHE_FLASH_ATTR httpdParseHeader(char *h, HttpdConnData *conn) {
|
|||||||
os_printf("URL = %s\n", conn->url);
|
os_printf("URL = %s\n", conn->url);
|
||||||
conn->getArgs=(char*)os_strstr(conn->url, "?");
|
conn->getArgs=(char*)os_strstr(conn->url, "?");
|
||||||
if (conn->getArgs!=0) {
|
if (conn->getArgs!=0) {
|
||||||
int x,l;
|
|
||||||
*conn->getArgs=0;
|
*conn->getArgs=0;
|
||||||
conn->getArgs++;
|
conn->getArgs++;
|
||||||
os_printf("GET args = %s\n", conn->getArgs);
|
os_printf("GET args = %s\n", conn->getArgs);
|
||||||
@@ -256,7 +255,7 @@ static void ICACHE_FLASH_ATTR httpdParseHeader(char *h, HttpdConnData *conn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void ICACHE_FLASH_ATTR httpdRecvCb(void *arg, char *data, unsigned short len) {
|
static void ICACHE_FLASH_ATTR httpdRecvCb(void *arg, char *data, unsigned short len) {
|
||||||
int x, l;
|
int x;
|
||||||
char *p, *e;
|
char *p, *e;
|
||||||
HttpdConnData *conn=httpdFindConnData(arg);
|
HttpdConnData *conn=httpdFindConnData(arg);
|
||||||
if (conn==NULL) return;
|
if (conn==NULL) return;
|
||||||
@@ -336,7 +335,6 @@ static void ICACHE_FLASH_ATTR httpdDisconCb(void *arg) {
|
|||||||
|
|
||||||
static void ICACHE_FLASH_ATTR httpdConnectCb(void *arg) {
|
static void ICACHE_FLASH_ATTR httpdConnectCb(void *arg) {
|
||||||
struct espconn *conn=arg;
|
struct espconn *conn=arg;
|
||||||
HttpdConnData *conndata;
|
|
||||||
int i;
|
int i;
|
||||||
//Find empty conndata in pool
|
//Find empty conndata in pool
|
||||||
for (i=0; i<MAX_CONN; i++) if (connData[i].conn==NULL) break;
|
for (i=0; i<MAX_CONN; i++) if (connData[i].conn==NULL) break;
|
||||||
|
|||||||
+4
-4
@@ -2,6 +2,7 @@
|
|||||||
Connector to let httpd use the espfs filesystem to serve the files in that.
|
Connector to let httpd use the espfs filesystem to serve the files in that.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "espmissingincludes.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <osapi.h>
|
#include <osapi.h>
|
||||||
#include "c_types.h"
|
#include "c_types.h"
|
||||||
@@ -58,14 +59,13 @@ typedef struct {
|
|||||||
int tokenPos;
|
int tokenPos;
|
||||||
} TplData;
|
} TplData;
|
||||||
|
|
||||||
typedef int (* TplCallback)(HttpdConnData *connData, char *token, void **arg);
|
typedef void (* TplCallback)(HttpdConnData *connData, char *token, void **arg);
|
||||||
|
|
||||||
int ICACHE_FLASH_ATTR cgiEspFsTemplate(HttpdConnData *connData) {
|
int ICACHE_FLASH_ATTR cgiEspFsTemplate(HttpdConnData *connData) {
|
||||||
TplData *tpd=connData->cgiData;
|
TplData *tpd=connData->cgiData;
|
||||||
int len;
|
int len;
|
||||||
int x, sp;
|
int x, sp=0;
|
||||||
char *p, *e;
|
char *e=NULL;
|
||||||
int sentTo;
|
|
||||||
char buff[1025];
|
char buff[1025];
|
||||||
|
|
||||||
if (connData->conn==NULL) {
|
if (connData->conn==NULL) {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#include "espmissingincludes.h"
|
||||||
#include "c_types.h"
|
#include "c_types.h"
|
||||||
#include "user_interface.h"
|
#include "user_interface.h"
|
||||||
#include "espconn.h"
|
#include "espconn.h"
|
||||||
@@ -20,12 +21,13 @@ void ICACHE_FLASH_ATTR ioLed(int ena) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ICACHE_FLASH_ATTR resetBtnTimerCb(void) {
|
static void ICACHE_FLASH_ATTR resetBtnTimerCb(void *arg) {
|
||||||
static int resetCnt=0;
|
static int resetCnt=0;
|
||||||
if (!GPIO_INPUT_GET(BTNGPIO)) {
|
if (!GPIO_INPUT_GET(BTNGPIO)) {
|
||||||
resetCnt++;
|
resetCnt++;
|
||||||
} else {
|
} else {
|
||||||
if (resetCnt>=6) { //3 sec pressed
|
if (resetCnt>=6) { //3 sec pressed
|
||||||
|
wifi_station_disconnect();
|
||||||
wifi_set_opmode(0x3); //reset to AP+STA mode
|
wifi_set_opmode(0x3); //reset to AP+STA mode
|
||||||
os_printf("Reset to AP mode. Restarting system...\n");
|
os_printf("Reset to AP mode. Restarting system...\n");
|
||||||
system_restart();
|
system_restart();
|
||||||
|
|||||||
+10
-2
@@ -1,3 +1,4 @@
|
|||||||
|
#include "espmissingincludes.h"
|
||||||
#include "ets_sys.h"
|
#include "ets_sys.h"
|
||||||
#include "driver/uart.h"
|
#include "driver/uart.h"
|
||||||
#include "osapi.h"
|
#include "osapi.h"
|
||||||
@@ -7,9 +8,16 @@
|
|||||||
#include "cgi.h"
|
#include "cgi.h"
|
||||||
|
|
||||||
HttpdBuiltInUrl builtInUrls[]={
|
HttpdBuiltInUrl builtInUrls[]={
|
||||||
// {"/", cgiLiteral, "Lalala etc"},
|
{"/", cgiRedirect, "/test2.html"},
|
||||||
|
{"/flash.bin", cgiReadFlash, NULL},
|
||||||
{"/led.cgi", cgiLed, NULL},
|
{"/led.cgi", cgiLed, NULL},
|
||||||
{"/test.cgi", cgiTest, NULL},
|
|
||||||
|
{"/wifi", cgiRedirect, "/wifi/wifi.tpl"},
|
||||||
|
{"/wifi/", cgiRedirect, "/wifi/wifi.tpl"},
|
||||||
|
{"/wifi/wifiscan.cgi", cgiWiFiScan, NULL},
|
||||||
|
{"/wifi/wifi.tpl", cgiEspFsTemplate, tplWlan},
|
||||||
|
{"/wifi/connect.cgi", cgiWiFiConnect},
|
||||||
|
|
||||||
{"*", cgiEspFsHook, NULL},
|
{"*", cgiEspFsHook, NULL},
|
||||||
{NULL, NULL, NULL}
|
{NULL, NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user