mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-27 21:26:43 +00:00
Updates for stmf407vg
This commit is contained in:
parent
161ce4d81e
commit
4913c71419
@ -1,18 +1,9 @@
|
|||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
#include "ArduinoJson.h"
|
#include "ArduinoJson.h"
|
||||||
#include "ArduinoLog.h"
|
#include "ArduinoLog.h"
|
||||||
#include <FS.h> // Include the SPIFFS library
|
|
||||||
#include "EEPROM.h"
|
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
|
||||||
#include "SPIFFS.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "hasp_config.h"
|
#include "hasp_config.h"
|
||||||
#include "hasp_debug.h"
|
#include "hasp_debug.h"
|
||||||
#include "hasp_http.h"
|
|
||||||
#include "hasp_wifi.h"
|
|
||||||
#include "hasp_mdns.h"
|
|
||||||
#include "hasp_gui.h"
|
#include "hasp_gui.h"
|
||||||
#include "hasp_ota.h"
|
#include "hasp_ota.h"
|
||||||
#include "hasp_spiffs.h"
|
#include "hasp_spiffs.h"
|
||||||
@ -21,9 +12,21 @@
|
|||||||
#include "hasp.h"
|
#include "hasp.h"
|
||||||
|
|
||||||
#include "hasp_conf.h"
|
#include "hasp_conf.h"
|
||||||
#if HASP_USE_MQTT
|
|
||||||
#include "hasp_mqtt.h"
|
#if HASP_USE_SPIFFS>0
|
||||||
|
#include <FS.h> // Include the SPIFFS library
|
||||||
|
#if defined(ARDUINO_ARCH_ESP32)
|
||||||
|
#include "SPIFFS.h"
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
#if HASP_USE_EEPROM>0
|
||||||
|
#include "EEPROM.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef FPSTR
|
||||||
|
#define FPSTR(pstr_pointer) (reinterpret_cast<const __FlashStringHelper *>(pstr_pointer))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
void confDebugSet(const char * name)
|
void confDebugSet(const char * name)
|
||||||
{
|
{
|
||||||
@ -75,8 +78,10 @@ void configStartDebug(bool setupdebug, String & configFile)
|
|||||||
if(setupdebug) {
|
if(setupdebug) {
|
||||||
debugStart(); // Debug started, now we can use it; HASP header sent
|
debugStart(); // Debug started, now we can use it; HASP header sent
|
||||||
Log.notice(F("FILE: [SUCCESS] SPI flash FS mounted"));
|
Log.notice(F("FILE: [SUCCESS] SPI flash FS mounted"));
|
||||||
|
#if HASP_USE_SPIFFS>0
|
||||||
spiffsInfo();
|
spiffsInfo();
|
||||||
spiffsList();
|
spiffsList();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
Log.notice(F("CONF: Loading %s"), configFile.c_str());
|
Log.notice(F("CONF: Loading %s"), configFile.c_str());
|
||||||
}
|
}
|
||||||
@ -86,6 +91,8 @@ void configGetConfig(JsonDocument & settings, bool setupdebug = false)
|
|||||||
String configFile((char *)0);
|
String configFile((char *)0);
|
||||||
configFile.reserve(128);
|
configFile.reserve(128);
|
||||||
configFile = String(FPSTR(HASP_CONFIG_FILE));
|
configFile = String(FPSTR(HASP_CONFIG_FILE));
|
||||||
|
|
||||||
|
#if HASP_USE_SPIFFS>0
|
||||||
File file = SPIFFS.open(configFile, "r");
|
File file = SPIFFS.open(configFile, "r");
|
||||||
|
|
||||||
if(file) {
|
if(file) {
|
||||||
@ -119,6 +126,7 @@ void configGetConfig(JsonDocument & settings, bool setupdebug = false)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// File does not exist or error reading file
|
// File does not exist or error reading file
|
||||||
if(setupdebug) {
|
if(setupdebug) {
|
||||||
@ -131,6 +139,7 @@ void configGetConfig(JsonDocument & settings, bool setupdebug = false)
|
|||||||
|
|
||||||
void configBackupToEeprom()
|
void configBackupToEeprom()
|
||||||
{
|
{
|
||||||
|
#if HASP_USE_SPIFFS>0
|
||||||
String configFile((char *)0);
|
String configFile((char *)0);
|
||||||
configFile.reserve(128);
|
configFile.reserve(128);
|
||||||
configFile = String(FPSTR(HASP_CONFIG_FILE));
|
configFile = String(FPSTR(HASP_CONFIG_FILE));
|
||||||
@ -154,10 +163,12 @@ void configBackupToEeprom()
|
|||||||
|
|
||||||
Log.verbose(F("CONF: Written %u to EEPROM"), index);
|
Log.verbose(F("CONF: Written %u to EEPROM"), index);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void configWriteConfig()
|
void configWriteConfig()
|
||||||
{
|
{
|
||||||
|
#if HASP_USE_SPIFFS>0
|
||||||
String configFile((char *)0);
|
String configFile((char *)0);
|
||||||
configFile.reserve(128);
|
configFile.reserve(128);
|
||||||
configFile = String(FPSTR(HASP_CONFIG_FILE));
|
configFile = String(FPSTR(HASP_CONFIG_FILE));
|
||||||
@ -264,16 +275,26 @@ void configWriteConfig()
|
|||||||
} else {
|
} else {
|
||||||
Log.notice(F("CONF: Configuration was not changed"));
|
Log.notice(F("CONF: Configuration was not changed"));
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void configSetup()
|
void configSetup()
|
||||||
{
|
{
|
||||||
|
#if HASP_USE_SPIFFS>0
|
||||||
if(!SPIFFS.begin()) {
|
if(!SPIFFS.begin()) {
|
||||||
Log.error(F("FILE: SPI flash init failed. Unable to mount FS: Using default settings..."));
|
#endif
|
||||||
|
|
||||||
|
#if HASP_USE_SPIFFS>0
|
||||||
} else {
|
} else {
|
||||||
|
#endif
|
||||||
DynamicJsonDocument settings(1024 + 128);
|
DynamicJsonDocument settings(1024 + 128);
|
||||||
|
Serial.print(__FILE__);
|
||||||
|
Serial.println(__LINE__);
|
||||||
|
|
||||||
configGetConfig(settings, true);
|
configGetConfig(settings, true);
|
||||||
|
|
||||||
|
Log.error(F("FILE: SPI flash init failed. Unable to mount FS: Using default settings..."));
|
||||||
|
#if HASP_USE_SPIFFS>0
|
||||||
Log.verbose(F("Loading debug settings"));
|
Log.verbose(F("Loading debug settings"));
|
||||||
debugSetConfig(settings[F("debug")]);
|
debugSetConfig(settings[F("debug")]);
|
||||||
Log.verbose(F("Loading GUI settings"));
|
Log.verbose(F("Loading GUI settings"));
|
||||||
@ -304,6 +325,7 @@ void configSetup()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
Log.notice(F("User configuration loaded"));
|
Log.notice(F("User configuration loaded"));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void configOutput(const JsonObject & settings)
|
void configOutput(const JsonObject & settings)
|
||||||
|
@ -6,17 +6,11 @@
|
|||||||
#include "hasp_dispatch.h"
|
#include "hasp_dispatch.h"
|
||||||
#include "hasp_config.h"
|
#include "hasp_config.h"
|
||||||
#include "hasp_debug.h"
|
#include "hasp_debug.h"
|
||||||
#include "hasp_http.h"
|
|
||||||
#include "hasp_mdns.h"
|
|
||||||
#include "hasp_wifi.h"
|
|
||||||
#include "hasp_gui.h"
|
#include "hasp_gui.h"
|
||||||
#include "hasp_ota.h"
|
#include "hasp_hal.h"
|
||||||
#include "hasp.h"
|
#include "hasp.h"
|
||||||
|
|
||||||
#include "hasp_conf.h"
|
#include "hasp_conf.h"
|
||||||
#if HASP_USE_MQTT
|
|
||||||
#include "hasp_mqtt.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
inline void dispatchPrintln(String header, String & data)
|
inline void dispatchPrintln(String header, String & data)
|
||||||
{
|
{
|
||||||
@ -272,42 +266,50 @@ void dispatchJsonl(char * payload)
|
|||||||
|
|
||||||
void dispatchIdle(const char * state)
|
void dispatchIdle(const char * state)
|
||||||
{
|
{
|
||||||
#if HASP_USE_MQTT
|
#if HASP_USE_MQTT>0
|
||||||
mqtt_send_state(F("idle"), state);
|
mqtt_send_state(F("idle"), state);
|
||||||
|
#else
|
||||||
|
Log.notice(F("OUT: idle = %s"), state);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void dispatchReboot(bool saveConfig)
|
void dispatchReboot(bool saveConfig)
|
||||||
{
|
{
|
||||||
if(saveConfig) configWriteConfig();
|
if(saveConfig) configWriteConfig();
|
||||||
#if HASP_USE_MQTT
|
#if HASP_USE_MQTT>0
|
||||||
mqttStop(); // Stop the MQTT Client first
|
mqttStop(); // Stop the MQTT Client first
|
||||||
#endif
|
#endif
|
||||||
debugStop();
|
debugStop();
|
||||||
|
#if HASP_USE_WIFI>0
|
||||||
wifiStop();
|
wifiStop();
|
||||||
|
#endif
|
||||||
Log.verbose(F("-------------------------------------"));
|
Log.verbose(F("-------------------------------------"));
|
||||||
Log.notice(F("STOP: Properly Rebooting the MCU now!"));
|
Log.notice(F("STOP: Properly Rebooting the MCU now!"));
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
ESP.restart();
|
//halRestart();
|
||||||
}
|
}
|
||||||
|
|
||||||
void dispatch_button(uint8_t id, const char * event)
|
void dispatch_button(uint8_t id, const char * event)
|
||||||
{
|
{
|
||||||
#if HASP_USE_MQTT
|
#if HASP_USE_MQTT > 0
|
||||||
mqtt_send_input(id, event);
|
mqtt_send_input(id, event);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void dispatchWebUpdate(const char * espOtaUrl)
|
void dispatchWebUpdate(const char * espOtaUrl)
|
||||||
{
|
{
|
||||||
|
#if HASP_USE_OTA > 0
|
||||||
Log.verbose(F("FWUP: Checking for updates at URL: %s"), espOtaUrl);
|
Log.verbose(F("FWUP: Checking for updates at URL: %s"), espOtaUrl);
|
||||||
otaHttpUpdate(espOtaUrl);
|
otaHttpUpdate(espOtaUrl);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void IRAM_ATTR dispatch_obj_attribute_str(uint8_t pageid, uint8_t btnid, const char * attribute, const char * data)
|
void IRAM_ATTR dispatch_obj_attribute_str(uint8_t pageid, uint8_t btnid, const char * attribute, const char * data)
|
||||||
{
|
{
|
||||||
#if HASP_USE_MQTT
|
#if HASP_USE_MQTT > 0
|
||||||
mqtt_send_obj_attribute_str(pageid, btnid, attribute, data);
|
mqtt_send_obj_attribute_str(pageid, btnid, attribute, data);
|
||||||
|
#else
|
||||||
|
Log.notice(F("OUT: json = {\"p[%u].b[%u].%s\":\"%s\"}"), pageid, btnid, attribute, data);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -397,6 +399,8 @@ void dispatchConfig(const char * topic, const char * payload)
|
|||||||
size_t size = serializeJson(doc, buffer, sizeof(buffer));
|
size_t size = serializeJson(doc, buffer, sizeof(buffer));
|
||||||
#if HASP_USE_MQTT
|
#if HASP_USE_MQTT
|
||||||
mqtt_send_state(F("config"), buffer);
|
mqtt_send_state(F("config"), buffer);
|
||||||
|
#else
|
||||||
|
Log.notice(F("OUT: config %s = %s"),topic,buffer);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -298,6 +298,7 @@ void oobeSetup()
|
|||||||
char ssid[32];
|
char ssid[32];
|
||||||
char pass[32];
|
char pass[32];
|
||||||
|
|
||||||
|
#if HASP_USE_WIFI>0
|
||||||
if(wifiShowAP(ssid, pass)) {
|
if(wifiShowAP(ssid, pass)) {
|
||||||
guiSetDim(100);
|
guiSetDim(100);
|
||||||
oobeSetupQR(ssid, pass);
|
oobeSetupQR(ssid, pass);
|
||||||
@ -314,4 +315,5 @@ void oobeSetup()
|
|||||||
Log.verbose(F("OOBE: Already calibrated"));
|
Log.verbose(F("OOBE: Already calibrated"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
@ -1,3 +1,4 @@
|
|||||||
|
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <ArduinoOTA.h>
|
#include <ArduinoOTA.h>
|
||||||
#include "ArduinoJson.h"
|
#include "ArduinoJson.h"
|
||||||
@ -184,4 +185,5 @@ void otaHttpUpdate(const char * espOtaUrl)
|
|||||||
#endif
|
#endif
|
||||||
mdnsStart();
|
mdnsStart();
|
||||||
// nextionSendCmd("page " + String(nextionActivePage));
|
// nextionSendCmd("page " + String(nextionActivePage));
|
||||||
}
|
}
|
||||||
|
#endif
|
@ -1,3 +1,5 @@
|
|||||||
|
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
||||||
|
|
||||||
#ifndef HASP_OTA_H
|
#ifndef HASP_OTA_H
|
||||||
#define HASP_OTA_H
|
#define HASP_OTA_H
|
||||||
|
|
||||||
@ -8,4 +10,5 @@ void otaLoop(void);
|
|||||||
void otaEverySecond(void);
|
void otaEverySecond(void);
|
||||||
void otaHttpUpdate(const char * espOtaUrl);
|
void otaHttpUpdate(const char * espOtaUrl);
|
||||||
|
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
@ -5,7 +5,6 @@
|
|||||||
#include "ArduinoJson.h"
|
#include "ArduinoJson.h"
|
||||||
#include "ArduinoLog.h"
|
#include "ArduinoLog.h"
|
||||||
|
|
||||||
#include "hasp_http.h"
|
|
||||||
#include "hasp_debug.h"
|
#include "hasp_debug.h"
|
||||||
#include "hasp_config.h"
|
#include "hasp_config.h"
|
||||||
#include "hasp_dispatch.h"
|
#include "hasp_dispatch.h"
|
||||||
|
@ -82,8 +82,13 @@ void tftShowConfig(TFT_eSPI & tft)
|
|||||||
tft.getSetup(tftSetup);
|
tft.getSetup(tftSetup);
|
||||||
|
|
||||||
Log.verbose(F("TFT: TFT_eSPI : v%s"), tftSetup.version.c_str());
|
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: Processor : ESP%x"), tftSetup.esp);
|
||||||
Log.verbose(F("TFT: CPU freq. : %i MHz"), ESP.getCpuFreqMHz());
|
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
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP8266)
|
#if defined(ARDUINO_ARCH_ESP8266)
|
||||||
Log.verbose(F("TFT: Voltage : %2.2f V"), ESP.getVcc() / 918.0); // 918 empirically determined
|
Log.verbose(F("TFT: Voltage : %2.2f V"), ESP.getVcc() / 918.0); // 918 empirically determined
|
||||||
@ -164,8 +169,8 @@ void tftShowConfig(TFT_eSPI & tft)
|
|||||||
// Get pin name for ESP8266
|
// Get pin name for ESP8266
|
||||||
int8_t getPinName(int8_t pin)
|
int8_t getPinName(int8_t pin)
|
||||||
{
|
{
|
||||||
// For ESP32 pin labels on boards use the GPIO number
|
// For ESP32 and STM32 pin labels on boards use the GPIO number
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
#ifndef ARDUINO_ARCH_ESP8266
|
||||||
return pin;
|
return pin;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -4,23 +4,17 @@
|
|||||||
|
|
||||||
#include "hasp_conf.h"
|
#include "hasp_conf.h"
|
||||||
|
|
||||||
#include "hasp_wifi.h"
|
#if HASP_USE_WIFI>0
|
||||||
#include "hasp_http.h"
|
|
||||||
#include "hasp_mdns.h"
|
|
||||||
#include "hasp_debug.h"
|
#include "hasp_debug.h"
|
||||||
#include "hasp_config.h"
|
#include "hasp_config.h"
|
||||||
#include "hasp_dispatch.h"
|
#include "hasp_dispatch.h"
|
||||||
#include "hasp_gui.h"
|
#include "hasp_gui.h"
|
||||||
#include "hasp.h"
|
#include "hasp.h"
|
||||||
|
|
||||||
#include "hasp_conf.h"
|
|
||||||
#if HASP_USE_MQTT
|
|
||||||
#include "hasp_mqtt.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
#if defined(ARDUINO_ARCH_ESP32)
|
||||||
#include <Wifi.h>
|
#include <Wifi.h>
|
||||||
#else
|
#elif defined(ARDUINO_ARCH_ESP8266)
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
|
|
||||||
static WiFiEventHandler gotIpEventHandler, disconnectedEventHandler;
|
static WiFiEventHandler gotIpEventHandler, disconnectedEventHandler;
|
||||||
@ -261,4 +255,6 @@ void wifiStop()
|
|||||||
WiFi.disconnect();
|
WiFi.disconnect();
|
||||||
WiFi.mode(WIFI_OFF);
|
WiFi.mode(WIFI_OFF);
|
||||||
Log.warning(F("WIFI: Stopped"));
|
Log.warning(F("WIFI: Stopped"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
x
Reference in New Issue
Block a user