Added c6 support

This commit is contained in:
cjkas 2026-03-29 21:53:57 +02:00
parent aa81b95bee
commit 72bfd26443
15 changed files with 143 additions and 54 deletions

View file

@ -17,6 +17,8 @@ jobs:
name: ESP32-C3 name: ESP32-C3
- env: esp32s3 - env: esp32s3
name: ESP32-S3 name: ESP32-S3
- env: esp32c6
name: ESP32-C6
steps: steps:
- name: Check out code - name: Check out code

View file

@ -43,6 +43,14 @@ jobs:
fwname: SomfyController.ino.esp32s3.bin fwname: SomfyController.ino.esp32s3.bin
fsname: SomfyController.littlefs.esp32s3.bin fsname: SomfyController.littlefs.esp32s3.bin
obname: SomfyController.onboard.esp32s3.bin obname: SomfyController.onboard.esp32s3.bin
- env: esp32c6
name: ESP32-C6
chip: ESP32-C6
addr_bootloader: "0x0"
addr_fs: "0x310000"
fwname: SomfyController.ino.esp32c6.bin
fsname: SomfyController.littlefs.esp32c6.bin
obname: SomfyController.onboard.esp32c6.bin
steps: steps:
- name: Get Release - name: Get Release

View file

@ -53,3 +53,14 @@ board_build.partitions = esp32_3MB.csv
[env:esp32s3] [env:esp32s3]
board = esp32-s3-devkitc-1 board = esp32-s3-devkitc-1
[env:esp32c6]
platform = https://github.com/mnowak32/platform-espressif32.git#boards/seeed_xiao_esp32c6
platform_packages =
framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#3.0.4
framework-arduinoespressif32-libs @ https://github.com/espressif/arduino-esp32/releases/download/3.0.4/esp32-arduino-libs-3.0.4.zip
board = seeed_xiao_esp32c6
board_build.partitions = esp32_3MB.csv
build_flags =
${env.build_flags}
-I${platformio.packages_dir}/framework-arduinoespressif32/libraries/Network/src

View file

