Add memory functions to device class

This commit is contained in:
fvanroie 2021-02-17 05:16:25 +01:00
parent a7e6def457
commit 09c9e7f066
12 changed files with 329 additions and 256 deletions

View File

@ -7,23 +7,24 @@
* INCLUDES * INCLUDES
*********************/ *********************/
#include "../../src/hal/hasp_hal.h" // for halGpioName() #include "../../src/hal/hasp_hal.h" // for halGpioName()
#include "../../src/dev/device.h"
#include "tft_espi_drv.h" #include "tft_espi_drv.h"
#include "ArduinoLog.h" #include "ArduinoLog.h"
#include "hasp_macro.h" #include "hasp_macro.h"
#if USE_TFT_ESPI != 0 #if USE_TFT_ESPI != 0
#include <stdbool.h> #include <stdbool.h>
#include "TFT_eSPI.h" #include "TFT_eSPI.h"
#include LV_DRV_DISP_INCLUDE #include LV_DRV_DISP_INCLUDE
#include LV_DRV_DELAY_INCLUDE #include LV_DRV_DELAY_INCLUDE
#include "bootscreen.h" // Sketch tab header for xbm images #include "bootscreen.h" // Sketch tab header for xbm images
/********************* /*********************
* DEFINES * DEFINES
*********************/ *********************/
#define TAG_TFT 22 #define TAG_TFT 22
/********************** /**********************
* TYPEDEFS * TYPEDEFS
@ -54,11 +55,11 @@ static TFT_eSPI tft;
*/ */
void tft_espi_init(uint8_t rotation, bool invert_display) void tft_espi_init(uint8_t rotation, bool invert_display)
{ {
#ifdef USE_DMA_TO_TFT #ifdef USE_DMA_TO_TFT
// DMA - should work with STM32F2xx/F4xx/F7xx processors // DMA - should work with STM32F2xx/F4xx/F7xx processors
// NOTE: >>>>>> DMA IS FOR SPI DISPLAYS ONLY <<<<<< // NOTE: >>>>>> DMA IS FOR SPI DISPLAYS ONLY <<<<<<
tft.initDMA(); // Initialise the DMA engine (tested with STM32F446 and STM32F767) tft.initDMA(); // Initialise the DMA engine (tested with STM32F446 and STM32F767)
#endif #endif
/* TFT init */ /* TFT init */
tft.begin(); tft.begin();
@ -77,11 +78,11 @@ void tft_espi_flush(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * c
/* Update TFT */ /* Update TFT */
tft.startWrite(); /* Start new TFT transaction */ tft.startWrite(); /* Start new TFT transaction */
tft.setWindow(area->x1, area->y1, area->x2, area->y2); /* set the working window */ tft.setWindow(area->x1, area->y1, area->x2, area->y2); /* set the working window */
#ifdef USE_DMA_TO_TFT #ifdef USE_DMA_TO_TFT
tft.pushPixelsDMA((uint16_t *)color_p, len); /* Write words at once */ tft.pushPixelsDMA((uint16_t *)color_p, len); /* Write words at once */
#else #else
tft.pushPixels((uint16_t *)color_p, len); /* Write words at once */ tft.pushPixels((uint16_t *)color_p, len); /* Write words at once */
#endif #endif
tft.endWrite(); /* terminate TFT transaction */ tft.endWrite(); /* terminate TFT transaction */
/* Tell lvgl that flushing is done */ /* Tell lvgl that flushing is done */
@ -98,7 +99,7 @@ void tft_espi_flush(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * c
// tft_espi_flush(x1, y1, x2, y2, color_p); // tft_espi_flush(x1, y1, x2, y2, color_p);
// } // }
#if defined(TOUCH_CS) #if defined(TOUCH_CS)
void tft_espi_calibrate(uint16_t * calData) void tft_espi_calibrate(uint16_t * calData)
{ {
@ -125,15 +126,15 @@ bool tft_espi_get_touch(int16_t * touchX, int16_t * touchY, uint16_t threshold)
{ {
return tft.getTouch((uint16_t *)touchX, (uint16_t *)touchY, threshold); return tft.getTouch((uint16_t *)touchX, (uint16_t *)touchY, threshold);
} }
#endif #endif
/********************** /**********************
* STATIC FUNCTIONS * STATIC FUNCTIONS
**********************/ **********************/
#if defined(ARDUINO_ARCH_ESP8266) #if defined(ARDUINO_ARCH_ESP8266)
ADC_MODE(ADC_VCC); // tftShowConfig measures the voltage on the pin ADC_MODE(ADC_VCC); // tftShowConfig measures the voltage on the pin
#endif #endif
static void tftOffsetInfo(uint8_t pin, uint8_t x_offset, uint8_t y_offset) static void tftOffsetInfo(uint8_t pin, uint8_t x_offset, uint8_t y_offset)
{ {
@ -160,21 +161,21 @@ static void tftShowConfig(TFT_eSPI & tft)
tft.getSetup(tftSetup); tft.getSetup(tftSetup);
LOG_VERBOSE(TAG_TFT, F("TFT_eSPI : v%s"), tftSetup.version.c_str()); LOG_VERBOSE(TAG_TFT, F("TFT_eSPI : v%s"), tftSetup.version.c_str());
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) #if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
LOG_VERBOSE(TAG_TFT, F("Processor : ESP%x"), tftSetup.esp); LOG_VERBOSE(TAG_TFT, F("Processor : ESP%x"), tftSetup.esp);
#else #else
LOG_VERBOSE(TAG_TFT, F("Processor : STM%x"), tftSetup.esp); LOG_VERBOSE(TAG_TFT, F("Processor : STM%x"), tftSetup.esp);
#endif #endif
LOG_VERBOSE(TAG_TFT, F("CPU freq. : %i MHz"), halGetCpuFreqMHz()); LOG_VERBOSE(TAG_TFT, F("CPU freq. : %i MHz"), haspDevice.get_cpu_frequency());
#if defined(ARDUINO_ARCH_ESP8266) #if defined(ARDUINO_ARCH_ESP8266)
LOG_VERBOSE(TAG_TFT, F("Voltage : %2.2f V"), ESP.getVcc() / 918.0); // 918 empirically determined LOG_VERBOSE(TAG_TFT, F("Voltage : %2.2f V"), ESP.getVcc() / 918.0); // 918 empirically determined
#endif #endif
LOG_VERBOSE(TAG_TFT, F("Transactns : %s"), (tftSetup.trans == 1) ? PSTR("Yes") : PSTR("No")); LOG_VERBOSE(TAG_TFT, F("Transactns : %s"), (tftSetup.trans == 1) ? PSTR("Yes") : PSTR("No"));
LOG_VERBOSE(TAG_TFT, F("Interface : %s"), (tftSetup.serial == 1) ? PSTR("SPI") : PSTR("Parallel")); LOG_VERBOSE(TAG_TFT, F("Interface : %s"), (tftSetup.serial == 1) ? PSTR("SPI") : PSTR("Parallel"));
#if defined(ARDUINO_ARCH_ESP8266) #if defined(ARDUINO_ARCH_ESP8266)
LOG_VERBOSE(TAG_TFT, F("SPI overlap: %s"), (tftSetup.overlap == 1) ? PSTR("Yes") : PSTR("No")); LOG_VERBOSE(TAG_TFT, F("SPI overlap: %s"), (tftSetup.overlap == 1) ? PSTR("Yes") : PSTR("No"));
#endif #endif
if(tftSetup.tft_driver != 0xE9D) // For ePaper displays the size is defined in the sketch if(tftSetup.tft_driver != 0xE9D) // For ePaper displays the size is defined in the sketch
{ {
@ -201,7 +202,7 @@ static void tftShowConfig(TFT_eSPI & tft)
tftPinInfo(F("MISO"), tftSetup.pin_tft_miso); tftPinInfo(F("MISO"), tftSetup.pin_tft_miso);
tftPinInfo(F("SCLK"), tftSetup.pin_tft_clk); tftPinInfo(F("SCLK"), tftSetup.pin_tft_clk);
#if defined(ARDUINO_ARCH_ESP8266) #if defined(ARDUINO_ARCH_ESP8266)
if(tftSetup.overlap == true) { if(tftSetup.overlap == true) {
LOG_VERBOSE(TAG_TFT, F("Overlap selected, following pins MUST be used:")); LOG_VERBOSE(TAG_TFT, F("Overlap selected, following pins MUST be used:"));
@ -212,7 +213,7 @@ static void tftShowConfig(TFT_eSPI & tft)
LOG_VERBOSE(TAG_TFT, F("TFT_DC and TFT_RST pins can be tftSetup defined")); LOG_VERBOSE(TAG_TFT, F("TFT_DC and TFT_RST pins can be tftSetup defined"));
} }
#endif #endif
tftPinInfo(F("TFT_CS"), tftSetup.pin_tft_cs); tftPinInfo(F("TFT_CS"), tftSetup.pin_tft_cs);
tftPinInfo(F("TFT_DC"), tftSetup.pin_tft_dc); tftPinInfo(F("TFT_DC"), tftSetup.pin_tft_dc);

View File

@ -39,19 +39,27 @@ class BaseDevice {
{ {
return true; return true;
} }
virtual size_t get_free_max_block()
{}
virtual size_t get_free_heap()
{}
virtual uint8_t get_heap_fragmentation()
{}
virtual uint16_t get_cpu_frequency()
{}
}; };
} // namespace dev } // namespace dev
#if defined(ESP32) #if defined(ESP32)
#warning Building for ESP32 Devices #warning Building for ESP32 Devices
#include "dev/esp32/esp32.h" #include "esp32/esp32.h"
#elif defined(ESP8266) #elif defined(ESP8266)
#warning Building for ESP8266 Devices #warning Building for ESP8266 Devices
#include "dev/esp8266/esp8266.h" #include "esp8266/esp8266.h"
#elif defined(STM32F4) #elif defined(STM32F4)
#warning Building for STM32F4xx Devices #warning Building for STM32F4xx Devices
#include "dev/stm32f4.h" #include "stm32f4/stm32f4.h"
#else #else
#warning Building for Generic Devices #warning Building for Generic Devices
using dev::BaseDevice; using dev::BaseDevice;

View File

@ -4,8 +4,8 @@
#include <Esp.h> #include <Esp.h>
#include "esp_system.h" #include "esp_system.h"
#include "dev/device.h" #include "../device.h"
#include "dev/esp32/esp32.h" #include "esp32.h"
#include "driver/adc.h" #include "driver/adc.h"
#include "esp_adc_cal.h" #include "esp_adc_cal.h"
@ -69,6 +69,31 @@ void Esp32Device::update_backlight()
} }
} }
size_t Esp32Device::get_free_max_block()
{
return ESP.getMaxAllocHeap();
}
size_t Esp32Device::get_free_heap()
{
return ESP.getFreeHeap();
}
uint8_t Esp32Device::get_heap_fragmentation()
{
uint32_t free = ESP.getFreeHeap();
if(free) {
return (int8_t)(100.00f - (float)ESP.getMaxAllocHeap() * 100.00f / (float)free);
} else {
return 100; // no free memory
}
}
uint16_t Esp32Device::get_cpu_frequency()
{
return ESP.getCpuFreqMHz();
}
} // namespace dev } // namespace dev
#if defined(LANBONL8) #if defined(LANBONL8)

View File

@ -4,7 +4,7 @@
#ifndef HASP_DEVICE_ESP32_H #ifndef HASP_DEVICE_ESP32_H
#define HASP_DEVICE_ESP32_H #define HASP_DEVICE_ESP32_H
#include "dev/device.h" #include "../device.h"
#if defined(ESP32) #if defined(ESP32)
@ -25,6 +25,14 @@ class Esp32Device : public BaseDevice {
bool get_backlight_power() override; bool get_backlight_power() override;
size_t get_free_max_block() override;
size_t get_free_heap() override;
uint8_t get_heap_fragmentation() override;
uint16_t get_cpu_frequency() override;
private: private:
uint8_t backlight_pin; uint8_t backlight_pin;
uint8_t backlight_level; uint8_t backlight_level;
@ -39,10 +47,10 @@ using dev::Esp32Device;
#if defined(LANBONL8) #if defined(LANBONL8)
#warning Building for Lanbon L8 #warning Building for Lanbon L8
#include "dev/esp32/lanbonl8.h" #include "lanbonl8.h"
#elif defined(M5STACK) #elif defined(M5STACK)
#warning Building for M5Stack core2 #warning Building for M5Stack core2
#include "dev/esp32/m5stackcore2.h" #include "m5stackcore2.h"
#else #else
extern dev::Esp32Device haspDevice; extern dev::Esp32Device haspDevice;
#endif #endif

View File

@ -4,7 +4,7 @@
#ifndef HASP_DEVICE_LANBONL8_H #ifndef HASP_DEVICE_LANBONL8_H
#define HASP_DEVICE_LANBONL8_H #define HASP_DEVICE_LANBONL8_H
#include "dev/esp32/esp32.h" #include "esp32.h"
#if defined(LANBONL8) #if defined(LANBONL8)

View File

@ -6,7 +6,7 @@
#if defined(M5STACK) #if defined(M5STACK)
#include "dev/esp32/esp32.h" #include "esp32.h"
namespace dev { namespace dev {

View File

@ -3,7 +3,7 @@
#include "Arduino.h" #include "Arduino.h"
#include <Esp.h> #include <Esp.h>
#include "dev/esp8266/esp8266.h" #include "esp8266.h"
#include "hasp_conf.h" #include "hasp_conf.h"
#include "hasp_debug.h" #include "hasp_debug.h"
@ -59,6 +59,26 @@ void Esp8266Device::update_backlight()
analogWrite(backlight_pin, backlight_power ? map(backlight_level, 0, 100, 0, 1023) : 0); analogWrite(backlight_pin, backlight_power ? map(backlight_level, 0, 100, 0, 1023) : 0);
} }
size_t Esp8266Device::get_free_max_block()
{
return ESP.getMaxFreeBlockSize();
}
size_t Esp8266Device::get_free_heap(void)
{
return ESP.getFreeHeap();
}
uint8_t Esp8266Device::get_heap_fragmentation()
{
return ESP.getHeapFragmentation();
}
uint16_t Esp8266Device::get_cpu_frequency()
{
return ESP.getCpuFreqMHz();
}
} // namespace dev } // namespace dev
dev::Esp8266Device haspDevice; dev::Esp8266Device haspDevice;

View File

@ -26,6 +26,14 @@ class Esp8266Device : public BaseDevice {
bool get_backlight_power() override; bool get_backlight_power() override;
size_t get_free_max_block() override;
size_t get_free_heap() override;
uint8_t get_heap_fragmentation() override;
uint16_t get_cpu_frequency() override;
private: private:
uint8_t backlight_pin; uint8_t backlight_pin;
uint8_t backlight_level; uint8_t backlight_level;

View File

@ -6,15 +6,15 @@
#include <Arduino.h> #include <Arduino.h>
void halRestartMcu(void); // void halRestartMcu(void);
uint8_t halGetHeapFragmentation(void);
String halGetResetInfo(void); String halGetResetInfo(void);
size_t halGetMaxFreeBlock(void); // uint8_t halGetHeapFragmentation(void);
size_t halGetFreeHeap(void); // size_t halGetMaxFreeBlock(void);
// size_t halGetFreeHeap(void);
String halGetCoreVersion(void); String halGetCoreVersion(void);
String halGetChipModel(); String halGetChipModel();
String halGetMacAddress(int start, const char * seperator); String halGetMacAddress(int start, const char * seperator);
uint16_t halGetCpuFreqMHz(void); // uint16_t halGetCpuFreqMHz(void);
String halDisplayDriverName(void); String halDisplayDriverName(void);
String halGpioName(uint8_t gpio); String halGpioName(uint8_t gpio);

View File

@ -875,7 +875,8 @@ void dispatch_reboot(bool saveConfig)
Serial.flush(); Serial.flush();
#endif #endif
halRestartMcu(); // halRestartMcu();
haspDevice.reboot();
} }
void dispatch_current_state() void dispatch_current_state()

View File

@ -19,15 +19,16 @@
//#include "time.h" //#include "time.h"
#if defined(ARDUINO_ARCH_ESP8266) #if defined(ARDUINO_ARCH_ESP8266)
#include <sntp.h> // sntp_servermode_dhcp() #include <sntp.h> // sntp_servermode_dhcp()
#include <ESP8266WiFi.h> #include <ESP8266WiFi.h>
#include <WiFiUdp.h> #include <WiFiUdp.h>
#elif defined(ARDUINO_ARCH_ESP32) #elif defined(ARDUINO_ARCH_ESP32)
#include <WiFi.h> #include <WiFi.h>
#include <WiFiUdp.h> #include <WiFiUdp.h>
#endif #endif
#include "hasp_conf.h" #include "hasp_conf.h"
#include "dev/device.h"
#include "hal/hasp_hal.h" #include "hal/hasp_hal.h"
#include "hasp_debug.h" #include "hasp_debug.h"
@ -37,27 +38,27 @@
#include "hasp/hasp.h" #include "hasp/hasp.h"
#ifdef USE_CONFIG_OVERRIDE #ifdef USE_CONFIG_OVERRIDE
#include "user_config_override.h" #include "user_config_override.h"
#endif #endif
#ifndef SERIAL_SPEED #ifndef SERIAL_SPEED
#define SERIAL_SPEED 115200 #define SERIAL_SPEED 115200
#endif #endif
#if HASP_USE_SYSLOG > 0 #if HASP_USE_SYSLOG > 0
#include <WiFiUdp.h> #include <WiFiUdp.h>
#ifndef SYSLOG_SERVER #ifndef SYSLOG_SERVER
#define SYSLOG_SERVER "" #define SYSLOG_SERVER ""
#endif #endif
#ifndef SYSLOG_PORT #ifndef SYSLOG_PORT
#define SYSLOG_PORT 514 #define SYSLOG_PORT 514
#endif #endif
#ifndef APP_NAME #ifndef APP_NAME
#define APP_NAME "HASP" #define APP_NAME "HASP"
#endif #endif
// variables for debug stream writer // variables for debug stream writer
// static String debugOutput((char *)0); // static String debugOutput((char *)0);
@ -72,7 +73,7 @@ uint8_t debugSyslogProtocol = 0;
// A UDP instance to let us send and receive packets over UDP // A UDP instance to let us send and receive packets over UDP
WiFiUDP * syslogClient; WiFiUDP * syslogClient;
#define SYSLOG_PROTO_IETF 0 #define SYSLOG_PROTO_IETF 0
// Create a new syslog instance with LOG_KERN facility // Create a new syslog instance with LOG_KERN facility
// Syslog syslog(syslogClient, SYSLOG_SERVER, SYSLOG_PORT, MQTT_CLIENT, APP_NAME, LOG_KERN); // Syslog syslog(syslogClient, SYSLOG_SERVER, SYSLOG_PORT, MQTT_CLIENT, APP_NAME, LOG_KERN);
@ -207,7 +208,7 @@ bool debugGetConfig(const JsonObject & settings)
if(debugTelePeriod != settings[FPSTR(FP_DEBUG_TELEPERIOD)].as<uint16_t>()) changed = true; if(debugTelePeriod != settings[FPSTR(FP_DEBUG_TELEPERIOD)].as<uint16_t>()) changed = true;
settings[FPSTR(FP_DEBUG_TELEPERIOD)] = debugTelePeriod; settings[FPSTR(FP_DEBUG_TELEPERIOD)] = debugTelePeriod;
#if HASP_USE_SYSLOG > 0 #if HASP_USE_SYSLOG > 0
if(strcmp(debugSyslogHost, settings[FPSTR(FP_CONFIG_HOST)].as<String>().c_str()) != 0) changed = true; if(strcmp(debugSyslogHost, settings[FPSTR(FP_CONFIG_HOST)].as<String>().c_str()) != 0) changed = true;
settings[FPSTR(FP_CONFIG_HOST)] = debugSyslogHost; settings[FPSTR(FP_CONFIG_HOST)] = debugSyslogHost;
@ -219,7 +220,7 @@ bool debugGetConfig(const JsonObject & settings)
if(debugSyslogFacility != settings[FPSTR(FP_CONFIG_LOG)].as<uint8_t>()) changed = true; if(debugSyslogFacility != settings[FPSTR(FP_CONFIG_LOG)].as<uint8_t>()) changed = true;
settings[FPSTR(FP_CONFIG_LOG)] = debugSyslogFacility; settings[FPSTR(FP_CONFIG_LOG)] = debugSyslogFacility;
#endif #endif
if(changed) configOutput(settings, TAG_DEBG); if(changed) configOutput(settings, TAG_DEBG);
return changed; return changed;
@ -244,8 +245,8 @@ bool debugSetConfig(const JsonObject & settings)
/* Teleperiod Settings*/ /* Teleperiod Settings*/
changed |= configSet(debugTelePeriod, settings[FPSTR(FP_DEBUG_TELEPERIOD)], F("debugTelePeriod")); changed |= configSet(debugTelePeriod, settings[FPSTR(FP_DEBUG_TELEPERIOD)], F("debugTelePeriod"));
/* Syslog Settings*/ /* Syslog Settings*/
#if HASP_USE_SYSLOG > 0 #if HASP_USE_SYSLOG > 0
if(!settings[FPSTR(FP_CONFIG_HOST)].isNull()) { if(!settings[FPSTR(FP_CONFIG_HOST)].isNull()) {
changed |= strcmp(debugSyslogHost, settings[FPSTR(FP_CONFIG_HOST)]) != 0; changed |= strcmp(debugSyslogHost, settings[FPSTR(FP_CONFIG_HOST)]) != 0;
strncpy(debugSyslogHost, settings[FPSTR(FP_CONFIG_HOST)], sizeof(debugSyslogHost)); strncpy(debugSyslogHost, settings[FPSTR(FP_CONFIG_HOST)], sizeof(debugSyslogHost));
@ -253,7 +254,7 @@ bool debugSetConfig(const JsonObject & settings)
changed |= configSet(debugSyslogPort, settings[FPSTR(FP_CONFIG_PORT)], F("debugSyslogPort")); changed |= configSet(debugSyslogPort, settings[FPSTR(FP_CONFIG_PORT)], F("debugSyslogPort"));
changed |= configSet(debugSyslogProtocol, settings[FPSTR(FP_CONFIG_PROTOCOL)], F("debugSyslogProtocol")); changed |= configSet(debugSyslogProtocol, settings[FPSTR(FP_CONFIG_PROTOCOL)], F("debugSyslogProtocol"));
changed |= configSet(debugSyslogFacility, settings[FPSTR(FP_CONFIG_LOG)], F("debugSyslogFacility")); changed |= configSet(debugSyslogFacility, settings[FPSTR(FP_CONFIG_LOG)], F("debugSyslogFacility"));
#endif #endif
return changed; return changed;
} }
@ -369,9 +370,9 @@ static void debugPrintTimestamp(int level, Print * _logOutput)
static void debugPrintHaspMemory(int level, Print * _logOutput) static void debugPrintHaspMemory(int level, Print * _logOutput)
{ {
size_t maxfree = halGetMaxFreeBlock(); size_t maxfree = haspDevice.get_free_max_block();
uint32_t totalfree = halGetFreeHeap(); size_t totalfree = haspDevice.get_free_heap();
uint8_t frag = halGetHeapFragmentation(); uint8_t frag = haspDevice.get_heap_fragmentation();
/* Print HASP Memory Info */ /* Print HASP Memory Info */
if(debugAnsiCodes) { if(debugAnsiCodes) {
@ -411,7 +412,7 @@ static void debugPrintPriority(int level, Print * _logOutput)
// } // }
switch(level) { switch(level) {
case LOG_LEVEL_FATAL...LOG_LEVEL_ERROR: case LOG_LEVEL_FATAL ... LOG_LEVEL_ERROR:
debugSendAnsiCode(F(TERM_COLOR_RED), _logOutput); debugSendAnsiCode(F(TERM_COLOR_RED), _logOutput);
break; break;
case LOG_LEVEL_WARNING: case LOG_LEVEL_WARNING:
@ -572,9 +573,9 @@ void debugPrintPrefix(uint8_t tag, int level, Print * _logOutput)
} }
debugPrintHaspMemory(level, _logOutput); debugPrintHaspMemory(level, _logOutput);
#if LV_MEM_CUSTOM == 0 #if LV_MEM_CUSTOM == 0
debugPrintLvglMemory(level, _logOutput); debugPrintLvglMemory(level, _logOutput);
#endif #endif
} }
return; return;
} }
@ -637,10 +638,10 @@ void debugPreSetup(JsonObject settings)
if(baudrate >= 9600u) { /* the baudrates are stored divided by 10 */ if(baudrate >= 9600u) { /* the baudrates are stored divided by 10 */
#if defined(STM32F4xx) #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.setRx(PA3); // User Serial2
Serial.setTx(PA2); Serial.setTx(PA2);
#endif #endif
#endif #endif
Serial.begin(baudrate); /* prepare for possible serial debug */ Serial.begin(baudrate); /* prepare for possible serial debug */
delay(10); delay(10);

View File

@ -7,10 +7,11 @@
#include "lvgl.h" #include "lvgl.h"
#if defined(ARDUINO_ARCH_ESP32) #if defined(ARDUINO_ARCH_ESP32)
#include "Update.h" #include "Update.h"
#endif #endif
#include "hasp_conf.h" #include "hasp_conf.h"
#include "dev/device.h"
#include "hasp_gui.h" #include "hasp_gui.h"
#include "hal/hasp_hal.h" #include "hal/hasp_hal.h"
@ -23,9 +24,9 @@
#if HASP_USE_HTTP > 0 #if HASP_USE_HTTP > 0
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) #if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
File fsUploadFile; File fsUploadFile;
#endif #endif
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
bool webServerStarted = false; bool webServerStarted = false;
@ -36,31 +37,31 @@ bool webServerStarted = false;
// char httpPassword[32] = ""; // char httpPassword[32] = "";
hasp_http_config_t http_config; hasp_http_config_t http_config;
#define HTTP_PAGE_SIZE (6 * 256) #define HTTP_PAGE_SIZE (6 * 256)
#if defined(STM32F4xx) && HASP_USE_ETHERNET > 0 #if defined(STM32F4xx) && HASP_USE_ETHERNET > 0
#include <EthernetWebServer_STM32.h> #include <EthernetWebServer_STM32.h>
EthernetWebServer webServer(80); EthernetWebServer webServer(80);
#endif #endif
#if defined(STM32F4xx) && HASP_USE_WIFI > 0 #if defined(STM32F4xx) && HASP_USE_WIFI > 0
#include <EthernetWebServer_STM32.h> #include <EthernetWebServer_STM32.h>
// #include <WiFi.h> // #include <WiFi.h>
EthernetWebServer webServer(80); EthernetWebServer webServer(80);
#endif #endif
#if defined(ARDUINO_ARCH_ESP8266) #if defined(ARDUINO_ARCH_ESP8266)
#include "StringStream.h" #include "StringStream.h"
#include <ESP8266WebServer.h> #include <ESP8266WebServer.h>
#include <detail/mimetable.h> #include <detail/mimetable.h>
ESP8266WebServer webServer(80); ESP8266WebServer webServer(80);
#endif #endif
#if defined(ARDUINO_ARCH_ESP32) #if defined(ARDUINO_ARCH_ESP32)
#include <WebServer.h> #include <WebServer.h>
#include <detail/mimetable.h> #include <detail/mimetable.h>
WebServer webServer(80); WebServer webServer(80);
#endif // ESP32 #endif // ESP32
HTTPUpload * upload; HTTPUpload * upload;
@ -112,12 +113,11 @@ const char HTTP_FOOTER[] PROGMEM = " by Francis Van Roie</div></body></html>";
// // Default link to compiled Nextion firmware images // // Default link to compiled Nextion firmware images
// String lcdFirmwareUrl = "http://haswitchplate.com/update/HASwitchPlate.tft"; // String lcdFirmwareUrl = "http://haswitchplate.com/update/HASwitchPlate.tft";
#if HASP_USE_MQTT > 0 #if HASP_USE_MQTT > 0
extern char mqttNodeName[16]; extern char mqttNodeName[16];
#else #else
char mqttNodeName[3] = "na"; char mqttNodeName[3] = "na";
#endif #endif
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
String getOption(int value, String label, bool selected) String getOption(int value, String label, bool selected)
@ -185,13 +185,13 @@ bool httpIsAuthenticated(const __FlashStringHelper * fstr_page)
} }
} }
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) #if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
LOG_TRACE(TAG_HTTP, F("Sending %S page to client connected from: %s"), fstr_page, LOG_TRACE(TAG_HTTP, F("Sending %S page to client connected from: %s"), fstr_page,
webServer.client().remoteIP().toString().c_str()); webServer.client().remoteIP().toString().c_str());
#else #else
// LOG_INFO(TAG_HTTP,F("Sending %s page to client connected from: %s"), page, // LOG_INFO(TAG_HTTP,F("Sending %s page to client connected from: %s"), page,
// String(webServer.client().remoteIP()).c_str()); // String(webServer.client().remoteIP()).c_str());
#endif #endif
return true; return true;
} }
@ -201,15 +201,15 @@ void webSendFooter()
char buffer[16]; char buffer[16];
haspGetVersion(buffer, sizeof(buffer)); haspGetVersion(buffer, sizeof(buffer));
#if defined(STM32F4xx) #if defined(STM32F4xx)
webServer.sendContent(HTTP_END); webServer.sendContent(HTTP_END);
webServer.sendContent(buffer); webServer.sendContent(buffer);
webServer.sendContent(HTTP_FOOTER); webServer.sendContent(HTTP_FOOTER);
#else #else
webServer.sendContent_P(HTTP_END); webServer.sendContent_P(HTTP_END);
webServer.sendContent(buffer); webServer.sendContent(buffer);
webServer.sendContent_P(HTTP_FOOTER); webServer.sendContent_P(HTTP_FOOTER);
#endif #endif
} }
void webSendPage(char * nodename, uint32_t httpdatalength, bool gohome = false) void webSendPage(char * nodename, uint32_t httpdatalength, bool gohome = false)
@ -235,29 +235,29 @@ void webSendPage(char * nodename, uint32_t httpdatalength, bool gohome = false)
} }
webServer.setContentLength(contentLength + httpdatalength); webServer.setContentLength(contentLength + httpdatalength);
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) #if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
webServer.send_P(200, PSTR("text/html"), HTTP_DOCTYPE); // 122 webServer.send_P(200, PSTR("text/html"), HTTP_DOCTYPE); // 122
#else #else
webServer.send(200, ("text/html"), HTTP_DOCTYPE); // 122 webServer.send(200, ("text/html"), HTTP_DOCTYPE); // 122
#endif #endif
snprintf_P(buffer, sizeof(buffer), HTTP_HEADER, nodename); snprintf_P(buffer, sizeof(buffer), HTTP_HEADER, nodename);
webServer.sendContent(buffer); // 17-2+len webServer.sendContent(buffer); // 17-2+len
} }
#if defined(STM32F4xx) #if defined(STM32F4xx)
webServer.sendContent(HTTP_SCRIPT); // 131 webServer.sendContent(HTTP_SCRIPT); // 131
webServer.sendContent(HTTP_STYLE); // 487 webServer.sendContent(HTTP_STYLE); // 487
// webServer.sendContent(HASP_STYLE); // 145 // webServer.sendContent(HASP_STYLE); // 145
if(gohome) webServer.sendContent(HTTP_META_GO_BACK); // 47 if(gohome) webServer.sendContent(HTTP_META_GO_BACK); // 47
webServer.sendContent(HTTP_HEADER_END); // 80 webServer.sendContent(HTTP_HEADER_END); // 80
#else #else
webServer.sendContent_P(HTTP_SCRIPT); // 131 webServer.sendContent_P(HTTP_SCRIPT); // 131
webServer.sendContent_P(HTTP_STYLE); // 487 webServer.sendContent_P(HTTP_STYLE); // 487
// webServer.sendContent_P(HASP_STYLE); // 145 // webServer.sendContent_P(HASP_STYLE); // 145
if(gohome) webServer.sendContent_P(HTTP_META_GO_BACK); // 47 if(gohome) webServer.sendContent_P(HTTP_META_GO_BACK); // 47
webServer.sendContent_P(HTTP_HEADER_END); // 80 webServer.sendContent_P(HTTP_HEADER_END); // 80
#endif #endif
} }
void saveConfig() void saveConfig()
@ -272,10 +272,10 @@ void saveConfig()
if(save == String(PSTR("hasp"))) { if(save == String(PSTR("hasp"))) {
haspSetConfig(settings.as<JsonObject>()); haspSetConfig(settings.as<JsonObject>());
#if HASP_USE_MQTT > 0 #if HASP_USE_MQTT > 0
} else if(save == String(PSTR("mqtt"))) { } else if(save == String(PSTR("mqtt"))) {
mqttSetConfig(settings.as<JsonObject>()); mqttSetConfig(settings.as<JsonObject>());
#endif #endif
} else if(save == String(PSTR("gui"))) { } else if(save == String(PSTR("gui"))) {
settings[FPSTR(FP_GUI_POINTER)] = webServer.hasArg(PSTR("cur")); settings[FPSTR(FP_GUI_POINTER)] = webServer.hasArg(PSTR("cur"));
@ -291,10 +291,10 @@ void saveConfig()
// Password might have changed // Password might have changed
if(!httpIsAuthenticated(F("config"))) return; if(!httpIsAuthenticated(F("config"))) return;
#if HASP_USE_WIFI > 0 #if HASP_USE_WIFI > 0
} else if(save == String(PSTR("wifi"))) { } else if(save == String(PSTR("wifi"))) {
wifiSetConfig(settings.as<JsonObject>()); wifiSetConfig(settings.as<JsonObject>());
#endif #endif
} }
} }
} }
@ -326,13 +326,13 @@ void webHandleRoot()
httpMessage += F("<p><form method='get' action='firmware'><button type='submit'>" D_HTTP_FIRMWARE_UPGRADE httpMessage += F("<p><form method='get' action='firmware'><button type='submit'>" D_HTTP_FIRMWARE_UPGRADE
"</button></form></p>"); "</button></form></p>");
#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
if(HASP_FS.exists(F("/edit.htm.gz"))) { if(HASP_FS.exists(F("/edit.htm.gz"))) {
httpMessage += httpMessage +=
F("<p><form method='get' action='edit.htm.gz?path=/'><button type='submit'>" D_HTTP_FILE_BROWSER F("<p><form method='get' action='edit.htm.gz?path=/'><button type='submit'>" D_HTTP_FILE_BROWSER
"</button></form></p>"); "</button></form></p>");
} }
#endif #endif
httpMessage += F("<p><form method='get' action='reboot'><button class='red' type='submit'>" D_HTTP_REBOOT httpMessage += F("<p><form method='get' action='reboot'><button class='red' type='submit'>" D_HTTP_REBOOT
"</button></form></p>"); "</button></form></p>");
@ -455,15 +455,15 @@ void webHandleAbout()
F("<p><h3>ArduinoLog</h3>Copyright&copy; 2017,2018 Thijs Elenbaas, MrRobot62, rahuldeo2047, NOX73, " F("<p><h3>ArduinoLog</h3>Copyright&copy; 2017,2018 Thijs Elenbaas, MrRobot62, rahuldeo2047, NOX73, "
"dhylands, Josha blemasle, mfalkvidd"); "dhylands, Josha blemasle, mfalkvidd");
httpMessage += FPSTR(MIT_LICENSE); httpMessage += FPSTR(MIT_LICENSE);
#if HASP_USE_SYSLOG > 0 #if HASP_USE_SYSLOG > 0
// Replaced with WiFiUDP client // Replaced with WiFiUDP client
// httpMessage += F("<p><h3>Syslog</h3>Copyright&copy; 2016 Martin Sloup"); // httpMessage += F("<p><h3>Syslog</h3>Copyright&copy; 2016 Martin Sloup");
// httpMessage += FPSTR(MIT_LICENSE); // httpMessage += FPSTR(MIT_LICENSE);
#endif #endif
#if HASP_USE_QRCODE > 0 #if HASP_USE_QRCODE > 0
httpMessage += F("<p><h3>QR Code generator</h3>Copyright&copy; Project Nayuki"); httpMessage += F("<p><h3>QR Code generator</h3>Copyright&copy; Project Nayuki");
httpMessage += FPSTR(MIT_LICENSE); httpMessage += FPSTR(MIT_LICENSE);
#endif #endif
httpMessage += F("<p><h3>AceButton</h3>Copyright&copy; 2018 Brian T. Park"); httpMessage += F("<p><h3>AceButton</h3>Copyright&copy; 2018 Brian T. Park");
httpMessage += FPSTR(MIT_LICENSE); httpMessage += FPSTR(MIT_LICENSE);
@ -527,12 +527,12 @@ void webHandleInfo()
httpMessage += F("s"); httpMessage += F("s");
httpMessage += F("<br/><b>Free Memory: </b>"); httpMessage += F("<br/><b>Free Memory: </b>");
Utilities::format_bytes(halGetFreeHeap(), size_buf, sizeof(size_buf)); Utilities::format_bytes(haspDevice.get_free_heap(), size_buf, sizeof(size_buf));
httpMessage += size_buf; httpMessage += size_buf;
httpMessage += F("<br/><b>Memory Fragmentation: </b>"); httpMessage += F("<br/><b>Memory Fragmentation: </b>");
httpMessage += String(halGetHeapFragmentation()); httpMessage += String(haspDevice.get_heap_fragmentation());
#if ARDUINO_ARCH_ESP32 #if ARDUINO_ARCH_ESP32
if(psramFound()) { if(psramFound()) {
httpMessage += F("<br/><b>Free PSRam: </b>"); httpMessage += F("<br/><b>Free PSRam: </b>");
Utilities::format_bytes(ESP.getFreePsram(), size_buf, sizeof(size_buf)); Utilities::format_bytes(ESP.getFreePsram(), size_buf, sizeof(size_buf));
@ -541,7 +541,7 @@ void webHandleInfo()
Utilities::format_bytes(ESP.getPsramSize(), size_buf, sizeof(size_buf)); Utilities::format_bytes(ESP.getPsramSize(), size_buf, sizeof(size_buf));
httpMessage += size_buf; httpMessage += size_buf;
} }
#endif #endif
/* LVGL Stats */ /* LVGL Stats */
lv_mem_monitor_t mem_mon; lv_mem_monitor_t mem_mon;
@ -562,7 +562,7 @@ void webHandleInfo()
httpMessage += String(haspGetPage()); httpMessage += String(haspGetPage());
/* Wifi Stats */ /* Wifi Stats */
#if HASP_USE_WIFI > 0 #if HASP_USE_WIFI > 0
httpMessage += F("</p/><p><b>SSID: </b>"); httpMessage += F("</p/><p><b>SSID: </b>");
httpMessage += String(WiFi.SSID()); httpMessage += String(WiFi.SSID());
httpMessage += F("</br><b>Signal Strength: </b>"); httpMessage += F("</br><b>Signal Strength: </b>");
@ -582,7 +582,7 @@ void webHandleInfo()
} else { } else {
httpMessage += F("Very Bad)"); httpMessage += F("Very Bad)");
} }
#if defined(STM32F4xx) #if defined(STM32F4xx)
byte mac[6]; byte mac[6];
WiFi.macAddress(mac); WiFi.macAddress(mac);
char macAddress[16]; char macAddress[16];
@ -594,7 +594,7 @@ void webHandleInfo()
httpMessage += String(WiFi.gatewayIP()); httpMessage += String(WiFi.gatewayIP());
httpMessage += F("</br><b>MAC Address: </b>"); httpMessage += F("</br><b>MAC Address: </b>");
httpMessage += String(macAddress); httpMessage += String(macAddress);
#else #else
httpMessage += F("</br><b>IP Address: </b>"); httpMessage += F("</br><b>IP Address: </b>");
httpMessage += String(WiFi.localIP().toString()); httpMessage += String(WiFi.localIP().toString());
httpMessage += F("</br><b>Gateway: </b>"); httpMessage += F("</br><b>Gateway: </b>");
@ -603,10 +603,10 @@ void webHandleInfo()
httpMessage += String(WiFi.dnsIP().toString()); httpMessage += String(WiFi.dnsIP().toString());
httpMessage += F("</br><b>MAC Address: </b>"); httpMessage += F("</br><b>MAC Address: </b>");
httpMessage += String(WiFi.macAddress()); httpMessage += String(WiFi.macAddress());
#endif #endif
#endif #endif
#if HASP_USE_ETHERNET > 0 #if HASP_USE_ETHERNET > 0
#if defined(ARDUINO_ARCH_ESP32) #if defined(ARDUINO_ARCH_ESP32)
httpMessage += F("</p/><p><b>Ethernet: </b>"); httpMessage += F("</p/><p><b>Ethernet: </b>");
httpMessage += String(ETH.linkSpeed()); httpMessage += String(ETH.linkSpeed());
httpMessage += F(" Mbps"); httpMessage += F(" Mbps");
@ -621,10 +621,10 @@ void webHandleInfo()
httpMessage += String(ETH.dnsIP().toString()); httpMessage += String(ETH.dnsIP().toString());
httpMessage += F("</br><b>MAC Address: </b>"); httpMessage += F("</br><b>MAC Address: </b>");
httpMessage += String(ETH.macAddress()); httpMessage += String(ETH.macAddress());
#endif #endif
#endif #endif
/* Mqtt Stats */ /* Mqtt Stats */
#if HASP_USE_MQTT > 0 #if HASP_USE_MQTT > 0
httpMessage += F("</p/><p><b>MQTT Status: </b>"); httpMessage += F("</p/><p><b>MQTT Status: </b>");
if(mqttIsConnected()) { // Check MQTT connection if(mqttIsConnected()) { // Check MQTT connection
httpMessage += F("Connected"); httpMessage += F("Connected");
@ -642,16 +642,16 @@ void webHandleInfo()
httpMessage += mqttClientId; httpMessage += mqttClientId;
} }
#endif // MQTT #endif // MQTT
/* ESP Stats */ /* ESP Stats */
httpMessage += F("</p/><p><b>MCU Model: </b>"); httpMessage += F("</p/><p><b>MCU Model: </b>");
httpMessage += halGetChipModel(); httpMessage += halGetChipModel();
httpMessage += F("<br/><b>CPU Frequency: </b>"); httpMessage += F("<br/><b>CPU Frequency: </b>");
httpMessage += String(halGetCpuFreqMHz()); httpMessage += String(haspDevice.get_cpu_frequency());
httpMessage += F("MHz"); httpMessage += F("MHz");
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) #if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
httpMessage += F("<br/><b>Flash Chip Size: </b>"); httpMessage += F("<br/><b>Flash Chip Size: </b>");
Utilities::format_bytes(ESP.getFlashChipSize(), size_buf, sizeof(size_buf)); Utilities::format_bytes(ESP.getFlashChipSize(), size_buf, sizeof(size_buf));
httpMessage += size_buf; httpMessage += size_buf;
@ -663,14 +663,14 @@ void webHandleInfo()
httpMessage += F("<br/><b>Free Program Space: </b>"); httpMessage += F("<br/><b>Free Program Space: </b>");
Utilities::format_bytes(ESP.getFreeSketchSpace(), size_buf, sizeof(size_buf)); Utilities::format_bytes(ESP.getFreeSketchSpace(), size_buf, sizeof(size_buf));
httpMessage += size_buf; httpMessage += size_buf;
#endif #endif
//#if defined(ARDUINO_ARCH_ESP32) //#if defined(ARDUINO_ARCH_ESP32)
// httpMessage += F("<br/><b>ESP SDK version: </b>"); // httpMessage += F("<br/><b>ESP SDK version: </b>");
// httpMessage += String(ESP.getSdkVersion()); // httpMessage += String(ESP.getSdkVersion());
//#else //#else
httpMessage += F("<br/><b>Core version: </b>"); httpMessage += F("<br/><b>Core version: </b>");
httpMessage += String(halGetCoreVersion()); httpMessage += halGetCoreVersion();
//#endif //#endif
httpMessage += F("<br/><b>Last Reset: </b>"); httpMessage += F("<br/><b>Last Reset: </b>");
httpMessage += halGetResetInfo(); httpMessage += halGetResetInfo();
@ -768,20 +768,20 @@ void webUploadProgress()
haspProgressVal(t); haspProgressVal(t);
} }
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) #if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
static inline void webUpdatePrintError() static inline void webUpdatePrintError()
{ {
#if defined(ARDUINO_ARCH_ESP8266) #if defined(ARDUINO_ARCH_ESP8266)
String output((char *)0); String output((char *)0);
output.reserve(128); output.reserve(128);
StringStream stream((String &)output); StringStream stream((String &)output);
Update.printError(stream); // ESP8266 only has printError() Update.printError(stream); // ESP8266 only has printError()
LOG_ERROR(TAG_HTTP, output.c_str()); LOG_ERROR(TAG_HTTP, output.c_str());
haspProgressMsg(output.c_str()); haspProgressMsg(output.c_str());
#elif defined(ARDUINO_ARCH_ESP32) #elif defined(ARDUINO_ARCH_ESP32)
LOG_ERROR(TAG_HTTP, Update.errorString()); // ESP32 has errorString() LOG_ERROR(TAG_HTTP, Update.errorString()); // ESP32 has errorString()
haspProgressMsg(Update.errorString()); haspProgressMsg(Update.errorString());
#endif #endif
} }
void webUpdateReboot() void webUpdateReboot()
@ -839,9 +839,9 @@ void webHandleFirmwareUpload()
} }
} }
} }
#endif #endif
#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
bool handleFileRead(String path) bool handleFileRead(String path)
{ {
if(!httpIsAuthenticated(F("fileread"))) return false; if(!httpIsAuthenticated(F("fileread"))) return false;
@ -973,7 +973,7 @@ void handleFileList()
LOG_TRACE(TAG_HTTP, F("handleFileList: %s"), path.c_str()); LOG_TRACE(TAG_HTTP, F("handleFileList: %s"), path.c_str());
path.clear(); path.clear();
#if defined(ARDUINO_ARCH_ESP32) #if defined(ARDUINO_ARCH_ESP32)
File root = HASP_FS.open("/", FILE_READ); File root = HASP_FS.open("/", FILE_READ);
File file = root.openNextFile(); File file = root.openNextFile();
String output = "["; String output = "[";
@ -998,7 +998,7 @@ void handleFileList()
} }
output += "]"; output += "]";
webServer.send(200, PSTR("text/json"), output); webServer.send(200, PSTR("text/json"), output);
#elif defined(ARDUINO_ARCH_ESP8266) #elif defined(ARDUINO_ARCH_ESP8266)
Dir dir = HASP_FS.openDir(path); Dir dir = HASP_FS.openDir(path);
String output = "["; String output = "[";
while(dir.next()) { while(dir.next()) {
@ -1020,24 +1020,24 @@ void handleFileList()
} }
output += "]"; output += "]";
webServer.send(200, PSTR("text/json"), output); webServer.send(200, PSTR("text/json"), output);
#endif #endif
} }
#endif #endif
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
#if HASP_USE_CONFIG > 0 #if HASP_USE_CONFIG > 0
void webHandleConfig() void webHandleConfig()
{ // http://plate01/config { // http://plate01/config
if(!httpIsAuthenticated(F("config"))) return; if(!httpIsAuthenticated(F("config"))) return;
saveConfig(); saveConfig();
// Reboot after saving wifi config in AP mode // Reboot after saving wifi config in AP mode
#if HASP_USE_WIFI > 0 && !defined(STM32F4xx) #if HASP_USE_WIFI > 0 && !defined(STM32F4xx)
if(WiFi.getMode() != WIFI_STA) { if(WiFi.getMode() != WIFI_STA) {
httpHandleReboot(); httpHandleReboot();
} }
#endif #endif
{ {
String httpMessage((char *)0); String httpMessage((char *)0);
@ -1046,15 +1046,15 @@ void webHandleConfig()
httpMessage += httpGetNodename(); httpMessage += httpGetNodename();
httpMessage += F("</h1><hr>"); 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'>" D_HTTP_WIFI_SETTINGS httpMessage += F("<p><form method='get' action='/config/wifi'><button type='submit'>" D_HTTP_WIFI_SETTINGS
"</button></form></p>"); "</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'>" D_HTTP_MQTT_SETTINGS httpMessage += F("<p><form method='get' action='/config/mqtt'><button type='submit'>" D_HTTP_MQTT_SETTINGS
"</button></form></p>"); "</button></form></p>");
#endif #endif
httpMessage += F("<p><form method='get' action='/config/http'><button type='submit'>" D_HTTP_HTTP_SETTINGS httpMessage += F("<p><form method='get' action='/config/http'><button type='submit'>" D_HTTP_HTTP_SETTINGS
"</button></form></p>"); "</button></form></p>");
@ -1062,14 +1062,14 @@ void webHandleConfig()
httpMessage += F("<p><form method='get' action='/config/gui'><button type='submit'>" D_HTTP_GUI_SETTINGS httpMessage += F("<p><form method='get' action='/config/gui'><button type='submit'>" D_HTTP_GUI_SETTINGS
"</button></form></p>"); "</button></form></p>");
// httpMessage += // httpMessage +=
// F("<p><form method='get' action='/config/hasp'><button type='submit'>HASP // F("<p><form method='get' action='/config/hasp'><button type='submit'>HASP
// Settings</button></form></p>"); // 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'>" D_HTTP_GPIO_SETTINGS httpMessage += F("<p><form method='get' action='/config/gpio'><button type='submit'>" D_HTTP_GPIO_SETTINGS
"</button></form></p>"); "</button></form></p>");
#endif #endif
httpMessage += F("<p><form method='get' action='/config/debug'><button type='submit'>" D_HTTP_DEBUG_SETTINGS httpMessage += F("<p><form method='get' action='/config/debug'><button type='submit'>" D_HTTP_DEBUG_SETTINGS
"</button></form></p>"); "</button></form></p>");
@ -1087,8 +1087,8 @@ void webHandleConfig()
webSendFooter(); webSendFooter();
} }
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
#if HASP_USE_MQTT > 0 #if HASP_USE_MQTT > 0
void webHandleMqttConfig() void webHandleMqttConfig()
{ // http://plate01/config/mqtt { // http://plate01/config/mqtt
if(!httpIsAuthenticated(F("config/mqtt"))) return; if(!httpIsAuthenticated(F("config/mqtt"))) return;
@ -1129,7 +1129,8 @@ void webHandleMqttConfig()
F("'><p><button type='submit' name='save' value='mqtt'>" D_HTTP_SAVE_SETTINGS "</button></form></p>"); F("'><p><button type='submit' name='save' value='mqtt'>" D_HTTP_SAVE_SETTINGS "</button></form></p>");
add_form_button(httpMessage, F("&#8617; " D_HTTP_CONFIGURATION), F("/config"), F("")); add_form_button(httpMessage, F("&#8617; " D_HTTP_CONFIGURATION), F("/config"), F(""));
// httpMessage += PSTR("<p><form method='get' action='/config'><button type='submit'>&#8617; " D_HTTP_CONFIGURATION // httpMessage += PSTR("<p><form method='get' action='/config'><button type='submit'>&#8617; "
// D_HTTP_CONFIGURATION
// "</button></form></p>"); // "</button></form></p>");
webSendPage(httpGetNodename(), httpMessage.length(), false); webSendPage(httpGetNodename(), httpMessage.length(), false);
@ -1138,7 +1139,7 @@ void webHandleMqttConfig()
// httpMessage.clear(); // httpMessage.clear();
webSendFooter(); webSendFooter();
} }
#endif #endif
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
void webHandleGuiConfig() void webHandleGuiConfig()
@ -1190,7 +1191,7 @@ void webHandleGuiConfig()
int8_t bcklpin = settings[FPSTR(FP_GUI_BACKLIGHTPIN)].as<int8_t>(); int8_t bcklpin = settings[FPSTR(FP_GUI_BACKLIGHTPIN)].as<int8_t>();
httpMessage += F("<p><b>Backlight Control</b> <select id='bckl' name='bckl'>"); httpMessage += F("<p><b>Backlight Control</b> <select id='bckl' name='bckl'>");
httpMessage += getOption(-1, F("None"), bcklpin == -1); httpMessage += getOption(-1, F("None"), bcklpin == -1);
#if defined(ARDUINO_ARCH_ESP32) #if defined(ARDUINO_ARCH_ESP32)
add_gpio_select_option(httpMessage, 5, bcklpin); // D8 on ESP32 for D1 mini 32 add_gpio_select_option(httpMessage, 5, bcklpin); // D8 on ESP32 for D1 mini 32
add_gpio_select_option(httpMessage, 12, bcklpin); // TFT_LED on the Liligo Pi add_gpio_select_option(httpMessage, 12, bcklpin); // TFT_LED on the Liligo Pi
add_gpio_select_option(httpMessage, 16, bcklpin); // D4 on ESP32 for D1 mini 32 add_gpio_select_option(httpMessage, 16, bcklpin); // D4 on ESP32 for D1 mini 32
@ -1201,25 +1202,25 @@ void webHandleGuiConfig()
add_gpio_select_option(httpMessage, 22, bcklpin); // D2 on ESP32 for D1 mini 32 add_gpio_select_option(httpMessage, 22, bcklpin); // D2 on ESP32 for D1 mini 32
add_gpio_select_option(httpMessage, 23, bcklpin); // D7 on ESP32 for D1 mini 32 add_gpio_select_option(httpMessage, 23, bcklpin); // D7 on ESP32 for D1 mini 32
add_gpio_select_option(httpMessage, 32, bcklpin); // TFT_LED on the Lolin D32 Pro add_gpio_select_option(httpMessage, 32, bcklpin); // TFT_LED on the Lolin D32 Pro
#else #else
httpMessage += getOption(5, F("D1 - GPIO 5"), bcklpin == 5); httpMessage += getOption(5, F("D1 - GPIO 5"), bcklpin == 5);
httpMessage += getOption(4, F("D2 - GPIO 4"), bcklpin == 4); httpMessage += getOption(4, F("D2 - GPIO 4"), bcklpin == 4);
httpMessage += getOption(0, F("D3 - GPIO 0"), bcklpin == 0); httpMessage += getOption(0, F("D3 - GPIO 0"), bcklpin == 0);
httpMessage += getOption(2, F("D4 - GPIO 2"), bcklpin == 2); httpMessage += getOption(2, F("D4 - GPIO 2"), bcklpin == 2);
#endif #endif
httpMessage += F("</select></p>"); httpMessage += F("</select></p>");
add_button(httpMessage, F(D_HTTP_SAVE_SETTINGS), F("name='save' value='gui'")); add_button(httpMessage, F(D_HTTP_SAVE_SETTINGS), F("name='save' value='gui'"));
close_form(httpMessage); close_form(httpMessage);
// httpMessage += // httpMessage +=
// F("<p><button type='submit' name='save' value='gui'>" D_HTTP_SAVE_SETTINGS "</button></p></form>"); // F("<p><button type='submit' name='save' value='gui'>" D_HTTP_SAVE_SETTINGS "</button></p></form>");
#if TOUCH_DRIVER == 2046 && defined(TOUCH_CS) #if TOUCH_DRIVER == 2046 && defined(TOUCH_CS)
add_form_button(httpMessage, F(D_HTTP_CALIBRATE), F("/config/gui"), F("name='action' value='calibrate'")); add_form_button(httpMessage, F(D_HTTP_CALIBRATE), F("/config/gui"), F("name='action' value='calibrate'"));
// httpMessage += PSTR("<p><form method='get' action='/config/gui'><button type='submit' " // httpMessage += PSTR("<p><form method='get' action='/config/gui'><button type='submit' "
// ">" D_HTTP_CALIBRATE "</button></form></p>"); // ">" D_HTTP_CALIBRATE "</button></form></p>");
#endif #endif
add_form_button(httpMessage, F("&#8617; " D_HTTP_CONFIGURATION), F("/config"), F("")); add_form_button(httpMessage, F("&#8617; " D_HTTP_CONFIGURATION), F("/config"), F(""));
@ -1235,8 +1236,8 @@ void webHandleGuiConfig()
if(webServer.hasArg(F("action"))) dispatch_text_line(webServer.arg(F("action")).c_str()); 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() void webHandleWifiConfig()
{ // http://plate01/config/wifi { // http://plate01/config/wifi
if(!httpIsAuthenticated(F("config/wifi"))) return; if(!httpIsAuthenticated(F("config/wifi"))) return;
@ -1262,28 +1263,28 @@ void webHandleWifiConfig()
httpMessage += httpMessage +=
F("'><p><button type='submit' name='save' value='wifi'>" D_HTTP_SAVE_SETTINGS "</button></p></form>"); F("'><p><button type='submit' name='save' value='wifi'>" D_HTTP_SAVE_SETTINGS "</button></p></form>");
#if HASP_USE_WIFI > 0 && !defined(STM32F4xx) #if HASP_USE_WIFI > 0 && !defined(STM32F4xx)
if(WiFi.getMode() == WIFI_STA) { if(WiFi.getMode() == WIFI_STA) {
add_form_button(httpMessage, F("&#8617; " D_HTTP_CONFIGURATION), F("/config"), F("")); add_form_button(httpMessage, F("&#8617; " D_HTTP_CONFIGURATION), F("/config"), F(""));
// httpMessage += PSTR("<p><form method='get' action='/config'><button type='submit'>&#8617; " // httpMessage += PSTR("<p><form method='get' action='/config'><button type='submit'>&#8617; "
// D_HTTP_CONFIGURATION // D_HTTP_CONFIGURATION
// "</button></form></p>"); // "</button></form></p>");
} }
#endif #endif
webSendPage(httpGetNodename(), httpMessage.length(), false); webSendPage(httpGetNodename(), httpMessage.length(), false);
webServer.sendContent(httpMessage); webServer.sendContent(httpMessage);
#if defined(STM32F4xx) #if defined(STM32F4xx)
httpMessage = ""; httpMessage = "";
#else #else
httpMessage.clear(); httpMessage.clear();
#endif #endif
webSendFooter(); webSendFooter();
} }
#endif #endif
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
#if HASP_USE_HTTP > 0 #if HASP_USE_HTTP > 0
void webHandleHttpConfig() void webHandleHttpConfig()
{ // http://plate01/config/http { // http://plate01/config/http
if(!httpIsAuthenticated(F("config/http"))) return; if(!httpIsAuthenticated(F("config/http"))) return;
@ -1340,10 +1341,10 @@ void webHandleHttpConfig()
// httpMessage.clear(); // httpMessage.clear();
webSendFooter(); webSendFooter();
} }
#endif #endif
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
#if defined(HASP_USE_GPIO) && (HASP_USE_GPIO > 0) #if defined(HASP_USE_GPIO) && (HASP_USE_GPIO > 0)
void webHandleGpioConfig() void webHandleGpioConfig()
{ // http://plate01/config/gpio { // http://plate01/config/gpio
if(!httpIsAuthenticated(F("config/gpio"))) return; if(!httpIsAuthenticated(F("config/gpio"))) return;
@ -1571,7 +1572,7 @@ void webHandleGpioOptions()
if(webServer.hasArg(F("action"))) dispatch_text_line(webServer.arg(F("action")).c_str()); // Security check 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() void webHandleDebugConfig()
@ -1604,7 +1605,7 @@ void webHandleDebugConfig()
httpMessage += settings[FPSTR(FP_DEBUG_TELEPERIOD)].as<String>(); httpMessage += settings[FPSTR(FP_DEBUG_TELEPERIOD)].as<String>();
httpMessage += F("'></p>"); 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' " httpMessage += F("<b>Syslog Hostame</b> <i><small>(optional)</small></i><input id='host' "
"name='host' maxlength=31 placeholder='logserver' value='"); "name='host' maxlength=31 placeholder='logserver' value='");
httpMessage += settings[FPSTR(FP_CONFIG_HOST)].as<String>(); httpMessage += settings[FPSTR(FP_CONFIG_HOST)].as<String>();
@ -1623,7 +1624,7 @@ void webHandleDebugConfig()
httpMessage += F(">IETF (RFC 5424) &nbsp; <input id='proto' name='proto' type='radio' value='1'"); httpMessage += F(">IETF (RFC 5424) &nbsp; <input id='proto' name='proto' type='radio' value='1'");
if(settings[FPSTR(FP_CONFIG_PROTOCOL)].as<uint8_t>() == 1) httpMessage += F(" checked"); if(settings[FPSTR(FP_CONFIG_PROTOCOL)].as<uint8_t>() == 1) httpMessage += F(" checked");
httpMessage += F(">BSD (RFC 3164)"); httpMessage += F(">BSD (RFC 3164)");
#endif #endif
httpMessage += httpMessage +=
F("</p><p><button type='submit' name='save' value='debug'>" D_HTTP_SAVE_SETTINGS "</button></p></form>"); F("</p><p><button type='submit' name='save' value='debug'>" D_HTTP_SAVE_SETTINGS "</button></p></form>");
@ -1664,24 +1665,24 @@ void webHandleHaspConfig()
httpMessage += F("<p><b>UI Theme</b> <i><small>(required)</small></i><select id='theme' name='theme'>"); httpMessage += F("<p><b>UI Theme</b> <i><small>(required)</small></i><select id='theme' name='theme'>");
uint8_t themeid = settings[FPSTR(FP_CONFIG_THEME)].as<uint8_t>(); uint8_t themeid = settings[FPSTR(FP_CONFIG_THEME)].as<uint8_t>();
// httpMessage += getOption(0, F("Built-in"), themeid == 0); // httpMessage += getOption(0, F("Built-in"), themeid == 0);
#if LV_USE_THEME_HASP == 1 #if LV_USE_THEME_HASP == 1
httpMessage += getOption(2, F("Hasp Dark"), themeid == 2); httpMessage += getOption(2, F("Hasp Dark"), themeid == 2);
httpMessage += getOption(1, F("Hasp Light"), themeid == 1); httpMessage += getOption(1, F("Hasp Light"), themeid == 1);
#endif #endif
#if LV_USE_THEME_EMPTY == 1 #if LV_USE_THEME_EMPTY == 1
httpMessage += getOption(0, F("Empty"), themeid == 0); httpMessage += getOption(0, F("Empty"), themeid == 0);
#endif #endif
#if LV_USE_THEME_MONO == 1 #if LV_USE_THEME_MONO == 1
httpMessage += getOption(3, F("Mono"), themeid == 3); httpMessage += getOption(3, F("Mono"), themeid == 3);
#endif #endif
#if LV_USE_THEME_MATERIAL == 1 #if LV_USE_THEME_MATERIAL == 1
httpMessage += getOption(5, F("Material Dark"), themeid == 5); httpMessage += getOption(5, F("Material Dark"), themeid == 5);
httpMessage += getOption(4, F("Material Light"), themeid == 4); httpMessage += getOption(4, F("Material Light"), themeid == 4);
#endif #endif
#if LV_USE_THEME_TEMPLATE == 1 #if LV_USE_THEME_TEMPLATE == 1
httpMessage += getOption(7, F("Template"), themeid == 7); httpMessage += getOption(7, F("Template"), themeid == 7);
#endif #endif
httpMessage += F("</select></br>"); httpMessage += F("</select></br>");
httpMessage += httpMessage +=
F("<b>Hue</b><div style='width:100%;background-image:linear-gradient(to " F("<b>Hue</b><div style='width:100%;background-image:linear-gradient(to "
@ -1691,7 +1692,7 @@ void webHandleHaspConfig()
httpMessage += F("'></div></p>"); httpMessage += F("'></div></p>");
httpMessage += F("<p><b>Default Font</b><select id='font' name='font'><option value=''>None</option>"); 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 root = HASP_FS.open("/");
File file = root.openNextFile(); File file = root.openNextFile();
@ -1702,7 +1703,7 @@ void webHandleHaspConfig()
getOption(file.name(), file.name(), filename == settings[FPSTR(FP_CONFIG_ZIFONT)].as<String>()); getOption(file.name(), file.name(), filename == settings[FPSTR(FP_CONFIG_ZIFONT)].as<String>());
file = root.openNextFile(); file = root.openNextFile();
} }
#elif defined(ARDUINO_ARCH_ESP8266) #elif defined(ARDUINO_ARCH_ESP8266)
Dir dir = HASP_FS.openDir("/"); Dir dir = HASP_FS.openDir("/");
while(dir.next()) { while(dir.next()) {
File file = dir.openFile("r"); File file = dir.openFile("r");
@ -1712,7 +1713,7 @@ void webHandleHaspConfig()
getOption(file.name(), file.name(), filename == settings[FPSTR(FP_CONFIG_ZIFONT)].as<String>()); getOption(file.name(), file.name(), filename == settings[FPSTR(FP_CONFIG_ZIFONT)].as<String>());
file.close(); file.close();
} }
#endif #endif
httpMessage += F("</select></p>"); httpMessage += F("</select></p>");
httpMessage += F("<p><b>Startup Layout</b> <i><small>(optional)</small></i><input id='pages' " httpMessage += F("<p><b>Startup Layout</b> <i><small>(optional)</small></i><input id='pages' "
@ -1742,21 +1743,21 @@ void webHandleHaspConfig()
// httpMessage.clear(); // httpMessage.clear();
webSendFooter(); webSendFooter();
} }
#endif // HASP_USE_CONFIG #endif // HASP_USE_CONFIG
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
void httpHandleNotFound() void httpHandleNotFound()
{ // webServer 404 { // webServer 404
#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
if(handleFileRead(webServer.uri())) return; if(handleFileRead(webServer.uri())) return;
#endif #endif
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) #if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
LOG_TRACE(TAG_HTTP, F("Sending 404 to client connected from: %s"), LOG_TRACE(TAG_HTTP, F("Sending 404 to client connected from: %s"),
webServer.client().remoteIP().toString().c_str()); webServer.client().remoteIP().toString().c_str());
#else #else
// LOG_TRACE(TAG_HTTP,F("Sending 404 to client connected from: %s"), String(webServer.client().remoteIP()).c_str()); // LOG_TRACE(TAG_HTTP,F("Sending 404 to client connected from: %s"), String(webServer.client().remoteIP()).c_str());
#endif #endif
String httpMessage((char *)0); String httpMessage((char *)0);
httpMessage.reserve(HTTP_PAGE_SIZE); httpMessage.reserve(HTTP_PAGE_SIZE);
@ -1828,8 +1829,8 @@ void httpHandleEspFirmware()
// espStartOta(webServer.arg("espFirmware")); // espStartOta(webServer.arg("espFirmware"));
} }
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
#if HASP_USE_CONFIG > 0 #if HASP_USE_CONFIG > 0
void webHandleSaveConfig() void webHandleSaveConfig()
{ {
if(!httpIsAuthenticated(F("saveConfig"))) return; if(!httpIsAuthenticated(F("saveConfig"))) return;
@ -1888,30 +1889,30 @@ void httpHandleResetConfig()
dispatch_reboot(false); // Do not save the current config dispatch_reboot(false); // Do not save the current config
} }
} }
#endif // HASP_USE_CONFIG #endif // HASP_USE_CONFIG
void httpStart() void httpStart()
{ {
webServer.begin(); webServer.begin();
webServerStarted = true; webServerStarted = true;
#if HASP_USE_WIFI > 0 #if HASP_USE_WIFI > 0
#if defined(STM32F4xx) #if defined(STM32F4xx)
IPAddress ip; IPAddress ip;
ip = WiFi.localIP(); ip = WiFi.localIP();
LOG_INFO(TAG_HTTP, F(D_SERVICE_STARTED " @ http://%d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]); LOG_INFO(TAG_HTTP, F(D_SERVICE_STARTED " @ http://%d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]);
#else #else
LOG_INFO(TAG_HTTP, F(D_SERVICE_STARTED " @ http://%s"), LOG_INFO(TAG_HTTP, F(D_SERVICE_STARTED " @ http://%s"),
(WiFi.getMode() != WIFI_STA ? WiFi.softAPIP().toString().c_str() : WiFi.localIP().toString().c_str())); (WiFi.getMode() != WIFI_STA ? WiFi.softAPIP().toString().c_str() : WiFi.localIP().toString().c_str()));
#endif #endif
#else #else
IPAddress ip; IPAddress ip;
#if defined(ARDUINO_ARCH_ESP32) #if defined(ARDUINO_ARCH_ESP32)
ip = ETH.localIP(); ip = ETH.localIP();
#else #else
ip = Ethernet.localIP(); ip = Ethernet.localIP();
#endif #endif
LOG_INFO(TAG_HTTP, F(D_SERVICE_STARTED " @ http://%d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]); LOG_INFO(TAG_HTTP, F(D_SERVICE_STARTED " @ http://%d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]);
#endif #endif
} }
void httpStop() void httpStop()
@ -1935,19 +1936,19 @@ void httpSetup()
webServer.on(F("/about"), webHandleAbout); webServer.on(F("/about"), webHandleAbout);
webServer.onNotFound(httpHandleNotFound); webServer.onNotFound(httpHandleNotFound);
#if HASP_USE_WIFI > 0 #if HASP_USE_WIFI > 0
#if !defined(STM32F4xx) #if !defined(STM32F4xx)
#if HASP_USE_CONFIG > 0 #if HASP_USE_CONFIG > 0
if(WiFi.getMode() != WIFI_STA) { if(WiFi.getMode() != WIFI_STA) {
LOG_TRACE(TAG_HTTP, F("Wifi access point")); LOG_TRACE(TAG_HTTP, F("Wifi access point"));
webServer.on(F("/"), webHandleWifiConfig); webServer.on(F("/"), webHandleWifiConfig);
return; return;
} }
#endif #endif
#endif #endif
#endif #endif
webServer.on(F("/page/"), []() { webServer.on(F("/page/"), []() {
String pageid = webServer.arg(F("page")); String pageid = webServer.arg(F("page"));
@ -1955,7 +1956,7 @@ void httpSetup()
haspSetPage(pageid.toInt()); haspSetPage(pageid.toInt());
}); });
#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
webServer.on(F("/list"), HTTP_GET, handleFileList); webServer.on(F("/list"), HTTP_GET, handleFileList);
// load editor // load editor
webServer.on(F("/edit"), HTTP_GET, []() { webServer.on(F("/edit"), HTTP_GET, []() {
@ -1976,7 +1977,7 @@ void httpSetup()
LOG_VERBOSE(TAG_HTTP, F("Headers: %d"), webServer.headers()); LOG_VERBOSE(TAG_HTTP, F("Headers: %d"), webServer.headers());
}, },
handleFileUpload); handleFileUpload);
#endif #endif
webServer.on(F("/"), webHandleRoot); webServer.on(F("/"), webHandleRoot);
webServer.on(F("/info"), webHandleInfo); webServer.on(F("/info"), webHandleInfo);
@ -1984,27 +1985,27 @@ void httpSetup()
webServer.on(F("/firmware"), webHandleFirmware); webServer.on(F("/firmware"), webHandleFirmware);
webServer.on(F("/reboot"), httpHandleReboot); webServer.on(F("/reboot"), httpHandleReboot);
#if HASP_USE_CONFIG > 0 #if HASP_USE_CONFIG > 0
webServer.on(F("/config/hasp"), webHandleHaspConfig); webServer.on(F("/config/hasp"), webHandleHaspConfig);
webServer.on(F("/config/http"), webHandleHttpConfig); webServer.on(F("/config/http"), webHandleHttpConfig);
webServer.on(F("/config/gui"), webHandleGuiConfig); webServer.on(F("/config/gui"), webHandleGuiConfig);
webServer.on(F("/config/debug"), webHandleDebugConfig); webServer.on(F("/config/debug"), webHandleDebugConfig);
#if HASP_USE_MQTT > 0 #if HASP_USE_MQTT > 0
webServer.on(F("/config/mqtt"), webHandleMqttConfig); webServer.on(F("/config/mqtt"), webHandleMqttConfig);
#endif #endif
#if HASP_USE_WIFI > 0 #if HASP_USE_WIFI > 0
webServer.on(F("/config/wifi"), webHandleWifiConfig); webServer.on(F("/config/wifi"), webHandleWifiConfig);
#endif #endif
#if HASP_USE_GPIO > 0 #if HASP_USE_GPIO > 0
webServer.on(F("/config/gpio"), webHandleGpioConfig); webServer.on(F("/config/gpio"), webHandleGpioConfig);
webServer.on(F("/config/gpio/options"), webHandleGpioOptions); webServer.on(F("/config/gpio/options"), webHandleGpioOptions);
#endif #endif
webServer.on(F("/saveConfig"), webHandleSaveConfig); webServer.on(F("/saveConfig"), webHandleSaveConfig);
webServer.on(F("/resetConfig"), httpHandleResetConfig); webServer.on(F("/resetConfig"), httpHandleResetConfig);
webServer.on(F("/config"), webHandleConfig); webServer.on(F("/config"), webHandleConfig);
#endif // HASP_USE_CONFIG #endif // HASP_USE_CONFIG
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) #if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
webServer.on( webServer.on(
F("/update"), HTTP_POST, F("/update"), HTTP_POST,
[]() { []() {
@ -2013,7 +2014,7 @@ void httpSetup()
}, },
webHandleFirmwareUpload); webHandleFirmwareUpload);
webServer.on(F("/espfirmware"), httpHandleEspFirmware); webServer.on(F("/espfirmware"), httpHandleEspFirmware);
#endif #endif
LOG_INFO(TAG_HTTP, F(D_SERVICE_STARTED)); LOG_INFO(TAG_HTTP, F(D_SERVICE_STARTED));
// webStart(); Wait for network connection // webStart(); Wait for network connection
@ -2027,9 +2028,9 @@ void httpReconnect()
if(webServerStarted) { if(webServerStarted) {
httpStop(); httpStop();
} else } else
#if HASP_USE_WIFI > 0 && !defined(STM32F4xx) #if HASP_USE_WIFI > 0 && !defined(STM32F4xx)
if(WiFi.status() == WL_CONNECTED || WiFi.getMode() != WIFI_STA) if(WiFi.status() == WL_CONNECTED || WiFi.getMode() != WIFI_STA)
#endif #endif
{ {
httpStart(); httpStart();
} }
@ -2048,7 +2049,7 @@ void httpEvery5Seconds()
} }
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
#if HASP_USE_CONFIG > 0 #if HASP_USE_CONFIG > 0
bool httpGetConfig(const JsonObject & settings) bool httpGetConfig(const JsonObject & settings)
{ {
bool changed = false; bool changed = false;
@ -2095,7 +2096,7 @@ bool httpSetConfig(const JsonObject & settings)
return changed; return changed;
} }
#endif // HASP_USE_CONFIG #endif // HASP_USE_CONFIG
size_t httpClientWrite(const uint8_t * buf, size_t size) size_t httpClientWrite(const uint8_t * buf, size_t size)
{ {