Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Commit

Permalink
ESP8266 SDK Core 2.3.0 compat (#563)
Browse files Browse the repository at this point in the history
* ESP8266 SDK Core 2.3.0 compat

* Lint
  • Loading branch information
OttoWinter committed Mar 24, 2019
1 parent 5f66f52 commit 3db10f4
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/esphome/defines.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#ifndef ESPHOME_DEFINES_H
#define ESPHOME_DEFINES_H

#ifdef ARDUINO_ARCH_ESP8266
#include <core_version.h>
#endif

#define ESPHOME_VERSION "1.13.0-dev"

#define HOT __attribute__((hot))
Expand Down Expand Up @@ -42,8 +46,10 @@
#define USE_PCA9685_OUTPUT
#define USE_GPIO_OUTPUT
#ifdef ARDUINO_ARCH_ESP8266
#ifndef ARDUINO_ESP8266_RELEASE_2_3_0
#define USE_ESP8266_PWM_OUTPUT
#endif
#endif
#define USE_LIGHT
#define USE_SWITCH
#define USE_OUTPUT_SWITCH
Expand Down
16 changes: 16 additions & 0 deletions src/esphome/esphal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,3 +266,19 @@ ISRInternalGPIOPin *GPIOPin::to_isr() const {
}

ESPHOME_NAMESPACE_END

#ifdef ARDUINO_ESP8266_RELEASE_2_3_0
// Fix 2.3.0 std missing memchr
extern "C" {
void *memchr(const void *s, int c, size_t n) {
if (n == 0)
return nullptr;
const uint8_t *p = reinterpret_cast<const uint8_t *>(s);
do {
if (*p++ == c)
return const_cast<void *>(reinterpret_cast<const void *>(p - 1));
} while (--n != 0);
return nullptr;
}
};
#endif
4 changes: 4 additions & 0 deletions src/esphome/light/neo_pixel_bus_light_output.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

#ifdef USE_NEO_PIXEL_BUS_LIGHT

#ifdef ARDUINO_ESP8266_RELEASE_2_3_0
#error The NeoPixelBus library requires at least arduino_core_version 2.4.x
#endif

#include "esphome/helpers.h"
#include "esphome/light/light_state.h"
#include "esphome/light/addressable_light.h"
Expand Down
4 changes: 2 additions & 2 deletions src/esphome/ota_component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ void OTAComponent::handle_() {
ESP_LOGV(TAG, "Auth: Nonce is %s", sbuf);

// Send nonce, 32 bytes hex MD5
if (this->client_.write(sbuf, 32) != 32) {
if (this->client_.write(reinterpret_cast<uint8_t *>(sbuf), 32) != 32) {
ESP_LOGW(TAG, "Auth: Writing nonce failed!");
goto error;
}
Expand Down Expand Up @@ -386,7 +386,7 @@ void OTAComponent::handle_() {
ESP_LOGW(TAG, "Update end failed! Error: %s", ss.c_str());
}
if (this->client_.connected()) {
this->client_.write(error_code);
this->client_.write(static_cast<uint8_t>(error_code));
this->client_.flush();
}
this->client_.stop();
Expand Down
4 changes: 4 additions & 0 deletions src/esphome/output/esp8266_pwm_output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

#ifdef USE_ESP8266_PWM_OUTPUT

#ifdef ARDUINO_ESP8266_RELEASE_2_3_0
#error ESP8266 PWM requires at least arduino_core_version 2.4.0
#endif

#include "esphome/output/esp8266_pwm_output.h"
#include "esphome/espmath.h"
#include "esphome/log.h"
Expand Down
13 changes: 10 additions & 3 deletions src/esphome/wifi_component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,10 @@ void WiFiComponent::setup_ap_config_() {
ESP_LOGCONFIG(TAG, " AP SSID: '%s'", this->ap_.get_ssid().c_str());
ESP_LOGCONFIG(TAG, " AP Password: '%s'", this->ap_.get_password().c_str());
if (this->ap_.get_manual_ip().has_value()) {
ESP_LOGCONFIG(TAG, " AP Static IP: '%s'", this->ap_.get_manual_ip()->static_ip.toString().c_str());
ESP_LOGCONFIG(TAG, " AP Gateway: '%s'", this->ap_.get_manual_ip()->gateway.toString().c_str());
ESP_LOGCONFIG(TAG, " AP Subnet: '%s'", this->ap_.get_manual_ip()->subnet.toString().c_str());
auto manual = *this->ap_.get_manual_ip();
ESP_LOGCONFIG(TAG, " AP Static IP: '%s'", manual.static_ip.toString().c_str());
ESP_LOGCONFIG(TAG, " AP Gateway: '%s'", manual.gateway.toString().c_str());
ESP_LOGCONFIG(TAG, " AP Subnet: '%s'", manual.subnet.toString().c_str());
}

this->ap_setup_ = this->wifi_start_ap_(this->ap_);
Expand Down Expand Up @@ -636,12 +637,14 @@ bool WiFiComponent::wifi_sta_connect_(WiFiAP ap) {
conf.bssid_set = 0;
}

#ifndef ARDUINO_ESP8266_RELEASE_2_3_0
if (ap.get_password().empty()) {
conf.threshold.authmode = AUTH_OPEN;
} else {
conf.threshold.authmode = AUTH_WPA_PSK;
}
conf.threshold.rssi = -127;
#endif

ETS_UART_INTR_DISABLE();
bool ret = wifi_station_set_config_current(&conf);
Expand Down Expand Up @@ -844,6 +847,7 @@ void WiFiComponent::wifi_event_callback(System_Event_t *event) {
ESP_LOGV(TAG, "Event: AP receive Probe Request MAC=%s RSSI=%d", format_mac_addr(it.mac).c_str(), it.rssi);
break;
}
#ifndef ARDUINO_ESP8266_RELEASE_2_3_0
case EVENT_OPMODE_CHANGED: {
auto it = event->event_info.opmode_changed;
ESP_LOGV(TAG, "Event: Changed Mode old=%s new=%s", get_op_mode_str(it.old_opmode),
Expand All @@ -856,6 +860,7 @@ void WiFiComponent::wifi_event_callback(System_Event_t *event) {
format_ip_addr(it.ip).c_str(), it.aid);
break;
}
#endif
default:
break;
}
Expand Down Expand Up @@ -904,6 +909,7 @@ bool WiFiComponent::wifi_scan_start_() {
config.bssid = nullptr;
config.channel = 0;
config.show_hidden = 1;
#ifndef ARDUINO_ESP8266_RELEASE_2_3_0
config.scan_type = WIFI_SCAN_TYPE_ACTIVE;
if (FIRST_SCAN) {
config.scan_time.active.min = 100;
Expand All @@ -912,6 +918,7 @@ bool WiFiComponent::wifi_scan_start_() {
config.scan_time.active.min = 400;
config.scan_time.active.max = 500;
}
#endif
FIRST_SCAN = false;
bool ret = wifi_station_scan(&config, &WiFiComponent::s_wifi_scan_done_callback);
if (!ret) {
Expand Down
6 changes: 6 additions & 0 deletions src/esphome/wifi_component.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define ESPHOME_WIFI_COMPONENT_H

#include <string>
#include "esphal.h"
#include <IPAddress.h>

#ifdef ARDUINO_ARCH_ESP32
Expand All @@ -12,6 +13,11 @@
#ifdef ARDUINO_ARCH_ESP8266
#include <ESP8266WiFiType.h>
#include <ESP8266WiFi.h>
#ifdef ARDUINO_ESP8266_RELEASE_2_3_0
extern "C" {
#include <user_interface.h>
};
#endif
#endif

#include "esphome/automation.h"
Expand Down

0 comments on commit 3db10f4

Please sign in to comment.