This commit is contained in:
fvanroie 2020-12-24 00:33:57 +00:00
commit 643f991435
27 changed files with 306 additions and 233 deletions

View File

@ -2,10 +2,9 @@
* Getting started
* [Quick start](quickstart.md)
* [Writing more pages](more-pages.md)
* [Custom navbar](custom-navbar.md)
* [Cover page](cover.md)
- [Hardware](./01-hardware.md)
- [Firmware Install](./02-installation.md)
- [Initial Setup](./03-wifi-setup.md)
* Objects
* [Button](13-objects?id=button)

View File

@ -60,6 +60,7 @@ build_flags =
-D HASP_VERSION_MAJOR=0
-D HASP_VERSION_MINOR=3
-D HASP_VERSION_REVISION=1
-D HASP_USE_CONFIG=1 ; Native application, not library
; -- Shared library dependencies in all environments
; Warning : don't put comments after github links => causes infinite download loop

View File

@ -527,7 +527,7 @@ void haspLoadPage(const char * pages)
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#if HASP_USE_CONFIG > 0
bool haspGetConfig(const JsonObject & settings)
{
bool changed = false;
@ -584,3 +584,4 @@ bool haspSetConfig(const JsonObject & settings)
return changed;
}
#endif // HASP_USE_CONFIG

View File

@ -1,6 +1,8 @@
/* MIT License - Copyright (c) 2020 Francis Van Roie
For full license information read the LICENSE file in the project folder */
#if HASP_USE_CONFIG > 0
#include "ArduinoJson.h"
#include "StreamUtils.h" // For EEPromStream
@ -478,4 +480,6 @@ bool configClearEeprom()
#else
return false;
#endif
}
}
#endif // HAS_USE_CONFIG

View File

@ -1,6 +1,8 @@
/* MIT License - Copyright (c) 2020 Francis Van Roie
For full license information read the LICENSE file in the project folder */
#if HASP_USE_CONFIG > 0
#ifndef HASP_CONFIG_H
#define HASP_CONFIG_H
@ -59,4 +61,6 @@ const char F_GPIO_CONFIG[] PROGMEM = "config";
const char HASP_CONFIG_FILE[] PROGMEM = "/config.json";
#endif
#endif
#endif // HASP_USE_CONFIG

View File

