mirror of
https://github.com/rstrouse/ESPSomfy-RTS.git
synced 2026-03-30 08:52:11 +02:00
Added c6 support
This commit is contained in:
parent
aa81b95bee
commit
72bfd26443
15 changed files with 143 additions and 54 deletions
2
.github/workflows/ci.yaml
vendored
2
.github/workflows/ci.yaml
vendored
|
|
@ -17,6 +17,8 @@ jobs:
|
|||
name: ESP32-C3
|
||||
- env: esp32s3
|
||||
name: ESP32-S3
|
||||
- env: esp32c6
|
||||
name: ESP32-C6
|
||||
|
||||
steps:
|
||||
- name: Check out code
|
||||
|
|
|
|||
8
.github/workflows/release.yaml
vendored
8
.github/workflows/release.yaml
vendored
|
|
@ -43,6 +43,14 @@ jobs:
|
|||
fwname: SomfyController.ino.esp32s3.bin
|
||||
fsname: SomfyController.littlefs.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:
|
||||
- name: Get Release
|
||||
|
|
|
|||
|
|
@ -53,3 +53,14 @@ board_build.partitions = esp32_3MB.csv
|
|||
|
||||
[env:esp32s3]
|
||||
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
|
||||
|
|
|
|||
|
|
@ -616,7 +616,9 @@ bool ShadeConfigFile::restoreFile(SomfyShadeController *s, const char *filename,
|
|||
if(opts.network) {
|
||||
settings.IP.save();
|
||||
settings.WIFI.save();
|
||||
#ifndef CONFIG_IDF_TARGET_ESP32C6
|
||||
settings.Ethernet.save();
|
||||
#endif
|
||||
}
|
||||
if(opts.mqtt) settings.MQTT.save();
|
||||
return true;
|
||||
|
|
@ -672,6 +674,7 @@ bool ShadeConfigFile::readNetRecord(restore_options_t &opts) {
|
|||
if(opts.network) {
|
||||
if(strncmp(settings.serverId, this->header.serverId, sizeof(settings.serverId)) == 0) {
|
||||
ESP_LOGI(TAG, "Restoring Ethernet adapter settings");
|
||||
#ifndef CONFIG_IDF_TARGET_ESP32C6
|
||||
settings.Ethernet.boardType = this->readUInt8(1);
|
||||
settings.Ethernet.phyType = static_cast<eth_phy_type_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.MDCPin = this->readInt8(16);
|
||||
settings.Ethernet.MDIOPin = this->readInt8(23);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
if(this->file.position() != startPos + this->header.netRecordSize) {
|
||||
|
|
@ -1035,6 +1039,7 @@ bool ShadeConfigFile::writeNetRecord() {
|
|||
this->writeBool(settings.MQTT.pubDisco);
|
||||
this->writeVarString(settings.MQTT.rootTopic);
|
||||
this->writeVarString(settings.MQTT.discoTopic);
|
||||
#ifndef CONFIG_IDF_TARGET_ESP32C6
|
||||
this->writeUInt8(settings.Ethernet.boardType);
|
||||
this->writeUInt8(static_cast<uint8_t>(settings.Ethernet.phyType));
|
||||
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.MDCPin);
|
||||
this->writeInt8(settings.Ethernet.MDIOPin, CFG_REC_END);
|
||||
#else
|
||||
this->writeUInt8(0, CFG_REC_END);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
bool ShadeConfigFile::writeTransRecord(transceiver_config_t &cfg) {
|
||||
|
|
|
|||
|
|
@ -155,21 +155,14 @@ bool ConfigSettings::begin() {
|
|||
case esp_chip_model_t::CHIP_ESP32S3:
|
||||
strcpy(this->chipModel, "s3");
|
||||
break;
|
||||
case esp_chip_model_t::CHIP_ESP32S2:
|
||||
strcpy(this->chipModel, "s2");
|
||||
break;
|
||||
case esp_chip_model_t::CHIP_ESP32C3:
|
||||
strcpy(this->chipModel, "c3");
|
||||
break;
|
||||
// case esp_chip_model_t::CHIP_ESP32C2:
|
||||
// strcpy(this->chipModel, "c2");
|
||||
// break;
|
||||
// case esp_chip_model_t::CHIP_ESP32C6:
|
||||
// strcpy(this->chipModel, "c6");
|
||||
// break;
|
||||
case esp_chip_model_t::CHIP_ESP32H2:
|
||||
strcpy(this->chipModel, "h2");
|
||||
#ifdef CHIP_ESP32C6
|
||||
case esp_chip_model_t::CHIP_ESP32C6:
|
||||
strcpy(this->chipModel, "c6");
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
sprintf(this->chipModel, "UNK%d", static_cast<int>(ci.model));
|
||||
break;
|
||||
|
|
@ -188,7 +181,9 @@ bool ConfigSettings::begin() {
|
|||
this->Security.begin();
|
||||
this->IP.begin();
|
||||
this->WIFI.begin();
|
||||
#ifndef CONFIG_IDF_TARGET_ESP32C6
|
||||
this->Ethernet.begin();
|
||||
#endif
|
||||
this->NTP.begin();
|
||||
this->MQTT.begin();
|
||||
this->print();
|
||||
|
|
@ -258,7 +253,9 @@ void ConfigSettings::print() {
|
|||
ESP_LOGD(TAG, "Connection Type: %u", (unsigned int) this->connType);
|
||||
this->NTP.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();
|
||||
#endif
|
||||
}
|
||||
void ConfigSettings::emitSockets() {}
|
||||
void ConfigSettings::emitSockets(uint8_t num) {}
|
||||
|
|
@ -590,6 +587,7 @@ bool WifiSettings::ssidExists(const char *ssid) {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
#ifndef CONFIG_IDF_TARGET_ESP32C6
|
||||
EthernetSettings::EthernetSettings() {}
|
||||
bool EthernetSettings::begin() {
|
||||
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",
|
||||
this->boardType, this->phyType, this->CLKMode, this->phyAddress, this->PWRPin, this->MDCPin, this->MDIOPin);
|
||||
}
|
||||
#endif // CONFIG_IDF_TARGET_ESP32C6
|
||||
void ConfigSettings::printAvailHeap() {
|
||||
ESP_LOGD(TAG, "Max Heap: %u", (unsigned int)ESP.getMaxAllocHeap());
|
||||
ESP_LOGD(TAG, "Free Heap: %u", (unsigned int)ESP.getFreeHeap());
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
#include <ArduinoJson.h>
|
||||
#ifndef CONFIG_IDF_TARGET_ESP32C6
|
||||
#include <ETH.h>
|
||||
#endif
|
||||
#ifndef configsettings_h
|
||||
#define configsettings_h
|
||||
#include "WResp.h"
|
||||
|
|
@ -88,6 +90,7 @@ class WifiSettings: BaseSettings {
|
|||
void print();
|
||||
|
||||
};
|
||||
#ifndef CONFIG_IDF_TARGET_ESP32C6
|
||||
class EthernetSettings: BaseSettings {
|
||||
public:
|
||||
EthernetSettings();
|
||||
|
|
@ -108,6 +111,7 @@ class EthernetSettings: BaseSettings {
|
|||
void print();
|
||||
bool usesPin(uint8_t pin);
|
||||
};
|
||||
#endif
|
||||
class IPSettings: BaseSettings {
|
||||
public:
|
||||
IPSettings();
|
||||
|
|
@ -180,7 +184,9 @@ class ConfigSettings: BaseSettings {
|
|||
uint8_t status;
|
||||
IPSettings IP;
|
||||
WifiSettings WIFI;
|
||||
#ifndef CONFIG_IDF_TARGET_ESP32C6
|
||||
EthernetSettings Ethernet;
|
||||
#endif
|
||||
NTPSettings NTP;
|
||||
MQTTSettings MQTT;
|
||||
SecuritySettings Security;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
#ifndef CONFIG_IDF_TARGET_ESP32C6
|
||||
#include <ETH.h>
|
||||
#endif
|
||||
#include <WiFi.h>
|
||||
#include <ESPmDNS.h>
|
||||
#include <esp_task_wdt.h>
|
||||
#include "esp_log.h"
|
||||
#include "ConfigSettings.h"
|
||||
#include "Network.h"
|
||||
#include "ESPNetwork.h"
|
||||
#include "Web.h"
|
||||
#include "Sockets.h"
|
||||
#include "Utils.h"
|
||||
|
|
@ -18,7 +20,7 @@ extern Web webServer;
|
|||
extern SocketEmitter sockEmit;
|
||||
extern MQTTClass mqtt;
|
||||
extern rebootDelay_t rebootDelay;
|
||||
extern Network net;
|
||||
extern ESPNetwork net;
|
||||
extern SomfyShadeController somfy;
|
||||
|
||||
static unsigned long _lastHeapEmit = 0;
|
||||
|
|
@ -27,13 +29,13 @@ static bool _apScanning = false;
|
|||
static uint32_t _lastMaxHeap = 0;
|
||||
static uint32_t _lastHeap = 0;
|
||||
int connectRetries = 0;
|
||||
void Network::end() {
|
||||
void ESPNetwork::end() {
|
||||
SSDP.end();
|
||||
mqtt.end();
|
||||
sockEmit.end();
|
||||
delay(100);
|
||||
}
|
||||
bool Network::setup() {
|
||||
bool ESPNetwork::setup() {
|
||||
WiFi.setScanMethod(WIFI_ALL_CHANNEL_SCAN);
|
||||
WiFi.setSortMethod(WIFI_CONNECT_AP_BY_SIGNAL);
|
||||
WiFi.persistent(false);
|
||||
|
|
@ -50,22 +52,24 @@ bool Network::setup() {
|
|||
sockEmit.begin();
|
||||
return true;
|
||||
}
|
||||
conn_types_t Network::preferredConnType() {
|
||||
conn_types_t ESPNetwork::preferredConnType() {
|
||||
switch(settings.connType) {
|
||||
case conn_types_t::wifi:
|
||||
return settings.WIFI.ssid[0] != '\0' ? conn_types_t::wifi : conn_types_t::ap;
|
||||
case conn_types_t::unset:
|
||||
case conn_types_t::ap:
|
||||
return conn_types_t::ap;
|
||||
#ifndef CONFIG_IDF_TARGET_ESP32C6
|
||||
case conn_types_t::ethernetpref:
|
||||
return settings.WIFI.ssid[0] != '\0' && (!ETH.linkUp() && this->ethStarted) ? conn_types_t::wifi : conn_types_t::ethernet;
|
||||
case conn_types_t::ethernet:
|
||||
return ETH.linkUp() || !this->ethStarted ? conn_types_t::ethernet : conn_types_t::ap;
|
||||
#endif
|
||||
default:
|
||||
return settings.connType;
|
||||
}
|
||||
}
|
||||
void Network::loop() {
|
||||
void ESPNetwork::loop() {
|
||||
// ORDER OF OPERATIONS:
|
||||
// ----------------------------------------------
|
||||
// 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();
|
||||
}
|
||||
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.
|
||||
if(SSDP.isStarted) SSDP.end();
|
||||
mqtt.disconnect();
|
||||
|
|
@ -169,7 +173,7 @@ bool Network::changeAP(const uint8_t *bssid, const int32_t channel) {
|
|||
this->connectStart = millis();
|
||||
return false;
|
||||
}
|
||||
void Network::emitSockets() {
|
||||
void ESPNetwork::emitSockets() {
|
||||
this->emitHeap();
|
||||
if(this->needsBroadcast ||
|
||||
(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;
|
||||
}
|
||||
}
|
||||
void Network::emitSockets(uint8_t num) {
|
||||
void ESPNetwork::emitSockets(uint8_t num) {
|
||||
#ifndef CONFIG_IDF_TARGET_ESP32C6
|
||||
if(this->connType == conn_types_t::ethernet) {
|
||||
JsonSockEvent *json = sockEmit.beginEmit("ethernet");
|
||||
json->beginObject();
|
||||
|
|
@ -188,7 +193,9 @@ void Network::emitSockets(uint8_t num) {
|
|||
json->endObject();
|
||||
sockEmit.endEmit(num);
|
||||
}
|
||||
else {
|
||||
else
|
||||
#endif
|
||||
{
|
||||
if(WiFi.status() == WL_CONNECTED) {
|
||||
JsonSockEvent *json = sockEmit.beginEmit("wifiStrength");
|
||||
json->beginObject();
|
||||
|
|
@ -222,7 +229,7 @@ void Network::emitSockets(uint8_t num) {
|
|||
}
|
||||
this->emitHeap(num);
|
||||
}
|
||||
void Network::setConnected(conn_types_t connType) {
|
||||
void ESPNetwork::setConnected(conn_types_t connType) {
|
||||
esp_task_wdt_reset();
|
||||
this->connType = connType;
|
||||
this->connectTime = millis();
|
||||
|
|
@ -240,6 +247,7 @@ void Network::setConnected(conn_types_t connType) {
|
|||
this->channel = WiFi.channel();
|
||||
this->connectAttempts++;
|
||||
}
|
||||
#ifndef CONFIG_IDF_TARGET_ESP32C6
|
||||
else if(this->connType == conn_types_t::ethernet) {
|
||||
if(this->softAPOpened) {
|
||||
ESP_LOGI(TAG, "Disconnecting from SoftAP");
|
||||
|
|
@ -250,6 +258,7 @@ void Network::setConnected(conn_types_t connType) {
|
|||
this->_connecting = false;
|
||||
this->wifiFallback = false;
|
||||
}
|
||||
#endif // CONFIG_IDF_TARGET_ESP32C6
|
||||
// NET: Begin this in the startup.
|
||||
//sockEmit.begin();
|
||||
esp_task_wdt_reset();
|
||||
|
|
@ -265,6 +274,7 @@ void Network::setConnected(conn_types_t connType) {
|
|||
settings.IP.dns2 = WiFi.dnsIP(1);
|
||||
}
|
||||
}
|
||||
#ifndef CONFIG_IDF_TARGET_ESP32C6
|
||||
else {
|
||||
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) {
|
||||
|
|
@ -284,14 +294,17 @@ void Network::setConnected(conn_types_t connType) {
|
|||
sockEmit.endEmit();
|
||||
esp_task_wdt_reset();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
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);
|
||||
}
|
||||
#ifndef CONFIG_IDF_TARGET_ESP32C6
|
||||
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);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
SSDP.setHTTPPort(80);
|
||||
SSDP.setSchemaURL(0, "upnp.xml");
|
||||
|
|
@ -335,7 +348,8 @@ void Network::setConnected(conn_types_t connType) {
|
|||
settings.printAvailHeap();
|
||||
this->needsBroadcast = true;
|
||||
}
|
||||
bool Network::connectWired() {
|
||||
#ifndef CONFIG_IDF_TARGET_ESP32C6
|
||||
bool ESPNetwork::connectWired() {
|
||||
if(ETH.linkUp()) {
|
||||
// If the ethernet link is re-established then we need to shut down wifi.
|
||||
if(WiFi.status() == WL_CONNECTED) {
|
||||
|
|
@ -391,8 +405,10 @@ bool Network::connectWired() {
|
|||
this->connectStart = millis();
|
||||
return true;
|
||||
}
|
||||
void Network::updateHostname() {
|
||||
#endif // CONFIG_IDF_TARGET_ESP32C6
|
||||
void ESPNetwork::updateHostname() {
|
||||
if(settings.hostname[0] != '\0' && this->connected()) {
|
||||
#ifndef CONFIG_IDF_TARGET_ESP32C6
|
||||
if(this->connType == conn_types_t::ethernet &&
|
||||
strcmp(settings.hostname, ETH.getHostname()) != 0) {
|
||||
ESP_LOGD(TAG, "Updating host name to %s...", settings.hostname);
|
||||
|
|
@ -400,7 +416,9 @@ void Network::updateHostname() {
|
|||
MDNS.setInstanceName(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);
|
||||
WiFi.setHostname(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) {
|
||||
// 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.
|
||||
|
|
@ -474,15 +492,18 @@ bool Network::connectWiFi(const uint8_t *bssid, const int32_t channel) {
|
|||
this->connectStart = millis();
|
||||
return true;
|
||||
}
|
||||
bool Network::connect(conn_types_t ctype) {
|
||||
bool ESPNetwork::connect(conn_types_t ctype) {
|
||||
esp_task_wdt_reset();
|
||||
if(this->connecting()) return true;
|
||||
if(this->disconnectTime == 0) this->disconnectTime = millis();
|
||||
#ifndef CONFIG_IDF_TARGET_ESP32C6
|
||||
if(ctype == conn_types_t::ethernet && this->connType != conn_types_t::ethernet) {
|
||||
// Here we need to call the connect to ethernet.
|
||||
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) {
|
||||
this->disconnectTime = millis();
|
||||
this->openSoftAP();
|
||||
|
|
@ -499,7 +520,7 @@ bool Network::connect(conn_types_t ctype) {
|
|||
|
||||
return true;
|
||||
}
|
||||
uint32_t Network::getChipId() {
|
||||
uint32_t ESPNetwork::getChipId() {
|
||||
uint32_t chipId = 0;
|
||||
uint64_t mac = ESP.getEfuseMac();
|
||||
for(int i=0; i<17; i=i+8) {
|
||||
|
|
@ -507,7 +528,7 @@ uint32_t Network::getChipId() {
|
|||
}
|
||||
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.
|
||||
int32_t strength = this->connected() ? WiFi.RSSI() + 10 : -127;
|
||||
int32_t chan = -1;
|
||||
|
|
@ -528,7 +549,7 @@ bool Network::getStrongestAP(const char *ssid, uint8_t *bssid, int32_t *channel)
|
|||
WiFi.scanDelete();
|
||||
return chan > 0;
|
||||
}
|
||||
bool Network::openSoftAP() {
|
||||
bool ESPNetwork::openSoftAP() {
|
||||
if(this->softAPOpened || this->openingSoftAP) return true;
|
||||
if(this->connected()) WiFi.disconnect(false);
|
||||
this->openingSoftAP = true;
|
||||
|
|
@ -538,20 +559,22 @@ bool Network::openSoftAP() {
|
|||
delay(200);
|
||||
return true;
|
||||
}
|
||||
bool Network::connected() {
|
||||
bool ESPNetwork::connected() {
|
||||
if(this->connecting()) 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;
|
||||
#ifndef CONFIG_IDF_TARGET_ESP32C6
|
||||
else if(this->connType == conn_types_t::ethernet) return ETH.linkUp();
|
||||
#endif
|
||||
else return this->connType != conn_types_t::unset;
|
||||
return false;
|
||||
}
|
||||
bool Network::connecting() {
|
||||
bool ESPNetwork::connecting() {
|
||||
if(this->_connecting && millis() > this->connectStart + CONNECT_TIMEOUT) this->_connecting = false;
|
||||
return this->_connecting;
|
||||
}
|
||||
void Network::clearConnecting() { this->_connecting = false; }
|
||||
void Network::networkEvent(WiFiEvent_t event) {
|
||||
void ESPNetwork::clearConnecting() { this->_connecting = false; }
|
||||
void ESPNetwork::networkEvent(WiFiEvent_t event) {
|
||||
switch(event) {
|
||||
case ARDUINO_EVENT_WIFI_READY: ESP_LOGI(TAG, "(evt) WiFi interface ready"); break;
|
||||
case ARDUINO_EVENT_WIFI_SCAN_DONE:
|
||||
|
|
@ -579,6 +602,7 @@ void Network::networkEvent(WiFiEvent_t event) {
|
|||
net.setConnected(conn_types_t::wifi);
|
||||
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:
|
||||
// If the Wifi is connected then drop that connection
|
||||
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.ethStarted = false;
|
||||
break;
|
||||
#endif
|
||||
case ARDUINO_EVENT_WIFI_AP_START:
|
||||
ESP_LOGI(TAG, "(evt) WiFi SoftAP Started IP: %s", WiFi.softAPIP().toString().c_str());
|
||||
net.openingSoftAP = false;
|
||||
|
|
@ -622,12 +647,14 @@ void Network::networkEvent(WiFiEvent_t event) {
|
|||
net.softAPOpened = false;
|
||||
break;
|
||||
default:
|
||||
#ifndef CONFIG_IDF_TARGET_ESP32C6
|
||||
if(event > ARDUINO_EVENT_ETH_START)
|
||||
ESP_LOGW(TAG, "(evt) Unknown Ethernet Event %d", event);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
void Network::emitHeap(uint8_t num) {
|
||||
void ESPNetwork::emitHeap(uint8_t num) {
|
||||
bool bEmit = false;
|
||||
bool bTimeEmit = millis() - _lastHeapEmit > 15000;
|
||||
bool bRoomEmit = false;
|
||||
|
|
@ -1,13 +1,14 @@
|
|||
#include <Arduino.h>
|
||||
#include <WiFi.h>
|
||||
|
||||
#ifndef Network_h
|
||||
#define Network_h
|
||||
#ifndef ESPNetwork_h
|
||||
#define ESPNetwork_h
|
||||
|
||||
//enum class conn_types_t : byte;
|
||||
|
||||
#define CONNECT_TIMEOUT 20000
|
||||
#define SSID_SCAN_INTERVAL 60000
|
||||
class Network {
|
||||
class ESPNetwork {
|
||||
protected:
|
||||
unsigned long lastEmit = 0;
|
||||
unsigned long lastMDNS = 0;
|
||||
|
|
@ -3,6 +3,7 @@
|
|||
#include <Update.h>
|
||||
#include <HTTPClient.h>
|
||||
#include <esp_task_wdt.h>
|
||||
#include <esp_chip_info.h>
|
||||
#include "esp_log.h"
|
||||
#include "ConfigSettings.h"
|
||||
#include "GitOTA.h"
|
||||
|
|
@ -11,7 +12,7 @@
|
|||
#include "Somfy.h"
|
||||
#include "Web.h"
|
||||
#include "WResp.h"
|
||||
#include "Network.h"
|
||||
#include "ESPNetwork.h"
|
||||
|
||||
|
||||
|
||||
|
|
@ -21,7 +22,7 @@ extern SocketEmitter sockEmit;
|
|||
extern SomfyShadeController somfy;
|
||||
extern rebootDelay_t rebootDelay;
|
||||
extern Web webServer;
|
||||
extern Network net;
|
||||
extern ESPNetwork net;
|
||||
|
||||
static const char *TAG = "OTA";
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
#include "ConfigSettings.h"
|
||||
#include "MQTT.h"
|
||||
#include "Somfy.h"
|
||||
#include "Network.h"
|
||||
#include "ESPNetwork.h"
|
||||
#include "Utils.h"
|
||||
|
||||
static const char *TAG = "MQTT";
|
||||
|
|
@ -19,7 +19,7 @@ static char g_content[MQTT_MAX_RESPONSE];
|
|||
|
||||
extern ConfigSettings settings;
|
||||
extern SomfyShadeController somfy;
|
||||
extern Network net;
|
||||
extern ESPNetwork net;
|
||||
extern rebootDelay_t rebootDelay;
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -383,6 +383,9 @@ void SSDPClass::_parsePacket(ssdp_packet_t *pkt, AsyncUDPPacket &p) {
|
|||
IPAddress SSDPClass::localIP()
|
||||
{
|
||||
// Make sure we don't get a null IPAddress.
|
||||
#ifdef CONFIG_IDF_TARGET_ESP32C6
|
||||
return WiFi.localIP();
|
||||
#else
|
||||
tcpip_adapter_ip_info_t ip;
|
||||
if (WiFi.getMode() == WIFI_STA) {
|
||||
if (tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &ip)) {
|
||||
|
|
@ -394,6 +397,7 @@ IPAddress SSDPClass::localIP()
|
|||
}
|
||||
}
|
||||
return IPAddress(ip.ip.addr);
|
||||
#endif
|
||||
}
|
||||
void SSDPClass::_sendResponse(IPAddress addr, uint16_t port, UPNPDeviceType *d, const char *st, response_types_t responseType) {
|
||||
char buffer[1460];
|
||||
|
|
|
|||
|
|
@ -5,13 +5,13 @@
|
|||
#include "Sockets.h"
|
||||
#include "ConfigSettings.h"
|
||||
#include "Somfy.h"
|
||||
#include "Network.h"
|
||||
#include "ESPNetwork.h"
|
||||
#include "GitOTA.h"
|
||||
|
||||
static const char *TAG = "Sockets";
|
||||
|
||||
extern ConfigSettings settings;
|
||||
extern Network net;
|
||||
extern ESPNetwork net;
|
||||
extern SomfyShadeController somfy;
|
||||
extern SocketEmitter sockEmit;
|
||||
extern GitUpdater git;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#include <ELECHOUSE_CC1101_SRC_DRV.h>
|
||||
#include <SPI.h>
|
||||
#include <esp_task_wdt.h>
|
||||
#include <esp_chip_info.h>
|
||||
#include "esp_log.h"
|
||||
#include "Utils.h"
|
||||
#include "ConfigSettings.h"
|
||||
|
|
@ -3159,12 +3160,14 @@ int8_t SomfyShade::validateJSON(JsonObject &obj) {
|
|||
(myPin != 255 && somfy.transceiver.usesPin(myPin)))
|
||||
ret = -10;
|
||||
}
|
||||
#ifndef CONFIG_IDF_TARGET_ESP32C6
|
||||
if(settings.connType == conn_types_t::ethernet || settings.connType == conn_types_t::ethernetpref) {
|
||||
if((upPin != 255 && settings.Ethernet.usesPin(upPin)) ||
|
||||
(downPin != 255 && somfy.transceiver.usesPin(downPin)) ||
|
||||
(myPin != 255 && somfy.transceiver.usesPin(myPin)))
|
||||
ret = -11;
|
||||
}
|
||||
#endif
|
||||
if(ret == 0) {
|
||||
for(uint8_t i = 0; i < SOMFY_MAX_SHADES; i++) {
|
||||
SomfyShade *shade = &somfy.shades[i];
|
||||
|
|
@ -4688,6 +4691,16 @@ void transceiver_config_t::load() {
|
|||
this->SCKPin = 15;
|
||||
this->CSNPin = 14;
|
||||
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:
|
||||
this->TXPin = 13;
|
||||
this->RXPin = 12;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
#include <LittleFS.h>
|
||||
#include <esp_task_wdt.h>
|
||||
#include "ConfigSettings.h"
|
||||
#include "Network.h"
|
||||
#include "ESPNetwork.h"
|
||||
#include "Web.h"
|
||||
#include "Sockets.h"
|
||||
#include "Utils.h"
|
||||
|
|
@ -17,7 +17,7 @@ static const char *TAG = "Main";
|
|||
ConfigSettings settings;
|
||||
Web webServer;
|
||||
SocketEmitter sockEmit;
|
||||
Network net;
|
||||
ESPNetwork net;
|
||||
rebootDelay_t rebootDelay;
|
||||
SomfyShadeController somfy;
|
||||
MQTTClass mqtt;
|
||||
|
|
@ -89,7 +89,12 @@ void setup() {
|
|||
net.setup();
|
||||
somfy.begin();
|
||||
//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
|
||||
#endif
|
||||
esp_task_wdt_add(NULL); //add current thread to WDT watch
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
#include "Web.h"
|
||||
#include "MQTT.h"
|
||||
#include "GitOTA.h"
|
||||
#include "Network.h"
|
||||
#include "ESPNetwork.h"
|
||||
#include <AsyncTCP.h>
|
||||
#include <ESPAsyncWebServer.h>
|
||||
#include <AsyncJson.h>
|
||||
|
|
@ -25,7 +25,7 @@ extern SomfyShadeController somfy;
|
|||
extern Web webServer;
|
||||
extern MQTTClass mqtt;
|
||||
extern GitUpdater git;
|
||||
extern Network net;
|
||||
extern ESPNetwork net;
|
||||
|
||||
//#define WEB_MAX_RESPONSE 34768
|
||||
#define WEB_MAX_RESPONSE 4096
|
||||
|
|
@ -2222,8 +2222,10 @@ void Web::begin() {
|
|||
JsonObject objEth = obj["ethernet"];
|
||||
if(settings.connType == conn_types_t::ethernet || settings.connType == conn_types_t::ethernetpref)
|
||||
reboot = true;
|
||||
#ifndef CONFIG_IDF_TARGET_ESP32C6
|
||||
settings.Ethernet.fromJSON(objEth);
|
||||
settings.Ethernet.save();
|
||||
#endif
|
||||
}
|
||||
if(reboot) {
|
||||
ESP_LOGI(TAG, "Rebooting ESP for new Network settings...");
|
||||
|
|
@ -2304,7 +2306,9 @@ void Web::begin() {
|
|||
settings.toJSON(obj);
|
||||
obj["fwVersion"] = settings.fwVersion.name;
|
||||
JsonObject eth = obj.createNestedObject("ethernet");
|
||||
#ifndef CONFIG_IDF_TARGET_ESP32C6
|
||||
settings.Ethernet.toJSON(eth);
|
||||
#endif
|
||||
JsonObject wifi = obj.createNestedObject("wifi");
|
||||
settings.WIFI.toJSON(wifi);
|
||||
JsonObject ip = obj.createNestedObject("ip");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue