diff --git a/Sming/SmingCore/Platform/AccessPoint.cpp b/Sming/SmingCore/Platform/AccessPoint.cpp index 56a4b060db..fc1aedeaf3 100644 --- a/Sming/SmingCore/Platform/AccessPoint.cpp +++ b/Sming/SmingCore/Platform/AccessPoint.cpp @@ -16,11 +16,14 @@ AccessPointClass::AccessPointClass() runConfig = NULL; } -void AccessPointClass::enable(bool enabled) +void AccessPointClass::enable(bool enabled, bool save) { uint8 mode = wifi_get_opmode() & ~SOFTAP_MODE; if (enabled) mode |= SOFTAP_MODE; - wifi_set_opmode(mode); + if (save) + wifi_set_opmode(mode); + else + wifi_set_opmode_current(mode); } bool AccessPointClass::isEnabled() diff --git a/Sming/SmingCore/Platform/AccessPoint.h b/Sming/SmingCore/Platform/AccessPoint.h index 954f82c3e3..c05e1d4b1c 100644 --- a/Sming/SmingCore/Platform/AccessPoint.h +++ b/Sming/SmingCore/Platform/AccessPoint.h @@ -35,8 +35,9 @@ class AccessPointClass : protected ISystemReadyHandler /** @brief Enable or disable WiFi AP * @param enabled True to enable AP. False to disable. + * @param save True to save operational mode to flash, False to set current operational mode only */ - void enable(bool enabled); + void enable(bool enabled, bool save = false); /** @brief Get WiFi AP enable status * @retval bool True if WiFi AP enabled. diff --git a/Sming/SmingCore/Platform/Station.cpp b/Sming/SmingCore/Platform/Station.cpp index be5c98bcf4..1aea18ff6d 100644 --- a/Sming/SmingCore/Platform/Station.cpp +++ b/Sming/SmingCore/Platform/Station.cpp @@ -26,11 +26,14 @@ StationClass::~StationClass() connectionTimer = NULL; } -void StationClass::enable(bool enabled) +void StationClass::enable(bool enabled, bool save) { uint8 mode = wifi_get_opmode() & ~STATION_MODE; if (enabled) mode |= STATION_MODE; - wifi_set_opmode(mode); + if (save) + wifi_set_opmode(mode); + else + wifi_set_opmode_current(mode); } bool StationClass::isEnabled() @@ -82,6 +85,11 @@ bool StationClass::config(String ssid, String password, bool autoConnectOnStartu return true; } +void StationClass::connect() +{ + wifi_station_connect(); +} + void StationClass::disconnect() { wifi_station_disconnect(); diff --git a/Sming/SmingCore/Platform/Station.h b/Sming/SmingCore/Platform/Station.h index bdc7f3177c..738006df73 100644 --- a/Sming/SmingCore/Platform/Station.h +++ b/Sming/SmingCore/Platform/Station.h @@ -85,8 +85,9 @@ class StationClass : protected ISystemReadyHandler /** @brief Enable / disable WiFi station * @param enabled True to enable station. False to disable. + * @param save True to save operational mode to flash, False to set current operational mode only */ - void enable(bool enabled); + void enable(bool enabled, bool save = false); /** @brief Get WiFi station enable status * @retval bool True if WiFi station enabled @@ -100,6 +101,10 @@ class StationClass : protected ISystemReadyHandler */ bool config(String ssid, String password, bool autoConnectOnStartup = true); + /** @brief Connect WiFi station to network + */ + void connect(); + /** @brief Disconnect WiFi station from network */ void disconnect(); diff --git a/Sming/SmingCore/Platform/WifiEvents.cpp b/Sming/SmingCore/Platform/WifiEvents.cpp new file mode 100644 index 0000000000..a811a31876 --- /dev/null +++ b/Sming/SmingCore/Platform/WifiEvents.cpp @@ -0,0 +1,138 @@ +/* + * WifiEvents.cpp + * + * Created on: 19 февр. 2016 г. + * Author: shurik + */ + +#include + +WifiEventsClass WifiEvents; + +WifiEventsClass::WifiEventsClass() +{ + wifi_set_event_handler_cb(staticWifiEventHandler); +} + +void WifiEventsClass::onStationConnect(onStationConnectDelegate delegateFunction) +{ + onSTAConnect = delegateFunction; +} + +void WifiEventsClass::onStationDisconnect(onStationDisconnectDelegate delegateFunction) +{ + onSTADisconnect = delegateFunction; +} + +void WifiEventsClass::onStationAuthModeChange(onStationAuthModeChangeDelegate delegateFunction) +{ + onSTAAuthModeChange = delegateFunction; +} + +void WifiEventsClass::onStationGotIP(onStationGotIPDelegate delegateFunction) +{ + onSTAGotIP = delegateFunction; +} + +void WifiEventsClass::onAccessPointConnect(onAccessPointConnectDelegate delegateFunction) +{ + onSOFTAPConnect = delegateFunction; +} + +void WifiEventsClass::onAccessPointDisconnect(onAccessPointDisconnectDelegate delegateFunction) +{ + onSOFTAPDisconnect = delegateFunction; +} + +void WifiEventsClass::onAccessPointProbeReqRecved(onAccessPointProbeReqRecvedDelegate delegateFunction) +{ + onSOFTAPProbeReqRecved = delegateFunction; +} + +void WifiEventsClass::staticWifiEventHandler(System_Event_t *evt) +{ + WifiEvents.WifiEventHandler(evt); +} + +void WifiEventsClass::WifiEventHandler(System_Event_t *evt) +{ + debugf("event %x\n", evt->event); + + switch (evt->event) + { + case EVENT_STAMODE_CONNECTED: + debugf("connect to ssid %s, channel %d\n", + evt->event_info.connected.ssid, + evt->event_info.connected.channel); + if (onSTAConnect) + { + onSTAConnect((const char *)evt->event_info.connected.ssid, + evt->event_info.connected.ssid_len, + evt->event_info.connected.bssid, + evt->event_info.connected.channel); + } + break; + case EVENT_STAMODE_DISCONNECTED: + debugf("disconnect from ssid %s, reason %d\n", + evt->event_info.disconnected.ssid, + evt->event_info.disconnected.reason); + if (onSTADisconnect) + { + onSTADisconnect((const char *)evt->event_info.disconnected.ssid, + evt->event_info.disconnected.ssid_len, + evt->event_info.disconnected.bssid, + evt->event_info.disconnected.reason); + } + break; + case EVENT_STAMODE_AUTHMODE_CHANGE: + debugf("mode: %d -> %d\n", + evt->event_info.auth_change.old_mode, + evt->event_info.auth_change.new_mode); + if (onSTAAuthModeChange) + { + onSTAAuthModeChange(evt->event_info.auth_change.old_mode, + evt->event_info.auth_change.new_mode); + } + break; + case EVENT_STAMODE_GOT_IP: + debugf("ip:" IPSTR ",mask:" IPSTR ",gw:" IPSTR, + IP2STR(&evt->event_info.got_ip.ip), + IP2STR(&evt->event_info.got_ip.mask), + IP2STR(&evt->event_info.got_ip.gw)); + debugf("\n"); + if (onSTAGotIP) + { + onSTAGotIP(evt->event_info.got_ip.ip, + evt->event_info.got_ip.mask, + evt->event_info.got_ip.gw); + } + break; + case EVENT_SOFTAPMODE_STACONNECTED: + debugf("station: " MACSTR "join, AID = %d\n", + MAC2STR(evt->event_info.sta_connected.mac), + evt->event_info.sta_connected.aid); + if (onSOFTAPConnect) + { + onSOFTAPConnect(evt->event_info.sta_connected.mac, evt->event_info.sta_connected.aid); + } + break; + case EVENT_SOFTAPMODE_STADISCONNECTED: + debugf("station: " MACSTR "leave, AID = %d\n", + MAC2STR(evt->event_info.sta_disconnected.mac), + evt->event_info.sta_disconnected.aid); + if (onSOFTAPDisconnect) + { + onSOFTAPDisconnect(evt->event_info.sta_disconnected.mac, evt->event_info.sta_disconnected.aid); + } + break; + case EVENT_SOFTAPMODE_PROBEREQRECVED: + if (onSOFTAPDisconnect) + { + onSOFTAPProbeReqRecved(evt->event_info.ap_probereqrecved.rssi, evt->event_info.ap_probereqrecved.mac); + } + break; + default: + break; + } + +} diff --git a/Sming/SmingCore/Platform/WifiEvents.h b/Sming/SmingCore/Platform/WifiEvents.h new file mode 100644 index 0000000000..e0afe4cb74 --- /dev/null +++ b/Sming/SmingCore/Platform/WifiEvents.h @@ -0,0 +1,52 @@ +/* + * WifiEvents.h + * + * Created on: 19 февр. 2016 г. + * Author: shurik + */ + +#ifndef SMINGCORE_PLATFORM_WIFIEVENTS_H_ +#define SMINGCORE_PLATFORM_WIFIEVENTS_H_ + +#include "../SmingCore/Delegate.h" +#include "../../Wiring/WString.h" +#include "../../Wiring/IPAddress.h" + +//Define WifiEvents Delegates types +typedef Delegate onStationConnectDelegate; +typedef Delegate onStationDisconnectDelegate; +typedef Delegate onStationAuthModeChangeDelegate; +typedef Delegate onStationGotIPDelegate; +typedef Delegate onAccessPointConnectDelegate; +typedef Delegate onAccessPointDisconnectDelegate; +typedef Delegate onAccessPointProbeReqRecvedDelegate; + +class WifiEventsClass +{ +public: + WifiEventsClass(); + + void onStationConnect(onStationConnectDelegate delegateFunction); + void onStationDisconnect(onStationDisconnectDelegate delegateFunction); + void onStationAuthModeChange(onStationAuthModeChangeDelegate delegateFunction); + void onStationGotIP(onStationGotIPDelegate delegateFunction); + void onAccessPointConnect(onAccessPointConnectDelegate delegateFunction); + void onAccessPointDisconnect(onAccessPointDisconnectDelegate delegateFunction); + void onAccessPointProbeReqRecved(onAccessPointProbeReqRecvedDelegate delegateFunction); + +private: + static void staticWifiEventHandler(System_Event_t *evt); + void WifiEventHandler(System_Event_t *evt); + + onStationConnectDelegate onSTAConnect = nullptr; + onStationDisconnectDelegate onSTADisconnect = nullptr; + onStationAuthModeChangeDelegate onSTAAuthModeChange = nullptr; + onStationGotIPDelegate onSTAGotIP = nullptr; + onAccessPointConnectDelegate onSOFTAPConnect = nullptr; + onAccessPointDisconnectDelegate onSOFTAPDisconnect = nullptr; + onAccessPointProbeReqRecvedDelegate onSOFTAPProbeReqRecved = nullptr; +}; + + +extern WifiEventsClass WifiEvents; +#endif /* SMINGCORE_PLATFORM_WIFIEVENTS_H_ */ diff --git a/Sming/SmingCore/SmingCore.h b/Sming/SmingCore/SmingCore.h index f0f8382e8f..06774bf78e 100644 --- a/Sming/SmingCore/SmingCore.h +++ b/Sming/SmingCore/SmingCore.h @@ -28,6 +28,7 @@ #include "SPISoft.h" #include "Platform/System.h" +#include "Platform/WifiEvents.h" #include "Platform/Station.h" #include "Platform/AccessPoint.h" #include "Platform/WDT.h" diff --git a/samples/Basic_WebSkeletonApp/.cproject b/samples/Basic_WebSkeletonApp/.cproject new file mode 100644 index 0000000000..b317b1cc50 --- /dev/null +++ b/samples/Basic_WebSkeletonApp/.cproject @@ -0,0 +1,95 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + make + + all + true + true + true + + + make + + rebuild + true + true + true + + + make + + flash + true + true + true + + + + diff --git a/samples/Basic_WebSkeletonApp/.project b/samples/Basic_WebSkeletonApp/.project new file mode 100644 index 0000000000..bae000f0ff --- /dev/null +++ b/samples/Basic_WebSkeletonApp/.project @@ -0,0 +1,27 @@ + + + Basic_WebSkeletonApp + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/samples/Basic_WebSkeletonApp/Makefile b/samples/Basic_WebSkeletonApp/Makefile new file mode 100644 index 0000000000..16d76cd676 --- /dev/null +++ b/samples/Basic_WebSkeletonApp/Makefile @@ -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 diff --git a/samples/Basic_WebSkeletonApp/Makefile-user.mk b/samples/Basic_WebSkeletonApp/Makefile-user.mk new file mode 100644 index 0000000000..265efd479c --- /dev/null +++ b/samples/Basic_WebSkeletonApp/Makefile-user.mk @@ -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 diff --git a/samples/Basic_WebSkeletonApp/README.md b/samples/Basic_WebSkeletonApp/README.md new file mode 100644 index 0000000000..975543ebd1 --- /dev/null +++ b/samples/Basic_WebSkeletonApp/README.md @@ -0,0 +1,14 @@ +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 +* demonstrate new way of catching wif-events with WifiEvents class +* if preconfigured wifi network is unreachable 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 :) diff --git a/samples/Basic_WebSkeletonApp/app/application.cpp b/samples/Basic_WebSkeletonApp/app/application.cpp new file mode 100644 index 0000000000..cb04a7d20c --- /dev/null +++ b/samples/Basic_WebSkeletonApp/app/application.cpp @@ -0,0 +1,63 @@ +#include +#include + +Timer counterTimer; +void counter_loop(); +unsigned long counter = 0; + +void STADisconnect(String ssid, uint8_t ssid_len, uint8_t bssid[6], uint8_t reason); +void STAGotIP(IPAddress ip, IPAddress mask, IPAddress gateway); + +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(); + + // Attach Wifi events handlers + WifiEvents.onStationDisconnect(STADisconnect); + WifiEvents.onStationGotIP(STAGotIP); + + startWebServer(); + + counterTimer.initializeMs(1000, counter_loop).start(); +} + +void counter_loop() +{ + counter++; +} + +void STADisconnect(String ssid, uint8_t ssid_len, uint8_t bssid[6], uint8_t reason) +{ + debugf("DISCONNECT - SSID: %s, REASON: %d\n", ssid.c_str(), reason); + + if (!WifiAccessPoint.isEnabled()) + { + debugf("Starting OWN AP"); + WifiStation.disconnect(); + WifiAccessPoint.enable(true); + WifiStation.connect(); + } +} + +void STAGotIP(IPAddress ip, IPAddress mask, IPAddress gateway) +{ + debugf("GOTIP - IP: %s, MASK: %s, GW: %s\n", ip.toString().c_str(), + mask.toString().c_str(), + gateway.toString().c_str()); + + if (WifiAccessPoint.isEnabled()) + { + debugf("Shutdown OWN AP"); + WifiAccessPoint.enable(false); + } + // Add commands to be executed after successfully connecting to AP and got IP from it +} diff --git a/samples/Basic_WebSkeletonApp/app/configuration.cpp b/samples/Basic_WebSkeletonApp/app/configuration.cpp new file mode 100644 index 0000000000..b7b99e5ea1 --- /dev/null +++ b/samples/Basic_WebSkeletonApp/app/configuration.cpp @@ -0,0 +1,48 @@ +#include + +ThermConfig ActiveConfig; + +ThermConfig loadConfig() +{ + StaticJsonBuffer 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 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); +} + + diff --git a/samples/Basic_WebSkeletonApp/app/webserver.cpp b/samples/Basic_WebSkeletonApp/app/webserver.cpp new file mode 100644 index 0000000000..e8623a6448 --- /dev/null +++ b/samples/Basic_WebSkeletonApp/app/webserver.cpp @@ -0,0 +1,121 @@ +#include + + +bool serverStarted = false; +HttpServer server; + +void onIndex(HttpRequest &request, HttpResponse &response) +{ + response.setCache(86400, true); // It's important to use cache for better performance. + response.sendFile("index.html"); +} + +void onConfiguration(HttpRequest &request, HttpResponse &response) +{ + + if (request.getRequestMethod() == RequestMethod::POST) + { + debugf("Update config"); + // Update config + if (request.getBody() == NULL) + { + debugf("NULL bodyBuf"); + return; + } + else + { + StaticJsonBuffer jsonBuffer; + JsonObject& root = jsonBuffer.parseObject(request.getBody()); + root.prettyPrintTo(Serial); //Uncomment it for debuging + + if (root["StaSSID"].success()) // Settings + { + uint8_t PrevStaEnable = ActiveConfig.StaEnable; + + ActiveConfig.StaSSID = String((const char *)root["StaSSID"]); + ActiveConfig.StaPassword = String((const char *)root["StaPassword"]); + ActiveConfig.StaEnable = root["StaEnable"]; + + if (PrevStaEnable && ActiveConfig.StaEnable) + { + WifiStation.enable(true); + WifiAccessPoint.enable(false); + WifiStation.config(ActiveConfig.StaSSID, ActiveConfig.StaPassword); + } + else if (ActiveConfig.StaEnable) + { + WifiStation.enable(true, true); + WifiAccessPoint.enable(false, true); + WifiStation.config(ActiveConfig.StaSSID, ActiveConfig.StaPassword); + } + else + { + WifiStation.enable(false, true); + WifiAccessPoint.enable(true, true); + WifiAccessPoint.config("TyTherm", "ENTERYOURPASSWD", AUTH_WPA2_PSK); + } + } + } + saveConfig(ActiveConfig); + } + else + { + response.setCache(86400, true); // It's important to use cache for better performance. + response.sendFile("config.html"); + } +} + +void onConfiguration_json(HttpRequest &request, HttpResponse &response) +{ + JsonObjectStream* stream = new JsonObjectStream(); + JsonObject& json = stream->getRoot(); + + json["StaSSID"] = ActiveConfig.StaSSID; + json["StaPassword"] = ActiveConfig.StaPassword; + json["StaEnable"] = ActiveConfig.StaEnable; + + response.sendJsonObject(stream); +} +void onFile(HttpRequest &request, HttpResponse &response) +{ + String file = request.getPath(); + if (file[0] == '/') + file = file.substring(1); + + if (file[0] == '.') + response.forbidden(); + else + { + response.setCache(86400, true); // It's important to use cache for better performance. + response.sendFile(file); + } +} + +void onAJAXGetState(HttpRequest &request, HttpResponse &response) +{ + JsonObjectStream* stream = new JsonObjectStream(); + JsonObject& json = stream->getRoot(); + + json["counter"] = counter; + + response.sendJsonObject(stream); +} + + +void startWebServer() +{ + if (serverStarted) return; + + server.listen(80); + server.addPath("/", onIndex); + server.addPath("/config", onConfiguration); + server.addPath("/config.json", onConfiguration_json); + server.addPath("/state", onAJAXGetState); + server.setDefaultHandler(onFile); + serverStarted = true; + + if (WifiStation.isEnabled()) + debugf("STA: %s", WifiStation.getIP().toString().c_str()); + if (WifiAccessPoint.isEnabled()) + debugf("AP: %s", WifiAccessPoint.getIP().toString().c_str()); +} diff --git a/samples/Basic_WebSkeletonApp/files/bootstrap.min.css.gz b/samples/Basic_WebSkeletonApp/files/bootstrap.min.css.gz new file mode 100644 index 0000000000..80c9946433 Binary files /dev/null and b/samples/Basic_WebSkeletonApp/files/bootstrap.min.css.gz differ diff --git a/samples/Basic_WebSkeletonApp/files/config.html b/samples/Basic_WebSkeletonApp/files/config.html new file mode 100644 index 0000000000..6a93eb7bef --- /dev/null +++ b/samples/Basic_WebSkeletonApp/files/config.html @@ -0,0 +1,69 @@ + + + + + + + + TyTherm configuration + + + + + + + + + + +
+
+ +