@ -19,12 +19,12 @@
//#include "time.h"
#if defined(ARDUINO_ARCH_ESP8266)
#include <sntp.h> // sntp_servermode_dhcp()
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <sntp.h> // sntp_servermode_dhcp()
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#elif defined(ARDUINO_ARCH_ESP32)
#include <WiFi.h>
#include <WiFiUdp.h>
#include <WiFi.h>
#include <WiFiUdp.h>
#endif
#include "hasp.h"
@ -35,27 +35,27 @@
#include "hasp_dispatch.h"
#ifdef USE_CONFIG_OVERRIDE
#include "user_config_override.h"
#include "user_config_override.h"
#endif
#ifndef SERIAL_SPEED
#define SERIAL_SPEED 115200
#define SERIAL_SPEED 115200
#endif
#if HASP_USE_SYSLOG > 0
#include <WiFiUdp.h>
#include <WiFiUdp.h>
#ifndef SYSLOG_SERVER
#define SYSLOG_SERVER ""
#endif
#ifndef SYSLOG_SERVER
#define SYSLOG_SERVER ""
#endif
#ifndef SYSLOG_PORT
#define SYSLOG_PORT 514
#endif
#ifndef SYSLOG_PORT
#define SYSLOG_PORT 514
#endif
#ifndef APP_NAME
#define APP_NAME "HASP"
#endif
#ifndef APP_NAME
#define APP_NAME "HASP"
#endif
// variables for debug stream writer
// static String debugOutput((char *)0);
@ -70,7 +70,7 @@ uint8_t debugSyslogProtocol = 0;
// A UDP instance to let us send and receive packets over UDP
WiFiUDP * syslogClient;
#define SYSLOG_PROTO_IETF 0
#define SYSLOG_PROTO_IETF 0
// Create a new syslog instance with LOG_KERN facility
// Syslog syslog(syslogClient, SYSLOG_SERVER, SYSLOG_PORT, MQTT_CLIENT, APP_NAME, LOG_KERN);
@ -193,6 +193,7 @@ void debugStop()
if(debugSerialStarted) Serial.flush();
}
#if HASP_USE_CONFIG > 0
bool debugGetConfig(const JsonObject & settings)
{
bool changed = false;
@ -203,7 +204,7 @@ bool debugGetConfig(const JsonObject & settings)
if(debugTelePeriod != settings[FPSTR(F_DEBUG_TELEPERIOD)].as<uint16_t>()) changed = true;
settings[FPSTR(F_DEBUG_TELEPERIOD)] = debugTelePeriod;
#if HASP_USE_SYSLOG > 0
#if HASP_USE_SYSLOG > 0
if(strcmp(debugSyslogHost, settings[FPSTR(F_CONFIG_HOST)].as<String>().c_str()) != 0) changed = true;
settings[FPSTR(F_CONFIG_HOST)] = debugSyslogHost;
@ -215,7 +216,7 @@ bool debugGetConfig(const JsonObject & settings)
if(debugSyslogFacility != settings[FPSTR(F_CONFIG_LOG)].as<uint8_t>()) changed = true;
settings[FPSTR(F_CONFIG_LOG)] = debugSyslogFacility;
#endif
#endif
if(changed) configOutput(settings, TAG_DEBG);
return changed;
@ -241,7 +242,7 @@ bool debugSetConfig(const JsonObject & settings)
changed |= configSet(debugTelePeriod, settings[FPSTR(F_DEBUG_TELEPERIOD)], F("debugTelePeriod"));
/* Syslog Settings*/
#if HASP_USE_SYSLOG > 0
#if HASP_USE_SYSLOG > 0
if(!settings[FPSTR(F_CONFIG_HOST)].isNull()) {
changed |= strcmp(debugSyslogHost, settings[FPSTR(F_CONFIG_HOST)]) != 0;
strncpy(debugSyslogHost, settings[FPSTR(F_CONFIG_HOST)], sizeof(debugSyslogHost));
@ -249,10 +250,11 @@ bool debugSetConfig(const JsonObject & settings)
changed |= configSet(debugSyslogPort, settings[FPSTR(F_CONFIG_PORT)], F("debugSyslogPort"));
changed |= configSet(debugSyslogProtocol, settings[FPSTR(F_CONFIG_PROTOCOL)], F("debugSyslogProtocol"));
changed |= configSet(debugSyslogFacility, settings[FPSTR(F_CONFIG_LOG)], F("debugSyslogFacility"));
#endif
#endif
return changed;
}
#endif // HASP_USE_CONFIG
inline void debugSendAnsiCode(const __FlashStringHelper * code, Print * _logOutput)
{
@ -546,9 +548,9 @@ void debugPrintPrefix(uint8_t tag, int level, Print * _logOutput)
}
debugPrintHaspMemory(level, _logOutput);
#if LV_MEM_CUSTOM == 0
#if LV_MEM_CUSTOM == 0
debugPrintLvglMemory(level, _logOutput);
#endif
#endif
}
return;
}
@ -605,15 +607,19 @@ void debugPreSetup(JsonObject settings)
Log.setPrefix(debugPrintPrefix); // Uncomment to get timestamps as prefix
Log.setSuffix(debugPrintSuffix); // Uncomment to get newline as suffix
uint32_t baudrate = settings[FPSTR(F_CONFIG_BAUD)].as<uint32_t>() * 10;
uint32_t baudrate = 0;
#if HASP_USE_CONFIG > 0
baudrate = settings[FPSTR(F_CONFIG_BAUD)].as<uint32_t>() * 10;
#endif
if(baudrate == 0) baudrate = SERIAL_SPEED;
if(baudrate >= 9600u) { /* the baudrates are stored divided by 10 */
#if defined(STM32F4xx)
#ifndef STM32_SERIAL1 // Define what Serial port to use for log output
#ifndef STM32_SERIAL1 // Define what Serial port to use for log output
Serial.setRx(PA3); // User Serial2
Serial.setTx(PA2);
#endif
#endif
#endif
Serial.begin(baudrate); /* prepare for possible serial debug */
delay(10);

View File

@ -24,8 +24,10 @@ void debugStopSyslog(void);
// void syslogSend(uint8_t log, const char * debugText);
/* ===== Read/Write Configuration ===== */
#if HASP_USE_CONFIG > 0
bool debugGetConfig(const JsonObject & settings);
bool debugSetConfig(const JsonObject & settings);
#endif
// void debugPrintPrefix(int level, Print * _logOutput);
// void debugPrintSuffix(int level, Print * _logOutput);

View File

@ -8,7 +8,6 @@
#include "hasp_dispatch.h"
#include "hasp_network.h" // for network_get_status()
#include "hasp_config.h"
#include "hasp_debug.h"
#include "hasp_object.h"
#include "hasp_gui.h"
@ -18,6 +17,10 @@
#include "hasp_hal.h"
#include "hasp.h"
#if HASP_USE_CONFIG > 0
#include "hasp_config.h"
#endif
extern unsigned long debugLastMillis; // UpdateStatus timer
uint8_t nCommands = 0;
@ -123,13 +126,16 @@ void dispatch_command(const char * topic, const char * payload)
} else if(topic == strstr_P(topic, PSTR("p["))) {
dispatch_process_button_attribute(topic, payload);
#if HASP_USE_WIFI > 0
#if HASP_USE_CONFIG > 0
#if HASP_USE_WIFI > 0
} else if(!strcmp_P(topic, F_CONFIG_SSID) || !strcmp_P(topic, F_CONFIG_PASS)) {
DynamicJsonDocument settings(45);
settings[topic] = payload;
wifiSetConfig(settings.as<JsonObject>());
#endif
#endif // HASP_USE_WIFI
#if HASP_USE_MQTT > 0
} else if(!strcmp_P(topic, PSTR("mqtthost")) || !strcmp_P(topic, PSTR("mqttport")) ||
!strcmp_P(topic, PSTR("mqttport")) || !strcmp_P(topic, PSTR("mqttuser")) ||
!strcmp_P(topic, PSTR("hostname"))) {
@ -137,11 +143,12 @@ void dispatch_command(const char * topic, const char * payload)
// memset(item, 0, sizeof(item));
// strncpy(item, topic + 4, 4);
#if HASP_USE_MQTT > 0
DynamicJsonDocument settings(45);
settings[topic + 4] = payload;
mqttSetConfig(settings.as<JsonObject>());
#endif
#endif // HASP_USE_MQTT
#endif // HASP_USE_CONFIG
} else {
if(strlen(payload) == 0) {
@ -167,11 +174,13 @@ void dispatch_topic_payload(const char * topic, const char * payload)
return;
}
#if HASP_USE_CONFIG > 0
if(topic == strstr_P(topic, PSTR("config/"))) { // startsWith command/
topic += 7u;
dispatch_config(topic, (char *)payload);
return;
}
#endif
dispatch_command(topic, (char *)payload); // dispatch as is
}
@ -237,6 +246,7 @@ void IRAM_ATTR dispatch_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, co
dispatch_state_msg(F("json"), payload);
}
#if HASP_USE_CONFIG > 0
// Get or Set a part of the config.json file
static void dispatch_config(const char * topic, const char * payload)
{
@ -281,42 +291,42 @@ static void dispatch_config(const char * topic, const char * payload)
haspGetConfig(settings);
}
#if HASP_USE_WIFI > 0
#if HASP_USE_WIFI > 0
else if(strcasecmp_P(topic, PSTR("wifi")) == 0) {
if(update)
wifiSetConfig(settings);
else
wifiGetConfig(settings);
}
#if HASP_USE_MQTT > 0
#if HASP_USE_MQTT > 0
else if(strcasecmp_P(topic, PSTR("mqtt")) == 0) {
if(update)
mqttSetConfig(settings);
else
mqttGetConfig(settings);
}
#endif
#if HASP_USE_TELNET > 0
// else if(strcasecmp_P(topic, PSTR("telnet")) == 0)
// telnetGetConfig(settings[F("telnet")]);
#endif
#if HASP_USE_MDNS > 0
#endif
#if HASP_USE_TELNET > 0
// else if(strcasecmp_P(topic, PSTR("telnet")) == 0)
// telnetGetConfig(settings[F("telnet")]);
#endif
#if HASP_USE_MDNS > 0
else if(strcasecmp_P(topic, PSTR("mdns")) == 0) {
if(update)
mdnsSetConfig(settings);
else
mdnsGetConfig(settings);
}
#endif
#if HASP_USE_HTTP > 0
#endif
#if HASP_USE_HTTP > 0
else if(strcasecmp_P(topic, PSTR("http")) == 0) {
if(update)
httpSetConfig(settings);
else
httpGetConfig(settings);
}
#endif
#endif
#endif
#endif
// Send output
if(!update) {
@ -325,6 +335,7 @@ static void dispatch_config(const char * topic, const char * payload)
dispatch_state_msg(F("config"), buffer);
}
}
#endif // HASP_USE_CONFIG
/********************************************** Input Events *******************************************/
// Map events to either ON or OFF (UP or DOWN)
@ -415,12 +426,12 @@ static inline void dispatch_state_msg(const __FlashStringHelper * subtopic, cons
#if !defined(HASP_USE_MQTT) && !defined(HASP_USE_TASMOTA_SLAVE)
Log.notice(TAG_MSGR, F("%s => %s"), String(subtopic).c_str(), payload);
#else
#if HASP_USE_MQTT > 0
#if HASP_USE_MQTT > 0
mqtt_send_state(subtopic, payload);
#endif
#if HASP_USE_TASMOTA_SLAVE > 0
#endif
#if HASP_USE_TASMOTA_SLAVE > 0
slave_send_state(subtopic, payload);
#endif
#endif
#endif
}
@ -603,7 +614,9 @@ void dispatch_web_update(const char *, const char * espOtaUrl)
// restart the device
void dispatch_reboot(bool saveConfig)
{
#if HASP_USE_CONFIG > 0
if(saveConfig) configWriteConfig();
#endif
#if HASP_USE_MQTT > 0
mqttStop(); // Stop the MQTT Client first
#endif
@ -632,10 +645,10 @@ void dispatch_output_statusupdate(const char *, const char *)
snprintf_P(data, sizeof(data), PSTR("{\"status\":\"available\",\"version\":\"%s\",\"uptime\":%lu,"), buffer,
long(millis() / 1000));
#if HASP_USE_WIFI > 0
#if HASP_USE_WIFI > 0
network_get_statusupdate(buffer, sizeof(buffer));
strcat(data, buffer);
#endif
#endif
snprintf_P(buffer, sizeof(buffer), PSTR("\"heapFree\":%u,\"heapFrag\":%u,\"espCore\":\"%s\","),
halGetFreeHeap(), halGetHeapFragmentation(), halGetCoreVersion().c_str());
strcat(data, buffer);
@ -643,10 +656,10 @@ void dispatch_output_statusupdate(const char *, const char *)
haspGetPage(), (HASP_NUM_PAGES));
strcat(data, buffer);
#if defined(ARDUINO_ARCH_ESP8266)
#if defined(ARDUINO_ARCH_ESP8266)
snprintf_P(buffer, sizeof(buffer), PSTR("\"espVcc\":%.2f,"), (float)ESP.getVcc() / 1000);
strcat(data, buffer);
#endif
#endif
snprintf_P(buffer, sizeof(buffer), PSTR("\"tftDriver\":\"%s\",\"tftWidth\":%u,\"tftHeight\":%u}"),
halDisplayDriverName().c_str(), (TFT_WIDTH), (TFT_HEIGHT));
@ -723,7 +736,9 @@ void dispatchSetup()
dispatch_add_command(PSTR("restart"), dispatch_reboot);
dispatch_add_command(PSTR("screenshot"), dispatch_screenshot);
dispatch_add_command(PSTR("factoryreset"), dispatch_factory_reset);
#if HASP_USE_CONFIG > 0
dispatch_add_command(PSTR("setupap"), oobeFakeSetup);
#endif
/* WARNING: remember to expand the commands array when adding new commands */
}

