working genpage

master
Ondřej Hruška 9 years ago
parent 3d8ebb9ed8
commit ed17164e1c
  1. 2
      esp_meas.pro
  2. 6
      esp_meas.pro.user
  3. 1
      html/index.tpl
  4. 2
      htmlpreview.sh
  5. 3
      libesphttpd/include/esp8266.h
  6. 2
      sbmp/crc32.c
  7. 85
      user/cgi.c
  8. 2
      user/cgi.h
  9. 4
      user/user_main.c

@ -3,7 +3,7 @@ CONFIG += console
CONFIG -= app_bundle CONFIG -= app_bundle
CONFIG -= qt CONFIG -= qt
DEFINES = DEFINES = ESPFS_HEATSHRINK
INCLUDEPATH = . \ INCLUDEPATH = . \
esp_iot_sdk_v1.5.2/include \ esp_iot_sdk_v1.5.2/include \

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.6.0, 2016-03-17T11:48:45. --> <!-- Written by QtCreator 3.6.0, 2016-03-17T20:40:21. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>
@ -106,7 +106,9 @@
</valuemap> </valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value> <value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value> <value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/> <valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges">
<value type="QString">PATH=/usr/lib/qt/bin:/usr/bin:/home/ondra/GNUstep/Tools:/usr/local/sbin:/usr/local/bin:/usr/bin:/opt/android-sdk/platform-tools:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/home/ondra/devel/esp/sdk/esp-open-sdk/xtensa-lx106-elf/bin</value>
</valuelist>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Debug</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Debug</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>

@ -10,6 +10,7 @@
<nav> <nav>
<ul> <ul>
<li><a href="/wifi">WiFi setup</a> <li><a href="/wifi">WiFi setup</a>
<li><a href="/random.tpl">Random numbers</a>
</ul> </ul>
<hr> <hr>

@ -8,3 +8,5 @@ for file in $(find html_preview/ -name "*.tpl")
do do
mv $file `echo $file | sed s/.tpl$/.html/` mv $file `echo $file | sed s/.tpl$/.html/`
done done
echo "Html preview updated."

@ -24,6 +24,9 @@
#define FLASH_FN ICACHE_FLASH_ATTR #define FLASH_FN ICACHE_FLASH_ATTR
// this ideally would allow flash arrays, but alas works only for uint32_t
#define FLASH_DATA ICACHE_RODATA_ATTR STORE_ATTR
#include "platform.h" #include "platform.h"
#include "espmissingincludes.h" #include "espmissingincludes.h"
#include "esp_sdk_ver.h" #include "esp_sdk_ver.h"

@ -66,7 +66,7 @@
/* hardware you could probably optimize the shift in assembler by */ /* hardware you could probably optimize the shift in assembler by */
/* using byte-swap instructions. */ /* using byte-swap instructions. */
static uint32_t ICACHE_RODATA_ATTR STORE_ATTR crc_32_tab[] = { /* CRC polynomial 0xedb88320 */ static uint32_t FLASH_DATA crc_32_tab[] = { /* CRC polynomial 0xedb88320 */
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,

@ -16,14 +16,15 @@ flash as a binary. Also handles the hit counter on the main page.
#include <esp8266.h> #include <esp8266.h>
#include "cgi.h" #include "cgi.h"
static long hitCounter=0; static long hitCounter = 0;
//Template code for the counter on the index page. //Template code for the counter on the index page.
int ICACHE_FLASH_ATTR tplCounter(HttpdConnData *connData, char *token, void **arg) { int ICACHE_FLASH_ATTR tplCounter(HttpdConnData *connData, char *token, void **arg)
{
char buff[128]; char buff[128];
if (token==NULL) return HTTPD_CGI_DONE; if (token == NULL) return HTTPD_CGI_DONE;
if (os_strcmp(token, "counter")==0) { if (os_strcmp(token, "counter") == 0) {
hitCounter++; hitCounter++;
os_sprintf(buff, "%ld", hitCounter); os_sprintf(buff, "%ld", hitCounter);
} }
@ -31,3 +32,79 @@ int ICACHE_FLASH_ATTR tplCounter(HttpdConnData *connData, char *token, void **ar
return HTTPD_CGI_DONE; return HTTPD_CGI_DONE;
} }
typedef struct {
uint32_t count_remain;
} RandomNumberState;
// better to put it in the fs...
int FLASH_FN cgiRandomNumbers(HttpdConnData *connData) {
RandomNumberState *rns=connData->cgiData;
char buff[128];
if (connData->conn == NULL) {
//Connection aborted. Clean up.
if (rns != NULL) free(rns);
return HTTPD_CGI_DONE;
}
if (rns == NULL) {
//First call to this cgi. Open the file so we can read it.
rns=(RandomNumberState *)malloc(sizeof(RandomNumberState));
connData->cgiData=rns;
// parse count
uint32_t count = 1;
int len = httpdFindArg(connData->getArgs, "count", buff, sizeof(buff));
if (len==-1) {
// no such get arg
} else {
count = (uint32_t)atoi(buff);
}
rns->count_remain = count;
printf("User wants %d numbers.", count);
httpdStartResponse(connData, 200);
httpdHeader(connData, "Content-Type", "text/html");
httpdEndHeaders(connData);
// start the page
httpdSend(connData, "<!DOCTYPE html>"
"<html>"
"<head>"
" <title>Generated page.</title>"
" <link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\">"
"</head>"
"<body>"
"<div id=\"main\">"
"<h1>Random numbers:</h1>"
"<ul>", -1);
return HTTPD_CGI_MORE;
}
// send end of the page
if (rns->count_remain == 0) {
httpdSend(connData, "</ul></body></html>", -1);
free(rns);
return HTTPD_CGI_DONE;
}
// print chunk of data
for (int i = 0; i < 100; i++) {
os_sprintf(buff, "<li>%lu\n", os_random());
httpdSend(connData, buff, -1);
if (--rns->count_remain == 0) {
break;
}
}
return HTTPD_CGI_MORE;
}

@ -6,4 +6,6 @@
int tplCounter(HttpdConnData *connData, char *token, void **arg); int tplCounter(HttpdConnData *connData, char *token, void **arg);
int cgiRandomNumbers(HttpdConnData *connData);
#endif #endif

@ -98,9 +98,11 @@ CgiUploadFlashDef uploadParams = {
* should be placed above the URLs they protect. * should be placed above the URLs they protect.
*/ */
static HttpdBuiltInUrl builtInUrls[] = { static HttpdBuiltInUrl builtInUrls[] = {
{"*", cgiRedirectApClientToHostname, "esp8266.nonet"}, {"*", cgiRedirectApClientToHostname, "esp8266.nonet"}, // redirect func for the captive portal
{"/", cgiEspFsTemplate, (void *)tplCounter}, {"/", cgiEspFsTemplate, (void *)tplCounter},
{"/random.tpl", cgiRandomNumbers, NULL},
//Enable the line below to protect the WiFi configuration with an username/password combo. //Enable the line below to protect the WiFi configuration with an username/password combo.
// {"/wifi/*", authBasic, (void *)myPassFn}, // {"/wifi/*", authBasic, (void *)myPassFn},

Loading…
Cancel
Save