TyTherm

+
+ +
+

 

+
+ +
+
+
+

Network

+
+
+
+
+ + +
+
+ + +
+
+ + +
+ + +
+
+
+
+ + + +
+
+ +
+ + \ No newline at end of file diff --git a/samples/Basic_WebSkeletonApp/files/config.js b/samples/Basic_WebSkeletonApp/files/config.js new file mode 100644 index 0000000000..2ff2d1e4d3 --- /dev/null +++ b/samples/Basic_WebSkeletonApp/files/config.js @@ -0,0 +1,38 @@ +function get_config() { + $.getJSON('/config.json', + function(data) { + $.each(data, function(key, value){ + document.getElementById(key).value = value; + if (data.StaEnable == 1) { + document.getElementById('StaEnable').checked = true; + } + else + document.getElementById('StaEnable').checked = false; + }); + }); +} + + +function post_netcfg(event) { + event.preventDefault(); + var formData = { + 'StaSSID' : document.getElementById('StaSSID').value, + 'StaPassword' : document.getElementById('StaPassword').value, + 'StaEnable' : (document.getElementById('StaEnable').checked ? 1 : 0) + }; + $.ajax({ + type : 'POST', + url : '/config', + contentType : 'application/json; charset=utf-8', + data : JSON.stringify(formData), + dataType : 'json' + }) +} + + +$( document ).ready(function() { + get_config(); + + document.getElementById('form_netcfg').addEventListener('submit', post_netcfg); + document.getElementById('netcfg_cancel').addEventListener('click', get_config); +}); \ No newline at end of file diff --git a/samples/Basic_WebSkeletonApp/files/index.html b/samples/Basic_WebSkeletonApp/files/index.html new file mode 100644 index 0000000000..eb890a0140 --- /dev/null +++ b/samples/Basic_WebSkeletonApp/files/index.html @@ -0,0 +1,51 @@ + + + + + + + + TyTherm Status + + + + + + + + + + +
+
+ +

