Skip to content

Commit

Permalink
* Add ability to get raw http request body + BasicWebSkeletonApp as e…
Browse files Browse the repository at this point in the history
…xample

* Add response.getBody() to get raw http request body if content type is other than FormUrlEncoded
* Add Simple Skeleton app to be used as starting point for some useful app demonstrating several nice concepts

* First attempt to get request body out from server

* bit polish

* Move parseRawBody() bit upper and return ERR_OK after it to speed thing up

* Add BasicWebSkeletonApp
  • Loading branch information
avr39-ripe committed Dec 22, 2015
1 parent 05c8b85 commit 0857d58
Show file tree
Hide file tree
Showing 20 changed files with 726 additions and 1 deletion.
112 changes: 112 additions & 0 deletions Basic_WebSkeletonApp/.cproject
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
<storageModule moduleId="org.eclipse.cdt.core.settings">
<cconfiguration id="0.358052692">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="0.358052692" moduleId="org.eclipse.cdt.core.settings" name="Default">
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.VCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration buildProperties="" description="" id="0.358052692" name="Default" parent="org.eclipse.cdt.build.core.prefbase.cfg">
<folderInfo id="0.358052692." name="/" resourcePath="">
<toolChain id="org.eclipse.cdt.build.core.prefbase.toolchain.248237832" name="No ToolChain" resourceTypeBasedDiscovery="false" superClass="org.eclipse.cdt.build.core.prefbase.toolchain">
<targetPlatform id="org.eclipse.cdt.build.core.prefbase.toolchain.248237832.173974313" name=""/>
<builder command="gmake" id="org.eclipse.cdt.build.core.settings.default.builder.1901258622" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="org.eclipse.cdt.build.core.settings.default.builder"/>
<tool id="org.eclipse.cdt.build.core.settings.holder.libs.578552754" name="holder for library settings" superClass="org.eclipse.cdt.build.core.settings.holder.libs"/>
<tool id="org.eclipse.cdt.build.core.settings.holder.1389766303" name="Assembly" superClass="org.eclipse.cdt.build.core.settings.holder">
<option id="org.eclipse.cdt.build.core.settings.holder.incpaths.564988597" superClass="org.eclipse.cdt.build.core.settings.holder.incpaths" valueType="includePath">
<listOptionValue builtIn="false" value="/usr/home/shurik/src/esp8266/esp-open-sdk/xtensa-lx106-elf/xtensa-lx106-elf/include"/>
<listOptionValue builtIn="false" value="/usr/home/shurik/src/esp8266/esp-open-sdk/sdk/include"/>
<listOptionValue builtIn="false" value="/usr/home/shurik/src/esp8266/Sming/Sming"/>
</option>
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.46217890" languageId="org.eclipse.cdt.core.assembly" languageName="Assembly" sourceContentType="org.eclipse.cdt.core.asmSource" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
</tool>
<tool id="org.eclipse.cdt.build.core.settings.holder.2137323629" name="GNU C++" superClass="org.eclipse.cdt.build.core.settings.holder">
<option id="org.eclipse.cdt.build.core.settings.holder.incpaths.2000940439" superClass="org.eclipse.cdt.build.core.settings.holder.incpaths" valueType="includePath">
<listOptionValue builtIn="false" value="/usr/home/shurik/src/esp8266/esp-open-sdk/xtensa-lx106-elf/xtensa-lx106-elf/include"/>
<listOptionValue builtIn="false" value="/usr/home/shurik/src/esp8266/esp-open-sdk/sdk/include"/>
<listOptionValue builtIn="false" value="/usr/home/shurik/src/esp8266/Sming/Sming"/>
</option>
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.227416399" languageId="org.eclipse.cdt.core.g++" languageName="GNU C++" sourceContentType="org.eclipse.cdt.core.cxxSource,org.eclipse.cdt.core.cxxHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
</tool>
<tool id="org.eclipse.cdt.build.core.settings.holder.1965288460" name="GNU C" superClass="org.eclipse.cdt.build.core.settings.holder">
<option id="org.eclipse.cdt.build.core.settings.holder.incpaths.827104310" superClass="org.eclipse.cdt.build.core.settings.holder.incpaths" valueType="includePath">
<listOptionValue builtIn="false" value="/usr/home/shurik/src/esp8266/esp-open-sdk/xtensa-lx106-elf/xtensa-lx106-elf/include"/>
<listOptionValue builtIn="false" value="/usr/home/shurik/src/esp8266/esp-open-sdk/sdk/include"/>
<listOptionValue builtIn="false" value="/usr/home/shurik/src/esp8266/Sming/Sming"/>
</option>
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.405688396" languageId="org.eclipse.cdt.core.gcc" languageName="GNU C" sourceContentType="org.eclipse.cdt.core.cSource,org.eclipse.cdt.core.cHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
</tool>
</toolChain>
</folderInfo>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
</cconfiguration>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<project id="TyTherm.null.1386076036" name="TyTherm"/>
</storageModule>
<storageModule moduleId="scannerConfiguration">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
<scannerConfigBuildInfo instanceId="0.2058741737">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.mingw.base.1135534147;cdt.managedbuild.toolchain.gnu.mingw.base.1135534147.86962463;cdt.managedbuild.tool.gnu.cpp.compiler.mingw.base.454898447;cdt.managedbuild.tool.gnu.cpp.compiler.input.501261625">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.mingw.base.1135534147;cdt.managedbuild.toolchain.gnu.mingw.base.1135534147.86962463;cdt.managedbuild.tool.gnu.c.compiler.mingw.base.2032390008;cdt.managedbuild.tool.gnu.c.compiler.input.1700912488">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="0.358052692">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="0.147001341">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="0.1962726862">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets">
<buildTargets>
<target name="all" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>all</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
<target name="rebuild" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>rebuild</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
<target name="flash" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>flash</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
</buildTargets>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
<storageModule moduleId="refreshScope" versionNumber="2">
<configuration configurationName="Default">
<resource resourceType="PROJECT" workspacePath="/TyTherm"/>
</configuration>
</storageModule>
</cproject>
27 changes: 27 additions & 0 deletions Basic_WebSkeletonApp/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>MeteoControl</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.core.ccnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
</natures>
</projectDescription>
24 changes: 24 additions & 0 deletions Basic_WebSkeletonApp/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#####################################################################
#### Please don't change this file. Use Makefile-user.mk instead ####
#####################################################################
# Including user Makefile.
# Should be used to set project-specific parameters
include ./Makefile-user.mk