View File

@ -437,6 +437,7 @@ hasp_gpio_config_t gpioGetPinConfig(uint8_t num)
}
////////////////////////////////////////////////////////////////////////////////////////////////////
#if HASP_USE_CONFIG > 0
bool gpioGetConfig(const JsonObject & settings)
{
bool changed = false;
@ -511,3 +512,4 @@ bool gpioSetConfig(const JsonObject & settings)
return changed;
}
#endif // HASP_USE_CONFIG

View File

@ -30,8 +30,11 @@ bool gpioInUse(uint8_t gpio);
bool gpioConfigInUse(uint8_t num);
int8_t gpioGetFreeConfigId();
hasp_gpio_config_t gpioGetPinConfig(uint8_t num);
#if HASP_USE_CONFIG > 0
bool gpioGetConfig(const JsonObject & settings);
bool gpioSetConfig(const JsonObject & settings);
#endif
#define HASP_GPIO_FREE 0x00
#define HASP_GPIO_USED 0x01

View File

@ -730,6 +730,7 @@ int8_t guiGetDim()
}
////////////////////////////////////////////////////////////////////////////////////////////////////
#if HASP_USE_CONFIG > 0
bool guiGetConfig(const JsonObject & settings)
{
bool changed = false;
@ -845,6 +846,7 @@ bool guiSetConfig(const JsonObject & settings)
return changed;
}
#endif // HASP_USE_CONFIG
/* **************************** SCREENSHOTS ************************************** */
#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 || HASP_USE_HTTP > 0