TyTherm

+
+ +
+

 

+
+
+
+
+

Counter

+
+
+

{counter}

+
+
+
+ +
+
+ +
+ + \ No newline at end of file diff --git a/samples/Basic_WebSkeletonApp/files/index.js b/samples/Basic_WebSkeletonApp/files/index.js new file mode 100644 index 0000000000..4733242d66 --- /dev/null +++ b/samples/Basic_WebSkeletonApp/files/index.js @@ -0,0 +1,9 @@ +$( document ).ready(function() { + + (function worker() { + $.getJSON('/state', function(data) { + document.getElementById('counter').textContent = data.counter; + setTimeout(worker, 5000); + }); + })(); +}); \ No newline at end of file diff --git a/samples/Basic_WebSkeletonApp/files/jquery-2.1.4.min.js.gz b/samples/Basic_WebSkeletonApp/files/jquery-2.1.4.min.js.gz new file mode 100644 index 0000000000..bc77dafe10 Binary files /dev/null and b/samples/Basic_WebSkeletonApp/files/jquery-2.1.4.min.js.gz differ diff --git a/samples/Basic_WebSkeletonApp/include/configuration.h b/samples/Basic_WebSkeletonApp/include/configuration.h new file mode 100644 index 0000000000..43d5c929c2 --- /dev/null +++ b/samples/Basic_WebSkeletonApp/include/configuration.h @@ -0,0 +1,30 @@ +#ifndef INCLUDE_CONFIGURATION_H_ +#define INCLUDE_CONFIGURATION_H_ + +#include +#include + +const char THERM_CONFIG_FILE[] = ".therm.conf"; // leading point for security reasons :) + +struct ThermConfig +{ + ThermConfig() + { + StaEnable = 1; //Enable WIFI Client + } + + String StaSSID; + String StaPassword; + uint8_t StaEnable; + +// ThermControl settings + + +}; + +ThermConfig loadConfig(); +void saveConfig(ThermConfig& cfg); + +extern ThermConfig ActiveConfig; + +#endif /* INCLUDE_CONFIGURATION_H_ */ diff --git a/samples/Basic_WebSkeletonApp/include/tytherm.h b/samples/Basic_WebSkeletonApp/include/tytherm.h new file mode 100644 index 0000000000..6fe5045df2 --- /dev/null +++ b/samples/Basic_WebSkeletonApp/include/tytherm.h @@ -0,0 +1,24 @@ +#ifndef INCLUDE_TYTHERM_H_ +#define INCLUDE_TYTHERM_H_ +#include +#include +#include + +//OneWire stuff +const uint8_t onewire_pin = 2; +extern OneWire ds; + +extern unsigned long counter; // Kind of heartbeat counter + +const uint8_t ConfigJsonBufferSize = 200; // Application configuration JsonBuffer size ,increase it if you have large config +const uint16_t ConfigFileBufferSize = 2048; // Application configuration FileBuffer size ,increase it if you have large config + +//Webserver +void startWebServer(); + +//STA disconnecter +const uint8_t StaConnectTimeout = 20; //15 sec to connect in STA mode +void StaConnectOk(); +void StaConnectFail(); + +#endif /* INCLUDE_HEATCONTROL_H_ */ diff --git a/samples/Basic_WebSkeletonApp/include/user_config.h b/samples/Basic_WebSkeletonApp/include/user_config.h new file mode 100644 index 0000000000..1c6ac36703 --- /dev/null +++ b/samples/Basic_WebSkeletonApp/include/user_config.h @@ -0,0 +1,45 @@ +#ifndef __USER_CONFIG_H__ +#define __USER_CONFIG_H__ + +#ifdef __cplusplus +extern "C" { +#endif + + // UART config + #define SERIAL_BAUD_RATE 115200 + + // ESP SDK config + #define LWIP_OPEN_SRC + #define USE_US_TIMER + + // Default types + #define __CORRECT_ISO_CPP_STDLIB_H_PROTO + #include + #include + + // Override c_types.h include and remove buggy espconn + #define _C_TYPES_H_ + #define _NO_ESPCON_ + + // Updated, compatible version of c_types.h + // Just removed types declared in + #include + + // System API declarations + #include + + // C++ Support + #include + // Extended string conversion for compatibility + #include + // Network base API + #include + + // Beta boards + #define BOARD_ESP01 + +#ifdef __cplusplus +} +#endif + +#endif