@ -616,7 +616,9 @@ bool ShadeConfigFile::restoreFile(SomfyShadeController *s, const char *filename,
if(opts.network) { if(opts.network) {
settings.IP.save(); settings.IP.save();
settings.WIFI.save(); settings.WIFI.save();
#ifndef CONFIG_IDF_TARGET_ESP32C6
settings.Ethernet.save(); settings.Ethernet.save();
#endif
} }
if(opts.mqtt) settings.MQTT.save(); if(opts.mqtt) settings.MQTT.save();
return true; return true;
@ -672,6 +674,7 @@ bool ShadeConfigFile::readNetRecord(restore_options_t &opts) {
if(opts.network) { if(opts.network) {
if(strncmp(settings.serverId, this->header.serverId, sizeof(settings.serverId)) == 0) { if(strncmp(settings.serverId, this->header.serverId, sizeof(settings.serverId)) == 0) {
ESP_LOGI(TAG, "Restoring Ethernet adapter settings"); ESP_LOGI(TAG, "Restoring Ethernet adapter settings");
#ifndef CONFIG_IDF_TARGET_ESP32C6
settings.Ethernet.boardType = this->readUInt8(1); settings.Ethernet.boardType = this->readUInt8(1);
settings.Ethernet.phyType = static_cast<eth_phy_type_t>(this->readUInt8(0)); settings.Ethernet.phyType = static_cast<eth_phy_type_t>(this->readUInt8(0));
settings.Ethernet.CLKMode = static_cast<eth_clock_mode_t>(this->readUInt8(0)); settings.Ethernet.CLKMode = static_cast<eth_clock_mode_t>(this->readUInt8(0));
@ -679,6 +682,7 @@ bool ShadeConfigFile::readNetRecord(restore_options_t &opts) {
settings.Ethernet.PWRPin = this->readInt8(1); settings.Ethernet.PWRPin = this->readInt8(1);
settings.Ethernet.MDCPin = this->readInt8(16); settings.Ethernet.MDCPin = this->readInt8(16);
settings.Ethernet.MDIOPin = this->readInt8(23); settings.Ethernet.MDIOPin = this->readInt8(23);
#endif
} }
} }
if(this->file.position() != startPos + this->header.netRecordSize) { if(this->file.position() != startPos + this->header.netRecordSize) {
@ -1035,6 +1039,7 @@ bool ShadeConfigFile::writeNetRecord() {
this->writeBool(settings.MQTT.pubDisco); this->writeBool(settings.MQTT.pubDisco);
this->writeVarString(settings.MQTT.rootTopic); this->writeVarString(settings.MQTT.rootTopic);
this->writeVarString(settings.MQTT.discoTopic); this->writeVarString(settings.MQTT.discoTopic);
#ifndef CONFIG_IDF_TARGET_ESP32C6
this->writeUInt8(settings.Ethernet.boardType); this->writeUInt8(settings.Ethernet.boardType);
this->writeUInt8(static_cast<uint8_t>(settings.Ethernet.phyType)); this->writeUInt8(static_cast<uint8_t>(settings.Ethernet.phyType));
this->writeUInt8(static_cast<uint8_t>(settings.Ethernet.CLKMode)); this->writeUInt8(static_cast<uint8_t>(settings.Ethernet.CLKMode));
@ -1042,6 +1047,9 @@ bool ShadeConfigFile::writeNetRecord() {
this->writeInt8(settings.Ethernet.PWRPin); this->writeInt8(settings.Ethernet.PWRPin);
this->writeInt8(settings.Ethernet.MDCPin); this->writeInt8(settings.Ethernet.MDCPin);
this->writeInt8(settings.Ethernet.MDIOPin, CFG_REC_END); this->writeInt8(settings.Ethernet.MDIOPin, CFG_REC_END);
#else
this->writeUInt8(0, CFG_REC_END);
#endif
return true; return true;
} }
bool ShadeConfigFile::writeTransRecord(transceiver_config_t &cfg) { bool ShadeConfigFile::writeTransRecord(transceiver_config_t &cfg) {

View file

@ -155,21 +155,14 @@ bool ConfigSettings::begin() {
case esp_chip_model_t::CHIP_ESP32S3: case esp_chip_model_t::CHIP_ESP32S3:
strcpy(this->chipModel, "s3"); strcpy(this->chipModel, "s3");
break; break;
case esp_chip_model_t::CHIP_ESP32S2:
strcpy(this->chipModel, "s2");
break;
case esp_chip_model_t::CHIP_ESP32C3: case esp_chip_model_t::CHIP_ESP32C3:
strcpy(this->chipModel, "c3"); strcpy(this->chipModel, "c3");
break; break;
// case esp_chip_model_t::CHIP_ESP32C2: #ifdef CHIP_ESP32C6
// strcpy(this->chipModel, "c2"); case esp_chip_model_t::CHIP_ESP32C6:
// break; strcpy(this->chipModel, "c6");
// case esp_chip_model_t::CHIP_ESP32C6:
// strcpy(this->chipModel, "c6");
// break;
case esp_chip_model_t::CHIP_ESP32H2:
strcpy(this->chipModel, "h2");
break; break;
#endif
default: default:
sprintf(this->chipModel, "UNK%d", static_cast<int>(ci.model)); sprintf(this->chipModel, "UNK%d", static_cast<int>(ci.model));
break; break;
@ -188,7 +181,9 @@ bool ConfigSettings::begin() {
this->Security.begin(); this->Security.begin();
this->IP.begin(); this->IP.begin();
this->WIFI.begin(); this->WIFI.begin();
#ifndef CONFIG_IDF_TARGET_ESP32C6
this->Ethernet.begin(); this->Ethernet.begin();
#endif
this->NTP.begin(); this->NTP.begin();
this->MQTT.begin(); this->MQTT.begin();
this->print(); this->print();
@ -258,7 +253,9 @@ void ConfigSettings::print() {
ESP_LOGD(TAG, "Connection Type: %u", (unsigned int) this->connType); ESP_LOGD(TAG, "Connection Type: %u", (unsigned int) this->connType);
this->NTP.print(); this->NTP.print();
if(this->connType == conn_types_t::wifi || this->connType == conn_types_t::unset) this->WIFI.print(); if(this->connType == conn_types_t::wifi || this->connType == conn_types_t::unset) this->WIFI.print();
#ifndef CONFIG_IDF_TARGET_ESP32C6
if(this->connType == conn_types_t::ethernet || this->connType == conn_types_t::ethernetpref) this->Ethernet.print(); if(this->connType == conn_types_t::ethernet || this->connType == conn_types_t::ethernetpref) this->Ethernet.print();
#endif
} }
void ConfigSettings::emitSockets() {} void ConfigSettings::emitSockets() {}
void ConfigSettings::emitSockets(uint8_t num) {} void ConfigSettings::emitSockets(uint8_t num) {}
@ -590,6 +587,7 @@ bool WifiSettings::ssidExists(const char *ssid) {
} }
return false; return false;
} }
#ifndef CONFIG_IDF_TARGET_ESP32C6
EthernetSettings::EthernetSettings() {} EthernetSettings::EthernetSettings() {}
bool EthernetSettings::begin() { bool EthernetSettings::begin() {
this->load(); this->load();
@ -653,6 +651,7 @@ void EthernetSettings::print() {
ESP_LOGD(TAG, "Ethernet Settings Board:%d PHYType:%d CLK:%d ADDR:%d PWR:%d MDC:%d MDIO:%d", ESP_LOGD(TAG, "Ethernet Settings Board:%d PHYType:%d CLK:%d ADDR:%d PWR:%d MDC:%d MDIO:%d",
this->boardType, this->phyType, this->CLKMode, this->phyAddress, this->PWRPin, this->MDCPin, this->MDIOPin); this->boardType, this->phyType, this->CLKMode, this->phyAddress, this->PWRPin, this->MDCPin, this->MDIOPin);
} }
#endif // CONFIG_IDF_TARGET_ESP32C6
void ConfigSettings::printAvailHeap() { void ConfigSettings::printAvailHeap() {
ESP_LOGD(TAG, "Max Heap: %u", (unsigned int)ESP.getMaxAllocHeap()); ESP_LOGD(TAG, "Max Heap: %u", (unsigned int)ESP.getMaxAllocHeap());
ESP_LOGD(TAG, "Free Heap: %u", (unsigned int)ESP.getFreeHeap()); ESP_LOGD(TAG, "Free Heap: %u", (unsigned int)ESP.getFreeHeap());

View file

@ -1,5 +1,7 @@
#include <ArduinoJson.h> #include <ArduinoJson.h>
#ifndef CONFIG_IDF_TARGET_ESP32C6
#include <ETH.h> #include <ETH.h>
#endif
#ifndef configsettings_h #ifndef configsettings_h
#define configsettings_h #define configsettings_h
#include "WResp.h" #include "WResp.h"
@ -88,6 +90,7 @@ class WifiSettings: BaseSettings {
void print(); void print();
}; };
#ifndef CONFIG_IDF_TARGET_ESP32C6
class EthernetSettings: BaseSettings { class EthernetSettings: BaseSettings {
public: public:
EthernetSettings(); EthernetSettings();
@ -108,6 +111,7 @@ class EthernetSettings: BaseSettings {
void print(); void print();
bool usesPin(uint8_t pin); bool usesPin(uint8_t pin);
}; };
#endif
class IPSettings: BaseSettings { class IPSettings: BaseSettings {
public: public:
IPSettings(); IPSettings();
@ -180,7 +184,9 @@ class ConfigSettings: BaseSettings {
uint8_t status; uint8_t status;
IPSettings IP; IPSettings IP;
WifiSettings WIFI; WifiSettings WIFI;
#ifndef CONFIG_IDF_TARGET_ESP32C6
EthernetSettings Ethernet; EthernetSettings Ethernet;
#endif
NTPSettings NTP; NTPSettings NTP;
MQTTSettings MQTT; MQTTSettings MQTT;
SecuritySettings Security; SecuritySettings Security;

View file

@ -1,10 +1,12 @@
#ifndef CONFIG_IDF_TARGET_ESP32C6
#include <ETH.h> #include <ETH.h>
#endif
#include <WiFi.h> #include <WiFi.h>
#include <ESPmDNS.h> #include <ESPmDNS.h>
#include <esp_task_wdt.h> #include <esp_task_wdt.h>
#include "esp_log.h" #include "esp_log.h"
#include "ConfigSettings.h" #include "ConfigSettings.h"
#include "Network.h" #include "ESPNetwork.h"
#include "Web.h" #include "Web.h"
#include "Sockets.h" #include "Sockets.h"
#include "Utils.h" #include "Utils.h"
@ -18,7 +20,7 @@ extern Web webServer;
extern SocketEmitter sockEmit; extern SocketEmitter sockEmit;
extern MQTTClass mqtt; extern MQTTClass mqtt;
extern rebootDelay_t rebootDelay; extern rebootDelay_t rebootDelay;
extern Network net; extern ESPNetwork net;
extern SomfyShadeController somfy; extern SomfyShadeController somfy;
static unsigned long _lastHeapEmit = 0; static unsigned long _lastHeapEmit = 0;
@ -27,13 +29,13 @@ static bool _apScanning = false;
static uint32_t _lastMaxHeap = 0; static uint32_t _lastMaxHeap = 0;
static uint32_t _lastHeap = 0; static uint32_t _lastHeap = 0;
int connectRetries = 0; int connectRetries = 0;
void Network::end() { void ESPNetwork::end() {
SSDP.end(); SSDP.end();
mqtt.end(); mqtt.end();
sockEmit.end(); sockEmit.end();
delay(100); delay(100);
} }
bool Network::setup() { bool ESPNetwork::setup() {
WiFi.setScanMethod(WIFI_ALL_CHANNEL_SCAN); WiFi.setScanMethod(WIFI_ALL_CHANNEL_SCAN);
WiFi.setSortMethod(WIFI_CONNECT_AP_BY_SIGNAL); WiFi.setSortMethod(WIFI_CONNECT_AP_BY_SIGNAL);
WiFi.persistent(false); WiFi.persistent(false);
@ -50,22 +52,24 @@ bool Network::setup() {
sockEmit.begin(); sockEmit.begin();
return true; return true;
} }
conn_types_t Network::preferredConnType() { conn_types_t ESPNetwork::preferredConnType() {
switch(settings.connType) { switch(settings.connType) {
case conn_types_t::wifi: case conn_types_t::wifi:
return settings.WIFI.ssid[0] != '\0' ? conn_types_t::wifi : conn_types_t::ap; return settings.WIFI.ssid[0] != '\0' ? conn_types_t::wifi : conn_types_t::ap;
case conn_types_t::unset: case conn_types_t::unset:
case conn_types_t::ap: case conn_types_t::ap:
return conn_types_t::ap; return conn_types_t::ap;
#ifndef CONFIG_IDF_TARGET_ESP32C6
case conn_types_t::ethernetpref: case conn_types_t::ethernetpref:
return settings.WIFI.ssid[0] != '\0' && (!ETH.linkUp() && this->ethStarted) ? conn_types_t::wifi : conn_types_t::ethernet; return settings.WIFI.ssid[0] != '\0' && (!ETH.linkUp() && this->ethStarted) ? conn_types_t::wifi : conn_types_t::ethernet;
case conn_types_t::ethernet: case conn_types_t::ethernet:
return ETH.linkUp() || !this->ethStarted ? conn_types_t::ethernet : conn_types_t::ap; return ETH.linkUp() || !this->ethStarted ? conn_types_t::ethernet : conn_types_t::ap;
#endif
default: default:
return settings.connType; return settings.connType;
} }
} }
void Network::loop() { void ESPNetwork::loop() {
// ORDER OF OPERATIONS: // ORDER OF OPERATIONS:
// ---------------------------------------------- // ----------------------------------------------
// 1. If we are in the middle of a connection process we need to simply bail after the connect method. The // 1. If we are in the middle of a connection process we need to simply bail after the connect method. The
@ -156,7 +160,7 @@ void Network::loop() {
} }
else if(!settings.ssdpBroadcast && SSDP.isStarted) SSDP.end(); else if(!settings.ssdpBroadcast && SSDP.isStarted) SSDP.end();
} }
bool Network::changeAP(const uint8_t *bssid, const int32_t channel) { bool ESPNetwork::changeAP(const uint8_t *bssid, const int32_t channel) {
esp_task_wdt_reset(); // Make sure we do not reboot here. esp_task_wdt_reset(); // Make sure we do not reboot here.
if(SSDP.isStarted) SSDP.end(); if(SSDP.isStarted) SSDP.end();
mqtt.disconnect(); mqtt.disconnect();
@ -169,7 +173,7 @@ bool Network::changeAP(const uint8_t *bssid, const int32_t channel) {
this->connectStart = millis(); this->connectStart = millis();
return false; return false;
} }
void Network::emitSockets() { void ESPNetwork::emitSockets() {
this->emitHeap(); this->emitHeap();
if(this->needsBroadcast || if(this->needsBroadcast ||
(this->connType == conn_types_t::wifi && (abs(abs(WiFi.RSSI()) - abs(this->lastRSSI)) > 1 || WiFi.channel() != this->lastChannel))) { (this->connType == conn_types_t::wifi && (abs(abs(WiFi.RSSI()) - abs(this->lastRSSI)) > 1 || WiFi.channel() != this->lastChannel))) {
@ -178,7 +182,8 @@ void Network::emitSockets() {
this->needsBroadcast = false; this->needsBroadcast = false;
} }
} }
void Network::emitSockets(uint8_t num) { void ESPNetwork::emitSockets(uint8_t num) {
#ifndef CONFIG_IDF_TARGET_ESP32C6
if(this->connType == conn_types_t::ethernet) { if(this->connType == conn_types_t::ethernet) {
JsonSockEvent *json = sockEmit.beginEmit("ethernet"); JsonSockEvent *json = sockEmit.beginEmit("ethernet");
json->beginObject(); json->beginObject();
@ -188,7 +193,9 @@ void Network::emitSockets(uint8_t num) {
json->endObject(); json->endObject();
sockEmit.endEmit(num); sockEmit.endEmit(num);
} }
else { else
#endif
{
if(WiFi.status() == WL_CONNECTED) { if(WiFi.status() == WL_CONNECTED) {
JsonSockEvent *json = sockEmit.beginEmit("wifiStrength"); JsonSockEvent *json = sockEmit.beginEmit("wifiStrength");
json->beginObject(); json->beginObject();
@ -222,7 +229,7 @@ void Network::emitSockets(uint8_t num) {
} }
this->emitHeap(num); this->emitHeap(num);
} }
void Network::setConnected(conn_types_t connType) { void ESPNetwork::setConnected(conn_types_t connType) {
esp_task_wdt_reset(); esp_task_wdt_reset();
this->connType = connType; this->connType = connType;
this->connectTime = millis(); this->connectTime = millis();
@ -240,6 +247,7 @@ void Network::setConnected(conn_types_t connType) {
this->channel = WiFi.channel(); this->channel = WiFi.channel();
this->connectAttempts++; this->connectAttempts++;
} }
#ifndef CONFIG_IDF_TARGET_ESP32C6
else if(this->connType == conn_types_t::ethernet) { else if(this->connType == conn_types_t::ethernet) {
if(this->softAPOpened) { if(this->softAPOpened) {
ESP_LOGI(TAG, "Disconnecting from SoftAP"); ESP_LOGI(TAG, "Disconnecting from SoftAP");
@ -250,6 +258,7 @@ void Network::setConnected(conn_types_t connType) {
this->_connecting = false; this->_connecting = false;
this->wifiFallback = false; this->wifiFallback = false;
} }
#endif // CONFIG_IDF_TARGET_ESP32C6
// NET: Begin this in the startup. // NET: Begin this in the startup.
//sockEmit.begin(); //sockEmit.begin();
esp_task_wdt_reset(); esp_task_wdt_reset();
@ -265,6 +274,7 @@ void Network::setConnected(conn_types_t connType) {
settings.IP.dns2 = WiFi.dnsIP(1); settings.IP.dns2 = WiFi.dnsIP(1);
} }
} }
#ifndef CONFIG_IDF_TARGET_ESP32C6
else { else {
ESP_LOGI(TAG, "Successfully Connected to Ethernet!!! %s%s %dMbps", ETH.localIP().toString().c_str(), ETH.fullDuplex() ? " FULL DUPLEX" : "", ETH.linkSpeed()); ESP_LOGI(TAG, "Successfully Connected to Ethernet!!! %s%s %dMbps", ETH.localIP().toString().c_str(), ETH.fullDuplex() ? " FULL DUPLEX" : "", ETH.linkSpeed());
if(settings.IP.dhcp) { if(settings.IP.dhcp) {
@ -284,14 +294,17 @@ void Network::setConnected(conn_types_t connType) {
sockEmit.endEmit(); sockEmit.endEmit();
esp_task_wdt_reset(); esp_task_wdt_reset();
} }
#endif
} }
else { else {
if(this->connType == conn_types_t::wifi) { if(this->connType == conn_types_t::wifi) {
ESP_LOGI(TAG, "Reconnected after %.3fsec IP: %s %s CH:%d (%d dBm) Disconnected %d times", 1.0 * (millis() - this->connectStart)/1000, WiFi.localIP().toString().c_str(), this->mac.c_str(), this->channel, this->strength, this->connectAttempts - 1); ESP_LOGI(TAG, "Reconnected after %.3fsec IP: %s %s CH:%d (%d dBm) Disconnected %d times", 1.0 * (millis() - this->connectStart)/1000, WiFi.localIP().toString().c_str(), this->mac.c_str(), this->channel, this->strength, this->connectAttempts - 1);
} }
#ifndef CONFIG_IDF_TARGET_ESP32C6
else { else {
ESP_LOGI(TAG, "Reconnected after %.3fsec IP: %s%s %dMbps Disconnected %d times", 1.0 * (millis() - this->connectStart)/1000, ETH.localIP().toString().c_str(), ETH.fullDuplex() ? " FULL DUPLEX" : "", ETH.linkSpeed(), this->connectAttempts - 1); ESP_LOGI(TAG, "Reconnected after %.3fsec IP: %s%s %dMbps Disconnected %d times", 1.0 * (millis() - this->connectStart)/1000, ETH.localIP().toString().c_str(), ETH.fullDuplex() ? " FULL DUPLEX" : "", ETH.linkSpeed(), this->connectAttempts - 1);
} }
#endif
} }
SSDP.setHTTPPort(80); SSDP.setHTTPPort(80);
SSDP.setSchemaURL(0, "upnp.xml"); SSDP.setSchemaURL(0, "upnp.xml");
@ -335,7 +348,8 @@ void Network::setConnected(conn_types_t connType) {
settings.printAvailHeap(); settings.printAvailHeap();
this->needsBroadcast = true; this->needsBroadcast = true;
} }
bool Network::connectWired() { #ifndef CONFIG_IDF_TARGET_ESP32C6
bool ESPNetwork::connectWired() {
if(ETH.linkUp()) { if(ETH.linkUp()) {
// If the ethernet link is re-established then we need to shut down wifi. // If the ethernet link is re-established then we need to shut down wifi.
if(WiFi.status() == WL_CONNECTED) { if(WiFi.status() == WL_CONNECTED) {
@ -391,8 +405,10 @@ bool Network::connectWired() {
this->connectStart = millis(); this->connectStart = millis();
return true; return true;
} }
void Network::updateHostname() { #endif // CONFIG_IDF_TARGET_ESP32C6
void ESPNetwork::updateHostname() {
if(settings.hostname[0] != '\0' && this->connected()) { if(settings.hostname[0] != '\0' && this->connected()) {
#ifndef CONFIG_IDF_TARGET_ESP32C6
if(this->connType == conn_types_t::ethernet && if(this->connType == conn_types_t::ethernet &&
strcmp(settings.hostname, ETH.getHostname()) != 0) { strcmp(settings.hostname, ETH.getHostname()) != 0) {
ESP_LOGD(TAG, "Updating host name to %s...", settings.hostname); ESP_LOGD(TAG, "Updating host name to %s...", settings.hostname);
@ -400,7 +416,9 @@ void Network::updateHostname() {
MDNS.setInstanceName(settings.hostname); MDNS.setInstanceName(settings.hostname);
SSDP.setName(0, settings.hostname); SSDP.setName(0, settings.hostname);
} }
else if(strcmp(settings.hostname, WiFi.getHostname()) != 0) { else
#endif
if(strcmp(settings.hostname, WiFi.getHostname()) != 0) {
ESP_LOGD(TAG, "Updating host name to %s...", settings.hostname); ESP_LOGD(TAG, "Updating host name to %s...", settings.hostname);
WiFi.setHostname(settings.hostname); WiFi.setHostname(settings.hostname);
MDNS.setInstanceName(settings.hostname); MDNS.setInstanceName(settings.hostname);
@ -408,7 +426,7 @@ void Network::updateHostname() {
} }
} }
} }
bool Network::connectWiFi(const uint8_t *bssid, const int32_t channel) { bool ESPNetwork::connectWiFi(const uint8_t *bssid, const int32_t channel) {
if(this->softAPOpened && WiFi.softAPgetStationNum() > 0) { if(this->softAPOpened && WiFi.softAPgetStationNum() > 0) {
// There is a client connected to the soft AP. We do not want to close out the connection. While both the // There is a client connected to the soft AP. We do not want to close out the connection. While both the
// Soft AP and a wifi connection can coexist on ESP32 the performance is abysmal. // Soft AP and a wifi connection can coexist on ESP32 the performance is abysmal.
@ -474,15 +492,18 @@ bool Network::connectWiFi(const uint8_t *bssid, const int32_t channel) {
this->connectStart = millis(); this->connectStart = millis();
return true; return true;
} }
bool Network::connect(conn_types_t ctype) { bool ESPNetwork::connect(conn_types_t ctype) {
esp_task_wdt_reset(); esp_task_wdt_reset();
if(this->connecting()) return true; if(this->connecting()) return true;
if(this->disconnectTime == 0) this->disconnectTime = millis(); if(this->disconnectTime == 0) this->disconnectTime = millis();
#ifndef CONFIG_IDF_TARGET_ESP32C6
if(ctype == conn_types_t::ethernet && this->connType != conn_types_t::ethernet) { if(ctype == conn_types_t::ethernet && this->connType != conn_types_t::ethernet) {
// Here we need to call the connect to ethernet. // Here we need to call the connect to ethernet.
this->connectWired(); this->connectWired();
} }
else if(ctype == conn_types_t::ap || (!this->connected() && millis() > this->disconnectTime + CONNECT_TIMEOUT)) { else
#endif
if(ctype == conn_types_t::ap || (!this->connected() && millis() > this->disconnectTime + CONNECT_TIMEOUT)) {
if(!this->softAPOpened && !this->openingSoftAP) { if(!this->softAPOpened && !this->openingSoftAP) {
this->disconnectTime = millis(); this->disconnectTime = millis();
this->openSoftAP(); this->openSoftAP();
@ -499,7 +520,7 @@ bool Network::connect(conn_types_t ctype) {
return true; return true;
} }
uint32_t Network::getChipId() { uint32_t ESPNetwork::getChipId() {
uint32_t chipId = 0; uint32_t chipId = 0;
uint64_t mac = ESP.getEfuseMac(); uint64_t mac = ESP.getEfuseMac();
for(int i=0; i<17; i=i+8) { for(int i=0; i<17; i=i+8) {
@ -507,7 +528,7 @@ uint32_t Network::getChipId() {
} }
return chipId; return chipId;
} }
bool Network::getStrongestAP(const char *ssid, uint8_t *bssid, int32_t *channel) { bool ESPNetwork::getStrongestAP(const char *ssid, uint8_t *bssid, int32_t *channel) {
// The new AP must be at least 10dbm greater. // The new AP must be at least 10dbm greater.
int32_t strength = this->connected() ? WiFi.RSSI() + 10 : -127; int32_t strength = this->connected() ? WiFi.RSSI() + 10 : -127;
int32_t chan = -1; int32_t chan = -1;
@ -528,7 +549,7 @@ bool Network::getStrongestAP(const char *ssid, uint8_t *bssid, int32_t *channel)
WiFi.scanDelete(); WiFi.scanDelete();
return chan > 0; return chan > 0;
} }
bool Network::openSoftAP() { bool ESPNetwork::openSoftAP() {
if(this->softAPOpened || this->openingSoftAP) return true; if(this->softAPOpened || this->openingSoftAP) return true;
if(this->connected()) WiFi.disconnect(false); if(this->connected()) WiFi.disconnect(false);
this->openingSoftAP = true; this->openingSoftAP = true;
@ -538,20 +559,22 @@ bool Network::openSoftAP() {
delay(200); delay(200);
return true; return true;
} }
bool Network::connected() { bool ESPNetwork::connected() {
if(this->connecting()) return false; if(this->connecting()) return false;
else if(this->connType == conn_types_t::unset) return false; else if(this->connType == conn_types_t::unset) return false;
else if(this->connType == conn_types_t::wifi) return WiFi.status() == WL_CONNECTED; else if(this->connType == conn_types_t::wifi) return WiFi.status() == WL_CONNECTED;
#ifndef CONFIG_IDF_TARGET_ESP32C6
else if(this->connType == conn_types_t::ethernet) return ETH.linkUp(); else if(this->connType == conn_types_t::ethernet) return ETH.linkUp();
#endif
else return this->connType != conn_types_t::unset; else return this->connType != conn_types_t::unset;
return false; return false;
} }
bool Network::connecting() { bool ESPNetwork::connecting() {
if(this->_connecting && millis() > this->connectStart + CONNECT_TIMEOUT) this->_connecting = false; if(this->_connecting && millis() > this->connectStart + CONNECT_TIMEOUT) this->_connecting = false;
return this->_connecting; return this->_connecting;
} }
void Network::clearConnecting() { this->_connecting = false; } void ESPNetwork::clearConnecting() { this->_connecting = false; }
void Network::networkEvent(WiFiEvent_t event) { void ESPNetwork::networkEvent(WiFiEvent_t event) {
switch(event) { switch(event) {
case ARDUINO_EVENT_WIFI_READY: ESP_LOGI(TAG, "(evt) WiFi interface ready"); break; case ARDUINO_EVENT_WIFI_READY: ESP_LOGI(TAG, "(evt) WiFi interface ready"); break;
case ARDUINO_EVENT_WIFI_SCAN_DONE: case ARDUINO_EVENT_WIFI_SCAN_DONE:
@ -579,6 +602,7 @@ void Network::networkEvent(WiFiEvent_t event) {
net.setConnected(conn_types_t::wifi); net.setConnected(conn_types_t::wifi);
break; break;
case ARDUINO_EVENT_WIFI_STA_LOST_IP: ESP_LOGW(TAG, "Lost IP address and IP address is reset to 0"); break; case ARDUINO_EVENT_WIFI_STA_LOST_IP: ESP_LOGW(TAG, "Lost IP address and IP address is reset to 0"); break;
#ifndef CONFIG_IDF_TARGET_ESP32C6
case ARDUINO_EVENT_ETH_GOT_IP: case ARDUINO_EVENT_ETH_GOT_IP:
// If the Wifi is connected then drop that connection // If the Wifi is connected then drop that connection
if(WiFi.status() == WL_CONNECTED) WiFi.disconnect(true); if(WiFi.status() == WL_CONNECTED) WiFi.disconnect(true);
@ -612,6 +636,7 @@ void Network::networkEvent(WiFiEvent_t event) {
net.connType = conn_types_t::unset; net.connType = conn_types_t::unset;
net.ethStarted = false; net.ethStarted = false;
break; break;
#endif
case ARDUINO_EVENT_WIFI_AP_START: case ARDUINO_EVENT_WIFI_AP_START:
ESP_LOGI(TAG, "(evt) WiFi SoftAP Started IP: %s", WiFi.softAPIP().toString().c_str()); ESP_LOGI(TAG, "(evt) WiFi SoftAP Started IP: %s", WiFi.softAPIP().toString().c_str());
net.openingSoftAP = false; net.openingSoftAP = false;
@ -622,12 +647,14 @@ void Network::networkEvent(WiFiEvent_t event) {
net.softAPOpened = false; net.softAPOpened = false;
break; break;
default: default:
#ifndef CONFIG_IDF_TARGET_ESP32C6
if(event > ARDUINO_EVENT_ETH_START) if(event > ARDUINO_EVENT_ETH_START)
ESP_LOGW(TAG, "(evt) Unknown Ethernet Event %d", event); ESP_LOGW(TAG, "(evt) Unknown Ethernet Event %d", event);
#endif
break; break;
} }
} }
void Network::emitHeap(uint8_t num) { void ESPNetwork::emitHeap(uint8_t num) {
bool bEmit = false; bool bEmit = false;
bool bTimeEmit = millis() - _lastHeapEmit > 15000; bool bTimeEmit = millis() - _lastHeapEmit > 15000;
bool bRoomEmit = false; bool bRoomEmit = false;

View file

@ -1,13 +1,14 @@
#include <Arduino.h> #include <Arduino.h>
#include <WiFi.h>
#ifndef Network_h #ifndef ESPNetwork_h
#define Network_h #define ESPNetwork_h
//enum class conn_types_t : byte; //enum class conn_types_t : byte;
#define CONNECT_TIMEOUT 20000 #define CONNECT_TIMEOUT 20000
#define SSID_SCAN_INTERVAL 60000 #define SSID_SCAN_INTERVAL 60000
class Network { class ESPNetwork {
protected: protected:
unsigned long lastEmit = 0; unsigned long lastEmit = 0;
unsigned long lastMDNS = 0; unsigned long lastMDNS = 0;

View file

@ -3,6 +3,7 @@
#include <Update.h> #include <Update.h>
#include <HTTPClient.h> #include <HTTPClient.h>
#include <esp_task_wdt.h> #include <esp_task_wdt.h>
#include <esp_chip_info.h>
#include "esp_log.h" #include "esp_log.h"
#include "ConfigSettings.h" #include "ConfigSettings.h"
#include "GitOTA.h" #include "GitOTA.h"
@ -11,7 +12,7 @@
#include "Somfy.h" #include "Somfy.h"
#include "Web.h" #include "Web.h"
#include "WResp.h" #include "WResp.h"
#include "Network.h" #include "ESPNetwork.h"
@ -21,7 +22,7 @@ extern SocketEmitter sockEmit;
extern SomfyShadeController somfy; extern SomfyShadeController somfy;
extern rebootDelay_t rebootDelay; extern rebootDelay_t rebootDelay;
extern Web webServer; extern Web webServer;
extern Network net; extern ESPNetwork net;
static const char *TAG = "OTA"; static const char *TAG = "OTA";

View file

@ -6,7 +6,7 @@
#include "ConfigSettings.h" #include "ConfigSettings.h"
#include "MQTT.h" #include "MQTT.h"
#include "Somfy.h" #include "Somfy.h"
#include "Network.h" #include "ESPNetwork.h"
#include "Utils.h" #include "Utils.h"
static const char *TAG = "MQTT"; static const char *TAG = "MQTT";
@ -19,7 +19,7 @@ static char g_content[MQTT_MAX_RESPONSE];
extern ConfigSettings settings; extern ConfigSettings settings;
extern SomfyShadeController somfy; extern SomfyShadeController somfy;
extern Network net; extern ESPNetwork net;
extern rebootDelay_t rebootDelay; extern rebootDelay_t rebootDelay;

View file

@ -383,6 +383,9 @@ void SSDPClass::_parsePacket(ssdp_packet_t *pkt, AsyncUDPPacket &p) {
IPAddress SSDPClass::localIP() IPAddress SSDPClass::localIP()
{ {
// Make sure we don't get a null IPAddress. // Make sure we don't get a null IPAddress.
#ifdef CONFIG_IDF_TARGET_ESP32C6
return WiFi.localIP();
#else
tcpip_adapter_ip_info_t ip; tcpip_adapter_ip_info_t ip;
if (WiFi.getMode() == WIFI_STA) { if (WiFi.getMode() == WIFI_STA) {
if (tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &ip)) { if (tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &ip)) {
@ -394,6 +397,7 @@ IPAddress SSDPClass::localIP()
} }
} }
return IPAddress(ip.ip.addr); return IPAddress(ip.ip.addr);
#endif
} }
void SSDPClass::_sendResponse(IPAddress addr, uint16_t port, UPNPDeviceType *d, const char *st, response_types_t responseType) { void SSDPClass::_sendResponse(IPAddress addr, uint16_t port, UPNPDeviceType *d, const char *st, response_types_t responseType) {
char buffer[1460]; char buffer[1460];

View file

@ -5,13 +5,13 @@
#include "Sockets.h" #include "Sockets.h"
#include "ConfigSettings.h" #include "ConfigSettings.h"
#include "Somfy.h" #include "Somfy.h"
#include "Network.h" #include "ESPNetwork.h"
#include "GitOTA.h" #include "GitOTA.h"
static const char *TAG = "Sockets"; static const char *TAG = "Sockets";
extern ConfigSettings settings; extern ConfigSettings settings;
extern Network net; extern ESPNetwork net;
extern SomfyShadeController somfy; extern SomfyShadeController somfy;
extern SocketEmitter sockEmit; extern SocketEmitter sockEmit;
extern GitUpdater git; extern GitUpdater git;

View file

@ -2,6 +2,7 @@
#include <ELECHOUSE_CC1101_SRC_DRV.h> #include <ELECHOUSE_CC1101_SRC_DRV.h>
#include <SPI.h> #include <SPI.h>
#include <esp_task_wdt.h> #include <esp_task_wdt.h>
#include <esp_chip_info.h>
#include "esp_log.h" #include "esp_log.h"
#include "Utils.h" #include "Utils.h"
#include "ConfigSettings.h" #include "ConfigSettings.h"
@ -3159,12 +3160,14 @@ int8_t SomfyShade::validateJSON(JsonObject &obj) {
(myPin != 255 && somfy.transceiver.usesPin(myPin))) (myPin != 255 && somfy.transceiver.usesPin(myPin)))
ret = -10; ret = -10;
} }
#ifndef CONFIG_IDF_TARGET_ESP32C6
if(settings.connType == conn_types_t::ethernet || settings.connType == conn_types_t::ethernetpref) { if(settings.connType == conn_types_t::ethernet || settings.connType == conn_types_t::ethernetpref) {
if((upPin != 255 && settings.Ethernet.usesPin(upPin)) || if((upPin != 255 && settings.Ethernet.usesPin(upPin)) ||
(downPin != 255 && somfy.transceiver.usesPin(downPin)) || (downPin != 255 && somfy.transceiver.usesPin(downPin)) ||
(myPin != 255 && somfy.transceiver.usesPin(myPin))) (myPin != 255 && somfy.transceiver.usesPin(myPin)))
ret = -11; ret = -11;
} }
#endif
if(ret == 0) { if(ret == 0) {
for(uint8_t i = 0; i < SOMFY_MAX_SHADES; i++) { for(uint8_t i = 0; i < SOMFY_MAX_SHADES; i++) {
SomfyShade *shade = &somfy.shades[i]; SomfyShade *shade = &somfy.shades[i];
@ -4688,6 +4691,16 @@ void transceiver_config_t::load() {
this->SCKPin = 15; this->SCKPin = 15;
this->CSNPin = 14; this->CSNPin = 14;
break; break;
#ifdef CHIP_ESP32C6
case esp_chip_model_t::CHIP_ESP32C6:
this->TXPin = 13;
this->RXPin = 12;
this->MOSIPin = 16;
this->MISOPin = 17;
this->SCKPin = 15;
this->CSNPin = 14;
break;
#endif
default: default:
this->TXPin = 13; this->TXPin = 13;
this->RXPin = 12; this->RXPin = 12;

View file

@ -3,7 +3,7 @@
#include <LittleFS.h> #include <LittleFS.h>
#include <esp_task_wdt.h> #include <esp_task_wdt.h>
#include "ConfigSettings.h" #include "ConfigSettings.h"
#include "Network.h" #include "ESPNetwork.h"
#include "Web.h" #include "Web.h"
#include "Sockets.h" #include "Sockets.h"
#include "Utils.h" #include "Utils.h"
@ -17,7 +17,7 @@ static const char *TAG = "Main";
ConfigSettings settings; ConfigSettings settings;
Web webServer; Web webServer;
SocketEmitter sockEmit; SocketEmitter sockEmit;
Network net; ESPNetwork net;
rebootDelay_t rebootDelay; rebootDelay_t rebootDelay;
SomfyShadeController somfy; SomfyShadeController somfy;
MQTTClass mqtt; MQTTClass mqtt;
@ -89,7 +89,12 @@ void setup() {
net.setup(); net.setup();
somfy.begin(); somfy.begin();
//git.checkForUpdate(); //git.checkForUpdate();
#if ESP_ARDUINO_VERSION_MAJOR >= 3
const esp_task_wdt_config_t wdt_config = { .timeout_ms = 15000, .idle_core_mask = 1, .trigger_panic = true };
esp_task_wdt_init(&wdt_config);
#else
esp_task_wdt_init(15, true); //enable panic so ESP32 restarts esp_task_wdt_init(15, true); //enable panic so ESP32 restarts
#endif
esp_task_wdt_add(NULL); //add current thread to WDT watch esp_task_wdt_add(NULL); //add current thread to WDT watch
} }

View file

@ -13,7 +13,7 @@
#include "Web.h" #include "Web.h"
#include "MQTT.h" #include "MQTT.h"
#include "GitOTA.h" #include "GitOTA.h"
#include "Network.h" #include "ESPNetwork.h"
#include <AsyncTCP.h> #include <AsyncTCP.h>
#include <ESPAsyncWebServer.h> #include <ESPAsyncWebServer.h>
#include <AsyncJson.h> #include <AsyncJson.h>
@ -25,7 +25,7 @@ extern SomfyShadeController somfy;
extern Web webServer; extern Web webServer;
extern MQTTClass mqtt; extern MQTTClass mqtt;
extern GitUpdater git; extern GitUpdater git;
extern Network net; extern ESPNetwork net;
//#define WEB_MAX_RESPONSE 34768 //#define WEB_MAX_RESPONSE 34768
#define WEB_MAX_RESPONSE 4096 #define WEB_MAX_RESPONSE 4096
@ -2222,8 +2222,10 @@ void Web::begin() {
JsonObject objEth = obj["ethernet"]; JsonObject objEth = obj["ethernet"];
if(settings.connType == conn_types_t::ethernet || settings.connType == conn_types_t::ethernetpref) if(settings.connType == conn_types_t::ethernet || settings.connType == conn_types_t::ethernetpref)
reboot = true; reboot = true;
#ifndef CONFIG_IDF_TARGET_ESP32C6
settings.Ethernet.fromJSON(objEth); settings.Ethernet.fromJSON(objEth);
settings.Ethernet.save(); settings.Ethernet.save();
#endif
} }
if(reboot) { if(reboot) {
ESP_LOGI(TAG, "Rebooting ESP for new Network settings..."); ESP_LOGI(TAG, "Rebooting ESP for new Network settings...");
@ -2304,7 +2306,9 @@ void Web::begin() {
settings.toJSON(obj); settings.toJSON(obj);
obj["fwVersion"] = settings.fwVersion.name; obj["fwVersion"] = settings.fwVersion.name;
JsonObject eth = obj.createNestedObject("ethernet"); JsonObject eth = obj.createNestedObject("ethernet");
#ifndef CONFIG_IDF_TARGET_ESP32C6
settings.Ethernet.toJSON(eth); settings.Ethernet.toJSON(eth);
#endif
JsonObject wifi = obj.createNestedObject("wifi"); JsonObject wifi = obj.createNestedObject("wifi");
settings.WIFI.toJSON(wifi); settings.WIFI.toJSON(wifi);
JsonObject ip = obj.createNestedObject("ip"); JsonObject ip = obj.createNestedObject("ip");