mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-28 05:36:37 +00:00
Remove settings Json from setup
This commit is contained in:
parent
0c23371841
commit
394f75253b
@ -59,7 +59,7 @@ enum lv_hasp_obj_type_t {
|
||||
/**
|
||||
* Create a hasp application
|
||||
*/
|
||||
void haspSetup(JsonObject settings);
|
||||
void haspSetup();
|
||||
void haspLoop(void);
|
||||
void haspFirstSetup(void);
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
using namespace ace_button;
|
||||
static AceButton * button[HASP_NUM_INPUTS]; // Connect your button between pin 2 and GND
|
||||
|
||||
static void IRAM_ATTR button_event_cb(AceButton * button, uint8_t eventType, uint8_t buttonState)
|
||||
static void button_event_cb(AceButton * button, uint8_t eventType, uint8_t buttonState)
|
||||
{
|
||||
char buffer[8];
|
||||
switch(eventType) {
|
||||
|
@ -73,6 +73,7 @@ void configStartDebug(bool setupdebug, String & configFile)
|
||||
if(setupdebug) {
|
||||
debugStart(); // Debug started, now we can use it; HASP header sent
|
||||
Log.notice(F("FILE: [SUCCESS] SPI flash FS mounted"));
|
||||
spiffsInfo();
|
||||
spiffsList();
|
||||
}
|
||||
Log.notice(F("CONF: Loading %s"), configFile.c_str());
|
||||
@ -112,7 +113,7 @@ void configGetConfig(JsonDocument & settings, bool setupdebug = false)
|
||||
Log.verbose(F("CONF: %s"), output.c_str());
|
||||
Log.notice(F("CONF: [SUCCESS] Loaded %s"), configFile.c_str());
|
||||
|
||||
if(setupdebug) debugSetup(settings[F("debug")]);
|
||||
if(setupdebug) debugSetup();
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -179,7 +180,7 @@ void configWriteConfig()
|
||||
}
|
||||
}
|
||||
|
||||
void configSetup(JsonObject dummy)
|
||||
void configSetup()
|
||||
{
|
||||
if(!SPIFFS.begin()) {
|
||||
Log.error(F("FILE: SPI flash init failed. Unable to mount FS: Using default settings..."));
|
||||
|
@ -32,7 +32,7 @@ const char F_DEBUG_TELEPERIOD[] PROGMEM = "teleperiod";
|
||||
|
||||
const char HASP_CONFIG_FILE[] PROGMEM = "/config.json";
|
||||
|
||||
void configSetup(JsonObject settings);
|
||||
void configSetup();
|
||||
void configStop(void);
|
||||
|
||||
void configSetConfig(JsonObject & settings);
|
||||
|
@ -190,10 +190,8 @@ void syslogSend(uint8_t priority, const char * debugText)
|
||||
}
|
||||
#endif
|
||||
|
||||
void debugSetup(JsonObject settings)
|
||||
void debugSetup()
|
||||
{
|
||||
// debugSetConfig(settings);
|
||||
|
||||
#if HASP_USE_SYSLOG != 0
|
||||
syslog = new Syslog(syslogClient, debugSyslogProtocol == 0 ? SYSLOG_PROTO_IETF : SYSLOG_PROTO_BSD);
|
||||
syslog->server(debugSyslogHost, debugSyslogPort);
|
||||
|
@ -7,7 +7,7 @@
|
||||
String debugHaspHeader(void);
|
||||
|
||||
void debugPreSetup(JsonObject settings);
|
||||
void debugSetup(JsonObject settings);
|
||||
void debugSetup();
|
||||
void debugLoop(void);
|
||||
void debugEverySecond(void);
|
||||
void debugStart(void);
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <Arduino.h>
|
||||
#include "ArduinoJson.h"
|
||||
|
||||
void gpioSetup(JsonObject settings)
|
||||
void gpioSetup()
|
||||
{
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
pinMode(D1, OUTPUT);
|
||||
|
@ -1,3 +1,3 @@
|
||||
#include "ArduinoJson.h"
|
||||
|
||||
void gpioSetup(JsonObject settings);
|
||||
void gpioSetup();
|
||||
|
@ -331,7 +331,7 @@ void webHandleFirmware()
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void httpSetup(const JsonObject & settings)
|
||||
void httpSetup()
|
||||
{
|
||||
if(WiFi.getMode() == WIFI_AP) {
|
||||
debugPrintln(F("HTTP: Wifi access point"));
|
||||
@ -1791,7 +1791,7 @@ void webStop()
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void httpSetup(const JsonObject & settings)
|
||||
void httpSetup()
|
||||
{
|
||||
// httpSetConfig(settings);
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include <Arduino.h>
|
||||
#include "ArduinoJson.h"
|
||||
|
||||
void httpSetup(const JsonObject & settings);
|
||||
void httpSetup();
|
||||
void httpLoop(void);
|
||||
void httpEvery5Seconds(void);
|
||||
void httpReconnect(void);
|
||||
|
@ -20,7 +20,7 @@
|
||||
|
||||
uint8_t mdnsEnabled = true;
|
||||
|
||||
void mdnsSetup(const JsonObject & settings)
|
||||
void mdnsSetup()
|
||||
{
|
||||
// mdnsSetConfig(settings);
|
||||
Log.verbose(F("MDNS: Setup Complete"));
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
#include "ArduinoJson.h"
|
||||
|
||||
void mdnsSetup(const JsonObject & settings);
|
||||
void mdnsSetup();
|
||||
void mdnsLoop(void);
|
||||
void mdnsStart(void);
|
||||
void mdnsStop(void);
|
||||
|
@ -3,18 +3,18 @@
|
||||
|
||||
#include "ArduinoJson.h"
|
||||
|
||||
void mqttSetup(const JsonObject & settings);
|
||||
void mqttSetup();
|
||||
void mqttLoop();
|
||||
void mqttEvery5Seconds(bool wifiIsConnected);
|
||||
void mqttStop();
|
||||
void mqttReconnect();
|
||||
|
||||
void IRAM_ATTR mqtt_send_state(const __FlashStringHelper * subtopic, const char * payload);
|
||||
void IRAM_ATTR mqtt_send_input(uint8_t id, const char * payload);
|
||||
void mqtt_send_input(uint8_t id, const char * payload);
|
||||
void IRAM_ATTR mqtt_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, const char * attribute, const char * data);
|
||||
|
||||
void mqtt_send_statusupdate(void);
|
||||
bool IRAM_ATTR mqttIsConnected(void);
|
||||
bool IRAM_ATTR mqttIsConnected();
|
||||
|
||||
bool mqttGetConfig(const JsonObject & settings);
|
||||
bool mqttSetConfig(const JsonObject & settings);
|
||||
|
@ -27,7 +27,7 @@
|
||||
#include <WiFi.h>
|
||||
#endif
|
||||
|
||||
WiFiClient wifiClient;
|
||||
static WiFiClient otaClient;
|
||||
|
||||
#define F_OTA_URL F("otaurl")
|
||||
|
||||
@ -41,10 +41,9 @@ void otaProgress()
|
||||
(ArduinoOTA.getCommand() == U_FLASH ? PSTR("Firmware") : PSTR("Filesystem")), otaPrecentageComplete);
|
||||
}
|
||||
|
||||
void otaSetup(JsonObject settings)
|
||||
void otaSetup()
|
||||
{
|
||||
if(!settings[F_OTA_URL].isNull()) {
|
||||
otaUrl = settings[F_OTA_URL].as<String>().c_str();
|
||||
if(strlen(otaUrl.c_str())) {
|
||||
Log.verbose(F("ORA url: %s"), otaUrl.c_str());
|
||||
}
|
||||
|
||||
@ -134,7 +133,13 @@ void otaHttpUpdate(const char * espOtaUrl)
|
||||
mdnsStop(); // Keep mDNS responder from breaking things
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
t_httpUpdate_return returnCode = ESPhttpUpdate.update(wifiClient, espOtaUrl);
|
||||
|
||||
ESPhttpUpdate.onStart(update_started);
|
||||
ESPhttpUpdate.onEnd(update_finished);
|
||||
ESPhttpUpdate.onProgress(update_progress);
|
||||
ESPhttpUpdate.onError(update_error);
|
||||
|
||||
t_httpUpdate_return returnCode = ESPhttpUpdate.update(otaClient, espOtaUrl);
|
||||
|
||||
switch(returnCode) {
|
||||
case HTTP_UPDATE_FAILED:
|
||||
@ -156,7 +161,7 @@ void otaHttpUpdate(const char * espOtaUrl)
|
||||
}
|
||||
|
||||
#else
|
||||
t_httpUpdate_return returnCode = httpUpdate.update(wifiClient, espOtaUrl);
|
||||
t_httpUpdate_return returnCode = httpUpdate.update(otaClient, espOtaUrl);
|
||||
|
||||
switch(returnCode) {
|
||||
case HTTP_UPDATE_FAILED:
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
#include "ArduinoJson.h"
|
||||
|
||||
void otaSetup(JsonObject settings);
|
||||
void otaSetup();
|
||||
void otaLoop(void);
|
||||
void otaEverySecond(void);
|
||||
void otaHttpUpdate(const char * espOtaUrl);
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
#include "ArduinoJson.h"
|
||||
|
||||
void telnetSetup(const JsonObject & settings);
|
||||
void telnetSetup();
|
||||
void telnetLoop(void);
|
||||
void telnetStop(void);
|
||||
|
||||
|
@ -10,7 +10,7 @@ ADC_MODE(ADC_VCC); // tftShowConfig measures the voltage on the pin
|
||||
|
||||
int8_t getPinName(int8_t pin);
|
||||
|
||||
void tftSetup(TFT_eSPI & tft, const JsonObject & settings)
|
||||
void tftSetup(TFT_eSPI & tft)
|
||||
{
|
||||
tftShowConfig(tft);
|
||||
}
|
||||
|
@ -2,9 +2,8 @@
|
||||
#define HASP_TFT_H
|
||||
|
||||
#include "TFT_eSPI.h"
|
||||
#include "ArduinoJson.h"
|
||||
|
||||
void tftSetup(TFT_eSPI & screen, const JsonObject & settings);
|
||||
void tftSetup(TFT_eSPI & screen);
|
||||
void tftLoop(void);
|
||||
void tftStop(void);
|
||||
|
||||
|
@ -52,7 +52,7 @@ String wifiGetMacAddress(int start, const char * seperator)
|
||||
byte mac[6];
|
||||
WiFi.macAddress(mac);
|
||||
String cMac((char *)0);
|
||||
cMac.reserve(128);
|
||||
cMac.reserve(32);
|
||||
|
||||
for(int i = start; i < 6; ++i) {
|
||||
if(mac[i] < 0x10) cMac += "0";
|
||||
@ -131,12 +131,10 @@ void wifiSTADisconnected(WiFiEventStationModeDisconnected info)
|
||||
}
|
||||
#endif
|
||||
|
||||
void wifiSetup(JsonObject settings)
|
||||
void wifiSetup()
|
||||
{
|
||||
char buffer[128];
|
||||
|
||||
// wifiSetConfig(settings);
|
||||
|
||||
if(strlen(wifiSsid) == 0) {
|
||||
String apSsdid = F("HASP-");
|
||||
apSsdid += wifiGetMacAddress(3, "");
|
||||
@ -176,9 +174,7 @@ void wifiSetup(JsonObject settings)
|
||||
|
||||
bool wifiEvery5Seconds()
|
||||
{
|
||||
if(WiFi.getMode() == WIFI_AP) return true;
|
||||
|
||||
if(WiFi.status() == WL_CONNECTED) {
|
||||
if(WiFi.getMode() == WIFI_AP || WiFi.status() == WL_CONNECTED) {
|
||||
return true;
|
||||
} else {
|
||||
wifiReconnectCounter++;
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
#include "ArduinoJson.h"
|
||||
|
||||
void wifiSetup(JsonObject settings);
|
||||
void wifiSetup();
|
||||
bool wifiEvery5Seconds(void);
|
||||
void wifiStop(void);
|
||||
|
||||
|
32
src/main.cpp
32
src/main.cpp
@ -1,6 +1,5 @@
|
||||
#include "hasp_conf.h" // load first
|
||||
#include <Arduino.h>
|
||||
#include "ArduinoJson.h"
|
||||
|
||||
#include "hasp_debug.h"
|
||||
#include "hasp_spiffs.h"
|
||||
@ -76,48 +75,41 @@ void setup()
|
||||
/****************************
|
||||
* Read & Apply User Configuration
|
||||
***************************/
|
||||
DynamicJsonDocument settings(128);
|
||||
configSetup(settings[F("debug")]);
|
||||
configSetup();
|
||||
|
||||
/****************************
|
||||
* Apply User Configuration
|
||||
***************************/
|
||||
debugSetup(settings[F("debug")]);
|
||||
gpioSetup(settings[F("gpio")]);
|
||||
|
||||
/* Init Graphics */
|
||||
// TFT_eSPI screen = TFT_eSPI();
|
||||
guiSetup(settings[F("gui")]);
|
||||
debugSetup();
|
||||
gpioSetup();
|
||||
guiSetup();
|
||||
|
||||
#if HASP_USE_WIFI
|
||||
wifiSetup(settings[F("wifi")]);
|
||||
wifiSetup();
|
||||
#endif
|
||||
haspSetup();
|
||||
|
||||
/* Init GUI Application */
|
||||
haspSetup(settings[F("hasp")]);
|
||||
|
||||
/* Init Network Services */
|
||||
#if HASP_USE_WIFI
|
||||
wifiSetup(settings[F("wifi")]);
|
||||
wifiSetup();
|
||||
|
||||
#if HASP_USE_HTTP
|
||||
httpSetup(settings[F("http")]);
|
||||
httpSetup();
|
||||
#endif
|
||||
|
||||
#if HASP_USE_MQTT
|
||||
mqttSetup(settings[F("mqtt")]);
|
||||
mqttSetup();
|
||||
#endif
|
||||
|
||||
#if HASP_USE_TELNET
|
||||
telnetSetup(settings[F("telnet")]);
|
||||
telnetSetup();
|
||||
#endif
|
||||
|
||||
#if HASP_USE_MDNS
|
||||
mdnsSetup(settings[F("mdns")]);
|
||||
mdnsSetup();
|
||||
#endif
|
||||
|
||||
#if HASP_USE_OTA
|
||||
otaSetup(settings[F("ota")]);
|
||||
otaSetup();
|
||||
#endif
|
||||
|
||||
#endif // WIFI
|
||||
|
Loading…
x
Reference in New Issue
Block a user