Skip to content

Commit

Permalink
Merge pull request #1 from GwangrokBaek/feature-https
Browse files Browse the repository at this point in the history
HTTPS 웹서버 구현 및 코드 분리
  • Loading branch information
GwangrokBaek authored Aug 26, 2021
2 parents 39ec55b + 009d4d1 commit 259e271
Show file tree
Hide file tree
Showing 11 changed files with 464 additions and 876 deletions.
3 changes: 1 addition & 2 deletions tasmota/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ typedef union {
} DisplayOptions;

const uint32_t settings_text_size = 699; // Settings->text_pool[size] = Settings->display_model (2D2) - Settings->text_pool (017)
const uint8_t MAX_TUYA_FUNCTIONS = 16;
const uint8_t MAX_TUYA_FUNCTIONS = 1;

typedef struct {
uint16_t cfg_holder; // 000 v6 header
Expand Down Expand Up @@ -689,7 +689,6 @@ typedef struct {
uint16_t syslog_port; // ECA
uint8_t syslog_level; // ECC
uint8_t webserver; // ECD
uint8_t weblog_level; // ECE
uint8_t mqtt_fingerprint[2][20]; // ECF

uint8_t ex_adc_param_type; // EF7 Free since 9.0.0.1
Expand Down
2 changes: 0 additions & 2 deletions tasmota/settings.ino
Original file line number Diff line number Diff line change
Expand Up @@ -877,8 +877,6 @@ void SettingsDefaultSet2(void) {
flag3.gui_hostname_ip |= GUI_SHOW_HOSTNAME;
flag3.mdns_enabled |= MDNS_ENABLED;
Settings->webserver = WEB_SERVER;
Settings->weblog_level = WEB_LOG_LEVEL;
SettingsUpdateText(SET_WEBPWD, PSTR(WEB_PASSWORD));
SettingsUpdateText(SET_CORS, PSTR(CORS_DOMAIN));

// Button
Expand Down
3 changes: 1 addition & 2 deletions tasmota/support.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2360,8 +2360,7 @@ void AddLogData(uint32_t loglevel, const char* log_data, const char* log_data_pa

if (!TasmotaGlobal.log_buffer) { return; } // Leave now if there is no buffer available

uint32_t highest_loglevel = Settings->weblog_level;
if (Settings->mqttlog_level > highest_loglevel) { highest_loglevel = Settings->mqttlog_level; }
uint32_t highest_loglevel = Settings->mqttlog_level;
if (TasmotaGlobal.syslog_level > highest_loglevel) { highest_loglevel = TasmotaGlobal.syslog_level; }
if (TasmotaGlobal.templog_level > highest_loglevel) { highest_loglevel = TasmotaGlobal.templog_level; }
if (TasmotaGlobal.uptime < 3) { highest_loglevel = LOG_LEVEL_DEBUG_MORE; } // Log all before setup correct log level
Expand Down
4 changes: 2 additions & 2 deletions tasmota/support_command.ino
Original file line number Diff line number Diff line change
Expand Up @@ -525,10 +525,10 @@ void CmndStatus(void)
}

if ((0 == payload) || (3 == payload)) {
Response_P(PSTR("{\"" D_CMND_STATUS D_STATUS3_LOGGING "\":{\"" D_CMND_SERIALLOG "\":%d,\"" D_CMND_WEBLOG "\":%d,\"" D_CMND_MQTTLOG "\":%d,\"" D_CMND_SYSLOG "\":%d,\""
Response_P(PSTR("{\"" D_CMND_STATUS D_STATUS3_LOGGING "\":{\"" D_CMND_SERIALLOG "\":%d,\"" D_CMND_MQTTLOG "\":%d,\"" D_CMND_SYSLOG "\":%d,\""
D_CMND_LOGHOST "\":\"%s\",\"" D_CMND_LOGPORT "\":%d,\"" D_CMND_SSID "\":[\"%s\",\"%s\"],\"" D_CMND_TELEPERIOD "\":%d,\""
D_JSON_RESOLUTION "\":\"%08X\",\"" D_CMND_SETOPTION "\":[\"%08X\",\"%s\",\"%08X\",\"%08X\",\"%08X\"]}}"),
Settings->seriallog_level, Settings->weblog_level, Settings->mqttlog_level, Settings->syslog_level,
Settings->seriallog_level, Settings->mqttlog_level, Settings->syslog_level,
SettingsText(SET_SYSLOG_HOST), Settings->syslog_port, EscapeJSONString(SettingsText(SET_STASSID1)).c_str(), EscapeJSONString(SettingsText(SET_STASSID2)).c_str(), Settings->tele_period,
Settings->flag2.data, Settings->flag.data, ToHex_P((unsigned char*)Settings->param, PARAM8_SIZE, stemp2, sizeof(stemp2)),
Settings->flag3.data, Settings->flag4.data, Settings->flag5.data);
Expand Down
9 changes: 5 additions & 4 deletions tasmota/support_tasmota.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1315,7 +1315,10 @@ void Every250mSeconds(void)
if (Settings->webserver) {

#ifdef ESP8266
if (!WifiIsInManagerMode()) { StartWebserver(Settings->webserver, WiFi.localIP()); }
if (!WifiIsInManagerMode()) {
StartWebserver(Settings->webserver, WiFi.localIP());
StartWebserverSecure();
}
#endif // ESP8266
#ifdef ESP32
#ifdef USE_ETHERNET
Expand All @@ -1328,6 +1331,7 @@ void Every250mSeconds(void)
MdnsAddServiceHttp();
} else {
StopWebserver();
StopWebserverSecure();
}
#ifdef USE_EMULATION
if (Settings->flag2.emulation) { UdpConnect(); }
Expand Down Expand Up @@ -1378,9 +1382,6 @@ void ArduinoOTAInit(void)
{
ArduinoOTA.setPort(8266);
ArduinoOTA.setHostname(NetworkHostname());
if (strlen(SettingsText(SET_WEBPWD))) {
ArduinoOTA.setPassword(SettingsText(SET_WEBPWD));
}

ArduinoOTA.onStart([]()
{
Expand Down
25 changes: 13 additions & 12 deletions tasmota/tasmota.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ const uint8_t MAX_PWMS = 5; // Max number of PWM channels
const uint8_t MAX_COUNTERS = 4; // Max number of counter sensors
const uint8_t MAX_TIMERS = 16; // Max number of Timers
const uint8_t MAX_PULSETIMERS = 8; // Max number of supported pulse timers
const uint8_t MAX_DOMOTICZ_IDX = 4; // Max number of Domoticz device, key and switch indices
const uint8_t MAX_DOMOTICZ_SNS_IDX = 12; // Max number of Domoticz sensors indices
const uint8_t MAX_KNX_GA = 10; // Max number of KNX Group Addresses to read that can be set
const uint8_t MAX_KNX_CB = 10; // Max number of KNX Group Addresses to write that can be set
const uint8_t MAX_DOMOTICZ_IDX = 1; // Max number of Domoticz device, key and switch indices
const uint8_t MAX_DOMOTICZ_SNS_IDX = 1; // Max number of Domoticz sensors indices
const uint8_t MAX_KNX_GA = 1; // Max number of KNX Group Addresses to read that can be set
const uint8_t MAX_KNX_CB = 1; // Max number of KNX Group Addresses to write that can be set
const uint8_t MAX_XNRG_DRIVERS = 32; // Max number of allowed energy drivers
const uint8_t MAX_XDSP_DRIVERS = 32; // Max number of allowed display drivers
const uint8_t MAX_XDRV_DRIVERS = 96; // Max number of allowed driver drivers
Expand All @@ -78,7 +78,7 @@ const uint8_t MAX_SHUTTER_RELAYS = 8; // Max number of shutter relays
const uint8_t MAX_SHUTTER_KEYS = 4; // Max number of shutter keys or buttons
const uint8_t MAX_PCF8574 = 4; // Max number of PCF8574 devices
const uint8_t MAX_RULE_SETS = 3; // Max number of rule sets of size 512 characters
const uint16_t MAX_RULE_SIZE = 512; // Max number of characters in rules
const uint16_t MAX_RULE_SIZE = 1; // Max number of characters in rules
const uint16_t VL53L0X_MAX_SENSORS = 8; // Max number of VL53L0X sensors

#ifdef ESP32
Expand Down Expand Up @@ -123,6 +123,8 @@ const char WIFI_HOSTNAME[] = "ZIGBANG"; // Expands to <MQTT_TOPIC>-<last 4 d
const uint8_t CONFIG_FILE_SIGN = 0xA5; // Configuration file signature
const uint8_t CONFIG_FILE_XOR = 0x5A; // Configuration file xor (0 = No Xor)

const uint8_t INPUT_BUFFER_SIZE = 100; // Max number of characters in serial command buffer

const uint32_t HLW_PREF_PULSE = 12530; // was 4975us = 201Hz = 1000W
const uint32_t HLW_UREF_PULSE = 1950; // was 1666us = 600Hz = 220V
const uint32_t HLW_IREF_PULSE = 3500; // was 1666us = 600Hz = 4.545A
Expand Down Expand Up @@ -163,17 +165,16 @@ const uint8_t OTA_ATTEMPTS = 10; // Number of times to try fetching t
const uint8_t OTA_ATTEMPTS = 5; // Number of times to try fetching the new firmware
#endif // ESP8266

const uint16_t INPUT_BUFFER_SIZE = 520; // Max number of characters in serial command buffer
const uint16_t FLOATSZ = 16; // Max number of characters in float result from dtostrfd (max 32)
const uint16_t CMDSZ = 24; // Max number of characters in command
const uint16_t TOPSZ = 151; // Max number of characters in topic string
const uint16_t TOPSZ = 100; // Max number of characters in topic string

#ifdef ESP8266
#ifdef PIO_FRAMEWORK_ARDUINO_MMU_CACHE16_IRAM48_SECHEAP_SHARED
const uint16_t LOG_BUFFER_SIZE = 4096; // Max number of characters in logbuffer used by weblog, syslog and mqttlog
//const uint16_t LOG_BUFFER_SIZE = 6144; // Max number of characters in logbuffer used by weblog, syslog and mqttlog
#else
const uint16_t LOG_BUFFER_SIZE = 4096; // Max number of characters in logbuffer used by weblog, syslog and mqttlog
const uint16_t LOG_BUFFER_SIZE = 1024; // Max number of characters in logbuffer used by weblog, syslog and mqttlog
#endif // PIO_FRAMEWORK_ARDUINO_MMU_CACHE16_IRAM48_SECHEAP_SHARED
#else // Not ESP8266
const uint16_t LOG_BUFFER_SIZE = 6144; // Max number of characters in logbuffer used by weblog, syslog and mqttlog
Expand All @@ -187,7 +188,7 @@ const uint16_t MAX_LOGSZ = 700; // Max number of characters in log l

const uint8_t SENSOR_MAX_MISS = 5; // Max number of missed sensor reads before deciding it's offline

const uint8_t MAX_BACKLOG = 30; // Max number of commands in backlog
const uint8_t MAX_BACKLOG = 10; // Max number of commands in backlog
const uint32_t MIN_BACKLOG_DELAY = 200; // Minimal backlog delay in mSeconds

const uint32_t SOFT_BAUDRATE = 9600; // Default software serial baudrate
Expand Down Expand Up @@ -329,7 +330,7 @@ enum XsnsFunctions {FUNC_SETTINGS_OVERRIDE, FUNC_PIN_STATE, FUNC_MODULE_INIT, FU
FUNC_SET_POWER, FUNC_SET_DEVICE_POWER, FUNC_SHOW_SENSOR, FUNC_ANY_KEY,
FUNC_ENERGY_EVERY_SECOND, FUNC_ENERGY_RESET,
FUNC_RULES_PROCESS, FUNC_TELEPERIOD_RULES_PROCESS, FUNC_SERIAL, FUNC_FREE_MEM, FUNC_BUTTON_PRESSED,
FUNC_WEB_ADD_BUTTON, FUNC_WEB_ADD_CONSOLE_BUTTON, FUNC_WEB_ADD_MANAGEMENT_BUTTON, FUNC_WEB_ADD_MAIN_BUTTON,
FUNC_WEB_ADD_BUTTON, FUNC_WEB_ADD_MANAGEMENT_BUTTON, FUNC_WEB_ADD_MAIN_BUTTON,
FUNC_WEB_ADD_HANDLER, FUNC_SET_CHANNELS, FUNC_SET_SCHEME, FUNC_HOTPLUG_SCAN,
FUNC_DEVICE_GROUP_ITEM };

Expand Down Expand Up @@ -399,10 +400,10 @@ enum DevGroupItemFlag { DGR_ITEM_FLAG_NO_SHARE = 1 };
enum DevGroupShareItem { DGR_SHARE_POWER = 1, DGR_SHARE_LIGHT_BRI = 2, DGR_SHARE_LIGHT_FADE = 4, DGR_SHARE_LIGHT_SCHEME = 8,
DGR_SHARE_LIGHT_COLOR = 16, DGR_SHARE_DIMMER_SETTINGS = 32, DGR_SHARE_EVENT = 64 };

enum CommandSource { SRC_IGNORE, SRC_MQTT, SRC_RESTART, SRC_BUTTON, SRC_SWITCH, SRC_BACKLOG, SRC_SERIAL, SRC_WEBGUI, SRC_WEBCOMMAND, SRC_WEBCONSOLE, SRC_PULSETIMER,
enum CommandSource { SRC_IGNORE, SRC_MQTT, SRC_RESTART, SRC_BUTTON, SRC_SWITCH, SRC_BACKLOG, SRC_SERIAL, SRC_WEBGUI, SRC_WEBCOMMAND, SRC_PULSETIMER,
SRC_TIMER, SRC_RULE, SRC_MAXPOWER, SRC_MAXENERGY, SRC_OVERTEMP, SRC_LIGHT, SRC_KNX, SRC_DISPLAY, SRC_WEMO, SRC_HUE, SRC_RETRY, SRC_REMOTE, SRC_SHUTTER,
SRC_THERMOSTAT, SRC_CHAT, SRC_TCL, SRC_BERRY, SRC_FILE, SRC_MAX };
const char kCommandSource[] PROGMEM = "I|MQTT|Restart|Button|Switch|Backlog|Serial|WebGui|WebCommand|WebConsole|PulseTimer|"
const char kCommandSource[] PROGMEM = "I|MQTT|Restart|Button|Switch|Backlog|Serial|WebGui|WebCommand|PulseTimer|"
"Timer|Rule|MaxPower|MaxEnergy|Overtemp|Light|Knx|Display|Wemo|Hue|Retry|Remote|Shutter|"
"Thermostat|Chat|TCL|Berry|File";

Expand Down
3 changes: 3 additions & 0 deletions tasmota/tasmota.ino
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,9 @@ void setup(void) {
SettingsUpdateText(SET_HOSTNAME, TasmotaGlobal.hostname);
}

mac_address.~String();
mac_part.~String();

RtcInit();
GpioInit();
ButtonInit();
Expand Down
Loading

0 comments on commit 259e271

Please sign in to comment.