mirror of
https://github.com/esphome/esphome.git
synced 2025-11-03 16:41:50 +00:00
Compare commits
16 Commits
2021.10.0b
...
2021.10.0b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4c83dc7c28 | ||
|
|
e10ab1da78 | ||
|
|
1b0e60374b | ||
|
|
3a760fbb44 | ||
|
|
6ef57a2973 | ||
|
|
3e9c7f2e9f | ||
|
|
430598b7a1 | ||
|
|
91611b09b4 | ||
|
|
ecd115851f | ||
|
|
4a1e50fed1 | ||
|
|
d6d037047b | ||
|
|
b5734c2b20 | ||
|
|
723fb7eaac | ||
|
|
63a9acaa19 | ||
|
|
0524f8c677 | ||
|
|
70b62f272e |
@@ -89,6 +89,7 @@ esphome/components/mcp23x17_base/* @jesserockz
|
||||
esphome/components/mcp23xxx_base/* @jesserockz
|
||||
esphome/components/mcp2515/* @danielschramm @mvturnho
|
||||
esphome/components/mcp9808/* @k7hpn
|
||||
esphome/components/md5/* @esphome/core
|
||||
esphome/components/mdns/* @esphome/core
|
||||
esphome/components/midea/* @dudanov
|
||||
esphome/components/mitsubishi/* @RubyBailey
|
||||
|
||||
@@ -758,7 +758,12 @@ def run_esphome(argv):
|
||||
args = parse_args(argv)
|
||||
CORE.dashboard = args.dashboard
|
||||
|
||||
setup_log(args.verbose, args.quiet)
|
||||
setup_log(
|
||||
args.verbose,
|
||||
args.quiet,
|
||||
# Show timestamp for dashboard access logs
|
||||
args.command == "dashboard",
|
||||
)
|
||||
if args.deprecated_argv_suggestion is not None and args.command != "vscode":
|
||||
_LOGGER.warning(
|
||||
"Calling ESPHome with the configuration before the command is deprecated "
|
||||
|
||||
@@ -35,7 +35,7 @@ def validate_adc_pin(value):
|
||||
if is_esp32c3():
|
||||
if not (0 <= value <= 4): # ADC1
|
||||
raise cv.Invalid("ESP32-C3: Only pins 0 though 4 support ADC.")
|
||||
if not (32 <= value <= 39): # ADC1
|
||||
elif not (32 <= value <= 39): # ADC1
|
||||
raise cv.Invalid("ESP32: Only pins 32 though 39 support ADC.")
|
||||
elif CORE.is_esp8266:
|
||||
from esphome.components.esp8266.gpio import CONF_ANALOG
|
||||
|
||||
@@ -11,6 +11,8 @@ namespace ble_client {
|
||||
|
||||
static const char *const TAG = "ble_client";
|
||||
|
||||
float BLEClient::get_setup_priority() const { return setup_priority::AFTER_BLUETOOTH; }
|
||||
|
||||
void BLEClient::setup() {
|
||||
auto ret = esp_ble_gattc_app_register(this->app_id);
|
||||
if (ret) {
|
||||
|
||||
@@ -81,6 +81,7 @@ class BLEClient : public espbt::ESPBTClient, public Component {
|
||||
void setup() override;
|
||||
void dump_config() override;
|
||||
void loop() override;
|
||||
float get_setup_priority() const override;
|
||||
|
||||
void gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if,
|
||||
esp_ble_gattc_cb_param_t *param) override;
|
||||
|
||||
@@ -27,13 +27,10 @@ from .const import ( # noqa
|
||||
KEY_ESP32,
|
||||
KEY_SDKCONFIG_OPTIONS,
|
||||
KEY_VARIANT,
|
||||
VARIANT_ESP32,
|
||||
VARIANT_ESP32S2,
|
||||
VARIANT_ESP32S3,
|
||||
VARIANT_ESP32C3,
|
||||
VARIANT_ESP32H2,
|
||||
VARIANTS,
|
||||
)
|
||||
from .boards import BOARD_TO_VARIANT
|
||||
|
||||
# force import gpio to register pin schema
|
||||
from .gpio import esp32_pin_to_code # noqa
|
||||
@@ -190,7 +187,7 @@ def _esp_idf_check_versions(value):
|
||||
platform_version = value.get(CONF_PLATFORM_VERSION, ESP_IDF_PLATFORM_VERSION)
|
||||
value[CONF_PLATFORM_VERSION] = str(platform_version)
|
||||
|
||||
if version != RECOMMENDED_ARDUINO_FRAMEWORK_VERSION:
|
||||
if version != RECOMMENDED_ESP_IDF_FRAMEWORK_VERSION:
|
||||
_LOGGER.warning(
|
||||
"The selected ESP-IDF framework version is not the recommended one. "
|
||||
"If there are connectivity or build issues please remove the manual version."
|
||||
@@ -199,6 +196,21 @@ def _esp_idf_check_versions(value):
|
||||
return value
|
||||
|
||||
|
||||
def _detect_variant(value):
|
||||
if CONF_VARIANT not in value:
|
||||
board = value[CONF_BOARD]
|
||||
if board not in BOARD_TO_VARIANT:
|
||||
raise cv.Invalid(
|
||||
"This board is unknown, please set the variant manually",
|
||||
path=[CONF_BOARD],
|
||||
)
|
||||
|
||||
value = value.copy()
|
||||
value[CONF_VARIANT] = BOARD_TO_VARIANT[board]
|
||||
|
||||
return value
|
||||
|
||||
|
||||
CONF_PLATFORM_VERSION = "platform_version"
|
||||
|
||||
ARDUINO_FRAMEWORK_SCHEMA = cv.All(
|
||||
@@ -250,12 +262,11 @@ CONFIG_SCHEMA = cv.All(
|
||||
cv.Schema(
|
||||
{
|
||||
cv.Required(CONF_BOARD): cv.string_strict,
|
||||
cv.Optional(CONF_VARIANT, default="ESP32"): cv.one_of(
|
||||
*VARIANTS, upper=True
|
||||
),
|
||||
cv.Optional(CONF_VARIANT): cv.one_of(*VARIANTS, upper=True),
|
||||
cv.Optional(CONF_FRAMEWORK, default={}): FRAMEWORK_SCHEMA,
|
||||
}
|
||||
),
|
||||
_detect_variant,
|
||||
set_core_data,
|
||||
)
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from .const import VARIANT_ESP32, VARIANT_ESP32S2, VARIANT_ESP32C3
|
||||
|
||||
ESP32_BASE_PINS = {
|
||||
"TX": 1,
|
||||
"RX": 3,
|
||||
@@ -925,3 +927,125 @@ ESP32_BOARD_PINS = {
|
||||
},
|
||||
"xinabox_cw02": {"LED": 27},
|
||||
}
|
||||
|
||||
"""
|
||||
BOARD_TO_VARIANT generated with:
|
||||
|
||||
git clone https://github.com/platformio/platform-espressif32
|
||||
for x in platform-espressif32/boards/*.json; do
|
||||
mcu=$(jq -r .build.mcu <"$x");
|
||||
fname=$(basename "$x")
|
||||
board="${fname%.*}"
|
||||
variant=$(echo "$mcu" | tr '[:lower:]' '[:upper:]')
|
||||
echo " \"$board\": VARIANT_${variant},"
|
||||
done | sort
|
||||
"""
|
||||
|
||||
BOARD_TO_VARIANT = {
|
||||
"alksesp32": VARIANT_ESP32,
|
||||
"az-delivery-devkit-v4": VARIANT_ESP32,
|
||||
"bpi-bit": VARIANT_ESP32,
|
||||
"briki_abc_esp32": VARIANT_ESP32,
|
||||
"briki_mbc-wb_esp32": VARIANT_ESP32,
|
||||
"d-duino-32": VARIANT_ESP32,
|
||||
"esp320": VARIANT_ESP32,
|
||||
"esp32-c3-devkitm-1": VARIANT_ESP32C3,
|
||||
"esp32cam": VARIANT_ESP32,
|
||||
"esp32-devkitlipo": VARIANT_ESP32,
|
||||
"esp32dev": VARIANT_ESP32,
|
||||
"esp32doit-devkit-v1": VARIANT_ESP32,
|
||||
"esp32doit-espduino": VARIANT_ESP32,
|
||||
"esp32-evb": VARIANT_ESP32,
|
||||
"esp32-gateway": VARIANT_ESP32,
|
||||
"esp32-poe-iso": VARIANT_ESP32,
|
||||
"esp32-poe": VARIANT_ESP32,
|
||||
"esp32-pro": VARIANT_ESP32,
|
||||
"esp32-s2-kaluga-1": VARIANT_ESP32S2,
|
||||
"esp32-s2-saola-1": VARIANT_ESP32S2,
|
||||
"esp32thing_plus": VARIANT_ESP32,
|
||||
"esp32thing": VARIANT_ESP32,
|
||||
"esp32vn-iot-uno": VARIANT_ESP32,
|
||||
"espea32": VARIANT_ESP32,
|
||||
"espectro32": VARIANT_ESP32,
|
||||
"espino32": VARIANT_ESP32,
|
||||
"esp-wrover-kit": VARIANT_ESP32,
|
||||
"etboard": VARIANT_ESP32,
|
||||
"featheresp32-s2": VARIANT_ESP32S2,
|
||||
"featheresp32": VARIANT_ESP32,
|
||||
"firebeetle32": VARIANT_ESP32,
|
||||
"fm-devkit": VARIANT_ESP32,
|
||||
"frogboard": VARIANT_ESP32,
|
||||
"healthypi4": VARIANT_ESP32,
|
||||
"heltec_wifi_kit_32_v2": VARIANT_ESP32,
|
||||
"heltec_wifi_kit_32": VARIANT_ESP32,
|
||||
"heltec_wifi_lora_32_V2": VARIANT_ESP32,
|
||||
"heltec_wifi_lora_32": VARIANT_ESP32,
|
||||
"heltec_wireless_stick_lite": VARIANT_ESP32,
|
||||
"heltec_wireless_stick": VARIANT_ESP32,
|
||||
"honeylemon": VARIANT_ESP32,
|
||||
"hornbill32dev": VARIANT_ESP32,
|
||||
"hornbill32minima": VARIANT_ESP32,
|
||||
"imbrios-logsens-v1p1": VARIANT_ESP32,
|
||||
"inex_openkb": VARIANT_ESP32,
|
||||
"intorobot": VARIANT_ESP32,
|
||||
"iotaap_magnolia": VARIANT_ESP32,
|
||||
"iotbusio": VARIANT_ESP32,
|
||||
"iotbusproteus": VARIANT_ESP32,
|
||||
"kits-edu": VARIANT_ESP32,
|
||||
"labplus_mpython": VARIANT_ESP32,
|
||||
"lolin32_lite": VARIANT_ESP32,
|
||||
"lolin32": VARIANT_ESP32,
|
||||
"lolin_d32_pro": VARIANT_ESP32,
|
||||
"lolin_d32": VARIANT_ESP32,
|
||||
"lopy4": VARIANT_ESP32,
|
||||
"lopy": VARIANT_ESP32,
|
||||
"m5stack-atom": VARIANT_ESP32,
|
||||
"m5stack-core2": VARIANT_ESP32,
|
||||
"m5stack-core-esp32": VARIANT_ESP32,
|
||||
"m5stack-coreink": VARIANT_ESP32,
|
||||
"m5stack-fire": VARIANT_ESP32,
|
||||
"m5stack-grey": VARIANT_ESP32,
|
||||
"m5stack-timer-cam": VARIANT_ESP32,
|
||||
"m5stick-c": VARIANT_ESP32,
|
||||
"magicbit": VARIANT_ESP32,
|
||||
"mgbot-iotik32a": VARIANT_ESP32,
|
||||
"mgbot-iotik32b": VARIANT_ESP32,
|
||||
"mhetesp32devkit": VARIANT_ESP32,
|
||||
"mhetesp32minikit": VARIANT_ESP32,
|
||||
"microduino-core-esp32": VARIANT_ESP32,
|
||||
"nano32": VARIANT_ESP32,
|
||||
"nina_w10": VARIANT_ESP32,
|
||||
"node32s": VARIANT_ESP32,
|
||||
"nodemcu-32s": VARIANT_ESP32,
|
||||
"nscreen-32": VARIANT_ESP32,
|
||||
"odroid_esp32": VARIANT_ESP32,
|
||||
"onehorse32dev": VARIANT_ESP32,
|
||||
"oroca_edubot": VARIANT_ESP32,
|
||||
"pico32": VARIANT_ESP32,
|
||||
"piranha_esp32": VARIANT_ESP32,
|
||||
"pocket_32": VARIANT_ESP32,
|
||||
"pycom_gpy": VARIANT_ESP32,
|
||||
"qchip": VARIANT_ESP32,
|
||||
"quantum": VARIANT_ESP32,
|
||||
"sensesiot_weizen": VARIANT_ESP32,
|
||||
"sg-o_airMon": VARIANT_ESP32,
|
||||
"s_odi_ultra": VARIANT_ESP32,
|
||||
"sparkfun_lora_gateway_1-channel": VARIANT_ESP32,
|
||||
"tinypico": VARIANT_ESP32,
|
||||
"ttgo-lora32-v1": VARIANT_ESP32,
|
||||
"ttgo-lora32-v21": VARIANT_ESP32,
|
||||
"ttgo-lora32-v2": VARIANT_ESP32,
|
||||
"ttgo-t1": VARIANT_ESP32,
|
||||
"ttgo-t7-v13-mini32": VARIANT_ESP32,
|
||||
"ttgo-t7-v14-mini32": VARIANT_ESP32,
|
||||
"ttgo-t-beam": VARIANT_ESP32,
|
||||
"ttgo-t-watch": VARIANT_ESP32,
|
||||
"turta_iot_node": VARIANT_ESP32,
|
||||
"vintlabs-devkit-v1": VARIANT_ESP32,
|
||||
"wemosbat": VARIANT_ESP32,
|
||||
"wemos_d1_mini32": VARIANT_ESP32,
|
||||
"wesp32": VARIANT_ESP32,
|
||||
"widora-air": VARIANT_ESP32,
|
||||
"wifiduino32": VARIANT_ESP32,
|
||||
"xinabox_cw02": VARIANT_ESP32,
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ void ESP32BLEBeacon::setup() {
|
||||
);
|
||||
}
|
||||
|
||||
float ESP32BLEBeacon::get_setup_priority() const { return setup_priority::DATA; }
|
||||
float ESP32BLEBeacon::get_setup_priority() const { return setup_priority::BLUETOOTH; }
|
||||
void ESP32BLEBeacon::ble_core_task(void *params) {
|
||||
ble_setup();
|
||||
|
||||
|
||||
@@ -154,7 +154,7 @@ void BLEServer::gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t ga
|
||||
}
|
||||
}
|
||||
|
||||
float BLEServer::get_setup_priority() const { return setup_priority::BLUETOOTH - 10; }
|
||||
float BLEServer::get_setup_priority() const { return setup_priority::AFTER_BLUETOOTH; }
|
||||
|
||||
void BLEServer::dump_config() { ESP_LOGCONFIG(TAG, "ESP32 BLE Server:"); }
|
||||
|
||||
|
||||
@@ -40,6 +40,8 @@ uint64_t ble_addr_to_uint64(const esp_bd_addr_t address) {
|
||||
return u;
|
||||
}
|
||||
|
||||
float ESP32BLETracker::get_setup_priority() const { return setup_priority::BLUETOOTH; }
|
||||
|
||||
void ESP32BLETracker::setup() {
|
||||
global_esp32_ble_tracker = this;
|
||||
this->scan_result_lock_ = xSemaphoreCreateMutex();
|
||||
|
||||
@@ -171,6 +171,7 @@ class ESP32BLETracker : public Component {
|
||||
/// Setup the FreeRTOS task and the Bluetooth stack.
|
||||
void setup() override;
|
||||
void dump_config() override;
|
||||
float get_setup_priority() const override;
|
||||
|
||||
void loop() override;
|
||||
|
||||
|
||||
@@ -19,7 +19,8 @@ from esphome.const import (
|
||||
CONF_TX_BUFFER_SIZE,
|
||||
)
|
||||
from esphome.core import CORE, EsphomeError, Lambda, coroutine_with_priority
|
||||
from esphome.components.esp32 import get_esp32_variant, VARIANT_ESP32S2, VARIANT_ESP32C3
|
||||
from esphome.components.esp32 import get_esp32_variant
|
||||
from esphome.components.esp32.const import VARIANT_ESP32S2, VARIANT_ESP32C3
|
||||
|
||||
CODEOWNERS = ["@esphome/core"]
|
||||
logger_ns = cg.esphome_ns.namespace("logger")
|
||||
|
||||
1
esphome/components/md5/__init__.py
Normal file
1
esphome/components/md5/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
CODEOWNERS = ["@esphome/core"]
|
||||
51
esphome/components/md5/md5.cpp
Normal file
51
esphome/components/md5/md5.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include "md5.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace md5 {
|
||||
|
||||
void MD5Digest::init() {
|
||||
memset(this->digest_, 0, 16);
|
||||
MD5Init(&this->ctx_);
|
||||
}
|
||||
|
||||
void MD5Digest::add(const uint8_t *data, size_t len) { MD5Update(&this->ctx_, data, len); }
|
||||
|
||||
void MD5Digest::calculate() { MD5Final(this->digest_, &this->ctx_); }
|
||||
|
||||
void MD5Digest::get_bytes(uint8_t *output) { memcpy(output, this->digest_, 16); }
|
||||
|
||||
void MD5Digest::get_hex(char *output) {
|
||||
for (size_t i = 0; i < 16; i++) {
|
||||
sprintf(output + i * 2, "%02x", this->digest_[i]);
|
||||
}
|
||||
}
|
||||
|
||||
bool MD5Digest::equals_bytes(const char *expected) {
|
||||
for (size_t i = 0; i < 16; i++) {
|
||||
if (expected[i] != this->digest_[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MD5Digest::equals_hex(const char *expected) {
|
||||
for (size_t i = 0; i < 16; i++) {
|
||||
auto high = parse_hex(expected[i * 2]);
|
||||
auto low = parse_hex(expected[i * 2 + 1]);
|
||||
if (!high.has_value() || !low.has_value()) {
|
||||
return false;
|
||||
}
|
||||
auto value = (*high << 4) | *low;
|
||||
if (value != this->digest_[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace md5
|
||||
} // namespace esphome
|
||||
58
esphome/components/md5/md5.h
Normal file
58
esphome/components/md5/md5.h
Normal file
@@ -0,0 +1,58 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/defines.h"
|
||||
|
||||
#ifdef USE_ESP_IDF
|
||||
#include "esp32/rom/md5_hash.h"
|
||||
#define MD5_CTX_TYPE MD5Context
|
||||
#endif
|
||||
|
||||
#if defined(USE_ARDUINO) && defined(USE_ESP32)
|
||||
#include "rom/md5_hash.h"
|
||||
#define MD5_CTX_TYPE MD5Context
|
||||
#endif
|
||||
|
||||
#if defined(USE_ARDUINO) && defined(USE_ESP8266)
|
||||
#include <md5.h>
|
||||
#define MD5_CTX_TYPE md5_context_t
|
||||
#endif
|
||||
|
||||
namespace esphome {
|
||||
namespace md5 {
|
||||
|
||||
class MD5Digest {
|
||||
public:
|
||||
MD5Digest() = default;
|
||||
~MD5Digest() = default;
|
||||
|
||||
/// Initialize a new MD5 digest computation.
|
||||
void init();
|
||||
|
||||
/// Add bytes of data for the digest.
|
||||
void add(const uint8_t *data, size_t len);
|
||||
void add(const char *data, size_t len) { this->add((const uint8_t *) data, len); }
|
||||
|
||||
/// Compute the digest, based on the provided data.
|
||||
void calculate();
|
||||
|
||||
/// Retrieve the MD5 digest as bytes.
|
||||
/// The output must be able to hold 16 bytes or more.
|
||||
void get_bytes(uint8_t *output);
|
||||
|
||||
/// Retrieve the MD5 digest as hex characters.
|
||||
/// The output must be able to hold 32 bytes or more.
|
||||
void get_hex(char *output);
|
||||
|
||||
/// Compare the digest against a provided byte-encoded digest (16 bytes).
|
||||
bool equals_bytes(const char *expected);
|
||||
|
||||
/// Compare the digest against a provided hex-encoded digest (32 bytes).
|
||||
bool equals_hex(const char *expected);
|
||||
|
||||
protected:
|
||||
MD5_CTX_TYPE ctx_{};
|
||||
uint8_t digest_[16];
|
||||
};
|
||||
|
||||
} // namespace md5
|
||||
} // namespace esphome
|
||||
@@ -96,23 +96,27 @@ bool Modbus::parse_modbus_byte_(uint8_t byte) {
|
||||
ESP_LOGW(TAG, "Modbus CRC Check failed! %02X!=%02X", computed_crc, remote_crc);
|
||||
return false;
|
||||
}
|
||||
|
||||
waiting_for_response = 0;
|
||||
std::vector<uint8_t> data(this->rx_buffer_.begin() + data_offset, this->rx_buffer_.begin() + data_offset + data_len);
|
||||
|
||||
bool found = false;
|
||||
for (auto *device : this->devices_) {
|
||||
if (device->address_ == address) {
|
||||
// Is it an error response?
|
||||
if ((function_code & 0x80) == 0x80) {
|
||||
ESP_LOGW(TAG, "Modbus error function code: 0x%X exception: %d", function_code, raw[2]);
|
||||
device->on_modbus_error(function_code & 0x7F, raw[2]);
|
||||
ESP_LOGD(TAG, "Modbus error function code: 0x%X exception: %d", function_code, raw[2]);
|
||||
if (waiting_for_response != 0) {
|
||||
device->on_modbus_error(function_code & 0x7F, raw[2]);
|
||||
} else {
|
||||
// Ignore modbus exception not related to a pending command
|
||||
ESP_LOGD(TAG, "Ignoring Modbus error - not expecting a response");
|
||||
}
|
||||
} else {
|
||||
device->on_modbus_data(data);
|
||||
}
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
waiting_for_response = 0;
|
||||
|
||||
if (!found) {
|
||||
ESP_LOGW(TAG, "Got Modbus frame from unknown address 0x%02X! ", address);
|
||||
}
|
||||
@@ -196,6 +200,7 @@ void Modbus::send_raw(const std::vector<uint8_t> &payload) {
|
||||
if (this->flow_control_pin_ != nullptr)
|
||||
this->flow_control_pin_->digital_write(false);
|
||||
waiting_for_response = payload[0];
|
||||
ESP_LOGV(TAG, "Modbus write raw: %s", hexencode(payload).c_str());
|
||||
last_send_ = millis();
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ from esphome.core import CORE, coroutine_with_priority
|
||||
|
||||
CODEOWNERS = ["@esphome/core"]
|
||||
DEPENDENCIES = ["network"]
|
||||
AUTO_LOAD = ["socket"]
|
||||
AUTO_LOAD = ["socket", "md5"]
|
||||
|
||||
CONF_ON_STATE_CHANGE = "on_state_change"
|
||||
CONF_ON_BEGIN = "on_begin"
|
||||
@@ -35,20 +35,12 @@ OTAEndTrigger = ota_ns.class_("OTAEndTrigger", automation.Trigger.template())
|
||||
OTAErrorTrigger = ota_ns.class_("OTAErrorTrigger", automation.Trigger.template())
|
||||
|
||||
|
||||
def validate_password_support(value):
|
||||
if CORE.using_arduino:
|
||||
return value
|
||||
if CORE.using_esp_idf:
|
||||
raise cv.Invalid("Password support is not implemented yet for ESP-IDF")
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
CONFIG_SCHEMA = cv.Schema(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(OTAComponent),
|
||||
cv.Optional(CONF_SAFE_MODE, default=True): cv.boolean,
|
||||
cv.SplitDefault(CONF_PORT, esp8266=8266, esp32=3232): cv.port,
|
||||
cv.Optional(CONF_PASSWORD): cv.All(cv.string, validate_password_support),
|
||||
cv.Optional(CONF_PASSWORD): cv.string,
|
||||
cv.Optional(
|
||||
CONF_REBOOT_TIMEOUT, default="5min"
|
||||
): cv.positive_time_period_milliseconds,
|
||||
|
||||
@@ -9,6 +9,7 @@ namespace esphome {
|
||||
namespace ota {
|
||||
|
||||
class ArduinoESP32OTABackend : public OTABackend {
|
||||
public:
|
||||
OTAResponseTypes begin(size_t image_size) override;
|
||||
void set_update_md5(const char *md5) override;
|
||||
OTAResponseTypes write(uint8_t *data, size_t len) override;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "ota_backend_esp_idf.h"
|
||||
#include "ota_component.h"
|
||||
#include <esp_ota_ops.h>
|
||||
#include "esphome/components/md5/md5.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace ota {
|
||||
@@ -24,15 +25,15 @@ OTAResponseTypes IDFOTABackend::begin(size_t image_size) {
|
||||
}
|
||||
return OTA_RESPONSE_ERROR_UNKNOWN;
|
||||
}
|
||||
this->md5_.init();
|
||||
return OTA_RESPONSE_OK;
|
||||
}
|
||||
|
||||
void IDFOTABackend::set_update_md5(const char *md5) {
|
||||
// pass
|
||||
}
|
||||
void IDFOTABackend::set_update_md5(const char *expected_md5) { memcpy(this->expected_bin_md5_, expected_md5, 32); }
|
||||
|
||||
OTAResponseTypes IDFOTABackend::write(uint8_t *data, size_t len) {
|
||||
esp_err_t err = esp_ota_write(this->update_handle_, data, len);
|
||||
this->md5_.add(data, len);
|
||||
if (err != ESP_OK) {
|
||||
if (err == ESP_ERR_OTA_VALIDATE_FAILED) {
|
||||
return OTA_RESPONSE_ERROR_MAGIC;
|
||||
@@ -45,6 +46,11 @@ OTAResponseTypes IDFOTABackend::write(uint8_t *data, size_t len) {
|
||||
}
|
||||
|
||||
OTAResponseTypes IDFOTABackend::end() {
|
||||
this->md5_.calculate();
|
||||
if (!this->md5_.equals_hex(this->expected_bin_md5_)) {
|
||||
this->abort();
|
||||
return OTA_RESPONSE_ERROR_UPDATE_END;
|
||||
}
|
||||
esp_err_t err = esp_ota_end(this->update_handle_);
|
||||
this->update_handle_ = 0;
|
||||
if (err == ESP_OK) {
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "ota_component.h"
|
||||
#include "ota_backend.h"
|
||||
#include <esp_ota_ops.h>
|
||||
#include "esphome/components/md5/md5.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace ota {
|
||||
@@ -20,6 +21,8 @@ class IDFOTABackend : public OTABackend {
|
||||
private:
|
||||
esp_ota_handle_t update_handle_{0};
|
||||
const esp_partition_t *partition_;
|
||||
md5::MD5Digest md5_{};
|
||||
char expected_bin_md5_[32];
|
||||
};
|
||||
|
||||
} // namespace ota
|
||||
|
||||
@@ -8,15 +8,12 @@
|
||||
#include "esphome/core/application.h"
|
||||
#include "esphome/core/hal.h"
|
||||
#include "esphome/core/util.h"
|
||||
#include "esphome/components/md5/md5.h"
|
||||
#include "esphome/components/network/util.h"
|
||||
|
||||
#include <cerrno>
|
||||
#include <cstdio>
|
||||
|
||||
#ifdef USE_OTA_PASSWORD
|
||||
#include <MD5Builder.h>
|
||||
#endif
|
||||
|
||||
namespace esphome {
|
||||
namespace ota {
|
||||
|
||||
@@ -173,12 +170,12 @@ void OTAComponent::handle_() {
|
||||
if (!this->password_.empty()) {
|
||||
buf[0] = OTA_RESPONSE_REQUEST_AUTH;
|
||||
this->writeall_(buf, 1);
|
||||
MD5Builder md5_builder{};
|
||||
md5_builder.begin();
|
||||
md5::MD5Digest md5{};
|
||||
md5.init();
|
||||
sprintf(sbuf, "%08X", random_uint32());
|
||||
md5_builder.add(sbuf);
|
||||
md5_builder.calculate();
|
||||
md5_builder.getChars(sbuf);
|
||||
md5.add(sbuf, 8);
|
||||
md5.calculate();
|
||||
md5.get_hex(sbuf);
|
||||
ESP_LOGV(TAG, "Auth: Nonce is %s", sbuf);
|
||||
|
||||
// Send nonce, 32 bytes hex MD5
|
||||
@@ -188,10 +185,10 @@ void OTAComponent::handle_() {
|
||||
}
|
||||
|
||||
// prepare challenge
|
||||
md5_builder.begin();
|
||||
md5_builder.add(this->password_.c_str());
|
||||
md5.init();
|
||||
md5.add(this->password_.c_str(), this->password_.length());
|
||||
// add nonce
|
||||
md5_builder.add(sbuf);
|
||||
md5.add(sbuf, 32);
|
||||
|
||||
// Receive cnonce, 32 bytes hex MD5
|
||||
if (!this->readall_(buf, 32)) {
|
||||
@@ -201,11 +198,11 @@ void OTAComponent::handle_() {
|
||||
sbuf[32] = '\0';
|
||||
ESP_LOGV(TAG, "Auth: CNonce is %s", sbuf);
|
||||
// add cnonce
|
||||
md5_builder.add(sbuf);
|
||||
md5.add(sbuf, 32);
|
||||
|
||||
// calculate result
|
||||
md5_builder.calculate();
|
||||
md5_builder.getChars(sbuf);
|
||||
md5.calculate();
|
||||
md5.get_hex(sbuf);
|
||||
ESP_LOGV(TAG, "Auth: Result is %s", sbuf);
|
||||
|
||||
// Receive result, 32 bytes hex MD5
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"""Constants used by esphome."""
|
||||
|
||||
__version__ = "2021.10.0b4"
|
||||
__version__ = "2021.10.0b8"
|
||||
|
||||
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#define USE_LOGGER
|
||||
#define USE_MDNS
|
||||
#define USE_NUMBER
|
||||
#define USE_OTA_PASSWORD
|
||||
#define USE_OTA_STATE_CALLBACK
|
||||
#define USE_POWER_SUPPLY
|
||||
#define USE_PROMETHEUS
|
||||
|
||||
@@ -49,8 +49,10 @@ def color(col: str, msg: str, reset: bool = True) -> bool:
|
||||
|
||||
|
||||
class ESPHomeLogFormatter(logging.Formatter):
|
||||
def __init__(self):
|
||||
super().__init__(fmt="%(asctime)s %(levelname)s %(message)s", style="%")
|
||||
def __init__(self, *, include_timestamp: bool):
|
||||
fmt = "%(asctime)s " if include_timestamp else ""
|
||||
fmt += "%(levelname)s %(message)s"
|
||||
super().__init__(fmt=fmt, style="%")
|
||||
|
||||
def format(self, record):
|
||||
formatted = super().format(record)
|
||||
@@ -64,7 +66,9 @@ class ESPHomeLogFormatter(logging.Formatter):
|
||||
return f"{prefix}{formatted}{Style.RESET_ALL}"
|
||||
|
||||
|
||||
def setup_log(debug=False, quiet=False):
|
||||
def setup_log(
|
||||
debug: bool = False, quiet: bool = False, include_timestamp: bool = False
|
||||
) -> None:
|
||||
import colorama
|
||||
|
||||
if debug:
|
||||
@@ -79,4 +83,6 @@ def setup_log(debug=False, quiet=False):
|
||||
logging.getLogger("urllib3").setLevel(logging.WARNING)
|
||||
|
||||
colorama.init()
|
||||
logging.getLogger().handlers[0].setFormatter(ESPHomeLogFormatter())
|
||||
logging.getLogger().handlers[0].setFormatter(
|
||||
ESPHomeLogFormatter(include_timestamp=include_timestamp)
|
||||
)
|
||||
|
||||
@@ -9,7 +9,7 @@ pyserial==3.5
|
||||
platformio==5.2.1
|
||||
esptool==3.1
|
||||
click==8.0.3
|
||||
esphome-dashboard==20211015.0
|
||||
esphome-dashboard==20211019.0
|
||||
aioesphomeapi==9.1.5
|
||||
|
||||
# esp-idf requires this, but doesn't bundle it by default
|
||||
|
||||
Reference in New Issue
Block a user