From 5c609796827792a94db82673ade3d67cf8f761dc Mon Sep 17 00:00:00 2001 From: arendst Date: Fri, 16 Feb 2018 17:35:51 +0100 Subject: [PATCH] v5.12.0b 5.12.0b * Add Webserver upload preflight request support (#1927) * Add Home Assistant clear other device (#1931) --- platformio.ini | 13 +++++++++++++ sonoff/_releasenotes.ino | 2 ++ sonoff/sonoff_template.h | 16 ++++++++++++++++ sonoff/webserver.ino | 9 +++++++++ sonoff/xdrv_07_home_assistant.ino | 6 +++++- 5 files changed, 45 insertions(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index 1cba5f3bc..5c6aa2ae9 100644 --- a/platformio.ini +++ b/platformio.ini @@ -20,6 +20,7 @@ src_dir = sonoff ;env_default = sonoff-IT ;env_default = sonoff-NL ;env_default = sonoff-PL +;env_default = sonoff-RU ;env_default = sonoff-CN [env:sonoff] @@ -143,6 +144,18 @@ extra_scripts = pio/strip-floats.py ; *** Serial Monitor options monitor_baud = 115200 +[env:sonoff-RU] +platform = espressif8266 +framework = arduino +board = esp01_1m +board_flash_mode = dout +build_flags = -Wl,-Tesp8266.flash.1m0.ld -DMY_LANGUAGE=ru-RU +lib_deps = PubSubClient, NeoPixelBus, IRremoteESP8266, ArduinoJSON +extra_scripts = pio/strip-floats.py + +; *** Serial Monitor options +monitor_baud = 115200 + [env:sonoff-CN] platform = espressif8266 framework = arduino diff --git a/sonoff/_releasenotes.ino b/sonoff/_releasenotes.ino index a004dd62b..b246a2022 100644 --- a/sonoff/_releasenotes.ino +++ b/sonoff/_releasenotes.ino @@ -5,6 +5,8 @@ * Add optional usage of %d or %04d in ota url to be replaced with chipid (#1871) * Add user configurable serial GPIOs to MagicHome and Arilux modules (#1887) * Add Russian language file (#1909) + * Add Webserver upload preflight request support (#1927) + * Add Home Assistant clear other device (#1931) * * 5.12.0a * Change platformio option sonoff-ds18x20 to sonoff-xxl enabling ds18x20 and all other sensors in one image diff --git a/sonoff/sonoff_template.h b/sonoff/sonoff_template.h index 905284941..1a8206c08 100644 --- a/sonoff/sonoff_template.h +++ b/sonoff/sonoff_template.h @@ -865,6 +865,22 @@ const mytmplt kModules[MAXMODULE] PROGMEM = { 0, GPIO_PWM4, // GPIO15 RGBW LED White 0, 0 + } + + { "Ledunia", // Ledunia (ESP8266) - http://ledunia.de/ + GPIO_USER, // GPIO00 (D0) + GPIO_USER, // GPIO01 (D7) Serial RXD + GPIO_USER, // GPIO02 (D2) + GPIO_USER, // GPIO03 (D8) Serial TXD + GPIO_USER, // GPIO04 (D4) 4 x WS2812 Leds, (DOUT) Extents WS2812 string + GPIO_USER, // GPIO05 (D5) Blue Led + 0, 0, 0, 0, 0, 0, // Flash connection + GPIO_USER, // GPIO12 (D12) + GPIO_USER, // GPIO13 (D13) + GPIO_USER, // GPIO14 (D14) + GPIO_USER, // GPIO15 (D15) + GPIO_USER, // GPIO16 (D16) + 0 // ADC0 Analog input (A0) }, */ diff --git a/sonoff/webserver.ino b/sonoff/webserver.ino index eff413f0a..ac1e64e61 100644 --- a/sonoff/webserver.ino +++ b/sonoff/webserver.ino @@ -347,6 +347,7 @@ void StartWebserver(int type, IPAddress ipweb) WebServer->on("/up", HandleUpgradeFirmware); WebServer->on("/u1", HandleUpgradeFirmwareStart); // OTA WebServer->on("/u2", HTTP_POST, HandleUploadDone, HandleUploadLoop); + WebServer->on("/u2", HTTP_OPTIONS, HandlePreflightRequest); WebServer->on("/cm", HandleHttpCommand); WebServer->on("/cs", HandleConsole); WebServer->on("/ax", HandleAjaxConsoleRefresh); @@ -1417,6 +1418,14 @@ void HandleUploadLoop() delay(0); } +void HandlePreflightRequest() +{ + WebServer->sendHeader(F("Access-Control-Allow-Origin"), F("*")); + WebServer->sendHeader(F("Access-Control-Allow-Methods"), F("GET, POST")); + WebServer->sendHeader(F("Access-Control-Allow-Headers"), F("authorization")); + WebServer->send(200, FPSTR(HDR_CTYPE_HTML), ""); +} + void HandleHttpCommand() { if (HttpUser()) { diff --git a/sonoff/xdrv_07_home_assistant.ino b/sonoff/xdrv_07_home_assistant.ino index cb776cc73..d377fe535 100644 --- a/sonoff/xdrv_07_home_assistant.ino +++ b/sonoff/xdrv_07_home_assistant.ino @@ -89,10 +89,14 @@ void HAssDiscovery() for (int i = 1; i <= devices_present; i++) { is_light = ((i == devices_present) && (light_type)); + mqtt_data[0] = '\0'; + snprintf_P(sidx, sizeof(sidx), PSTR("_%d"), i); + // Clear "other" topic first in case the device has been reconfigured + snprintf_P(stopic, sizeof(stopic), PSTR(HOME_ASSISTANT_DISCOVERY_PREFIX "/%s/%s%s/config"), (is_light) ? "switch" : "light", mqtt_topic, (1 == devices_present) ? "" : sidx); + MqttPublish(stopic, true); snprintf_P(stopic, sizeof(stopic), PSTR(HOME_ASSISTANT_DISCOVERY_PREFIX "/%s/%s%s/config"), (is_light) ? "light" : "switch", mqtt_topic, (1 == devices_present) ? "" : sidx); - mqtt_data[0] = '\0'; if (Settings.flag.hass_discovery) { char name[33]; char value_template[33];