View File

@ -32,9 +32,9 @@ bool guiGetBacklight();
bool IRAM_ATTR guiCheckSleep();
/* ===== Read/Write Configuration ===== */
#if HASP_USE_CONFIG > 0
bool guiGetConfig(const JsonObject & settings);
bool guiSetConfig(const JsonObject & settings);
// lv_res_t guiChangeTheme(uint8_t themeid, uint16_t hue, String font, uint8_t fontsize);
#endif
#endif

View File

@ -899,7 +899,8 @@ void handleFileList()
}
#endif
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
#if HASP_USE_CONFIG > 0
void webHandleConfig()
{ // http://plate01/config
if(!httpIsAuthenticated(F("config"))) return;
@ -914,10 +915,10 @@ void webHandleConfig()
if(save == String(PSTR("hasp"))) {
haspSetConfig(settings.as<JsonObject>());
#if HASP_USE_MQTT > 0
#if HASP_USE_MQTT > 0
} else if(save == String(PSTR("mqtt"))) {
mqttSetConfig(settings.as<JsonObject>());
#endif
#endif
} else if(save == String(PSTR("gui"))) {
settings[FPSTR(F_GUI_POINTER)] = webServer.hasArg(PSTR("pointer"));
@ -932,20 +933,20 @@ void webHandleConfig()
// Password might have changed
if(!httpIsAuthenticated(F("config"))) return;
#if HASP_USE_WIFI > 0
#if HASP_USE_WIFI > 0
} else if(save == String(PSTR("wifi"))) {
wifiSetConfig(settings.as<JsonObject>());
#endif
#endif
}
}
}
// Reboot after saving wifi config in AP mode
#if HASP_USE_WIFI > 0 && !defined(STM32F4xx)
// Reboot after saving wifi config in AP mode
#if HASP_USE_WIFI > 0 && !defined(STM32F4xx)
if(WiFi.getMode() != WIFI_STA) {
httpHandleReboot();
}
#endif
#endif
{
String httpMessage((char *)0);
@ -954,15 +955,15 @@ void webHandleConfig()
httpMessage += httpGetNodename();
httpMessage += F("</h1><hr>");
#if HASP_USE_WIFI > 0
#if HASP_USE_WIFI > 0
httpMessage +=
F("<p><form method='get' action='/config/wifi'><button type='submit'>Wifi Settings</button></form></p>");
#endif
#endif
#if HASP_USE_MQTT > 0
#if HASP_USE_MQTT > 0
httpMessage +=
F("<p><form method='get' action='/config/mqtt'><button type='submit'>MQTT Settings</button></form></p>");
#endif
#endif
httpMessage +=
F("<p><form method='get' action='/config/http'><button type='submit'>HTTP Settings</button></form></p>");
@ -973,10 +974,10 @@ void webHandleConfig()
httpMessage +=
F("<p><form method='get' action='/config/hasp'><button type='submit'>HASP Settings</button></form></p>");
#if HASP_USE_GPIO > 0
#if HASP_USE_GPIO > 0
httpMessage +=
F("<p><form method='get' action='/config/gpio'><button type='submit'>GPIO Settings</button></form></p>");
#endif
#endif
httpMessage +=
F("<p><form method='get' action='/config/debug'><button type='submit'>Debug Settings</button></form></p>");
@ -994,8 +995,8 @@ void webHandleConfig()
webSendFooter();
}
////////////////////////////////////////////////////////////////////////////////////////////////////
#if HASP_USE_MQTT > 0
////////////////////////////////////////////////////////////////////////////////////////////////////
#if HASP_USE_MQTT > 0
void webHandleMqttConfig()
{ // http://plate01/config/mqtt
if(!httpIsAuthenticated(F("config/mqtt"))) return;
@ -1042,7 +1043,7 @@ void webHandleMqttConfig()
// httpMessage.clear();
webSendFooter();
}
#endif
#endif
////////////////////////////////////////////////////////////////////////////////////////////////////
void webHandleGuiConfig()
@ -1090,7 +1091,7 @@ void webHandleGuiConfig()
int8_t bcklpin = settings[FPSTR(F_GUI_BACKLIGHTPIN)].as<int8_t>();
httpMessage += F("<p><b>Backlight Control</b> <select id='bcklpin' name='bcklpin'>");
httpMessage += getOption(-1, F("None"), bcklpin == -1);
#if defined(ARDUINO_ARCH_ESP32)
#if defined(ARDUINO_ARCH_ESP32)
httpMessage += getOption(5, F("GPIO 5"), bcklpin == 5); // D8 on ESP32 for D1 mini 32
httpMessage += getOption(16, F("GPIO 16"), bcklpin == 16); // D4 on ESP32 for D1 mini 32
httpMessage += getOption(17, F("GPIO 17"), bcklpin == 17); // D3 on ESP32 for D1 mini 32
@ -1100,12 +1101,12 @@ void webHandleGuiConfig()
httpMessage += getOption(22, F("GPIO 22"), bcklpin == 22); // D2 on ESP32 for D1 mini 32
httpMessage += getOption(23, F("GPIO 23"), bcklpin == 23); // D7 on ESP32 for D1 mini 32
httpMessage += getOption(32, F("GPIO 32"), bcklpin == 32); // TFT_LED on the Lolin D32 Pro
#else
#else
httpMessage += getOption(5, F("D1 - GPIO 5"), bcklpin == 5);
httpMessage += getOption(4, F("D2 - GPIO 4"), bcklpin == 4);
httpMessage += getOption(0, F("D3 - GPIO 0"), bcklpin == 0);
httpMessage += getOption(2, F("D4 - GPIO 2"), bcklpin == 2);
#endif
#endif
httpMessage += F("</select></p>");
httpMessage += F("<p><button type='submit' name='save' value='gui'>Save Settings</button></p></form>");
@ -1124,8 +1125,8 @@ void webHandleGuiConfig()
if(webServer.hasArg(F("action"))) dispatch_text_line(webServer.arg(F("action")).c_str());
}
////////////////////////////////////////////////////////////////////////////////////////////////////
#if HASP_USE_WIFI > 0
////////////////////////////////////////////////////////////////////////////////////////////////////
#if HASP_USE_WIFI > 0
void webHandleWifiConfig()
{ // http://plate01/config/wifi
if(!httpIsAuthenticated(F("config/wifi"))) return;
@ -1150,26 +1151,26 @@ void webHandleWifiConfig()
}
httpMessage += F("'><p><button type='submit' name='save' value='wifi'>Save Settings</button></p></form>");
#if HASP_USE_WIFI > 0 && !defined(STM32F4xx)
#if HASP_USE_WIFI > 0 && !defined(STM32F4xx)
if(WiFi.getMode() == WIFI_STA) {
httpMessage +=
PSTR("<p><form method='get' action='/config'><button type='submit'>Configuration</button></form></p>");
}
#endif
#endif
webSendPage(httpGetNodename(), httpMessage.length(), false);
webServer.sendContent(httpMessage);
#if defined(STM32F4xx)
#if defined(STM32F4xx)
httpMessage = "";
#else
#else
httpMessage.clear();
#endif
#endif
webSendFooter();
}
#endif
#endif
////////////////////////////////////////////////////////////////////////////////////////////////////
#if HASP_USE_HTTP > 0
////////////////////////////////////////////////////////////////////////////////////////////////////
#if HASP_USE_HTTP > 0
void webHandleHttpConfig()
{ // http://plate01/config/http
if(!httpIsAuthenticated(F("config/http"))) return;
@ -1204,10 +1205,10 @@ void webHandleHttpConfig()
// httpMessage.clear();
webSendFooter();
}
#endif
#endif
////////////////////////////////////////////////////////////////////////////////////////////////////
#if defined(HASP_USE_GPIO) && (HASP_USE_GPIO > 0)
////////////////////////////////////////////////////////////////////////////////////////////////////
#if defined(HASP_USE_GPIO) && (HASP_USE_GPIO > 0)
void webHandleGpioConfig()
{ // http://plate01/config/gpio
if(!httpIsAuthenticated(F("config/gpio"))) return;
@ -1407,7 +1408,7 @@ void webHandleGpioOptions()
if(webServer.hasArg(F("action"))) dispatch_text_line(webServer.arg(F("action")).c_str()); // Security check
}
#endif // HASP_USE_GPIO
#endif // HASP_USE_GPIO
////////////////////////////////////////////////////////////////////////////////////////////////////
void webHandleDebugConfig()
@ -1440,7 +1441,7 @@ void webHandleDebugConfig()
httpMessage += settings[FPSTR(F_DEBUG_TELEPERIOD)].as<String>();
httpMessage += F("'></p>");
#if HASP_USE_SYSLOG > 0
#if HASP_USE_SYSLOG > 0
httpMessage += F("<b>Syslog Hostame</b> <i><small>(optional)</small></i><input id='host' "
"name='host' maxlength=31 placeholder='logserver' value='");
httpMessage += settings[FPSTR(F_CONFIG_HOST)].as<String>();
@ -1459,7 +1460,7 @@ void webHandleDebugConfig()
httpMessage += F(">IETF (RFC 5424) &nbsp; <input id='proto' name='proto' type='radio' value='1'");
if(settings[FPSTR(F_CONFIG_PROTOCOL)].as<uint8_t>() == 1) httpMessage += F(" checked");
httpMessage += F(">BSD (RFC 3164)");
#endif
#endif
httpMessage += F("</p><p><button type='submit' name='save' value='debug'>Save Settings</button></p></form>");
@ -1496,24 +1497,24 @@ void webHandleHaspConfig()
httpMessage += F("<p><b>UI Theme</b> <i><small>(required)</small></i><select id='theme' name='theme'>");
uint8_t themeid = settings[FPSTR(F_CONFIG_THEME)].as<uint8_t>();
// httpMessage += getOption(0, F("Built-in"), themeid == 0);
#if LV_USE_THEME_HASP == 1
// httpMessage += getOption(0, F("Built-in"), themeid == 0);
#if LV_USE_THEME_HASP == 1
httpMessage += getOption(2, F("Hasp Dark"), themeid == 2);
httpMessage += getOption(1, F("Hasp Light"), themeid == 1);
#endif
#if LV_USE_THEME_EMPTY == 1
#endif
#if LV_USE_THEME_EMPTY == 1
httpMessage += getOption(0, F("Empty"), themeid == 0);
#endif
#if LV_USE_THEME_MONO == 1
#endif
#if LV_USE_THEME_MONO == 1
httpMessage += getOption(3, F("Mono"), themeid == 3);
#endif
#if LV_USE_THEME_MATERIAL == 1
#endif
#if LV_USE_THEME_MATERIAL == 1
httpMessage += getOption(5, F("Material Dark"), themeid == 5);
httpMessage += getOption(4, F("Material Light"), themeid == 4);
#endif
#if LV_USE_THEME_TEMPLATE == 1
#endif
#if LV_USE_THEME_TEMPLATE == 1
httpMessage += getOption(7, F("Template"), themeid == 7);
#endif
#endif
httpMessage += F("</select></br>");
httpMessage +=
F("<b>Hue</b><div style='width:100%;background-image:linear-gradient(to "
@ -1523,7 +1524,7 @@ void webHandleHaspConfig()
httpMessage += F("'></div></p>");
httpMessage += F("<p><b>Default Font</b><select id='font' name='font'><option value=''>None</option>");
#if defined(ARDUINO_ARCH_ESP32)
#if defined(ARDUINO_ARCH_ESP32)
File root = HASP_FS.open("/");
File file = root.openNextFile();
@ -1534,17 +1535,17 @@ void webHandleHaspConfig()
getOption(file.name(), file.name(), filename == settings[FPSTR(F_CONFIG_ZIFONT)].as<String>());
file = root.openNextFile();
}
#elif defined(ARDUINO_ARCH_ESP8266)
#elif defined(ARDUINO_ARCH_ESP8266)
Dir dir = HASP_FS.openDir("/");
while(dir.next()) {
File file = dir.openFile("r");
File file = dir.openFile("r");
String filename = file.name();
if(filename.endsWith(".zi"))
httpMessage +=
getOption(file.name(), file.name(), filename == settings[FPSTR(F_CONFIG_ZIFONT)].as<String>());
file.close();
}
#endif
#endif
httpMessage += F("</select></p>");
httpMessage += F("<p><b>Startup Layout</b> <i><small>(optional)</small></i><input id='pages' "
@ -1571,6 +1572,7 @@ void webHandleHaspConfig()
// httpMessage.clear();
webSendFooter();
}
#endif // HASP_USE_CONFIG
////////////////////////////////////////////////////////////////////////////////////////////////////
void httpHandleNotFound()
@ -1602,14 +1604,6 @@ void httpHandleNotFound()
webServer.send(404, PSTR("text/plain"), httpMessage.c_str());
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void webHandleSaveConfig()
{
if(!httpIsAuthenticated(F("saveConfig"))) return;
configWriteConfig();
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void webHandleFirmware()
{
@ -1664,6 +1658,15 @@ void httpHandleEspFirmware()
// espStartOta(webServer.arg("espFirmware"));
}
////////////////////////////////////////////////////////////////////////////////////////////////////
#if HASP_USE_CONFIG > 0
void webHandleSaveConfig()
{
if(!httpIsAuthenticated(F("saveConfig"))) return;
configWriteConfig();
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void httpHandleResetConfig()
{ // http://plate01/resetConfig
@ -1713,6 +1716,7 @@ void httpHandleResetConfig()
dispatch_reboot(false); // Do not save the current config
}
}
#endif // HASP_USE_CONFIG
void httpStart()
{
@ -1750,109 +1754,96 @@ void httpSetup()
{
// httpSetConfig(settings);
#if HASP_USE_WIFI > 0
#if !defined(STM32F4xx)
if(WiFi.getMode() != WIFI_STA) {
Log.notice(TAG_HTTP, F("Wifi access point"));
webServer.on(F("/"), webHandleWifiConfig);
} else {
#endif
#endif
webServer.on(F("/page/"), []() {
String pageid = webServer.arg(F("page"));
webServer.send(200, PSTR("text/plain"), "Page: '" + pageid + "'");
haspSetPage(pageid.toInt());
});
#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
webServer.on(F("/list"), HTTP_GET, handleFileList);
// load editor
webServer.on(F("/edit"), HTTP_GET, []() {
if(!handleFileRead("/edit.htm")) {
char mimetype[16];
snprintf(mimetype, sizeof(mimetype), PSTR("text/plain"));
webServer.send_P(404, mimetype, PSTR("FileNotFound"));
}
});
webServer.on(F("/edit"), HTTP_PUT, handleFileCreate);
webServer.on(F("/edit"), HTTP_DELETE, handleFileDelete);
// first callback is called after the request has ended with all parsed arguments
// second callback handles file uploads at that location
webServer.on(
F("/edit"), HTTP_POST,
[]() {
webServer.send(200, "text/plain", "");
Log.verbose(TAG_HTTP, F("Headers: %d"), webServer.headers());
},
handleFileUpload);
#endif
// get heap status, analog input value and all GPIO statuses in one json call
/*webServer.on(F("/all"), HTTP_GET, []() {
String json;
json.reserve(128);
json += F("{\"heap\":");
json += String(ESP.getFreeHeap());
json += F(", \"analog\":");
json += String(analogRead(A0));
json += F("}");
char mimetype[128];
sprintf(mimetype, PSTR("text/json"));
webServer.send(200, mimetype, json);
json.clear();
});*/
webServer.on(F("/"), webHandleRoot);
webServer.on(F("/info"), webHandleInfo);
webServer.on(F("/config/hasp"), webHandleHaspConfig);
webServer.on(F("/config/http"), webHandleHttpConfig);
webServer.on(F("/config/gui"), webHandleGuiConfig);
webServer.on(F("/config/debug"), webHandleDebugConfig);
#if HASP_USE_MQTT > 0
webServer.on(F("/config/mqtt"), webHandleMqttConfig);
#endif
#if HASP_USE_WIFI > 0
webServer.on(F("/config/wifi"), webHandleWifiConfig);
#endif
#if HASP_USE_GPIO > 0
webServer.on(F("/config/gpio"), webHandleGpioConfig);
webServer.on(F("/config/gpio/options"), webHandleGpioOptions);
#endif
webServer.on(F("/screenshot"), webHandleScreenshot);
webServer.on(F("/saveConfig"), webHandleSaveConfig);
webServer.on(F("/resetConfig"), httpHandleResetConfig);
webServer.on(F("/firmware"), webHandleFirmware);
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
webServer.on(
F("/update"), HTTP_POST,
[]() {
webServer.send(200, "text/plain", "");
Log.verbose(TAG_HTTP, F("Total size: %s"), webServer.hostHeader().c_str());
},
webHandleFirmwareUpdate);
webServer.on(F("/espfirmware"), httpHandleEspFirmware);
#endif
webServer.on(F("/reboot"), httpHandleReboot);
webServer.onNotFound(httpHandleNotFound);
#if HASP_USE_WIFI > 0
#if !defined(STM32F4xx)
}
#endif
#endif
// Shared pages
webServer.on(F("/about"), webHandleAbout);
webServer.on(F("/config"), webHandleConfig);
webServer.onNotFound(httpHandleNotFound);
// ask server to track these headers
const char * headerkeys[] = {"Content-Length"}; // "Authentication"
size_t headerkeyssize = sizeof(headerkeys) / sizeof(char *);
webServer.collectHeaders(headerkeys, headerkeyssize);
// Shared pages
webServer.on(F("/about"), webHandleAbout);
webServer.onNotFound(httpHandleNotFound);
#if HASP_USE_WIFI > 0
#if !defined(STM32F4xx)
#if HASP_USE_CONFIG > 0
if(WiFi.getMode() != WIFI_STA) {
Log.notice(TAG_HTTP, F("Wifi access point"));
webServer.on(F("/"), webHandleWifiConfig);
return;
}
#endif
#endif
#endif
webServer.on(F("/page/"), []() {
String pageid = webServer.arg(F("page"));
webServer.send(200, PSTR("text/plain"), "Page: '" + pageid + "'");
haspSetPage(pageid.toInt());
});
#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
webServer.on(F("/list"), HTTP_GET, handleFileList);
// load editor
webServer.on(F("/edit"), HTTP_GET, []() {
if(!handleFileRead("/edit.htm")) {
char mimetype[16];
snprintf(mimetype, sizeof(mimetype), PSTR("text/plain"));
webServer.send_P(404, mimetype, PSTR("FileNotFound"));
}
});
webServer.on(F("/edit"), HTTP_PUT, handleFileCreate);
webServer.on(F("/edit"), HTTP_DELETE, handleFileDelete);
// first callback is called after the request has ended with all parsed arguments
// second callback handles file uploads at that location
webServer.on(
F("/edit"), HTTP_POST,
[]() {
webServer.send(200, "text/plain", "");
Log.verbose(TAG_HTTP, F("Headers: %d"), webServer.headers());
},
handleFileUpload);
#endif
webServer.on(F("/"), webHandleRoot);
webServer.on(F("/info"), webHandleInfo);
webServer.on(F("/screenshot"), webHandleScreenshot);
webServer.on(F("/firmware"), webHandleFirmware);
webServer.on(F("/reboot"), httpHandleReboot);
webServer.onNotFound(httpHandleNotFound);
#if HASP_USE_CONFIG > 0
webServer.on(F("/config/hasp"), webHandleHaspConfig);
webServer.on(F("/config/http"), webHandleHttpConfig);
webServer.on(F("/config/gui"), webHandleGuiConfig);
webServer.on(F("/config/debug"), webHandleDebugConfig);
#if HASP_USE_MQTT > 0
webServer.on(F("/config/mqtt"), webHandleMqttConfig);
#endif
#if HASP_USE_WIFI > 0
webServer.on(F("/config/wifi"), webHandleWifiConfig);
#endif
#if HASP_USE_GPIO > 0
webServer.on(F("/config/gpio"), webHandleGpioConfig);
webServer.on(F("/config/gpio/options"), webHandleGpioOptions);
#endif
webServer.on(F("/saveConfig"), webHandleSaveConfig);
webServer.on(F("/resetConfig"), httpHandleResetConfig);
webServer.on(F("/config"), webHandleConfig);
#endif // HASP_USE_CONFIG
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
webServer.on(
F("/update"), HTTP_POST,
[]() {
webServer.send(200, "text/plain", "");
Log.verbose(TAG_HTTP, F("Total size: %s"), webServer.hostHeader().c_str());
},
webHandleFirmwareUpdate);
webServer.on(F("/espfirmware"), httpHandleEspFirmware);
#endif
Log.trace(TAG_HTTP, F("Setup Complete"));
// webStart(); Wait for network connection
}
@ -1886,6 +1877,7 @@ void httpEvery5Seconds()
}
////////////////////////////////////////////////////////////////////////////////////////////////////
#if HASP_USE_CONFIG > 0
bool httpGetConfig(const JsonObject & settings)
{
bool changed = false;
@ -1932,6 +1924,7 @@ bool httpSetConfig(const JsonObject & settings)
return changed;
}
#endif // HASP_USE_CONFIG
size_t httpClientWrite(const uint8_t * buf, size_t size)
{

View File

@ -15,7 +15,9 @@ void httpStop(void);
size_t httpClientWrite(const uint8_t * buf, size_t size); // Screenshot Write Data
#if HASP_USE_CONFIG > 0
bool httpGetConfig(const JsonObject & settings);
bool httpSetConfig(const JsonObject & settings);
#endif // HASP_USE_CONFIG
#endif

View File

@ -83,6 +83,7 @@ void mdnsStop()
#endif
}
#if HASP_USE_CONFIG > 0
bool mdnsGetConfig(const JsonObject & settings)
{
bool changed = false;
@ -108,5 +109,6 @@ bool mdnsSetConfig(const JsonObject & settings)
return changed;
}
#endif // HASP_USE_CONFIG
#endif // HASP_USE_MDNS

View File

@ -13,7 +13,9 @@ void mdnsStart(void);
void mdnsStop(void);
/* ===== Read/Write Configuration ===== */
#if HASP_USE_CONFIG > 0
bool mdnsGetConfig(const JsonObject & settings);
bool mdnsSetConfig(const JsonObject & settings);
#endif
#endif

View File

@ -409,6 +409,7 @@ void mqttStop()
}
}
#if HASP_USE_CONFIG > 0
bool mqttGetConfig(const JsonObject & settings)
{
bool changed = false;
@ -493,5 +494,6 @@ bool mqttSetConfig(const JsonObject & settings)
return changed;
}
#endif // HASP_USE_CONFIG
#endif // HASP_USE_MQTT

