mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-24 11:46:34 +00:00
Add stù32f4 http and mqtt
This commit is contained in:
parent
cb5225ccf6
commit
3d0d3a49b5
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,6 +5,7 @@
|
||||
.git
|
||||
.pio
|
||||
data/*
|
||||
src/user_setups/active/*
|
||||
src/user_config_override.h
|
||||
platformio_override.ini
|
||||
|
||||
|
@ -7,40 +7,82 @@
|
||||
|
||||
#define HASP_USE_APP 1
|
||||
|
||||
/* Network */
|
||||
#define HASP_HAS_NETWORK (ARDUINO_ARCH_ESP32>0 || ARDUINO_ARCH_ESP8266>0)
|
||||
/* Network Services */
|
||||
#define HASP_HAS_NETWORK (ARDUINO_ARCH_ESP32 > 0 || ARDUINO_ARCH_ESP8266 > 0)
|
||||
|
||||
#ifndef HASP_USE_OTA
|
||||
#define HASP_USE_OTA (HASP_HAS_NETWORK)
|
||||
#define HASP_USE_WIFI (HASP_HAS_NETWORK)
|
||||
#define HASP_USE_MQTT (HASP_HAS_NETWORK)
|
||||
#define HASP_USE_HTTP (HASP_HAS_NETWORK)
|
||||
#define HASP_USE_MDNS (HASP_HAS_NETWORK)
|
||||
#define HASP_USE_SYSLOG (HASP_HAS_NETWORK)
|
||||
#define HASP_USE_TELNET (HASP_HAS_NETWORK)
|
||||
|
||||
/* Filesystem */
|
||||
#define HASP_HAS_FILESYSTEM (ARDUINO_ARCH_ESP32>0 || ARDUINO_ARCH_ESP8266>0)
|
||||
|
||||
#define HASP_USE_SPIFFS (HASP_HAS_FILESYSTEM)
|
||||
#define HASP_USE_EEPROM 1
|
||||
#define HASP_USE_SDCARD 0
|
||||
|
||||
#define HASP_USE_GPIO 1
|
||||
|
||||
#define HASP_USE_QRCODE 1
|
||||
#define HASP_USE_PNGDECODE 0
|
||||
|
||||
#define HASP_NUM_INPUTS 3 // Buttons
|
||||
#define HASP_NUM_OUTPUTS 3
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
#define HASP_NUM_PAGES 12
|
||||
#else
|
||||
#define HASP_NUM_PAGES 4
|
||||
#endif
|
||||
|
||||
#ifndef HASP_USE_WIFI
|
||||
#define HASP_USE_WIFI (HASP_HAS_NETWORK)
|
||||
#endif
|
||||
|
||||
#if HASP_USE_SPIFFS>0
|
||||
#ifndef HASP_USE_MQTT
|
||||
#define HASP_USE_MQTT 1
|
||||
#endif
|
||||
|
||||
#ifndef HASP_USE_HTTP
|
||||
#define HASP_USE_HTTP 1
|
||||
#endif
|
||||
|
||||
#ifndef HASP_USE_MDNS
|
||||
#define HASP_USE_MDNS (HASP_HAS_NETWORK)
|
||||
#endif
|
||||
|
||||
#ifndef HASP_USE_SYSLOG
|
||||
#define HASP_USE_SYSLOG (HASP_HAS_NETWORK)
|
||||
#endif
|
||||
|
||||
#ifndef HASP_USE_TELNET
|
||||
#define HASP_USE_TELNET 0
|
||||
#endif
|
||||
|
||||
/* Filesystem */
|
||||
#define HASP_HAS_FILESYSTEM (ARDUINO_ARCH_ESP32 > 0 || ARDUINO_ARCH_ESP8266 > 0)
|
||||
|
||||
#ifndef HASP_USE_SPIFFS
|
||||
#define HASP_USE_SPIFFS (HASP_HAS_FILESYSTEM)
|
||||
#endif
|
||||
|
||||
#ifndef HASP_USE_EEPROM
|
||||
#define HASP_USE_EEPROM 1
|
||||
#endif
|
||||
|
||||
#ifndef HASP_USE_SDCARD
|
||||
#define HASP_USE_SDCARD 0
|
||||
#endif
|
||||
|
||||
#ifndef HASP_USE_GPIO
|
||||
#define HASP_USE_GPIO 1
|
||||
#endif
|
||||
|
||||
#ifndef HASP_USE_QRCODE
|
||||
#define HASP_USE_QRCODE 1
|
||||
#endif
|
||||
|
||||
#ifndef HASP_USE_PNGDECODE
|
||||
#define HASP_USE_PNGDECODE 0
|
||||
#endif
|
||||
|
||||
#ifndef HASP_NUM_INPUTS
|
||||
#define HASP_NUM_INPUTS 3 // Buttons
|
||||
#endif
|
||||
|
||||
#ifndef HASP_NUM_OUTPUTS
|
||||
#define HASP_NUM_OUTPUTS 3
|
||||
#endif
|
||||
|
||||
#ifndef HASP_NUM_PAGES
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
#define HASP_NUM_PAGES 4
|
||||
#else
|
||||
#define HASP_NUM_PAGES 12
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Includes */
|
||||
#if HASP_USE_SPIFFS > 0
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
#include "SPIFFS.h"
|
||||
#endif
|
||||
@ -48,52 +90,56 @@
|
||||
#include "hasp_spiffs.h"
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
|
||||
// #include "lv_zifont.h"
|
||||
#endif
|
||||
#include "lv_zifont.h"
|
||||
#endif
|
||||
#endif // SPIFFS
|
||||
|
||||
#if HASP_USE_EEPROM>0
|
||||
#if HASP_USE_EEPROM > 0
|
||||
#include "hasp_eeprom.h"
|
||||
#endif
|
||||
|
||||
#if HASP_USE_WIFI>0
|
||||
#if HASP_USE_WIFI > 0
|
||||
#include "hasp_wifi.h"
|
||||
#endif
|
||||
|
||||
#if HASP_USE_MQTT>0
|
||||
#if HASP_USE_MQTT > 0
|
||||
#include "hasp_mqtt.h"
|
||||
#endif
|
||||
|
||||
#if HASP_USE_HTTP>0
|
||||
#if HASP_USE_HTTP > 0
|
||||
#include "hasp_http.h"
|
||||
#endif
|
||||
|
||||
#if HASP_USE_TELNET>0
|
||||
#if HASP_USE_TELNET > 0
|
||||
#include "hasp_telnet.h"
|
||||
#endif
|
||||
|
||||
#if HASP_USE_MDNS>0
|
||||
#if HASP_USE_MDNS > 0
|
||||
#include "hasp_mdns.h"
|
||||
#endif
|
||||
|
||||
#if HASP_USE_BUTTON>0
|
||||
#if HASP_USE_BUTTON > 0
|
||||
#include "hasp_button.h"
|
||||
#endif
|
||||
|
||||
#if HASP_USE_OTA>0
|
||||
#if HASP_USE_OTA > 0
|
||||
#include "hasp_ota.h"
|
||||
#endif
|
||||
|
||||
#if HASP_USE_TASMOTA_SLAVE>0
|
||||
#if HASP_USE_TASMOTA_SLAVE > 0
|
||||
#include "hasp_slave.h"
|
||||
#endif
|
||||
|
||||
#if HASP_USE_ETHERNET>0
|
||||
#if HASP_USE_ETHERNET > 0
|
||||
#include "hasp_ethernet.h"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef FPSTR
|
||||
#define FPSTR(pstr_pointer) (reinterpret_cast<const __FlashStringHelper *>(pstr_pointer))
|
||||
#endif
|
||||
|
||||
#ifndef PGM_P
|
||||
#define PGM_P const char *
|
||||
#endif
|
||||
|
||||
#endif // HASP_CONF_H
|
13
include/stm32f4/hal_conf_custom.h
Normal file
13
include/stm32f4/hal_conf_custom.h
Normal file
@ -0,0 +1,13 @@
|
||||
/* Include the normal default core configuration */
|
||||
#include "stm32f4xx_hal_conf_default.h"
|
||||
|
||||
/* Remove the default PHY address */
|
||||
#ifdef LAN8742A_PHY_ADDRESS
|
||||
#undef LAN8742A_PHY_ADDRESS
|
||||
#endif
|
||||
|
||||
/* Section 2: PHY configuration section */
|
||||
/* Redefine LAN8742A PHY Address*/
|
||||
#ifndef LAN8742A_PHY_ADDRESS
|
||||
#define LAN8742A_PHY_ADDRESS 0x01U //HASP_PHY_ADDRESS
|
||||
#endif
|
2
lib/lvgl
2
lib/lvgl
@ -1 +1 @@
|
||||
Subproject commit 21f52a939133d91acc82a3a98767d35de4e2d7a5
|
||||
Subproject commit 5f739643f4b22254f5742504fcda3b7de50fb88b
|
@ -22,6 +22,8 @@ extra_configs =
|
||||
default_envs =
|
||||
; Uncomment the needed environments in platformio_override.ini
|
||||
; You can also create new environments in in platformio_override.ini
|
||||
DevEBox_STM32F4xx
|
||||
black_f407vg
|
||||
${override.extra_default_envs}
|
||||
|
||||
; -- Location of the configuration files
|
||||
@ -93,6 +95,7 @@ stm32_flags=
|
||||
-D IRAM_ATTR= ; No IRAM_ATTR available on STM32
|
||||
-D STM32
|
||||
-D STREAMUTILS_USE_EEPROM_UPDATE=1 ; update cell only when changed
|
||||
-D MQTT_MAX_PACKET_SIZE=2048 ; longer PubSubClient messages
|
||||
|
||||
; -- By default there are no ${override.build_flags} set
|
||||
; -- to use it, copy platformio_override.ini from the template
|
||||
@ -196,9 +199,10 @@ build_flags =
|
||||
-D HASP_OUTPUT_PIN=PA1 ; User LED D2 on DevEBox board
|
||||
-D HASP_INPUT_PIN=PA0 ; User Button K1 on DevEBox board
|
||||
-D STM32_SERIAL1 ; Set this option to use Serial1 as default sersial port, leave out if using Serial2
|
||||
-D USE_BUILTIN_ETHERNET=1
|
||||
-D HASP_USE_ETHERNET=1
|
||||
-D HAL_ETH_MODULE_ENABLED=1
|
||||
-D LAN8742A_PHY_ADDRESS=0x01U
|
||||
;-D LAN8742A_PHY_ADDRESS=0x01U ; Moved to include\stm32f4\hal_conf_custom.h
|
||||
; -D DP83848_PHY_ADDRESS=0x01U
|
||||
|
||||
lib_deps =
|
||||
@ -208,6 +212,7 @@ lib_deps =
|
||||
; STM32duino STM32Ethernet@^1.0.5
|
||||
https://github.com/stm32duino/LwIP.git
|
||||
https://github.com/stm32duino/STM32Ethernet.git
|
||||
EthernetWebServer_STM32
|
||||
|
||||
src_filter = +<*> -<.git/> -<.svn/> -<example/> -<examples/> -<test/> -<tests/> -<lv_lib_zifont/> +<stm32f4/>
|
||||
|
||||
|
@ -206,6 +206,7 @@ void configWriteConfig()
|
||||
Log.verbose(F("WIFI: Settings changed"));
|
||||
writefile = true;
|
||||
}
|
||||
#endif
|
||||
#if HASP_USE_MQTT
|
||||
if(settings[F("mqtt")].as<JsonObject>().isNull()) settings.createNestedObject(F("mqtt"));
|
||||
changed = mqttGetConfig(settings[F("mqtt")]);
|
||||
@ -240,7 +241,6 @@ void configWriteConfig()
|
||||
configOutput(settings[F("http")]);
|
||||
writefile = true;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if(settings[F("debug")].as<JsonObject>().isNull()) settings.createNestedObject(F("debug"));
|
||||
@ -350,6 +350,7 @@ void configSetup()
|
||||
#if HASP_USE_WIFI
|
||||
Log.verbose(F("Loading WiFi settings"));
|
||||
wifiSetConfig(settings[F("wifi")]);
|
||||
#endif
|
||||
#if HASP_USE_MQTT
|
||||
Log.verbose(F("Loading MQTT settings"));
|
||||
mqttSetConfig(settings[F("mqtt")]);
|
||||
@ -366,8 +367,7 @@ void configSetup()
|
||||
Log.verbose(F("Loading HTTP settings"));
|
||||
httpSetConfig(settings[F("http")]);
|
||||
#endif
|
||||
#endif // Wifi
|
||||
// }
|
||||
// }
|
||||
Log.notice(F("User configuration loaded"));
|
||||
}
|
||||
//#endif
|
||||
|
@ -161,14 +161,13 @@ void dispatchDim(String strDimLevel)
|
||||
// Set the current state
|
||||
if(strDimLevel.length() != 0) guiSetDim(strDimLevel.toInt());
|
||||
dispatchPrintln(F("DIM"), strDimLevel);
|
||||
char buffer[8];
|
||||
|
||||
#if HASP_USE_MQTT > 0
|
||||
char buffer[8];
|
||||
itoa(guiGetDim(), buffer, DEC);
|
||||
mqtt_send_state(F("dim"), buffer);
|
||||
#endif
|
||||
#if HASP_USE_TASMOTA_SLAVE > 0
|
||||
char buffer[8];
|
||||
itoa(guiGetDim(), buffer, DEC);
|
||||
slave_send_state(F("dim"), buffer);
|
||||
#endif
|
||||
|
@ -22,11 +22,16 @@ void ethernetSetup()
|
||||
IPAddress ip = Ethernet.localIP();
|
||||
Log.notice(F("ETH: DHCP Success got IP=%d.%d.%d.%d"),ip[0], ip[1], ip[2], ip[3]);
|
||||
}
|
||||
|
||||
uint8_t *mac;
|
||||
mac = Ethernet.MACAddress();
|
||||
Log.notice(F("ETH: MAC Address %x:%x:%x:%x:%x:%x"),*mac,*(mac+1),*(mac+2),*(mac+3),*(mac+4),*(mac+5));
|
||||
|
||||
}
|
||||
|
||||
void ethernetLoop(void)
|
||||
{
|
||||
Ethernet.maintain();
|
||||
Ethernet.maintain();
|
||||
}
|
||||
|
||||
|
||||
|
@ -41,6 +41,11 @@ File pFileOut;
|
||||
#endif
|
||||
uint8_t guiSnapshot = 0;
|
||||
|
||||
#if defined(STM32F4xx)
|
||||
//#include <EthernetWebServer_STM32.h>
|
||||
// EthernetWebServer * webClient(0);
|
||||
#endif
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
#include <ESP8266WebServer.h>
|
||||
ESP8266WebServer * webClient; // for snatshot
|
||||
@ -75,7 +80,7 @@ static uint8_t guiRotation = TFT_ROTATION;
|
||||
#if ESP32 > 0 || ESP8266 > 0
|
||||
static Ticker tick; /* timer for interrupt handler */
|
||||
#else
|
||||
static Ticker tick(lv_tick_handler,guiTickPeriod);
|
||||
static Ticker tick(lv_tick_handler, guiTickPeriod);
|
||||
#endif
|
||||
static TFT_eSPI tft; // = TFT_eSPI(); /* TFT instance */
|
||||
static uint16_t calData[5] = {0, 65535, 0, 65535, 0};
|
||||
@ -171,14 +176,15 @@ static bool guiCheckSleep()
|
||||
/* Flush VDB bytes to a stream */
|
||||
static void gui_take_screenshot(uint8_t * data_p, size_t len)
|
||||
{
|
||||
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
||||
size_t res = 0;
|
||||
switch(guiSnapshot) {
|
||||
#if HASP_USE_SPIFFS > 0
|
||||
case 1:
|
||||
res = pFileOut.write(data_p, len);
|
||||
break;
|
||||
#endif
|
||||
case 2:
|
||||
res = webClient->client().write(data_p, len);
|
||||
res = httpClientWrite(data_p, len);
|
||||
break;
|
||||
default:
|
||||
res = 0; // nothing to do
|
||||
@ -186,7 +192,6 @@ static void gui_take_screenshot(uint8_t * data_p, size_t len)
|
||||
if(res != len) {
|
||||
Log.warning(F("GUI: Pixelbuffer not completely sent"));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Experimetnal Display flushing */
|
||||
@ -197,7 +202,6 @@ static void IRAM_ATTR tft_espi_flush(lv_disp_drv_t * disp, const lv_area_t * are
|
||||
/* Update TFT */
|
||||
tft.startWrite(); /* Start new TFT transaction */
|
||||
tft.setWindow(area->x1, area->y1, area->x2, area->y2); /* set the working window */
|
||||
tft.setSwapBytes(true); /* set endianess */
|
||||
tft.pushPixels((uint16_t *)color_p, len); /* Write words at once */
|
||||
tft.endWrite(); /* terminate TFT transaction */
|
||||
|
||||
@ -617,11 +621,12 @@ void guiSetup()
|
||||
{
|
||||
/* TFT init */
|
||||
tft.begin();
|
||||
tft.setSwapBytes(true); /* set endianess */
|
||||
|
||||
#ifdef USE_DMA_TO_TFT
|
||||
// DMA - should work with STM32F2xx/F4xx/F7xx processors
|
||||
// NOTE: >>>>>> DMA IS FOR SPI DISPLAYS ONLY <<<<<<
|
||||
tft.initDMA(); // Initialise the DMA engine (tested with STM32F446 and STM32F767)
|
||||
// DMA - should work with STM32F2xx/F4xx/F7xx processors
|
||||
// NOTE: >>>>>> DMA IS FOR SPI DISPLAYS ONLY <<<<<<
|
||||
tft.initDMA(); // Initialise the DMA engine (tested with STM32F446 and STM32F767)
|
||||
#endif
|
||||
|
||||
tft.setRotation(guiRotation); /* 1/3=Landscape or 0/2=Portrait orientation */
|
||||
@ -652,10 +657,10 @@ tft.initDMA(); // Initialise the DMA engine (tested with STM32F446 and STM32F767
|
||||
#else
|
||||
static lv_disp_buf_t disp_buf;
|
||||
static lv_color_t guiVdbBuffer1[16 * 512u]; // 16 KBytes
|
||||
static lv_color_t guiVdbBuffer2[16 * 512u]; // 16 KBytes
|
||||
// static lv_color_t guiVdbBuffer2[16 * 512u]; // 16 KBytes
|
||||
guiVDBsize = sizeof(guiVdbBuffer1) / sizeof(guiVdbBuffer1[0]);
|
||||
lv_disp_buf_init(&disp_buf, guiVdbBuffer1, guiVdbBuffer2, guiVDBsize);
|
||||
//lv_disp_buf_init(&disp_buf, guiVdbBuffer1, NULL, guiVDBsize);
|
||||
// lv_disp_buf_init(&disp_buf, guiVdbBuffer1, guiVdbBuffer2, guiVDBsize);
|
||||
lv_disp_buf_init(&disp_buf, guiVdbBuffer1, NULL, guiVDBsize);
|
||||
#endif
|
||||
|
||||
/* Initialize PNG decoder */
|
||||
@ -781,27 +786,27 @@ tft.initDMA(); // Initialise the DMA engine (tested with STM32F446 and STM32F767
|
||||
tick.attach_ms(guiTickPeriod, lv_tick_handler);
|
||||
#else
|
||||
|
||||
/*
|
||||
#if defined(TIM1)
|
||||
TIM_TypeDef * Instance = TIM1;
|
||||
#else
|
||||
TIM_TypeDef * Instance = TIM2;
|
||||
#endif
|
||||
*/
|
||||
/*
|
||||
#if defined(TIM1)
|
||||
TIM_TypeDef * Instance = TIM1;
|
||||
#else
|
||||
TIM_TypeDef * Instance = TIM2;
|
||||
#endif
|
||||
*/
|
||||
// Instantiate HardwareTimer object. Thanks to 'new' instanciation, HardwareTimer is not destructed when setup()
|
||||
// function is finished.
|
||||
/* static HardwareTimer * MyTim = new HardwareTimer(Instance);
|
||||
MyTim->pause();
|
||||
MyTim->setPrescaleFactor(1);
|
||||
MyTim->setMode(0, TIMER_OUTPUT_COMPARE, NC);
|
||||
MyTim->setOverflow(1000 * guiTickPeriod, MICROSEC_FORMAT); // MicroSec
|
||||
MyTim->setCount(0,MICROSEC_FORMAT);
|
||||
MyTim->refresh();
|
||||
MyTim->detachInterrupt();
|
||||
MyTim->attachInterrupt((void (*)(HardwareTimer *))lv_tick_handler);
|
||||
MyTim->detachInterrupt(0);
|
||||
MyTim->attachInterrupt(0,(void (*)(HardwareTimer *))lv_tick_handler);
|
||||
MyTim->resume();*/
|
||||
/* static HardwareTimer * MyTim = new HardwareTimer(Instance);
|
||||
MyTim->pause();
|
||||
MyTim->setPrescaleFactor(1);
|
||||
MyTim->setMode(0, TIMER_OUTPUT_COMPARE, NC);
|
||||
MyTim->setOverflow(1000 * guiTickPeriod, MICROSEC_FORMAT); // MicroSec
|
||||
MyTim->setCount(0,MICROSEC_FORMAT);
|
||||
MyTim->refresh();
|
||||
MyTim->detachInterrupt();
|
||||
MyTim->attachInterrupt((void (*)(HardwareTimer *))lv_tick_handler);
|
||||
MyTim->detachInterrupt(0);
|
||||
MyTim->attachInterrupt(0,(void (*)(HardwareTimer *))lv_tick_handler);
|
||||
MyTim->resume();*/
|
||||
tick.start();
|
||||
#endif
|
||||
|
||||
@ -816,14 +821,13 @@ void IRAM_ATTR guiLoop()
|
||||
tick.update();
|
||||
#endif
|
||||
|
||||
//lv_tick_handler();
|
||||
// lv_tick_handler();
|
||||
lv_task_handler(); /* let the GUI do its work */
|
||||
guiCheckSleep();
|
||||
|
||||
#if TOUCH_DRIVER == 1
|
||||
touch.loop();
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void guiStop()
|
||||
@ -969,14 +973,15 @@ bool guiSetConfig(const JsonObject & settings)
|
||||
}
|
||||
|
||||
if(calData[0] != 0 || calData[1] != 65535 || calData[2] != 0 || calData[3] != 65535) {
|
||||
Log.trace(F("calData set [%u, %u, %u, %u, %u]"), calData[0], calData[1], calData[2], calData[3],calData[4]);
|
||||
Log.trace(F("calData set [%u, %u, %u, %u, %u]"), calData[0], calData[1], calData[2], calData[3],
|
||||
calData[4]);
|
||||
oobeSetAutoCalibrate(false);
|
||||
} else {
|
||||
Log.notice(F("First Touch Calibration enabled"));
|
||||
oobeSetAutoCalibrate(true);
|
||||
}
|
||||
|
||||
if (status) tft.setTouch(calData);
|
||||
|
||||
if(status) tft.setTouch(calData);
|
||||
changed |= status;
|
||||
}
|
||||
|
||||
@ -991,23 +996,15 @@ static void guiSetBmpHeader(uint8_t * buffer_p, int32_t data)
|
||||
*buffer_p++ = (data >> 24) & 0xFF;
|
||||
}
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
static void guiSendBmpHeader();
|
||||
|
||||
void guiTakeScreenshot(ESP8266WebServer & client)
|
||||
#endif
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
static void guiSendBmpHeader();
|
||||
|
||||
void guiTakeScreenshot(WebServer & client)
|
||||
#endif // ESP32{
|
||||
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
||||
void guiTakeScreenshot()
|
||||
{
|
||||
webClient = &client;
|
||||
lv_disp_t * disp = lv_disp_get_default();
|
||||
// webClient = &client;
|
||||
// lv_disp_t * disp = lv_disp_get_default();
|
||||
|
||||
webClient->setContentLength(122 + disp->driver.hor_res * disp->driver.ver_res * sizeof(lv_color_t));
|
||||
webClient->send(200, PSTR("image/bmp"), "");
|
||||
// webClient->setContentLength(122 + disp->driver.hor_res * disp->driver.ver_res * sizeof(lv_color_t));
|
||||
// webClient->send(200, PSTR("image/bmp"), "");
|
||||
|
||||
guiSnapshot = 2;
|
||||
guiSendBmpHeader();
|
||||
@ -1068,15 +1065,17 @@ static void guiSendBmpHeader()
|
||||
buffer[70 + 0] = 0x20;
|
||||
|
||||
if(guiSnapshot == 1) {
|
||||
#if HASP_USE_SPIFFS > 0
|
||||
size_t len = pFileOut.write(buffer, 122);
|
||||
if(len != sizeof(buffer)) {
|
||||
Log.warning(F("GUI: Data written does not match header size"));
|
||||
} else {
|
||||
Log.verbose(F("GUI: Bitmap header written"));
|
||||
}
|
||||
#endif
|
||||
|
||||
} else if(guiSnapshot == 2) {
|
||||
if(webClient->client().write(buffer, 122) != 122) {
|
||||
if(httpClientWrite(buffer, 122) != 122) {
|
||||
Log.warning(F("GUI: Data sent does not match header size"));
|
||||
} else {
|
||||
Log.verbose(F("GUI: Bitmap header sent"));
|
||||
@ -1093,6 +1092,7 @@ static void guiSendBmpHeader()
|
||||
* @param[in] pFileName Output binary file name.
|
||||
*
|
||||
**/
|
||||
#if HASP_USE_SPIFFS > 0
|
||||
void guiTakeScreenshot(const char * pFileName)
|
||||
{
|
||||
pFileOut = SPIFFS.open(pFileName, "w");
|
||||
|
@ -6,15 +6,17 @@
|
||||
|
||||
#include "lvgl.h"
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
#include <ESP8266WebServer.h>
|
||||
void guiTakeScreenshot(ESP8266WebServer & client);
|
||||
#endif
|
||||
// #if defined(ARDUINO_ARCH_ESP8266)
|
||||
// #include <ESP8266WebServer.h>
|
||||
// void guiTakeScreenshot(ESP8266WebServer & client);
|
||||
// #endif
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
#include <WebServer.h>
|
||||
void guiTakeScreenshot(WebServer & client);
|
||||
#endif // ESP32
|
||||
// #if defined(ARDUINO_ARCH_ESP32)
|
||||
// #include <WebServer.h>
|
||||
// void guiTakeScreenshot(WebServer & client);
|
||||
// #endif // ESP32
|
||||
|
||||
void guiTakeScreenshot();
|
||||
|
||||
void guiSetup();
|
||||
void guiLoop(void);
|
||||
|
112
src/hasp_hal.cpp
112
src/hasp_hal.cpp
@ -1,10 +1,17 @@
|
||||
#if defined(ESP32) || defined(ESP8266)
|
||||
#include <ESP.h>
|
||||
#if defined(STM32F4xx)
|
||||
#include <Stm32Ethernet.h>
|
||||
#endif
|
||||
|
||||
#include "hasp_hal.h"
|
||||
|
||||
#if ESP32
|
||||
#if defined(ESP8266)
|
||||
#include <ESP.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#endif
|
||||
|
||||
#if defined(ESP32)
|
||||
#include <ESP.h>
|
||||
#include <Wifi.h>
|
||||
#include "esp_system.h"
|
||||
#endif
|
||||
|
||||
@ -107,8 +114,6 @@ String halGetResetInfo()
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
String halGetCoreVersion()
|
||||
{
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
@ -155,13 +160,12 @@ String halGetChipModel()
|
||||
return model;
|
||||
}
|
||||
|
||||
|
||||
/*******************************/
|
||||
/* Memory Management Functions */
|
||||
|
||||
#if defined(STM32F4xx)
|
||||
#include <malloc.h> // for mallinfo()
|
||||
#include <unistd.h> // for sbrk()
|
||||
#include <malloc.h> // for mallinfo()
|
||||
#include <unistd.h> // for sbrk()
|
||||
|
||||
int freeHighMemory()
|
||||
{
|
||||
@ -177,29 +181,29 @@ int freeHighMemory()
|
||||
#endif
|
||||
|
||||
/*
|
||||
extern char *fake_heap_end; // current heap start
|
||||
extern char *fake_heap_start; // current heap end
|
||||
extern char *fake_heap_end; // current heap start
|
||||
extern char *fake_heap_start; // current heap end
|
||||
|
||||
char* getHeapStart() {
|
||||
return fake_heap_start;
|
||||
}
|
||||
|
||||
char* getHeapEnd() {
|
||||
return (char*)sbrk(0);
|
||||
}
|
||||
|
||||
char* getHeapLimit() {
|
||||
return fake_heap_end;
|
||||
char* getHeapStart() {
|
||||
return fake_heap_start;
|
||||
}
|
||||
|
||||
int getMemUsed() { // returns the amount of used memory in bytes
|
||||
struct mallinfo mi = mallinfo();
|
||||
return mi.uordblks;
|
||||
}
|
||||
char* getHeapEnd() {
|
||||
return (char*)sbrk(0);
|
||||
}
|
||||
|
||||
int getMemFree() { // returns the amount of free memory in bytes
|
||||
struct mallinfo mi = mallinfo();
|
||||
return mi.fordblks + freeHighMemory();
|
||||
char* getHeapLimit() {
|
||||
return fake_heap_end;
|
||||
}
|
||||
|
||||
int getMemUsed() { // returns the amount of used memory in bytes
|
||||
struct mallinfo mi = mallinfo();
|
||||
return mi.uordblks;
|
||||
}
|
||||
|
||||
int getMemFree() { // returns the amount of free memory in bytes
|
||||
struct mallinfo mi = mallinfo();
|
||||
return mi.fordblks + freeHighMemory();
|
||||
} */
|
||||
|
||||
size_t halGetMaxFreeBlock()
|
||||
@ -239,3 +243,57 @@ uint8_t halGetHeapFragmentation()
|
||||
return (int8_t)(100.00f - (float)freeHighMemory() * 100.00f / (float)halGetFreeHeap());
|
||||
#endif
|
||||
}
|
||||
|
||||
String halGetMacAddress(int start, const char * seperator)
|
||||
{
|
||||
byte mac[6];
|
||||
|
||||
#if defined(STM32F4xx)
|
||||
uint8_t * mac_p;
|
||||
mac_p = Ethernet.MACAddress();
|
||||
for(uint8_t i = 0; i < 6; i++) mac[i] = *(mac_p + i);
|
||||
#else
|
||||
WiFi.macAddress(mac);
|
||||
#endif
|
||||
|
||||
String cMac((char *)0);
|
||||
cMac.reserve(32);
|
||||
|
||||
for(int i = start; i < 6; ++i) {
|
||||
if(mac[i] < 0x10) cMac += "0";
|
||||
cMac += String(mac[i], HEX);
|
||||
if(i < 5) cMac += seperator;
|
||||
}
|
||||
cMac.toUpperCase();
|
||||
return cMac;
|
||||
}
|
||||
|
||||
uint16_t halGetCpuFreqMHz()
|
||||
{
|
||||
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_32)
|
||||
return ESP.getCpuFreqMHz();
|
||||
#else
|
||||
return (F_CPU / 1000 / 1000);
|
||||
#endif
|
||||
}
|
||||
|
||||
String halFormatBytes(size_t bytes)
|
||||
{
|
||||
String output((char *)0);
|
||||
output.reserve(128);
|
||||
|
||||
if(bytes < 1024) {
|
||||
output += bytes;
|
||||
} else if(bytes < (1024 * 1024)) {
|
||||
output += bytes / 1024.0;
|
||||
output += "K";
|
||||
} else if(bytes < (1024 * 1024 * 1024)) {
|
||||
output += bytes / 1024.0 / 1024.0;
|
||||
output += "M";
|
||||
} else {
|
||||
output += bytes / 1024.0 / 1024.0 / 1024.0;
|
||||
output += "G";
|
||||
}
|
||||
output += "B";
|
||||
return output;
|
||||
}
|
@ -10,5 +10,8 @@ size_t halGetMaxFreeBlock(void);
|
||||
size_t halGetFreeHeap(void);
|
||||
String halGetCoreVersion(void);
|
||||
String halGetChipModel();
|
||||
String halGetMacAddress(int start, const char * seperator);
|
||||
uint16_t halGetCpuFreqMHz(void);
|
||||
String halFormatBytes(size_t bytes);
|
||||
|
||||
#endif
|
1740
src/hasp_http.cpp
1740
src/hasp_http.cpp
File diff suppressed because it is too large
Load Diff
@ -9,6 +9,8 @@ void httpLoop(void);
|
||||
void httpEvery5Seconds(void);
|
||||
void httpReconnect(void);
|
||||
|
||||
size_t httpClientWrite(const uint8_t *buf, size_t size); // Screenshot Write Data
|
||||
|
||||
bool httpGetConfig(const JsonObject & settings);
|
||||
bool httpSetConfig(const JsonObject & settings);
|
||||
|
||||
|
@ -11,10 +11,15 @@
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
#include <Wifi.h>
|
||||
#else
|
||||
WiFiClient mqttNetworkClient;
|
||||
#elif defined(ARDUINO_ARCH_ESP8266)
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <EEPROM.h>
|
||||
#include <ESP.h>
|
||||
WiFiClient mqttNetworkClient;
|
||||
#else
|
||||
#include <STM32Ethernet.h>
|
||||
EthernetClient mqttNetworkClient;
|
||||
#endif
|
||||
|
||||
#include "hasp_hal.h"
|
||||
@ -97,8 +102,7 @@ const String mqttLightSubscription = "hasp/" + String(haspGetNodename())
|
||||
const String mqttLightBrightSubscription = "hasp/" + String(haspGetNodename()) + "/brightness/#";
|
||||
*/
|
||||
|
||||
WiFiClient mqttWifiClient;
|
||||
PubSubClient mqttClient(mqttWifiClient);
|
||||
PubSubClient mqttClient(mqttNetworkClient);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Send changed values OUT
|
||||
@ -179,11 +183,13 @@ void mqtt_send_statusupdate()
|
||||
snprintf_P(data, sizeof(data), PSTR("{\"status\":\"available\",\"version\":\"%s\",\"uptime\":%lu,"),
|
||||
haspGetVersion().c_str(), long(millis() / 1000));
|
||||
strcat(buffer, data);
|
||||
#if HASP_USE_WIFI
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("\"ssid\":\"%s\",\"rssi\":%i,\"ip\":\"%s\","), WiFi.SSID().c_str(),
|
||||
WiFi.RSSI(), WiFi.localIP().toString().c_str());
|
||||
strcat(data, buffer);
|
||||
#endif
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("\"heapFree\":%u,\"heapFrag\":%u,\"espCore\":\"%s\","),
|
||||
ESP.getFreeHeap(), halGetHeapFragmentation(), halGetCoreVersion().c_str());
|
||||
halGetFreeHeap(), halGetHeapFragmentation(), halGetCoreVersion().c_str());
|
||||
strcat(data, buffer);
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("\"espCanUpdate\":\"false\",\"page\":%u,\"numPages\":%u,"),
|
||||
haspGetPage(), (HASP_NUM_PAGES));
|
||||
@ -339,10 +345,18 @@ void mqttReconnect()
|
||||
bool mqttFirstConnect = true;
|
||||
|
||||
{
|
||||
#if HASP_USE_WIFI>0
|
||||
byte mac[6];
|
||||
WiFi.macAddress(mac);
|
||||
snprintf_P(mqttClientId, sizeof(mqttClientId), PSTR("%s-%2x%2x%2x"), mqttNodeName, mac[3], mac[4], mac[5]);
|
||||
snprintf_P(mqttClientId, sizeof(mqttClientId), PSTR("%s-%02x%02x%02x"), mqttNodeName, mac[3], mac[4], mac[5]);
|
||||
#endif
|
||||
#if HASP_USE_ETHERNET>0
|
||||
uint8_t * mac;
|
||||
mac = Ethernet.MACAddress();
|
||||
snprintf_P(mqttClientId, sizeof(mqttClientId), PSTR("%s-%02x%02x%02x"), mqttNodeName, *(mac+3), *(mac+4), *(mac+5));
|
||||
#endif
|
||||
}
|
||||
Log.verbose(mqttClientId);
|
||||
|
||||
// Attempt to connect and set LWT and Clean Session
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("%sstatus"), mqttNodeTopic);
|
||||
@ -537,7 +551,7 @@ bool mqttSetConfig(const JsonObject & settings)
|
||||
}
|
||||
// Prefill node name
|
||||
if(strlen(mqttNodeName) == 0) {
|
||||
String mac = wifiGetMacAddress(3, "");
|
||||
String mac = halGetMacAddress(3, "");
|
||||
mac.toLowerCase();
|
||||
snprintf_P(mqttNodeName, sizeof(mqttNodeName), PSTR("plate_%s"), mac.c_str());
|
||||
changed = true;
|
||||
|
@ -102,25 +102,4 @@ void spiffsSetup()
|
||||
Log.verbose(F("FILE: SPI Flash FS mounted"));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
String spiffsFormatBytes(size_t bytes)
|
||||
{
|
||||
String output((char *)0);
|
||||
output.reserve(128);
|
||||
|
||||
if(bytes < 1024) {
|
||||
output += bytes;
|
||||
} else if(bytes < (1024 * 1024)) {
|
||||
output += bytes / 1024.0;
|
||||
output += "K";
|
||||
} else if(bytes < (1024 * 1024 * 1024)) {
|
||||
output += bytes / 1024.0 / 1024.0;
|
||||
output += "M";
|
||||
} else {
|
||||
output += bytes / 1024.0 / 1024.0 / 1024.0;
|
||||
output += "G";
|
||||
}
|
||||
output += "B";
|
||||
return output;
|
||||
}
|
@ -7,6 +7,5 @@ void spiffsSetup(void);
|
||||
|
||||
void spiffsList();
|
||||
void spiffsInfo();
|
||||
String spiffsFormatBytes(size_t bytes);
|
||||
|
||||
#endif
|
@ -12,8 +12,16 @@
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
#include <Wifi.h>
|
||||
#else
|
||||
WiFiClient telnetClient;
|
||||
static WiFiServer * telnetServer;
|
||||
#elif defined(ARDUINO_ARCH_ESP8266)
|
||||
#include <ESP8266WiFi.h>
|
||||
WiFiClient telnetClient;
|
||||
static WiFiServer * telnetServer;
|
||||
#else
|
||||
#include <STM32Ethernet.h>
|
||||
EthernetClient telnetClient;
|
||||
static EthernetServer telnetServer(23);
|
||||
#endif
|
||||
|
||||
#define TELNET_UNAUTHENTICATED 0
|
||||
@ -21,12 +29,14 @@
|
||||
#define TELNET_USERNAME_NOK 99
|
||||
#define TELNET_AUTHENTICATED 255
|
||||
|
||||
#if HASP_USE_HTTP > 0
|
||||
extern char httpUser[32];
|
||||
extern char httpPassword[32];
|
||||
#endif
|
||||
|
||||
uint8_t telnetLoginState = TELNET_UNAUTHENTICATED;
|
||||
WiFiClient telnetClient;
|
||||
static WiFiServer * telnetServer;
|
||||
// WiFiClient telnetClient;
|
||||
// static WiFiServer * telnetServer;
|
||||
uint16_t telnetPort = 23;
|
||||
bool telnetInCommandMode = false;
|
||||
uint8_t telnetEnabled = true; // Enable telnet debug output
|
||||
@ -36,7 +46,7 @@ char telnetInputBuffer[128];
|
||||
|
||||
void telnetClientDisconnect()
|
||||
{
|
||||
Log.notice(F("Closing session from %s"), telnetClient.remoteIP().toString().c_str());
|
||||
// Log.notice(F("Closing session from %s"), telnetClient.remoteIP().toString().c_str());
|
||||
telnetClient.stop();
|
||||
Log.unregisterOutput(1); // telnetClient
|
||||
telnetLoginState = TELNET_UNAUTHENTICATED;
|
||||
@ -51,7 +61,7 @@ void telnetClientLogon()
|
||||
telnetLoginState = TELNET_AUTHENTICATED; // User and Pass are correct
|
||||
telnetLoginAttempt = 0; // Reset attempt counter
|
||||
Log.registerOutput(1, &telnetClient, LOG_LEVEL_VERBOSE, true);
|
||||
Log.notice(F("Client login from %s"), telnetClient.remoteIP().toString().c_str());
|
||||
// Log.notice(F("Client login from %s"), telnetClient.remoteIP().toString().c_str());
|
||||
telnetClient.flush();
|
||||
/* Echo locally as separate string */
|
||||
// telnetClient.print(F("TELNET: Client login from "));
|
||||
@ -66,17 +76,25 @@ void telnetAcceptClient()
|
||||
telnetClient.stop(); // client disconnected
|
||||
Log.unregisterOutput(1); // telnetClient
|
||||
}
|
||||
telnetClient = telnetServer->available(); // ready for new client
|
||||
Log.notice(F("Client connected from %s"), telnetClient.remoteIP().toString().c_str());
|
||||
telnetClient = telnetServer.available(); // ready for new client
|
||||
// Log.notice(F("Client connected from %s"), telnetClient.remoteIP().toString().c_str());
|
||||
if(!telnetClient) {
|
||||
Log.notice(F("Client NOT connected"));
|
||||
return;
|
||||
}
|
||||
Log.notice(F("Client connected"));
|
||||
|
||||
/* Avoid a buffer here */
|
||||
telnetClient.print(0xFF); // DO TERMINAL-TYPE
|
||||
telnetClient.print(0xFD);
|
||||
telnetClient.print(0x1B);
|
||||
#if HASP_USE_HTTP > 0
|
||||
if(strlen(httpUser) != 0 || strlen(httpPassword) != 0) {
|
||||
telnetClient.print(F("\r\nUsername: "));
|
||||
telnetLoginState = TELNET_UNAUTHENTICATED;
|
||||
} else {
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
telnetClientLogon();
|
||||
}
|
||||
telnetInputIndex = 0; // reset input buffer index
|
||||
@ -100,6 +118,7 @@ static void telnetProcessLine()
|
||||
switch(telnetLoginState) {
|
||||
case TELNET_UNAUTHENTICATED: {
|
||||
telnetClient.printf(PSTR("Password: %c%c%c"), 0xFF, 0xFB, 0x01); // Hide characters
|
||||
#if HASP_USE_HTTP > 0
|
||||
telnetLoginState = strcmp(telnetInputBuffer, httpUser) == 0 ? TELNET_USERNAME_OK : TELNET_USERNAME_NOK;
|
||||
break;
|
||||
}
|
||||
@ -112,13 +131,16 @@ static void telnetProcessLine()
|
||||
telnetLoginState = TELNET_UNAUTHENTICATED;
|
||||
telnetLoginAttempt++; // Subsequent attempt
|
||||
telnetClient.println(F("Authorization failed!\r\n"));
|
||||
Log.warning(F("Incorrect login attempt from %s"), telnetClient.remoteIP().toString().c_str());
|
||||
// Log.warning(F("Incorrect login attempt from %s"), telnetClient.remoteIP().toString().c_str());
|
||||
if(telnetLoginAttempt >= 3) {
|
||||
telnetClientDisconnect();
|
||||
} else {
|
||||
telnetClient.print(F("Username: "));
|
||||
}
|
||||
}
|
||||
#else
|
||||
telnetClientLogon();
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@ -173,6 +195,15 @@ void telnetSetup()
|
||||
// telnetSetConfig(settings);
|
||||
|
||||
if(telnetEnabled) { // Setup telnet server for remote debug output
|
||||
#if defined(STM32F4xx)
|
||||
// if(!telnetServer) telnetServer = new EthernetServer(telnetPort);
|
||||
// if(telnetServer) {
|
||||
telnetServer.begin();
|
||||
Log.notice(F("Debug telnet console started"));
|
||||
// } else {
|
||||
// Log.error(F("Failed to start telnet server"));
|
||||
//}
|
||||
#else
|
||||
if(!telnetServer) telnetServer = new WiFiServer(telnetPort);
|
||||
if(telnetServer) {
|
||||
telnetServer->setNoDelay(true);
|
||||
@ -189,12 +220,41 @@ void telnetSetup()
|
||||
} else {
|
||||
Log.error(F("Failed to start telnet server"));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void IRAM_ATTR telnetLoop()
|
||||
{ // Basic telnet client handling code from: https://gist.github.com/tablatronix/4793677ca748f5f584c95ec4a2b10303
|
||||
|
||||
#if defined(STM32F4xx)
|
||||
Ethernet.schedule();
|
||||
// if(telnetServer)
|
||||
{ // client is connected
|
||||
EthernetClient client = telnetServer.available();
|
||||
if(client) {
|
||||
if(!telnetClient || !telnetClient.connected()) {
|
||||
//telnetAcceptClient(client);
|
||||
|
||||
telnetClient = client; // ready for new client
|
||||
// Log.notice(F("Client connected from %s"), telnetClient.remoteIP().toString().c_str());
|
||||
if(!telnetClient) {
|
||||
Log.notice(F("Client NOT connected"));
|
||||
return;
|
||||
}
|
||||
Log.notice(F("Client connected"));
|
||||
|
||||
/* Avoid a buffer here */
|
||||
// telnetClient.print(0xFF); // DO TERMINAL-TYPE
|
||||
// telnetClient.print(0xFD);
|
||||
// telnetClient.print(0x1B);
|
||||
|
||||
} else {
|
||||
//client.stop(); // have client, block new connections
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
if(telnetServer && telnetServer->hasClient()) { // client is connected
|
||||
if(!telnetClient || !telnetClient.connected()) {
|
||||
telnetAcceptClient();
|
||||
@ -209,6 +269,7 @@ void IRAM_ATTR telnetLoop()
|
||||
telnetProcessCharacter(telnetClient.read()); // client input processing
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool telnetGetConfig(const JsonObject & settings)
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "TFT_eSPI.h"
|
||||
|
||||
#include "hasp_tft.h"
|
||||
#include "hasp_hal.h"
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
ADC_MODE(ADC_VCC); // tftShowConfig measures the voltage on the pin
|
||||
@ -84,11 +85,10 @@ void tftShowConfig(TFT_eSPI & tft)
|
||||
Log.verbose(F("TFT: TFT_eSPI : v%s"), tftSetup.version.c_str());
|
||||
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_32)
|
||||
Log.verbose(F("TFT: Processor : ESP%x"), tftSetup.esp);
|
||||
Log.verbose(F("TFT: CPU freq. : %i MHz"), ESP.getCpuFreqMHz());
|
||||
#else
|
||||
Log.verbose(F("TFT: Processor : STM%x"), tftSetup.esp);
|
||||
Log.verbose(F("TFT: CPU freq. : %i MHz"), F_CPU / 1000 / 1000);
|
||||
#endif
|
||||
Log.verbose(F("TFT: CPU freq. : %i MHz"), halGetCpuFreqMHz());
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
Log.verbose(F("TFT: Voltage : %2.2f V"), ESP.getVcc() / 918.0); // 918 empirically determined
|
||||
|
@ -41,22 +41,6 @@ uint8_t wifiReconnectCounter = 0;
|
||||
// const byte DNS_PORT = 53;
|
||||
// DNSServer dnsServer;
|
||||
|
||||
String wifiGetMacAddress(int start, const char * seperator)
|
||||
{
|
||||
byte mac[6];
|
||||
WiFi.macAddress(mac);
|
||||
String cMac((char *)0);
|
||||
cMac.reserve(32);
|
||||
|
||||
for(int i = start; i < 6; ++i) {
|
||||
if(mac[i] < 0x10) cMac += "0";
|
||||
cMac += String(mac[i], HEX);
|
||||
if(i < 5) cMac += seperator;
|
||||
}
|
||||
cMac.toUpperCase();
|
||||
return cMac;
|
||||
}
|
||||
|
||||
void wifiConnected(IPAddress ipaddress)
|
||||
{
|
||||
Log.notice(F("WIFI: Received IP address %s"), ipaddress.toString().c_str());
|
||||
|
94
src/main.cpp
94
src/main.cpp
@ -9,6 +9,10 @@
|
||||
#include "hasp_oobe.h"
|
||||
#include "hasp_gpio.h"
|
||||
|
||||
#if HASP_USE_ETHERNET > 0
|
||||
#include <STM32Ethernet.h>
|
||||
#endif
|
||||
|
||||
bool isConnected;
|
||||
uint8_t mainLoopCounter = 0;
|
||||
unsigned long mainLastLoopTime = 0;
|
||||
@ -42,32 +46,19 @@ void setup()
|
||||
* Apply User Configuration
|
||||
***************************/
|
||||
debugSetup();
|
||||
gpioSetup();
|
||||
|
||||
#if HASP_USE_GPIO
|
||||
guiSetup();
|
||||
gpioSetup();
|
||||
#endif
|
||||
|
||||
#if HASP_USE_WIFI
|
||||
wifiSetup();
|
||||
#endif
|
||||
|
||||
guiSetup();
|
||||
oobeSetup();
|
||||
haspSetup();
|
||||
|
||||
#if HASP_USE_WIFI
|
||||
|
||||
#if HASP_USE_HTTP
|
||||
httpSetup();
|
||||
#endif
|
||||
|
||||
#if HASP_USE_MQTT
|
||||
mqttSetup();
|
||||
#endif
|
||||
|
||||
#if HASP_USE_TELNET
|
||||
telnetSetup();
|
||||
#endif
|
||||
|
||||
#if HASP_USE_MDNS
|
||||
mdnsSetup();
|
||||
#endif
|
||||
@ -76,12 +67,22 @@ void setup()
|
||||
otaSetup();
|
||||
#endif
|
||||
|
||||
#endif // WIFI
|
||||
|
||||
#if HASP_USE_ETHERNET
|
||||
#if HASP_USE_ETHERNET > 0
|
||||
ethernetSetup();
|
||||
#endif
|
||||
|
||||
#if HASP_USE_MQTT
|
||||
mqttSetup();
|
||||
#endif
|
||||
|
||||
#if HASP_USE_HTTP
|
||||
httpSetup();
|
||||
#endif
|
||||
|
||||
#if HASP_USE_TELNET > 0
|
||||
telnetSetup();
|
||||
#endif
|
||||
|
||||
#if HASP_USE_TASMOTA_SLAVE
|
||||
slaveSetup();
|
||||
#endif
|
||||
@ -92,21 +93,21 @@ void setup()
|
||||
void loop()
|
||||
{
|
||||
/* Storage Loops */
|
||||
/*
|
||||
#if HASP_USE_EEPROM
|
||||
// eepromLoop(); // Not used
|
||||
#endif
|
||||
/*
|
||||
#if HASP_USE_EEPROM
|
||||
// eepromLoop(); // Not used
|
||||
#endif
|
||||
|
||||
#if HASP_USE_SPIFFS
|
||||
// spiffsLoop(); // Not used
|
||||
#endif
|
||||
#if HASP_USE_SPIFFS
|
||||
// spiffsLoop(); // Not used
|
||||
#endif
|
||||
|
||||
#if HASP_USE_SDCARD
|
||||
// sdcardLoop(); // Not used
|
||||
#endif
|
||||
#if HASP_USE_SDCARD
|
||||
// sdcardLoop(); // Not used
|
||||
#endif
|
||||
|
||||
// configLoop(); // Not used
|
||||
*/
|
||||
// configLoop(); // Not used
|
||||
*/
|
||||
|
||||
/* Graphics Loops */
|
||||
// tftLoop();
|
||||
@ -120,7 +121,9 @@ void loop()
|
||||
#endif
|
||||
|
||||
/* Network Services Loops */
|
||||
#if HASP_USE_WIFI
|
||||
#if HASP_USE_ETHERNET > 0
|
||||
ethernetLoop();
|
||||
#endif
|
||||
|
||||
#if HASP_USE_MQTT
|
||||
mqttLoop();
|
||||
@ -130,10 +133,6 @@ void loop()
|
||||
httpLoop();
|
||||
#endif // HTTP
|
||||
|
||||
#if HASP_USE_TELNET
|
||||
telnetLoop();
|
||||
#endif // TELNET
|
||||
|
||||
#if HASP_USE_MDNS
|
||||
mdnsLoop();
|
||||
#endif // MDNS
|
||||
@ -142,11 +141,9 @@ void loop()
|
||||
otaLoop();
|
||||
#endif // OTA
|
||||
|
||||
#endif // WIFI
|
||||
|
||||
#if HASP_USE_ETHERNET
|
||||
ethernetLoop();
|
||||
#endif
|
||||
#if HASP_USE_TELNET > 0
|
||||
telnetLoop();
|
||||
#endif // TELNET
|
||||
|
||||
#if HASP_USE_TASMOTA_SLAVE
|
||||
slaveLoop();
|
||||
@ -163,17 +160,24 @@ void loop()
|
||||
debugEverySecond();
|
||||
|
||||
/* Run Every 5 Seconds */
|
||||
#if HASP_USE_WIFI
|
||||
if(mainLoopCounter == 0 || mainLoopCounter == 5) {
|
||||
#if HASP_USE_WIFI > 0
|
||||
isConnected = wifiEvery5Seconds();
|
||||
#if HASP_USE_HTTP
|
||||
#endif
|
||||
|
||||
#if HASP_USE_ETHERNET > 0
|
||||
isConnected = Ethernet.linkStatus() == LinkON;
|
||||
Serial.print(Ethernet.linkStatus());
|
||||
#endif
|
||||
|
||||
#if HASP_USE_HTTP > 0
|
||||
httpEvery5Seconds();
|
||||
#endif
|
||||
#if HASP_USE_MQTT
|
||||
|
||||
#if HASP_USE_MQTT > 0
|
||||
mqttEvery5Seconds(isConnected);
|
||||
#endif
|
||||
}
|
||||
#endif // Wifi
|
||||
|
||||
/* Reset loop counter every 10 seconds */
|
||||
if(mainLoopCounter >= 9) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user