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