View File

@ -17,8 +17,10 @@ void IRAM_ATTR mqtt_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, const
bool IRAM_ATTR mqttIsConnected();
#if HASP_USE_CONFIG > 0
bool mqttGetConfig(const JsonObject & settings);
bool mqttSetConfig(const JsonObject & settings);
#endif
String mqttGetNodename(void);

View File

@ -1,6 +1,8 @@
/* MIT License - Copyright (c) 2020 Francis Van Roie
For full license information read the LICENSE file in the project folder */
#if HASP_USE_CONFIG > 0
#include "hasp_conf.h"
#include "lvgl.h"
@ -362,4 +364,5 @@ void oobeFakeSetup(const char *, const char *)
Log.trace(TAG_OOBE, F("Already calibrated"));
}
#endif
}
}
#endif // HASP_USE_CONFIG

View File

@ -1,6 +1,10 @@
/* MIT License - Copyright (c) 2020 Francis Van Roie
For full license information read the LICENSE file in the project folder */
#if HASP_USE_CONFIG > 0
void oobeSetAutoCalibrate(bool cal);
bool oobeSetup();
void oobeFakeSetup(const char *, const char *); // for testing purposes only
void oobeFakeSetup(const char *, const char *); // for testing purposes only
#endif // HASP_USE_CONFIG

