mirror of
https://github.com/esphome/esphome.git
synced 2026-09-16 17:48:40 +00:00
[esp32_ble_server][espnow][time] Fix logic bugs (#14553)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
3c7956e72d
commit
3db436e48e
@@ -7,6 +7,7 @@
|
||||
|
||||
#ifdef USE_ESP32
|
||||
|
||||
#include <algorithm>
|
||||
#include <nvs_flash.h>
|
||||
#include <freertos/FreeRTOSConfig.h>
|
||||
#include <esp_bt_main.h>
|
||||
@@ -38,21 +39,16 @@ void BLEServer::loop() {
|
||||
case RUNNING: {
|
||||
// Start all services that are pending to start
|
||||
if (!this->services_to_start_.empty()) {
|
||||
uint16_t index_to_remove = 0;
|
||||
// Iterate over the services to start
|
||||
for (unsigned i = 0; i < this->services_to_start_.size(); i++) {
|
||||
BLEService *service = this->services_to_start_[i];
|
||||
for (auto &service : this->services_to_start_) {
|
||||
if (service->is_created()) {
|
||||
service->start(); // Needs to be called once per characteristic in the service
|
||||
} else {
|
||||
index_to_remove = i + 1;
|
||||
}
|
||||
}
|
||||
// Remove the services that have been started
|
||||
if (index_to_remove > 0) {
|
||||
this->services_to_start_.erase(this->services_to_start_.begin(),
|
||||
this->services_to_start_.begin() + index_to_remove - 1);
|
||||
}
|
||||
// Remove services that have been started
|
||||
this->services_to_start_.erase(
|
||||
std::remove_if(this->services_to_start_.begin(), this->services_to_start_.end(),
|
||||
[](BLEService *service) { return service->is_starting() || service->is_running(); }),
|
||||
this->services_to_start_.end());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ class OnReceiveTrigger : public Trigger<const ESPNowRecvInfo &, const uint8_t *,
|
||||
|
||||
protected:
|
||||
bool has_address_{false};
|
||||
const uint8_t *address_[ESP_NOW_ETH_ALEN];
|
||||
uint8_t address_[ESP_NOW_ETH_ALEN];
|
||||
};
|
||||
class OnUnknownPeerTrigger : public Trigger<const ESPNowRecvInfo &, const uint8_t *, uint8_t>,
|
||||
public ESPNowUnknownPeerHandler {
|
||||
@@ -167,7 +167,7 @@ class OnBroadcastedTrigger : public Trigger<const ESPNowRecvInfo &, const uint8_
|
||||
|
||||
protected:
|
||||
bool has_address_{false};
|
||||
const uint8_t *address_[ESP_NOW_ETH_ALEN];
|
||||
uint8_t address_[ESP_NOW_ETH_ALEN];
|
||||
};
|
||||
|
||||
} // namespace esphome::espnow
|
||||
|
||||
@@ -90,7 +90,7 @@ void RealTimeClock::synchronize_epoch_(uint32_t epoch) {
|
||||
};
|
||||
struct timezone tz = {0, 0};
|
||||
int ret = settimeofday(&timev, &tz);
|
||||
if (ret == EINVAL) {
|
||||
if (ret != 0 && errno == EINVAL) {
|
||||
// Some ESP8266 frameworks abort when timezone parameter is not NULL
|
||||
// while ESP32 expects it not to be NULL
|
||||
ret = settimeofday(&timev, nullptr);
|
||||
|
||||
Reference in New Issue
Block a user