# Important parameters check.
# We need to make sure SMING_HOME and ESP_HOME variables are set.
# You can use Makefile-user.mk in each project or use enviromental variables to set it globally.

ifndef SMING_HOME
$(error SMING_HOME is not set. Please configure it in Makefile-user.mk)
endif
ifndef ESP_HOME
$(error ESP_HOME is not set. Please configure it in Makefile-user.mk)
endif

# Include main Sming Makefile
ifeq ($(RBOOT_ENABLED), 1)
include $(SMING_HOME)/Makefile-rboot.mk
else
include $(SMING_HOME)/Makefile-project.mk
endif
29 changes: 29 additions & 0 deletions Basic_WebSkeletonApp/Makefile-user.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## Local build configuration
## Parameters configured here will override default and ENV values.
## Uncomment and change examples:

## ESP_HOME sets the path where ESP tools and SDK are located.
## Windows:
# ESP_HOME = c:/Espressif

## MacOS / Linux:
#ESP_HOME = /opt/esp-open-sdk

## SMING_HOME sets the path where Sming framework is located.
## Windows:
# SMING_HOME = c:/tools/sming/Sming

# MacOS / Linux
# SMING_HOME = /opt/sming/Sming

## COM port parameter is reqruied to flash firmware correctly.
## Windows:
# COM_PORT = COM3

# MacOS / Linux:
# COM_PORT = /dev/tty.usbserial