View File

@ -313,6 +313,7 @@ void IRAM_ATTR telnetLoop()
#endif
}
#if HASP_USE_CONFIG > 0
bool telnetGetConfig(const JsonObject & settings)
{
bool changed = false;
@ -345,5 +346,6 @@ bool telnetSetConfig(const JsonObject & settings)
return changed;
}
#endif // HASP_USE_CONFIG
#endif

View File

@ -22,9 +22,10 @@ void telnetStop(void);
/* ===== Getter and Setter Functions ===== */
/* ===== Read/Write Configuration ===== */
#if HASP_USE_CONFIG > 0
bool telnetSetConfig(const JsonObject & settings);
bool telnetGetConfig(const JsonObject & settings);
#endif
#define TELNET_UNAUTHENTICATED 0
#define TELNET_USERNAME_OK 10

View File

@ -508,7 +508,7 @@ void wifi_get_statusupdate(char * buffer, size_t len)
}
/* ============ Confiuration =============================================================== */
#if HASP_USE_CONFIG > 0
bool wifiGetConfig(const JsonObject & settings)
{
bool changed = false;
@ -549,5 +549,6 @@ bool wifiSetConfig(const JsonObject & settings)
return changed;
}
#endif // HASP_USE_CONFIG
#endif

View File

@ -15,7 +15,9 @@ void wifiStop(void);
bool wifiValidateSsid(const char * ssid, const char * pass);
void wifi_get_statusupdate(char * buffer, size_t len);
#if HASP_USE_CONFIG > 0
bool wifiGetConfig(const JsonObject & settings);
bool wifiSetConfig(const JsonObject & settings);
#endif
#endif

