1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-05 17:41:49 +00:00

Compare commits

...

14 Commits

Author SHA1 Message Date
Otto Winter
60e6366521 Bump version to v1.14.4 2020-06-05 12:56:23 +02:00
Otto Winter
072b2c445c Add ESP8266 core v2.6.2 (#905)
* Add ESP8266 core v2.6.2

* Upstream ESP8266 Wifi fixes

* Replace disable_interrupt with InterruptLock C++ class

* Update code to use InterruptLock

* Lint

* Update dht.cpp

* Improve InterruptLock docs, mark as ICACHE_RAM_ATTR

* Fixes
2020-06-05 12:56:10 +02:00
Otto Winter
219fe41831 Update ESP32 BLE ADV parse to match BLE spec (#904)
* Update ESP32 BLE ADV parse to match BLE spec

* Update xiaomi

* Update ruuvi

* Format

* Update esp32_ble_tracker.cpp

* Fix log

* Format

* Update xiaomi_ble.cpp
2020-06-05 12:55:24 +02:00
Otto Winter
dcc8bb83af Ignore ESP32 Camera unknown framesizes (#901)
Fixes https://github.com/esphome/issues/issues/866
2020-06-05 12:52:05 +02:00
Otto Winter
a8e3521f3c web_server call setup_controller (#899) 2020-06-05 12:52:05 +02:00
Otto Winter
706dc6d116 Fix MQTT logs Int or String expected Python 3 (#898)
Fixes https://github.com/esphome/issues/issues/850
2020-06-05 12:52:04 +02:00
Guillermo Ruffino
84accb6df6 fix climate_ir on receive optional (#897)
* fix climate on receive optional

* add climate tests
2020-06-05 12:52:04 +02:00
warpzone
8421570b18 fix the problem of missing part of advertising packet when activ… (#868)
* fix the problem of missing part of advertising packet when active scan is enabled.

* fix for ci-suggest-changes
2020-06-05 12:52:04 +02:00
Otto Winter
d355543ac9 Merge branch '1.14.4' 2020-06-05 12:42:56 +02:00
Otto Winter
3a597c5aa6 Fix gitignore intellij idea 2020-06-05 12:38:05 +02:00
Otto Winter
c7dddaded4 Upgrade docker base image to 2.1.1 2020-06-05 12:28:37 +02:00
Otto Winter
aae4b2ea5d Upgrade docker base image to 2.1.0 2020-06-05 12:27:26 +02:00
Otto Winter
310e2a0b20 Fix build 2020-06-05 12:25:29 +02:00
Niklas Wagner
0b04d143ac Upgrade dependencies 2020-06-05 12:00:20 +02:00
31 changed files with 486 additions and 290 deletions

1
.gitignore vendored
View File

@@ -114,3 +114,4 @@ config/
tests/build/ tests/build/
tests/.esphome/ tests/.esphome/
/.temp-clang-tidy.cpp /.temp-clang-tidy.cpp
/.idea/

View File

@@ -3,7 +3,7 @@
variables: variables:
DOCKER_DRIVER: overlay2 DOCKER_DRIVER: overlay2
DOCKER_HOST: tcp://docker:2375/ DOCKER_HOST: tcp://docker:2375/
BASE_VERSION: '2.0.1' BASE_VERSION: '2.1.1'
TZ: UTC TZ: UTC
stages: stages:
@@ -33,7 +33,7 @@ stages:
- docker info - docker info
- docker login -u "$DOCKER_USER" -p "$DOCKER_PASSWORD" - docker login -u "$DOCKER_USER" -p "$DOCKER_PASSWORD"
script: script:
- docker run --rm --privileged multiarch/qemu-user-static:4.1.0-1 --reset -p yes - docker run --rm --privileged multiarch/qemu-user-static:5.0.0-2 --reset -p yes
- TAG="${CI_COMMIT_TAG#v}" - TAG="${CI_COMMIT_TAG#v}"
- TAG="${TAG:-${CI_COMMIT_SHA:0:7}}" - TAG="${TAG:-${CI_COMMIT_SHA:0:7}}"
- echo "Tag ${TAG}" - echo "Tag ${TAG}"

View File

@@ -1,4 +1,4 @@
ARG BUILD_FROM=esphome/esphome-base-amd64:2.0.1 ARG BUILD_FROM=esphome/esphome-base-amd64:2.1.1
FROM ${BUILD_FROM} FROM ${BUILD_FROM}
COPY . . COPY . .

View File

@@ -1,4 +1,4 @@
FROM esphome/esphome-base-amd64:2.0.1 FROM esphome/esphome-base-amd64:2.1.1
RUN \ RUN \
apt-get update \ apt-get update \

View File

@@ -44,6 +44,9 @@ class ClimateIR : public climate::Climate, public Component, public remote_base:
/// Transmit via IR the state of this climate controller. /// Transmit via IR the state of this climate controller.
virtual void transmit_state() = 0; virtual void transmit_state() = 0;
// Dummy implement on_receive so implementation is optional for inheritors
bool on_receive(remote_base::RemoteReceiveData data) override { return false; };
bool supports_cool_{true}; bool supports_cool_{true};
bool supports_heat_{true}; bool supports_heat_{true};

View File

@@ -32,9 +32,11 @@ void DallasComponent::setup() {
ESP_LOGCONFIG(TAG, "Setting up DallasComponent..."); ESP_LOGCONFIG(TAG, "Setting up DallasComponent...");
yield(); yield();
disable_interrupts(); std::vector<uint64_t> raw_sensors;
std::vector<uint64_t> raw_sensors = this->one_wire_->search_vec(); {
enable_interrupts(); InterruptLock lock;
raw_sensors = this->one_wire_->search_vec();
}
for (auto &address : raw_sensors) { for (auto &address : raw_sensors) {
std::string s = uint64_to_string(address); std::string s = uint64_to_string(address);
@@ -108,16 +110,17 @@ DallasTemperatureSensor *DallasComponent::get_sensor_by_index(uint8_t index, uin
void DallasComponent::update() { void DallasComponent::update() {
this->status_clear_warning(); this->status_clear_warning();
disable_interrupts();
bool result; bool result;
if (!this->one_wire_->reset()) { {
result = false; InterruptLock lock;
} else { if (!this->one_wire_->reset()) {
result = true; result = false;
this->one_wire_->skip(); } else {
this->one_wire_->write8(DALLAS_COMMAND_START_CONVERSION); result = true;
this->one_wire_->skip();
this->one_wire_->write8(DALLAS_COMMAND_START_CONVERSION);
}
} }
enable_interrupts();
if (!result) { if (!result) {
ESP_LOGE(TAG, "Requesting conversion failed"); ESP_LOGE(TAG, "Requesting conversion failed");
@@ -127,9 +130,11 @@ void DallasComponent::update() {
for (auto *sensor : this->sensors_) { for (auto *sensor : this->sensors_) {
this->set_timeout(sensor->get_address_name(), sensor->millis_to_wait_for_conversion(), [this, sensor] { this->set_timeout(sensor->get_address_name(), sensor->millis_to_wait_for_conversion(), [this, sensor] {
disable_interrupts(); bool res;
bool res = sensor->read_scratch_pad(); {
enable_interrupts(); InterruptLock lock;
res = sensor->read_scratch_pad();
}
if (!res) { if (!res) {
ESP_LOGW(TAG, "'%s' - Reseting bus for read failed!", sensor->get_name().c_str()); ESP_LOGW(TAG, "'%s' - Reseting bus for read failed!", sensor->get_name().c_str());
@@ -170,7 +175,7 @@ const std::string &DallasTemperatureSensor::get_address_name() {
return this->address_name_; return this->address_name_;
} }
bool DallasTemperatureSensor::read_scratch_pad() { bool ICACHE_RAM_ATTR DallasTemperatureSensor::read_scratch_pad() {
ESPOneWire *wire = this->parent_->one_wire_; ESPOneWire *wire = this->parent_->one_wire_;
if (!wire->reset()) { if (!wire->reset()) {
return false; return false;
@@ -185,9 +190,11 @@ bool DallasTemperatureSensor::read_scratch_pad() {
return true; return true;
} }
bool DallasTemperatureSensor::setup_sensor() { bool DallasTemperatureSensor::setup_sensor() {
disable_interrupts(); bool r;
bool r = this->read_scratch_pad(); {
enable_interrupts(); InterruptLock lock;
r = this->read_scratch_pad();
}
if (!r) { if (!r) {
ESP_LOGE(TAG, "Reading scratchpad failed: reset"); ESP_LOGE(TAG, "Reading scratchpad failed: reset");
@@ -222,20 +229,21 @@ bool DallasTemperatureSensor::setup_sensor() {
} }
ESPOneWire *wire = this->parent_->one_wire_; ESPOneWire *wire = this->parent_->one_wire_;
disable_interrupts(); {
if (wire->reset()) { InterruptLock lock;
wire->select(this->address_); if (wire->reset()) {
wire->write8(DALLAS_COMMAND_WRITE_SCRATCH_PAD); wire->select(this->address_);
wire->write8(this->scratch_pad_[2]); // high alarm temp wire->write8(DALLAS_COMMAND_WRITE_SCRATCH_PAD);
wire->write8(this->scratch_pad_[3]); // low alarm temp wire->write8(this->scratch_pad_[2]); // high alarm temp
wire->write8(this->scratch_pad_[4]); // resolution wire->write8(this->scratch_pad_[3]); // low alarm temp
wire->reset(); wire->write8(this->scratch_pad_[4]); // resolution
wire->reset();
// write value to EEPROM // write value to EEPROM
wire->select(this->address_); wire->select(this->address_);
wire->write8(0x48); wire->write8(0x48);
}
} }
enable_interrupts();
delay(20); // allow it to finish operation delay(20); // allow it to finish operation
wire->reset(); wire->reset();

View File

@@ -12,7 +12,7 @@ const int ONE_WIRE_ROM_SEARCH = 0xF0;
ESPOneWire::ESPOneWire(GPIOPin *pin) : pin_(pin) {} ESPOneWire::ESPOneWire(GPIOPin *pin) : pin_(pin) {}
bool HOT ESPOneWire::reset() { bool HOT ICACHE_RAM_ATTR ESPOneWire::reset() {
uint8_t retries = 125; uint8_t retries = 125;
// Wait for communication to clear // Wait for communication to clear
@@ -39,7 +39,7 @@ bool HOT ESPOneWire::reset() {
return r; return r;
} }
void HOT ESPOneWire::write_bit(bool bit) { void HOT ICACHE_RAM_ATTR ESPOneWire::write_bit(bool bit) {
// Initiate write/read by pulling low. // Initiate write/read by pulling low.
this->pin_->pin_mode(OUTPUT); this->pin_->pin_mode(OUTPUT);
this->pin_->digital_write(false); this->pin_->digital_write(false);
@@ -60,7 +60,7 @@ void HOT ESPOneWire::write_bit(bool bit) {
} }
} }
bool HOT ESPOneWire::read_bit() { bool HOT ICACHE_RAM_ATTR ESPOneWire::read_bit() {
// Initiate read slot by pulling LOW for at least 1µs // Initiate read slot by pulling LOW for at least 1µs
this->pin_->pin_mode(OUTPUT); this->pin_->pin_mode(OUTPUT);
this->pin_->digital_write(false); this->pin_->digital_write(false);
@@ -76,43 +76,43 @@ bool HOT ESPOneWire::read_bit() {
return r; return r;
} }
void ESPOneWire::write8(uint8_t val) { void ICACHE_RAM_ATTR ESPOneWire::write8(uint8_t val) {
for (uint8_t i = 0; i < 8; i++) { for (uint8_t i = 0; i < 8; i++) {
this->write_bit(bool((1u << i) & val)); this->write_bit(bool((1u << i) & val));
} }
} }
void ESPOneWire::write64(uint64_t val) { void ICACHE_RAM_ATTR ESPOneWire::write64(uint64_t val) {
for (uint8_t i = 0; i < 64; i++) { for (uint8_t i = 0; i < 64; i++) {
this->write_bit(bool((1ULL << i) & val)); this->write_bit(bool((1ULL << i) & val));
} }
} }
uint8_t ESPOneWire::read8() { uint8_t ICACHE_RAM_ATTR ESPOneWire::read8() {
uint8_t ret = 0; uint8_t ret = 0;
for (uint8_t i = 0; i < 8; i++) { for (uint8_t i = 0; i < 8; i++) {
ret |= (uint8_t(this->read_bit()) << i); ret |= (uint8_t(this->read_bit()) << i);
} }
return ret; return ret;
} }
uint64_t ESPOneWire::read64() { uint64_t ICACHE_RAM_ATTR ESPOneWire::read64() {
uint64_t ret = 0; uint64_t ret = 0;
for (uint8_t i = 0; i < 8; i++) { for (uint8_t i = 0; i < 8; i++) {
ret |= (uint64_t(this->read_bit()) << i); ret |= (uint64_t(this->read_bit()) << i);
} }
return ret; return ret;
} }
void ESPOneWire::select(uint64_t address) { void ICACHE_RAM_ATTR ESPOneWire::select(uint64_t address) {
this->write8(ONE_WIRE_ROM_SELECT); this->write8(ONE_WIRE_ROM_SELECT);
this->write64(address); this->write64(address);
} }
void ESPOneWire::reset_search() { void ICACHE_RAM_ATTR ESPOneWire::reset_search() {
this->last_discrepancy_ = 0; this->last_discrepancy_ = 0;
this->last_device_flag_ = false; this->last_device_flag_ = false;
this->last_family_discrepancy_ = 0; this->last_family_discrepancy_ = 0;
this->rom_number_ = 0; this->rom_number_ = 0;
} }
uint64_t HOT ESPOneWire::search() { uint64_t HOT ICACHE_RAM_ATTR ESPOneWire::search() {
if (this->last_device_flag_) { if (this->last_device_flag_) {
return 0u; return 0u;
} }
@@ -196,7 +196,7 @@ uint64_t HOT ESPOneWire::search() {
return this->rom_number_; return this->rom_number_;
} }
std::vector<uint64_t> ESPOneWire::search_vec() { std::vector<uint64_t> ICACHE_RAM_ATTR ESPOneWire::search_vec() {
std::vector<uint64_t> res; std::vector<uint64_t> res;
this->reset_search(); this->reset_search();
@@ -206,12 +206,12 @@ std::vector<uint64_t> ESPOneWire::search_vec() {
return res; return res;
} }
void ESPOneWire::skip() { void ICACHE_RAM_ATTR ESPOneWire::skip() {
this->write8(0xCC); // skip ROM this->write8(0xCC); // skip ROM
} }
GPIOPin *ESPOneWire::get_pin() { return this->pin_; } GPIOPin *ESPOneWire::get_pin() { return this->pin_; }
uint8_t *ESPOneWire::rom_number8_() { return reinterpret_cast<uint8_t *>(&this->rom_number_); } uint8_t ICACHE_RAM_ATTR *ESPOneWire::rom_number8_() { return reinterpret_cast<uint8_t *>(&this->rom_number_); }
} // namespace dallas } // namespace dallas
} // namespace esphome } // namespace esphome

View File

@@ -71,80 +71,101 @@ void DHT::set_dht_model(DHTModel model) {
this->model_ = model; this->model_ = model;
this->is_auto_detect_ = model == DHT_MODEL_AUTO_DETECT; this->is_auto_detect_ = model == DHT_MODEL_AUTO_DETECT;
} }
bool HOT DHT::read_sensor_(float *temperature, float *humidity, bool report_errors) { bool HOT ICACHE_RAM_ATTR DHT::read_sensor_(float *temperature, float *humidity, bool report_errors) {
*humidity = NAN; *humidity = NAN;
*temperature = NAN; *temperature = NAN;
disable_interrupts(); int error_code = 0;
this->pin_->digital_write(false); int8_t i = 0;
this->pin_->pin_mode(OUTPUT);
this->pin_->digital_write(false);
if (this->model_ == DHT_MODEL_DHT11) {
delayMicroseconds(18000);
} else if (this->model_ == DHT_MODEL_SI7021) {
delayMicroseconds(500);
this->pin_->digital_write(true);
delayMicroseconds(40);
} else {
delayMicroseconds(800);
}
this->pin_->pin_mode(INPUT_PULLUP);
delayMicroseconds(40);
uint8_t data[5] = {0, 0, 0, 0, 0}; uint8_t data[5] = {0, 0, 0, 0, 0};
uint8_t bit = 7;
uint8_t byte = 0;
for (int8_t i = -1; i < 40; i++) { {
uint32_t start_time = micros(); InterruptLock lock;
// Wait for rising edge this->pin_->digital_write(false);
while (!this->pin_->digital_read()) { this->pin_->pin_mode(OUTPUT);
if (micros() - start_time > 90) { this->pin_->digital_write(false);
enable_interrupts();
if (report_errors) { if (this->model_ == DHT_MODEL_DHT11) {
if (i < 0) { delayMicroseconds(18000);
ESP_LOGW(TAG, "Waiting for DHT communication to clear failed!"); } else if (this->model_ == DHT_MODEL_SI7021) {
} else { delayMicroseconds(500);
ESP_LOGW(TAG, "Rising edge for bit %d failed!", i); this->pin_->digital_write(true);
} delayMicroseconds(40);
} else {
delayMicroseconds(800);
}
this->pin_->pin_mode(INPUT_PULLUP);
delayMicroseconds(40);
uint8_t bit = 7;
uint8_t byte = 0;
for (i = -1; i < 40; i++) {
uint32_t start_time = micros();
// Wait for rising edge
while (!this->pin_->digital_read()) {
if (micros() - start_time > 90) {
if (i < 0)
error_code = 1;
else
error_code = 2;
break;
} }
return false;
} }
} if (error_code != 0)
break;
start_time = micros(); start_time = micros();
uint32_t end_time = start_time; uint32_t end_time = start_time;
// Wait for falling edge // Wait for falling edge
while (this->pin_->digital_read()) { while (this->pin_->digital_read()) {
if ((end_time = micros()) - start_time > 90) { if ((end_time = micros()) - start_time > 90) {
enable_interrupts(); if (i < 0)
if (report_errors) { error_code = 3;
if (i < 0) { else
ESP_LOGW(TAG, "Requesting data from DHT failed!"); error_code = 4;
} else { break;
ESP_LOGW(TAG, "Falling edge for bit %d failed!", i);
}
} }
return false;
} }
} if (error_code != 0)
break;
if (i < 0) if (i < 0)
continue; continue;
if (end_time - start_time >= 40) { if (end_time - start_time >= 40) {
data[byte] |= 1 << bit; data[byte] |= 1 << bit;
}
if (bit == 0) {
bit = 7;
byte++;
} else
bit--;
} }
if (bit == 0) {
bit = 7;
byte++;
} else
bit--;
} }
enable_interrupts(); if (!report_errors && error_code != 0)
return false;
switch (error_code) {
case 1:
ESP_LOGW(TAG, "Waiting for DHT communication to clear failed!");
return false;
case 2:
ESP_LOGW(TAG, "Rising edge for bit %d failed!", i);
return false;
case 3:
ESP_LOGW(TAG, "Requesting data from DHT failed!");
return false;
case 4:
ESP_LOGW(TAG, "Falling edge for bit %d failed!", i);
return false;
case 0:
default:
break;
}
ESP_LOGVV(TAG, ESP_LOGVV(TAG,
"Data: Hum=0b" BYTE_TO_BINARY_PATTERN BYTE_TO_BINARY_PATTERN "Data: Hum=0b" BYTE_TO_BINARY_PATTERN BYTE_TO_BINARY_PATTERN

View File

@@ -203,10 +203,6 @@ void ESP32BLETracker::gap_scan_result(const esp_ble_gap_cb_param_t::ble_scan_res
} }
} }
std::string hexencode_string(const std::string &raw_data) {
return hexencode(reinterpret_cast<const uint8_t *>(raw_data.c_str()), raw_data.size());
}
ESPBTUUID::ESPBTUUID() : uuid_() {} ESPBTUUID::ESPBTUUID() : uuid_() {}
ESPBTUUID ESPBTUUID::from_uint16(uint16_t uuid) { ESPBTUUID ESPBTUUID::from_uint16(uint16_t uuid) {
ESPBTUUID ret; ESPBTUUID ret;
@@ -266,13 +262,13 @@ std::string ESPBTUUID::to_string() {
} }
ESPBLEiBeacon::ESPBLEiBeacon(const uint8_t *data) { memcpy(&this->beacon_data_, data, sizeof(beacon_data_)); } ESPBLEiBeacon::ESPBLEiBeacon(const uint8_t *data) { memcpy(&this->beacon_data_, data, sizeof(beacon_data_)); }
optional<ESPBLEiBeacon> ESPBLEiBeacon::from_manufacturer_data(const std::string &data) { optional<ESPBLEiBeacon> ESPBLEiBeacon::from_manufacturer_data(const ServiceData &data) {
if (data.size() != 25) if (!data.uuid.contains(0x4C, 0x00))
return {};
if (data[0] != 0x4C || data[1] != 0x00)
return {}; return {};
return ESPBLEiBeacon(reinterpret_cast<const uint8_t *>(data.data())); if (data.data.size() != 23)
return {};
return ESPBLEiBeacon(data.data.data());
} }
void ESPBTDevice::parse_scan_rst(const esp_ble_gap_cb_param_t::ble_scan_result_evt_param &param) { void ESPBTDevice::parse_scan_rst(const esp_ble_gap_cb_param_t::ble_scan_result_evt_param &param) {
@@ -304,8 +300,8 @@ void ESPBTDevice::parse_scan_rst(const esp_ble_gap_cb_param_t::ble_scan_result_e
ESP_LOGVV(TAG, " RSSI: %d", this->rssi_); ESP_LOGVV(TAG, " RSSI: %d", this->rssi_);
ESP_LOGVV(TAG, " Name: '%s'", this->name_.c_str()); ESP_LOGVV(TAG, " Name: '%s'", this->name_.c_str());
if (this->tx_power_.has_value()) { for (auto &it : this->tx_powers_) {
ESP_LOGVV(TAG, " TX Power: %d", *this->tx_power_); ESP_LOGVV(TAG, " TX Power: %d", it);
} }
if (this->appearance_.has_value()) { if (this->appearance_.has_value()) {
ESP_LOGVV(TAG, " Appearance: %u", *this->appearance_); ESP_LOGVV(TAG, " Appearance: %u", *this->appearance_);
@@ -313,24 +309,25 @@ void ESPBTDevice::parse_scan_rst(const esp_ble_gap_cb_param_t::ble_scan_result_e
if (this->ad_flag_.has_value()) { if (this->ad_flag_.has_value()) {
ESP_LOGVV(TAG, " Ad Flag: %u", *this->ad_flag_); ESP_LOGVV(TAG, " Ad Flag: %u", *this->ad_flag_);
} }
for (auto uuid : this->service_uuids_) { for (auto &uuid : this->service_uuids_) {
ESP_LOGVV(TAG, " Service UUID: %s", uuid.to_string().c_str()); ESP_LOGVV(TAG, " Service UUID: %s", uuid.to_string().c_str());
} }
ESP_LOGVV(TAG, " Manufacturer data: %s", hexencode_string(this->manufacturer_data_).c_str()); for (auto &data : this->manufacturer_datas_) {
ESP_LOGVV(TAG, " Service data: %s", hexencode_string(this->service_data_).c_str()); ESP_LOGVV(TAG, " Manufacturer data: %s", hexencode(data.data).c_str());
}
if (this->service_data_uuid_.has_value()) { for (auto &data : this->service_datas_) {
ESP_LOGVV(TAG, " Service Data UUID: %s", this->service_data_uuid_->to_string().c_str()); ESP_LOGVV(TAG, " Service data:");
ESP_LOGVV(TAG, " UUID: %s", data.uuid.to_string().c_str());
ESP_LOGVV(TAG, " Data: %s", hexencode(data.data).c_str());
} }
ESP_LOGVV(TAG, "Adv data: %s", ESP_LOGVV(TAG, "Adv data: %s", hexencode(param.ble_adv, param.adv_data_len + param.scan_rsp_len).c_str());
hexencode_string(std::string(reinterpret_cast<const char *>(param.ble_adv), param.adv_data_len)).c_str());
#endif #endif
} }
void ESPBTDevice::parse_adv_(const esp_ble_gap_cb_param_t::ble_scan_result_evt_param &param) { void ESPBTDevice::parse_adv_(const esp_ble_gap_cb_param_t::ble_scan_result_evt_param &param) {
size_t offset = 0; size_t offset = 0;
const uint8_t *payload = param.ble_adv; const uint8_t *payload = param.ble_adv;
uint8_t len = param.adv_data_len; uint8_t len = param.adv_data_len + param.scan_rsp_len;
while (offset + 2 < len) { while (offset + 2 < len) {
const uint8_t field_length = payload[offset++]; // First byte is length of adv record const uint8_t field_length = payload[offset++]; // First byte is length of adv record
@@ -343,25 +340,52 @@ void ESPBTDevice::parse_adv_(const esp_ble_gap_cb_param_t::ble_scan_result_evt_p
const uint8_t record_length = field_length - 1; const uint8_t record_length = field_length - 1;
offset += record_length; offset += record_length;
// See also Generic Access Profile Assigned Numbers:
// https://www.bluetooth.com/specifications/assigned-numbers/generic-access-profile/ See also ADVERTISING AND SCAN
// RESPONSE DATA FORMAT: https://www.bluetooth.com/specifications/bluetooth-core-specification/ (vol 3, part C, 11)
// See also Core Specification Supplement: https://www.bluetooth.com/specifications/bluetooth-core-specification/
// (called CSS here)
switch (record_type) { switch (record_type) {
case ESP_BLE_AD_TYPE_NAME_CMPL: { case ESP_BLE_AD_TYPE_NAME_CMPL: {
// CSS 1.2 LOCAL NAME
// "The Local Name data type shall be the same as, or a shortened version of, the local name assigned to the
// device." CSS 1: Optional in this context; shall not appear more than once in a block.
this->name_ = std::string(reinterpret_cast<const char *>(record), record_length); this->name_ = std::string(reinterpret_cast<const char *>(record), record_length);
break; break;
} }
case ESP_BLE_AD_TYPE_TX_PWR: { case ESP_BLE_AD_TYPE_TX_PWR: {
this->tx_power_ = *payload; // CSS 1.5 TX POWER LEVEL
// "The TX Power Level data type indicates the transmitted power level of the packet containing the data type."
// CSS 1: Optional in this context (may appear more than once in a block).
this->tx_powers_.push_back(*payload);
break; break;
} }
case ESP_BLE_AD_TYPE_APPEARANCE: { case ESP_BLE_AD_TYPE_APPEARANCE: {
// CSS 1.12 APPEARANCE
// "The Appearance data type defines the external appearance of the device."
// See also https://www.bluetooth.com/specifications/gatt/characteristics/
// CSS 1: Optional in this context; shall not appear more than once in a block and shall not appear in both
// the AD and SRD of the same extended advertising interval.
this->appearance_ = *reinterpret_cast<const uint16_t *>(record); this->appearance_ = *reinterpret_cast<const uint16_t *>(record);
break; break;
} }
case ESP_BLE_AD_TYPE_FLAG: { case ESP_BLE_AD_TYPE_FLAG: {
// CSS 1.3 FLAGS
// "The Flags data type contains one bit Boolean flags. The Flags data type shall be included when any of the
// Flag bits are non-zero and the advertising packet is connectable, otherwise the Flags data type may be
// omitted."
// CSS 1: Optional in this context; shall not appear more than once in a block.
this->ad_flag_ = *record; this->ad_flag_ = *record;
break; break;
} }
// CSS 1.1 SERVICE UUID
// The Service UUID data type is used to include a list of Service or Service Class UUIDs.
// There are six data types defined for the three sizes of Service UUIDs that may be returned:
// CSS 1: Optional in this context (may appear more than once in a block).
case ESP_BLE_AD_TYPE_16SRV_CMPL: case ESP_BLE_AD_TYPE_16SRV_CMPL:
case ESP_BLE_AD_TYPE_16SRV_PART: { case ESP_BLE_AD_TYPE_16SRV_PART: {
// • 16-bit Bluetooth Service UUIDs
for (uint8_t i = 0; i < record_length / 2; i++) { for (uint8_t i = 0; i < record_length / 2; i++) {
this->service_uuids_.push_back(ESPBTUUID::from_uint16(*reinterpret_cast<const uint16_t *>(record + 2 * i))); this->service_uuids_.push_back(ESPBTUUID::from_uint16(*reinterpret_cast<const uint16_t *>(record + 2 * i)));
} }
@@ -369,6 +393,7 @@ void ESPBTDevice::parse_adv_(const esp_ble_gap_cb_param_t::ble_scan_result_evt_p
} }
case ESP_BLE_AD_TYPE_32SRV_CMPL: case ESP_BLE_AD_TYPE_32SRV_CMPL:
case ESP_BLE_AD_TYPE_32SRV_PART: { case ESP_BLE_AD_TYPE_32SRV_PART: {
// • 32-bit Bluetooth Service UUIDs
for (uint8_t i = 0; i < record_length / 4; i++) { for (uint8_t i = 0; i < record_length / 4; i++) {
this->service_uuids_.push_back(ESPBTUUID::from_uint32(*reinterpret_cast<const uint32_t *>(record + 4 * i))); this->service_uuids_.push_back(ESPBTUUID::from_uint32(*reinterpret_cast<const uint32_t *>(record + 4 * i)));
} }
@@ -376,41 +401,70 @@ void ESPBTDevice::parse_adv_(const esp_ble_gap_cb_param_t::ble_scan_result_evt_p
} }
case ESP_BLE_AD_TYPE_128SRV_CMPL: case ESP_BLE_AD_TYPE_128SRV_CMPL:
case ESP_BLE_AD_TYPE_128SRV_PART: { case ESP_BLE_AD_TYPE_128SRV_PART: {
// • Global 128-bit Service UUIDs
this->service_uuids_.push_back(ESPBTUUID::from_raw(record)); this->service_uuids_.push_back(ESPBTUUID::from_raw(record));
break; break;
} }
case ESP_BLE_AD_MANUFACTURER_SPECIFIC_TYPE: { case ESP_BLE_AD_MANUFACTURER_SPECIFIC_TYPE: {
this->manufacturer_data_ = std::string(reinterpret_cast<const char *>(record), record_length); // CSS 1.4 MANUFACTURER SPECIFIC DATA
// "The Manufacturer Specific data type is used for manufacturer specific data. The first two data octets shall
// contain a company identifier from Assigned Numbers. The interpretation of any other octets within the data
// shall be defined by the manufacturer specified by the company identifier."
// CSS 1: Optional in this context (may appear more than once in a block).
if (record_length < 2) {
ESP_LOGV(TAG, "Record length too small for ESP_BLE_AD_MANUFACTURER_SPECIFIC_TYPE");
break;
}
ServiceData data{};
data.uuid = ESPBTUUID::from_uint16(*reinterpret_cast<const uint16_t *>(record));
data.data.assign(record + 2UL, record + record_length);
this->manufacturer_datas_.push_back(data);
break; break;
} }
// CSS 1.11 SERVICE DATA
// "The Service Data data type consists of a service UUID with the data associated with that service."
// CSS 1: Optional in this context (may appear more than once in a block).
case ESP_BLE_AD_TYPE_SERVICE_DATA: { case ESP_BLE_AD_TYPE_SERVICE_DATA: {
// «Service Data - 16 bit UUID»
// Size: 2 or more octets
// The first 2 octets contain the 16 bit Service UUID fol- lowed by additional service data
if (record_length < 2) { if (record_length < 2) {
ESP_LOGV(TAG, "Record length too small for ESP_BLE_AD_TYPE_SERVICE_DATA"); ESP_LOGV(TAG, "Record length too small for ESP_BLE_AD_TYPE_SERVICE_DATA");
break; break;
} }
this->service_data_uuid_ = ESPBTUUID::from_uint16(*reinterpret_cast<const uint16_t *>(record)); ServiceData data{};
if (record_length > 2) data.uuid = ESPBTUUID::from_uint16(*reinterpret_cast<const uint16_t *>(record));
this->service_data_ = std::string(reinterpret_cast<const char *>(record + 2), record_length - 2UL); data.data.assign(record + 2UL, record + record_length);
this->service_datas_.push_back(data);
break; break;
} }
case ESP_BLE_AD_TYPE_32SERVICE_DATA: { case ESP_BLE_AD_TYPE_32SERVICE_DATA: {
// «Service Data - 32 bit UUID»
// Size: 4 or more octets
// The first 4 octets contain the 32 bit Service UUID fol- lowed by additional service data
if (record_length < 4) { if (record_length < 4) {
ESP_LOGV(TAG, "Record length too small for ESP_BLE_AD_TYPE_32SERVICE_DATA"); ESP_LOGV(TAG, "Record length too small for ESP_BLE_AD_TYPE_32SERVICE_DATA");
break; break;
} }
this->service_data_uuid_ = ESPBTUUID::from_uint32(*reinterpret_cast<const uint32_t *>(record)); ServiceData data{};
if (record_length > 4) data.uuid = ESPBTUUID::from_uint32(*reinterpret_cast<const uint32_t *>(record));
this->service_data_ = std::string(reinterpret_cast<const char *>(record + 4), record_length - 4UL); data.data.assign(record + 4UL, record + record_length);
this->service_datas_.push_back(data);
break; break;
} }
case ESP_BLE_AD_TYPE_128SERVICE_DATA: { case ESP_BLE_AD_TYPE_128SERVICE_DATA: {
// «Service Data - 128 bit UUID»
// Size: 16 or more octets
// The first 16 octets contain the 128 bit Service UUID followed by additional service data
if (record_length < 16) { if (record_length < 16) {
ESP_LOGV(TAG, "Record length too small for ESP_BLE_AD_TYPE_128SERVICE_DATA"); ESP_LOGV(TAG, "Record length too small for ESP_BLE_AD_TYPE_128SERVICE_DATA");
break; break;
} }
this->service_data_uuid_ = ESPBTUUID::from_raw(record); ServiceData data{};
if (record_length > 16) data.uuid = ESPBTUUID::from_raw(record);
this->service_data_ = std::string(reinterpret_cast<const char *>(record + 16), record_length - 16UL); data.data.assign(record + 16UL, record + record_length);
this->service_datas_.push_back(data);
break; break;
} }
default: { default: {
@@ -427,16 +481,6 @@ std::string ESPBTDevice::address_str() const {
return mac; return mac;
} }
uint64_t ESPBTDevice::address_uint64() const { return ble_addr_to_uint64(this->address_); } uint64_t ESPBTDevice::address_uint64() const { return ble_addr_to_uint64(this->address_); }
esp_ble_addr_type_t ESPBTDevice::get_address_type() const { return this->address_type_; }
int ESPBTDevice::get_rssi() const { return this->rssi_; }
const std::string &ESPBTDevice::get_name() const { return this->name_; }
const optional<int8_t> &ESPBTDevice::get_tx_power() const { return this->tx_power_; }
const optional<uint16_t> &ESPBTDevice::get_appearance() const { return this->appearance_; }
const optional<uint8_t> &ESPBTDevice::get_ad_flag() const { return this->ad_flag_; }
const std::vector<ESPBTUUID> &ESPBTDevice::get_service_uuids() const { return this->service_uuids_; }
const std::string &ESPBTDevice::get_manufacturer_data() const { return this->manufacturer_data_; }
const std::string &ESPBTDevice::get_service_data() const { return this->service_data_; }
const optional<ESPBTUUID> &ESPBTDevice::get_service_data_uuid() const { return this->service_data_uuid_; }
void ESP32BLETracker::dump_config() { void ESP32BLETracker::dump_config() {
ESP_LOGCONFIG(TAG, "BLE Tracker:"); ESP_LOGCONFIG(TAG, "BLE Tracker:");
@@ -477,8 +521,8 @@ void ESP32BLETracker::print_bt_device_info(const ESPBTDevice &device) {
ESP_LOGD(TAG, " Address Type: %s", address_type_s); ESP_LOGD(TAG, " Address Type: %s", address_type_s);
if (!device.get_name().empty()) if (!device.get_name().empty())
ESP_LOGD(TAG, " Name: '%s'", device.get_name().c_str()); ESP_LOGD(TAG, " Name: '%s'", device.get_name().c_str());
if (device.get_tx_power().has_value()) { for (auto &tx_power : device.get_tx_powers()) {
ESP_LOGD(TAG, " TX Power: %d", *device.get_tx_power()); ESP_LOGD(TAG, " TX Power: %d", tx_power);
} }
} }

View File

@@ -31,11 +31,18 @@ class ESPBTUUID {
esp_bt_uuid_t uuid_; esp_bt_uuid_t uuid_;
}; };
using adv_data_t = std::vector<uint8_t>;
struct ServiceData {
ESPBTUUID uuid;
adv_data_t data;
};
class ESPBLEiBeacon { class ESPBLEiBeacon {
public: public:
ESPBLEiBeacon() { memset(&this->beacon_data_, 0, sizeof(this->beacon_data_)); } ESPBLEiBeacon() { memset(&this->beacon_data_, 0, sizeof(this->beacon_data_)); }
ESPBLEiBeacon(const uint8_t *data); ESPBLEiBeacon(const uint8_t *data);
static optional<ESPBLEiBeacon> from_manufacturer_data(const std::string &data); static optional<ESPBLEiBeacon> from_manufacturer_data(const ServiceData &data);
uint16_t get_major() { return reverse_bits_16(this->beacon_data_.major); } uint16_t get_major() { return reverse_bits_16(this->beacon_data_.major); }
uint16_t get_minor() { return reverse_bits_16(this->beacon_data_.minor); } uint16_t get_minor() { return reverse_bits_16(this->beacon_data_.minor); }
@@ -44,7 +51,6 @@ class ESPBLEiBeacon {
protected: protected:
struct { struct {
uint16_t manufacturer_id;
uint8_t sub_type; uint8_t sub_type;
uint8_t proximity_uuid[16]; uint8_t proximity_uuid[16];
uint16_t major; uint16_t major;
@@ -61,18 +67,33 @@ class ESPBTDevice {
uint64_t address_uint64() const; uint64_t address_uint64() const;
esp_ble_addr_type_t get_address_type() const; esp_ble_addr_type_t get_address_type() const { return this->address_type_; }
int get_rssi() const; int get_rssi() const { return rssi_; }
const std::string &get_name() const; const std::string &get_name() const { return this->name_; }
const optional<int8_t> &get_tx_power() const;
const optional<uint16_t> &get_appearance() const; ESPDEPRECATED("Use get_tx_powers() instead")
const optional<uint8_t> &get_ad_flag() const; optional<int8_t> get_tx_power() const {
const std::vector<ESPBTUUID> &get_service_uuids() const; if (this->tx_powers_.empty())
const std::string &get_manufacturer_data() const; return {};
const std::string &get_service_data() const; return this->tx_powers_[0];
const optional<ESPBTUUID> &get_service_data_uuid() const; }
const optional<ESPBLEiBeacon> get_ibeacon() const { const std::vector<int8_t> &get_tx_powers() const { return tx_powers_; }
return ESPBLEiBeacon::from_manufacturer_data(this->manufacturer_data_);
const optional<uint16_t> &get_appearance() const { return appearance_; }
const optional<uint8_t> &get_ad_flag() const { return ad_flag_; }
const std::vector<ESPBTUUID> &get_service_uuids() const { return service_uuids_; }
const std::vector<ServiceData> &get_manufacturer_datas() const { return manufacturer_datas_; }
const std::vector<ServiceData> &get_service_datas() const { return service_datas_; }
optional<ESPBLEiBeacon> get_ibeacon() const {
for (auto &it : this->manufacturer_datas_) {
auto res = ESPBLEiBeacon::from_manufacturer_data(it);
if (res.has_value())
return *res;
}
return {};
} }
protected: protected:
@@ -84,13 +105,12 @@ class ESPBTDevice {
esp_ble_addr_type_t address_type_{BLE_ADDR_TYPE_PUBLIC}; esp_ble_addr_type_t address_type_{BLE_ADDR_TYPE_PUBLIC};
int rssi_{0}; int rssi_{0};
std::string name_{}; std::string name_{};
optional<int8_t> tx_power_{}; std::vector<int8_t> tx_powers_{};
optional<uint16_t> appearance_{}; optional<uint16_t> appearance_{};
optional<uint8_t> ad_flag_{}; optional<uint8_t> ad_flag_{};
std::vector<ESPBTUUID> service_uuids_; std::vector<ESPBTUUID> service_uuids_;
std::string manufacturer_data_{}; std::vector<ServiceData> manufacturer_datas_{};
std::string service_data_{}; std::vector<ServiceData> service_datas_{};
optional<ESPBTUUID> service_data_uuid_{};
}; };
class ESP32BLETracker; class ESP32BLETracker;

View File

@@ -85,6 +85,8 @@ void ESP32Camera::dump_config() {
case FRAMESIZE_UXGA: case FRAMESIZE_UXGA:
ESP_LOGCONFIG(TAG, " Resolution: 1600x1200 (UXGA)"); ESP_LOGCONFIG(TAG, " Resolution: 1600x1200 (UXGA)");
break; break;
default:
break;
} }
if (this->is_failed()) { if (this->is_failed()) {

View File

@@ -42,23 +42,24 @@ bool HX711Sensor::read_sensor_(uint32_t *result) {
this->status_clear_warning(); this->status_clear_warning();
uint32_t data = 0; uint32_t data = 0;
disable_interrupts(); {
for (uint8_t i = 0; i < 24; i++) { InterruptLock lock;
this->sck_pin_->digital_write(true); for (uint8_t i = 0; i < 24; i++) {
delayMicroseconds(1); this->sck_pin_->digital_write(true);
data |= uint32_t(this->dout_pin_->digital_read()) << (23 - i); delayMicroseconds(1);
this->sck_pin_->digital_write(false); data |= uint32_t(this->dout_pin_->digital_read()) << (23 - i);
delayMicroseconds(1); this->sck_pin_->digital_write(false);
} delayMicroseconds(1);
}
// Cycle clock pin for gain setting // Cycle clock pin for gain setting
for (uint8_t i = 0; i < this->gain_; i++) { for (uint8_t i = 0; i < this->gain_; i++) {
this->sck_pin_->digital_write(true); this->sck_pin_->digital_write(true);
delayMicroseconds(1); delayMicroseconds(1);
this->sck_pin_->digital_write(false); this->sck_pin_->digital_write(false);
delayMicroseconds(1); delayMicroseconds(1);
}
} }
enable_interrupts();
if (data & 0x800000ULL) { if (data & 0x800000ULL) {
data |= 0xFF000000ULL; data |= 0xFF000000ULL;

View File

@@ -67,22 +67,22 @@ void RemoteTransmitterComponent::send_internal(uint32_t send_times, uint32_t sen
uint32_t on_time, off_time; uint32_t on_time, off_time;
this->calculate_on_off_time_(this->temp_.get_carrier_frequency(), &on_time, &off_time); this->calculate_on_off_time_(this->temp_.get_carrier_frequency(), &on_time, &off_time);
for (uint32_t i = 0; i < send_times; i++) { for (uint32_t i = 0; i < send_times; i++) {
disable_interrupts(); {
for (int32_t item : this->temp_.get_data()) { InterruptLock lock;
if (item > 0) { for (int32_t item : this->temp_.get_data()) {
const auto length = uint32_t(item); if (item > 0) {
this->mark_(on_time, off_time, length); const auto length = uint32_t(item);
} else { this->mark_(on_time, off_time, length);
const auto length = uint32_t(-item); } else {
this->space_(length); const auto length = uint32_t(-item);
this->space_(length);
}
App.feed_wdt();
} }
App.feed_wdt();
} }
enable_interrupts();
if (i + 1 < send_times) { if (i + 1 < send_times) {
delay(send_wait / 1000UL); delay_microseconds_accurate(send_wait);
delayMicroseconds(send_wait % 1000UL);
} }
} }
} }

View File

@@ -295,24 +295,25 @@ void ICACHE_RAM_ATTR HOT ESP8266SoftwareSerial::write_byte(uint8_t data) {
return; return;
} }
disable_interrupts(); {
uint32_t wait = this->bit_time_; InterruptLock lock;
const uint32_t start = ESP.getCycleCount(); uint32_t wait = this->bit_time_;
// Start bit const uint32_t start = ESP.getCycleCount();
this->write_bit_(false, &wait, start); // Start bit
this->write_bit_(data & (1 << 0), &wait, start); this->write_bit_(false, &wait, start);
this->write_bit_(data & (1 << 1), &wait, start); this->write_bit_(data & (1 << 0), &wait, start);
this->write_bit_(data & (1 << 2), &wait, start); this->write_bit_(data & (1 << 1), &wait, start);
this->write_bit_(data & (1 << 3), &wait, start); this->write_bit_(data & (1 << 2), &wait, start);
this->write_bit_(data & (1 << 4), &wait, start); this->write_bit_(data & (1 << 3), &wait, start);
this->write_bit_(data & (1 << 5), &wait, start); this->write_bit_(data & (1 << 4), &wait, start);
this->write_bit_(data & (1 << 6), &wait, start); this->write_bit_(data & (1 << 5), &wait, start);
this->write_bit_(data & (1 << 7), &wait, start); this->write_bit_(data & (1 << 6), &wait, start);
// Stop bit this->write_bit_(data & (1 << 7), &wait, start);
this->write_bit_(true, &wait, start); // Stop bit
if (this->stop_bits_ == 2) this->write_bit_(true, &wait, start);
this->wait_(&wait, start); if (this->stop_bits_ == 2)
enable_interrupts(); this->wait_(&wait, start);
}
} }
void ICACHE_RAM_ATTR ESP8266SoftwareSerial::wait_(uint32_t *wait, const uint32_t &start) { void ICACHE_RAM_ATTR ESP8266SoftwareSerial::wait_(uint32_t *wait, const uint32_t &start) {
while (ESP.getCycleCount() - start < *wait) while (ESP.getCycleCount() - start < *wait)
@@ -323,7 +324,7 @@ bool ICACHE_RAM_ATTR ESP8266SoftwareSerial::read_bit_(uint32_t *wait, const uint
this->wait_(wait, start); this->wait_(wait, start);
return this->rx_pin_->digital_read(); return this->rx_pin_->digital_read();
} }
void ESP8266SoftwareSerial::write_bit_(bool bit, uint32_t *wait, const uint32_t &start) { void ICACHE_RAM_ATTR ESP8266SoftwareSerial::write_bit_(bool bit, uint32_t *wait, const uint32_t &start) {
this->tx_pin_->digital_write(bit); this->tx_pin_->digital_write(bit);
this->wait_(wait, start); this->wait_(wait, start);
} }

View File

@@ -64,6 +64,7 @@ void WebServer::set_js_url(const char *js_url) { this->js_url_ = js_url; }
void WebServer::setup() { void WebServer::setup() {
ESP_LOGCONFIG(TAG, "Setting up web server..."); ESP_LOGCONFIG(TAG, "Setting up web server...");
this->setup_controller();
this->base_->init(); this->base_->init();
this->events_.onConnect([this](AsyncEventSourceClient *client) { this->events_.onConnect([this](AsyncEventSourceClient *client) {

View File

@@ -6,8 +6,16 @@
#include <utility> #include <utility>
#include <algorithm> #include <algorithm>
extern "C" {
#include "lwip/err.h" #include "lwip/err.h"
#include "lwip/dns.h" #include "lwip/dns.h"
#include "lwip/dhcp.h"
#include "lwip/init.h" // LWIP_VERSION_
#if LWIP_IPV6
#include "lwip/netif.h" // struct netif
#endif
}
#include "esphome/core/helpers.h" #include "esphome/core/helpers.h"
#include "esphome/core/log.h" #include "esphome/core/log.h"
@@ -74,6 +82,19 @@ bool WiFiComponent::wifi_apply_power_save_() {
} }
return wifi_set_sleep_type(power_save); return wifi_set_sleep_type(power_save);
} }
#if LWIP_VERSION_MAJOR != 1
/*
lwip v2 needs to be notified of IP changes, see also
https://github.com/d-a-v/Arduino/blob/0e7d21e17144cfc5f53c016191daca8723e89ee8/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp#L251
*/
#undef netif_set_addr // need to call lwIP-v1.4 netif_set_addr()
extern "C" {
struct netif *eagle_lwip_getif(int netif_index);
void netif_set_addr(struct netif *netif, const ip4_addr_t *ip, const ip4_addr_t *netmask, const ip4_addr_t *gw);
};
#endif
bool WiFiComponent::wifi_sta_ip_config_(optional<ManualIP> manual_ip) { bool WiFiComponent::wifi_sta_ip_config_(optional<ManualIP> manual_ip) {
// enable STA // enable STA
if (!this->wifi_mode_(true, {})) if (!this->wifi_mode_(true, {}))
@@ -94,6 +115,13 @@ bool WiFiComponent::wifi_sta_ip_config_(optional<ManualIP> manual_ip) {
bool ret = true; bool ret = true;
#if LWIP_VERSION_MAJOR != 1
// get current->previous IP address
// (check below)
ip_info previp{};
wifi_get_ip_info(STATION_IF, &previp);
#endif
struct ip_info info {}; struct ip_info info {};
info.ip.addr = static_cast<uint32_t>(manual_ip->static_ip); info.ip.addr = static_cast<uint32_t>(manual_ip->static_ip);
info.gw.addr = static_cast<uint32_t>(manual_ip->gateway); info.gw.addr = static_cast<uint32_t>(manual_ip->gateway);
@@ -122,6 +150,14 @@ bool WiFiComponent::wifi_sta_ip_config_(optional<ManualIP> manual_ip) {
dns_setserver(1, &dns); dns_setserver(1, &dns);
} }
#if LWIP_VERSION_MAJOR != 1
// trigger address change by calling lwIP-v1.4 api
// only when ip is already set by other mean (generally dhcp)
if (previp.ip.addr != 0 && previp.ip.addr != info.ip.addr) {
netif_set_addr(eagle_lwip_getif(STATION_IF), reinterpret_cast<const ip4_addr_t *>(&info.ip),
reinterpret_cast<const ip4_addr_t *>(&info.netmask), reinterpret_cast<const ip4_addr_t *>(&info.gw));
}
#endif
return ret; return ret;
} }
@@ -133,10 +169,31 @@ IPAddress WiFiComponent::wifi_sta_ip_() {
return {ip.ip.addr}; return {ip.ip.addr};
} }
bool WiFiComponent::wifi_apply_hostname_() { bool WiFiComponent::wifi_apply_hostname_() {
bool ret = wifi_station_set_hostname(const_cast<char *>(App.get_name().c_str())); const std::string &hostname = App.get_name();
bool ret = wifi_station_set_hostname(const_cast<char *>(hostname.c_str()));
if (!ret) { if (!ret) {
ESP_LOGV(TAG, "Setting WiFi Hostname failed!"); ESP_LOGV(TAG, "Setting WiFi Hostname failed!");
} }
// inform dhcp server of hostname change using dhcp_renew()
for (netif *intf = netif_list; intf; intf = intf->next) {
// unconditionally update all known interfaces
#if LWIP_VERSION_MAJOR == 1
intf->hostname = (char *) wifi_station_get_hostname();
#else
intf->hostname = wifi_station_get_hostname();
#endif
if (netif_dhcp_data(intf) != nullptr) {
// renew already started DHCP leases
err_t lwipret = dhcp_renew(intf);
if (lwipret != ERR_OK) {
ESP_LOGW(TAG, "wifi_apply_hostname_(%s): lwIP error %d on interface %c%c (index %d)", intf->hostname,
(int) lwipret, intf->name[0], intf->name[1], intf->num);
ret = false;
}
}
}
return ret; return ret;
} }

View File

@@ -63,22 +63,17 @@ bool parse_xiaomi_data_byte(uint8_t data_type, const uint8_t *data, uint8_t data
return false; return false;
} }
} }
optional<XiaomiParseResult> parse_xiaomi(const esp32_ble_tracker::ESPBTDevice &device) { bool parse_xiaomi_service_data(XiaomiParseResult &result, const esp32_ble_tracker::ServiceData &service_data) {
if (!device.get_service_data_uuid().has_value()) { if (!service_data.uuid.contains(0x95, 0xFE)) {
// ESP_LOGVV(TAG, "Xiaomi no service data");
return {};
}
if (!device.get_service_data_uuid()->contains(0x95, 0xFE)) {
// ESP_LOGVV(TAG, "Xiaomi no service data UUID magic bytes"); // ESP_LOGVV(TAG, "Xiaomi no service data UUID magic bytes");
return {}; return false;
} }
const auto *raw = reinterpret_cast<const uint8_t *>(device.get_service_data().data()); const auto raw = service_data.data;
if (device.get_service_data().size() < 14) { if (raw.size() < 14) {
// ESP_LOGVV(TAG, "Xiaomi service data too short!"); // ESP_LOGVV(TAG, "Xiaomi service data too short!");
return {}; return false;
} }
bool is_lywsdcgq = (raw[1] & 0x20) == 0x20 && raw[2] == 0xAA && raw[3] == 0x01; bool is_lywsdcgq = (raw[1] & 0x20) == 0x20 && raw[2] == 0xAA && raw[3] == 0x01;
@@ -88,10 +83,9 @@ optional<XiaomiParseResult> parse_xiaomi(const esp32_ble_tracker::ESPBTDevice &d
if (!is_lywsdcgq && !is_hhccjcy01 && !is_lywsd02 && !is_cgg1) { if (!is_lywsdcgq && !is_hhccjcy01 && !is_lywsd02 && !is_cgg1) {
// ESP_LOGVV(TAG, "Xiaomi no magic bytes"); // ESP_LOGVV(TAG, "Xiaomi no magic bytes");
return {}; return false;
} }
XiaomiParseResult result;
result.type = XiaomiParseResult::TYPE_HHCCJCY01; result.type = XiaomiParseResult::TYPE_HHCCJCY01;
if (is_lywsdcgq) { if (is_lywsdcgq) {
result.type = XiaomiParseResult::TYPE_LYWSDCGQ; result.type = XiaomiParseResult::TYPE_LYWSDCGQ;
@@ -111,7 +105,7 @@ optional<XiaomiParseResult> parse_xiaomi(const esp32_ble_tracker::ESPBTDevice &d
const uint8_t *raw_data = &raw[raw_offset]; const uint8_t *raw_data = &raw[raw_offset];
uint8_t data_offset = 0; uint8_t data_offset = 0;
uint8_t data_length = device.get_service_data().size() - raw_offset; uint8_t data_length = raw.size() - raw_offset;
bool success = false; bool success = false;
while (true) { while (true) {
@@ -136,6 +130,15 @@ optional<XiaomiParseResult> parse_xiaomi(const esp32_ble_tracker::ESPBTDevice &d
data_offset += 3 + datapoint_length; data_offset += 3 + datapoint_length;
} }
return success;
}
optional<XiaomiParseResult> parse_xiaomi(const esp32_ble_tracker::ESPBTDevice &device) {
XiaomiParseResult result;
bool success = false;
for (auto &service_data : device.get_service_datas()) {
if (parse_xiaomi_service_data(result, service_data))
success = true;
}
if (!success) if (!success)
return {}; return {};
return result; return result;

View File

@@ -3,7 +3,7 @@
MAJOR_VERSION = 1 MAJOR_VERSION = 1
MINOR_VERSION = 14 MINOR_VERSION = 14
PATCH_VERSION = '3' PATCH_VERSION = '4'
__short_version__ = '{}.{}'.format(MAJOR_VERSION, MINOR_VERSION) __short_version__ = '{}.{}'.format(MAJOR_VERSION, MINOR_VERSION)
__version__ = '{}.{}'.format(__short_version__, PATCH_VERSION) __version__ = '{}.{}'.format(__short_version__, PATCH_VERSION)

View File

@@ -567,10 +567,12 @@ class EsphomeCore(object):
return os.path.basename(self.config_path) return os.path.basename(self.config_path)
def relative_config_path(self, *path): def relative_config_path(self, *path):
# pylint: disable=no-value-for-parameter
path_ = os.path.expanduser(os.path.join(*path)) path_ = os.path.expanduser(os.path.join(*path))
return os.path.join(self.config_dir, path_) return os.path.join(self.config_dir, path_)
def relative_build_path(self, *path): def relative_build_path(self, *path):
# pylint: disable=no-value-for-parameter
path_ = os.path.expanduser(os.path.join(*path)) path_ = os.path.expanduser(os.path.join(*path))
return os.path.join(self.build_path, path_) return os.path.join(self.build_path, path_)

View File

@@ -156,21 +156,6 @@ ParseOnOffState parse_on_off(const char *str, const char *on, const char *off) {
const char *HOSTNAME_CHARACTER_WHITELIST = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_"; const char *HOSTNAME_CHARACTER_WHITELIST = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
void disable_interrupts() {
#ifdef ARDUINO_ARCH_ESP32
portDISABLE_INTERRUPTS();
#else
noInterrupts();
#endif
}
void enable_interrupts() {
#ifdef ARDUINO_ARCH_ESP32
portENABLE_INTERRUPTS();
#else
interrupts();
#endif
}
uint8_t crc8(uint8_t *data, uint8_t len) { uint8_t crc8(uint8_t *data, uint8_t len) {
uint8_t crc = 0; uint8_t crc = 0;
@@ -193,8 +178,8 @@ void delay_microseconds_accurate(uint32_t usec) {
if (usec <= 16383UL) { if (usec <= 16383UL) {
delayMicroseconds(usec); delayMicroseconds(usec);
} else { } else {
delay(usec / 1000UL); delay(usec / 16383UL);
delayMicroseconds(usec % 1000UL); delayMicroseconds(usec % 16383UL);
} }
} }
@@ -330,4 +315,13 @@ std::string hexencode(const uint8_t *data, uint32_t len) {
return res; return res;
} }
#ifdef ARDUINO_ARCH_ESP8266
ICACHE_RAM_ATTR InterruptLock::InterruptLock() { xt_state_ = xt_rsil(15); }
ICACHE_RAM_ATTR InterruptLock::~InterruptLock() { xt_wsr_ps(xt_state_); }
#endif
#ifdef ARDUINO_ARCH_ESP32
ICACHE_RAM_ATTR InterruptLock::InterruptLock() { portENABLE_INTERRUPTS(); }
ICACHE_RAM_ATTR InterruptLock::~InterruptLock() { portDISABLE_INTERRUPTS(); }
#endif
} // namespace esphome } // namespace esphome

View File

@@ -133,16 +133,38 @@ uint16_t encode_uint16(uint8_t msb, uint8_t lsb);
/// Decode a 16-bit unsigned integer into an array of two values: most significant byte, least significant byte. /// Decode a 16-bit unsigned integer into an array of two values: most significant byte, least significant byte.
std::array<uint8_t, 2> decode_uint16(uint16_t value); std::array<uint8_t, 2> decode_uint16(uint16_t value);
/** Cross-platform method to disable interrupts. /***
* An interrupt helper class.
* *
* Useful when you need to do some timing-dependent communication. * This behaves like std::lock_guard. As long as the value is visible in the current stack, all interrupts
* (including flash reads) will be disabled.
* *
* @see Do not forget to call `enable_interrupts()` again or otherwise things will go very wrong. * Please note all functions called when the interrupt lock must be marked ICACHE_RAM_ATTR (loading code into
* instruction cache is done via interrupts; disabling interrupts prevents data not already in cache from being
* pulled from flash).
*
* Example:
*
* ```cpp
* // interrupts are enabled
* {
* InterruptLock lock;
* // do something
* // interrupts are disabled
* }
* // interrupts are enabled
* ```
*/ */
void disable_interrupts(); class InterruptLock {
public:
InterruptLock();
~InterruptLock();
/// Cross-platform method to enable interrupts after they have been disabled. protected:
void enable_interrupts(); #ifdef ARDUINO_ARCH_ESP8266
uint32_t xt_state_;
#endif
};
/// Calculate a crc8 of data with the provided data length. /// Calculate a crc8 of data with the provided data length.
uint8_t crc8(uint8_t *data, uint8_t len); uint8_t crc8(uint8_t *data, uint8_t len);
@@ -158,6 +180,7 @@ ParseOnOffState parse_on_off(const char *str, const char *on = nullptr, const ch
// Encode raw data to a human-readable string (for debugging) // Encode raw data to a human-readable string (for debugging)
std::string hexencode(const uint8_t *data, uint32_t len); std::string hexencode(const uint8_t *data, uint32_t len);
template<typename T> std::string hexencode(const T &data) { return hexencode(data.data(), data.size()); }
// https://stackoverflow.com/questions/7858817/unpacking-a-tuple-to-call-a-matching-function-pointer/7858971#7858971 // https://stackoverflow.com/questions/7858817/unpacking-a-tuple-to-call-a-matching-function-pointer/7858971#7858971
template<int...> struct seq {}; // NOLINT template<int...> struct seq {}; // NOLINT

View File

@@ -105,16 +105,18 @@ void ESPPreferences::save_esp8266_flash_() {
return; return;
ESP_LOGVV(TAG, "Saving preferences to flash..."); ESP_LOGVV(TAG, "Saving preferences to flash...");
disable_interrupts(); SpiFlashOpResult erase_res, write_res = SPI_FLASH_RESULT_OK;
auto erase_res = spi_flash_erase_sector(get_esp8266_flash_sector()); {
InterruptLock lock;
erase_res = spi_flash_erase_sector(get_esp8266_flash_sector());
if (erase_res == SPI_FLASH_RESULT_OK) {
write_res = spi_flash_write(get_esp8266_flash_address(), this->flash_storage_, ESP8266_FLASH_STORAGE_SIZE * 4);
}
}
if (erase_res != SPI_FLASH_RESULT_OK) { if (erase_res != SPI_FLASH_RESULT_OK) {
enable_interrupts();
ESP_LOGV(TAG, "Erase ESP8266 flash failed!"); ESP_LOGV(TAG, "Erase ESP8266 flash failed!");
return; return;
} }
auto write_res = spi_flash_write(get_esp8266_flash_address(), this->flash_storage_, ESP8266_FLASH_STORAGE_SIZE * 4);
enable_interrupts();
if (write_res != SPI_FLASH_RESULT_OK) { if (write_res != SPI_FLASH_RESULT_OK) {
ESP_LOGV(TAG, "Write ESP8266 flash failed!"); ESP_LOGV(TAG, "Write ESP8266 flash failed!");
return; return;
@@ -173,9 +175,11 @@ ESPPreferences::ESPPreferences()
void ESPPreferences::begin() { void ESPPreferences::begin() {
this->flash_storage_ = new uint32_t[ESP8266_FLASH_STORAGE_SIZE]; this->flash_storage_ = new uint32_t[ESP8266_FLASH_STORAGE_SIZE];
ESP_LOGVV(TAG, "Loading preferences from flash..."); ESP_LOGVV(TAG, "Loading preferences from flash...");
disable_interrupts();
spi_flash_read(get_esp8266_flash_address(), this->flash_storage_, ESP8266_FLASH_STORAGE_SIZE * 4); {
enable_interrupts(); InterruptLock lock;
spi_flash_read(get_esp8266_flash_address(), this->flash_storage_, ESP8266_FLASH_STORAGE_SIZE * 4);
}
} }
ESPPreferenceObject ESPPreferences::make_preference(size_t length, uint32_t type, bool in_flash) { ESPPreferenceObject ESPPreferences::make_preference(size_t length, uint32_t type, bool in_flash) {

View File

@@ -45,6 +45,9 @@ def validate_board(value):
validate_platform = cv.one_of('ESP32', 'ESP8266', upper=True) validate_platform = cv.one_of('ESP32', 'ESP8266', upper=True)
PLATFORMIO_ESP8266_LUT = { PLATFORMIO_ESP8266_LUT = {
'2.6.3': 'espressif8266@2.4.0',
'2.6.2': 'espressif8266@2.3.1',
'2.6.1': 'espressif8266@2.3.0',
'2.5.2': 'espressif8266@2.2.3', '2.5.2': 'espressif8266@2.2.3',
'2.5.1': 'espressif8266@2.1.0', '2.5.1': 'espressif8266@2.1.0',
'2.5.0': 'espressif8266@2.0.1', '2.5.0': 'espressif8266@2.0.1',
@@ -62,8 +65,8 @@ PLATFORMIO_ESP32_LUT = {
'1.0.1': 'espressif32@1.6.0', '1.0.1': 'espressif32@1.6.0',
'1.0.2': 'espressif32@1.9.0', '1.0.2': 'espressif32@1.9.0',
'1.0.3': 'espressif32@1.10.0', '1.0.3': 'espressif32@1.10.0',
'1.0.4': 'espressif32@1.11.0', '1.0.4': 'espressif32@1.12.1',
'RECOMMENDED': 'espressif32@1.11.0', 'RECOMMENDED': 'espressif32@1.12.1',
'LATEST': 'espressif32', 'LATEST': 'espressif32',
'DEV': ARDUINO_VERSION_ESP32_DEV, 'DEV': ARDUINO_VERSION_ESP32_DEV,
} }

View File

@@ -67,7 +67,9 @@ def initialize(config, subscriptions, on_message, username, password, client_id)
tls_version=tls_version, ciphers=None) tls_version=tls_version, ciphers=None)
try: try:
client.connect(str(config[CONF_MQTT][CONF_BROKER]), config[CONF_MQTT][CONF_PORT]) host = str(config[CONF_MQTT][CONF_BROKER])
port = int(config[CONF_MQTT][CONF_PORT])
client.connect(host, port)
except socket.error as err: except socket.error as err:
raise EsphomeError("Cannot connect to MQTT broker: {}".format(err)) raise EsphomeError("Cannot connect to MQTT broker: {}".format(err))
@@ -127,7 +129,7 @@ def clear_topic(config, topic, username=None, password=None, client_id=None):
# From marvinroger/async-mqtt-client -> scripts/get-fingerprint/get-fingerprint.py # From marvinroger/async-mqtt-client -> scripts/get-fingerprint/get-fingerprint.py
def get_fingerprint(config): def get_fingerprint(config):
addr = str(config[CONF_MQTT][CONF_BROKER]), config[CONF_MQTT][CONF_PORT] addr = str(config[CONF_MQTT][CONF_BROKER]), int(config[CONF_MQTT][CONF_PORT])
_LOGGER.info("Getting fingerprint from %s:%s", addr[0], addr[1]) _LOGGER.info("Getting fingerprint from %s:%s", addr[0], addr[1])
try: try:
cert_pem = ssl.get_server_certificate(addr) cert_pem = ssl.get_server_certificate(addr)

View File

@@ -60,6 +60,7 @@ FILTER_PLATFORMIO_LINES = [
r"Using cache: .*", r"Using cache: .*",
r'Installing dependencies', r'Installing dependencies',
r'.* @ .* is already installed', r'.* @ .* is already installed',
r'Building in .* mode',
] ]

View File

@@ -179,7 +179,7 @@ class _Schema(vol.Schema):
self._extra_schemas.append(validator) self._extra_schemas.append(validator)
return self return self
# pylint: disable=arguments-differ # pylint: disable=signature-differs,arguments-differ
def extend(self, *schemas, **kwargs): def extend(self, *schemas, **kwargs):
extra = kwargs.pop('extra', None) extra = kwargs.pop('extra', None)
if kwargs: if kwargs:

View File

@@ -42,7 +42,7 @@ build_flags = ${common.build_flags}
src_filter = ${common.src_filter} +<tests/livingroom8266.cpp> src_filter = ${common.src_filter} +<tests/livingroom8266.cpp>
[env:livingroom32] [env:livingroom32]
platform = espressif32@1.11.0 platform = espressif32@1.12.1
board = nodemcu-32s board = nodemcu-32s
framework = arduino framework = arduino
lib_deps = ${common.lib_deps} lib_deps = ${common.lib_deps}

View File

@@ -1,13 +1,13 @@
voluptuous==0.11.7 voluptuous==0.11.7
PyYAML==5.1.2 PyYAML==5.3.1
paho-mqtt==1.4.0 paho-mqtt==1.5.0
colorlog==4.0.2 colorlog==4.1.0
tornado==5.1.1 tornado==5.1.1
typing>=3.6.6;python_version<"3.5" typing>=3.6.6;python_version<"3.5"
protobuf==3.10.0 protobuf==3.11.3
tzlocal==2.0.0 tzlocal==2.0.0
pytz==2019.3 pytz==2020.1
pyserial==3.4 pyserial==3.4
ifaddr==0.1.6 ifaddr==0.1.6
platformio==4.0.3 platformio==4.3.4
esptool==2.7 esptool==2.8

View File

@@ -1,16 +1,16 @@
voluptuous==0.11.7 voluptuous==0.11.7
PyYAML==5.1.2 PyYAML==5.3.1
paho-mqtt==1.4.0 paho-mqtt==1.5.0
colorlog==4.0.2 colorlog==4.1.0
tornado==5.1.1 tornado==5.1.1
typing>=3.6.6;python_version<"3.5" typing>=3.6.6;python_version<"3.5"
protobuf==3.10.0 protobuf==3.11.3
tzlocal==2.0.0 tzlocal==2.0.0
pytz==2019.3 pytz==2020.1
pyserial==3.4 pyserial==3.4
ifaddr==0.1.6 ifaddr==0.1.6
platformio==4.0.3 platformio==4.3.4
esptool==2.7 esptool==2.8
pylint==1.9.4 ; python_version<"3" pylint==1.9.4 ; python_version<"3"
pylint==2.3.0 ; python_version>"3" pylint==2.3.0 ; python_version>"3"

View File

@@ -24,14 +24,14 @@ DOWNLOAD_URL = '{}/archive/v{}.zip'.format(GITHUB_URL, const.__version__)
REQUIRES = [ REQUIRES = [
'voluptuous==0.11.7', 'voluptuous==0.11.7',
'PyYAML==5.1.2', 'PyYAML==5.3.1',
'paho-mqtt==1.4.0', 'paho-mqtt==1.5.0',
'colorlog==4.0.2', 'colorlog==4.1.0',
'tornado==5.1.1', 'tornado==5.1.1',
'typing>=3.6.6;python_version<"3.6"', 'typing>=3.6.6;python_version<"3.6"',
'protobuf==3.10.0', 'protobuf==3.11.3',
'tzlocal==2.0.0', 'tzlocal==2.0.0',
'pytz==2019.3', 'pytz==2020.1',
'pyserial==3.4', 'pyserial==3.4',
'ifaddr==0.1.6', 'ifaddr==0.1.6',
] ]
@@ -41,8 +41,8 @@ REQUIRES = [
# This means they have to be in your $PATH. # This means they have to be in your $PATH.
if os.environ.get('ESPHOME_USE_SUBPROCESS') is None: if os.environ.get('ESPHOME_USE_SUBPROCESS') is None:
REQUIRES.extend([ REQUIRES.extend([
'platformio==4.0.3', 'platformio==4.3.4',
'esptool==2.7', 'esptool==2.8',
]) ])
CLASSIFIERS = [ CLASSIFIERS = [

View File

@@ -618,7 +618,7 @@ sensor:
name: "Windspeed" name: "Windspeed"
wind_direction_degrees: wind_direction_degrees:
name: "Winddirection Degrees" name: "Winddirection Degrees"
pin: pin:
number: GPIO04 number: GPIO04
mode: INPUT mode: INPUT
- platform: zyaura - platform: zyaura
@@ -1033,7 +1033,7 @@ light:
name: "Test For Custom Lambda Effect" name: "Test For Custom Lambda Effect"
lambda: |- lambda: |-
it[0] = current_color; it[0] = current_color;
- automation: - automation:
name: Custom Effect name: Custom Effect
sequence: sequence:
@@ -1105,6 +1105,11 @@ climate:
sensor: my_sensor sensor: my_sensor
- platform: coolix - platform: coolix
name: Coolix Climate name: Coolix Climate
- platform: fujitsu_general
name: Fujitsu General Climate
- platform: yashima
name: Yashima Climate
switch: switch:
- platform: gpio - platform: gpio
@@ -1302,7 +1307,7 @@ interval:
static uint16_t btn_left_state = id(btn_left)->get_value(); static uint16_t btn_left_state = id(btn_left)->get_value();
ESP_LOGD("adaptive touch", "___ Touch Pad '%s' (T%u): val: %u state: %u tres:%u", id(btn_left)->get_name().c_str(), id(btn_left)->get_touch_pad(), id(btn_left)->get_value(), btn_left_state, id(btn_left)->get_threshold()); ESP_LOGD("adaptive touch", "___ Touch Pad '%s' (T%u): val: %u state: %u tres:%u", id(btn_left)->get_name().c_str(), id(btn_left)->get_touch_pad(), id(btn_left)->get_value(), btn_left_state, id(btn_left)->get_threshold());
btn_left_state = ((uint32_t) id(btn_left)->get_value() + 63 * (uint32_t)btn_left_state) >> 6; btn_left_state = ((uint32_t) id(btn_left)->get_value() + 63 * (uint32_t)btn_left_state) >> 6;
id(btn_left)->set_threshold(btn_left_state * 0.9); id(btn_left)->set_threshold(btn_left_state * 0.9);