# Com port speed
# COM_SPEED = 115200

SPIFF_SIZE = 196608
13 changes: 13 additions & 0 deletions Basic_WebSkeletonApp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Basic application that can be used as a start point for some useful App.

Features:

* can setup wifi ssid and wifi password for STA (wifi client) mode either from own AP or as connected to some wifi network
* if preconfigured wifi network is unreachable after 20 seconds start AP named TyTherm with hardcoded password (see source)
* can enable/disable STA (wifi client) mode
* own AP autodisable after successful connection to preconfigured wifi network
* form population and sending is done with json+ajax
* demonstrate usage of getting raw http request body to be processed as json
* demonstrate how to fill html template on client side with more flexible than Smings Templating - JavaScript

App called TyTherm because it is base for TinY TermOmeter :)
54 changes: 54 additions & 0 deletions Basic_WebSkeletonApp/app/application.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include <user_config.h>
#include <tytherm.h>

Timer counterTimer;
void counter_loop();
unsigned long counter = 0;

void init()
{
spiffs_mount(); // Mount file system, in order to work with files
Serial.begin(SERIAL_BAUD_RATE); // 115200 by default
Serial.systemDebugOutput(false);
Serial.commandProcessing(false);

//SET higher CPU freq & disable wifi sleep
system_update_cpu_freq(SYS_CPU_160MHZ);
wifi_set_sleep_type(NONE_SLEEP_T);

ActiveConfig = loadConfig();

if (ActiveConfig.StaEnable)
{
WifiStation.waitConnection(StaConnectOk, StaConnectTimeout, StaConnectFail);
WifiStation.enable(true);
WifiStation.config(ActiveConfig.StaSSID, ActiveConfig.StaPassword);
}
else
{
WifiStation.enable(false);
}

startWebServer();

counterTimer.initializeMs(1000, counter_loop).start();
}

void counter_loop()
{
counter++;
}

void StaConnectOk()
{
Serial.println("connected to AP");
WifiAccessPoint.enable(false);
}

void StaConnectFail()
{
Serial.println("connection FAILED");
WifiStation.disconnect();
WifiAccessPoint.config("TyTherm", "ENTERYOURPASSWD", AUTH_WPA2_PSK);
WifiAccessPoint.enable(true);
}
48 changes: 48 additions & 0 deletions Basic_WebSkeletonApp/app/configuration.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include <tytherm.h>

ThermConfig ActiveConfig;

ThermConfig loadConfig()
{
StaticJsonBuffer<ConfigJsonBufferSize> jsonBuffer;
ThermConfig cfg;
if (fileExist(THERM_CONFIG_FILE))
{
int size = fileGetSize(THERM_CONFIG_FILE);
char* jsonString = new char[size + 1];
fileGetContent(THERM_CONFIG_FILE, jsonString, size + 1);
JsonObject& root = jsonBuffer.parseObject(jsonString);

JsonObject& network = root["network"];
cfg.StaSSID = String((const char*)network["StaSSID"]);
cfg.StaPassword = String((const char*)network["StaPassword"]);
cfg.StaEnable = network["StaEnable"];

delete[] jsonString;
}
else
{
//Factory defaults if no config file present
cfg.StaSSID = WIFI_SSID;
cfg.StaPassword = WIFI_PWD;
}
return cfg;
}

void saveConfig(ThermConfig& cfg)
{
StaticJsonBuffer<ConfigJsonBufferSize> jsonBuffer;
JsonObject& root = jsonBuffer.createObject();

JsonObject& network = jsonBuffer.createObject();
root["network"] = network;
network["StaSSID"] = cfg.StaSSID.c_str();
network["StaPassword"] = cfg.StaPassword.c_str();
network["StaEnable"] = cfg.StaEnable;

char buf[ConfigFileBufferSize];
root.prettyPrintTo(buf, sizeof(buf));
fileSetContent(THERM_CONFIG_FILE, buf);
}


Loading

0 comments on commit 0857d58

Please sign in to comment.