View File

@ -36,7 +36,9 @@ void setup()
/****************************
* Read & Apply User Configuration
***************************/
#if HASP_USE_CONFIG > 0
configSetup(); // also runs debugPreSetup(), debugSetup() and debugStart()
#endif
dispatchSetup();
guiSetup();
@ -57,7 +59,10 @@ void setup()
networkSetup();
#endif
if(!oobeSetup()) {
#if HASP_USE_CONFIG > 0
if(!oobeSetup())
#endif
{
haspSetup();
}

View File

@ -20,7 +20,7 @@ build_flags =
${esp32.build_flags}
;region -- TFT_eSPI build options ------------------------
${lcd.st7789}
${lcd.st7789v}
-D TFT_RST=19 ; FCP pin2 RESET
-D TFT_CLK=18 ; FCP pin3 SCL
-D TFT_DC=21 ; FCP pin4 D/C

View File

@ -23,7 +23,7 @@ lolin24 =
-D SPI_TOUCH_FREQUENCY=2500000
-D SPI_READ_FREQUENCY=20000000
-D USER_SETUP_LOADED=1
-D TOUCH_DRIVER=2046 ; XPT2046 Resistive touch panel driver
-D TOUCH_DRIVER=2046 ; XPT2046 Resistive SPI touch panel driver
-D SUPPORT_TRANSACTIONS
raspberrypi =
@ -35,7 +35,7 @@ raspberrypi =
-D SPI_FREQUENCY=80000000
-D SPI_TOUCH_FREQUENCY=2500000
-D USER_SETUP_LOADED=1
-D TOUCH_DRIVER=2046 ; XPT2046 Resistive touch panel driver
-D TOUCH_DRIVER=2046 ; XPT2046 Resistive SPI touch panel driver
-D SUPPORT_TRANSACTIONS
mrb3511 =
@ -45,18 +45,31 @@ mrb3511 =
-D TFT_HEIGHT=480
-D TFT_ROTATION=0 ; see TFT_ROTATION values
-D USER_SETUP_LOADED=1
-D TOUCH_DRIVER=911 ; GT911 Capacitive touch panel driver
-D TOUCH_DRIVER=911 ; GT911 Capacitive I2C touch panel driver
-D SUPPORT_TRANSACTIONS
st7789 =
st7789v =
-D ST7789_DRIVER=1
-D CGRAM_OFFSET=1 ; Library will add offsets required
;-D CGRAM_OFFSET=1 ; Library will add offsets required, only for 240x240
-D TFT_SDA_READ ; Read from display, it only provides an SDA pin
-D TFT_WIDTH=240
-D TFT_HEIGHT=320
-D TFT_ROTATION=0 ; see TFT_ROTATION values
-D TFT_RGB_ORDER=TFT_RGB ; Colour order Red-Green-Blue
;-D TFT_RGB_ORDER TFT_BGR ; Colour order Blue-Green-Red
-D SPI_FREQUENCY=80000000
-D SPI_READ_FREQUENCY=6000000
-D USER_SETUP_LOADED=1
-D TOUCH_DRIVER=6336 ; FT6336U Capacitive I2C touch panel driver
-D SUPPORT_TRANSACTIONS
wireless-tag =
-D ST7796_DRIVER=1
-D TFT_WIDTH=320
-D TFT_HEIGHT=480
-D TFT_ROTATION=0 ; see TFT_ROTATION values
-D SPI_FREQUENCY=25000000
-D SPI_TOUCH_FREQUENCY=2500000
-D SPI_FREQUENCY=40000000
-D SPI_READ_FREQUENCY=20000000
-D USER_SETUP_LOADED=1
-D TOUCH_DRIVER=2046 ; XPT2046 Resistive touch panel driver
-D SUPPORT_TRANSACTIONS
-D TOUCH_DRIVER=6336 ; FT6336U Capacitive I2C touch panel driver
-D SUPPORT_TRANSACTIONS