Skip to content

Commit

Permalink
Merge pull request letscontrolit#5004 from TD-er/bugfix/ESP8266_WiFi_…
Browse files Browse the repository at this point in the history
…AP_capabilities

[ESP8266 WiFi] Initialize flags for AP capabilities
  • Loading branch information
TD-er authored Mar 21, 2024
2 parents 8ca65fb + 548dd59 commit 71a3290
Show file tree
Hide file tree
Showing 42 changed files with 673 additions and 509 deletions.
4 changes: 3 additions & 1 deletion platformio_core_defs.ini
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,9 @@ lib_ignore =
;platform = https://github.com/Jason2866/platform-espressif32.git
platform = https://github.com/tasmota/platform-espressif32/releases/download/2024.02.10/platform-espressif32.zip
;platform_packages =
platform_packages = framework-arduinoespressif32 @ https://github.com/Jason2866/esp32-arduino-lib-builder/releases/download/2151/framework-arduinoespressif32-release_v5.1-1a0b6e0.zip
;platform_packages = framework-arduinoespressif32 @ https://github.com/Jason2866/esp32-arduino-lib-builder/releases/download/2119/framework-arduinoespressif32-release_v5.1-a28d368.zip
;platform_packages = framework-arduinoespressif32 @ https://github.com/Jason2866/esp32-arduino-lib-builder/releases/download/2180/framework-arduinoespressif32-all-release_v5.1-735d740.zip
platform_packages = framework-arduinoespressif32 @ https://github.com/Jason2866/esp32-arduino-lib-builder/releases/download/2189/framework-arduinoespressif32-all-release_v5.1-be1a568.zip
build_flags = -DESP32_STAGE
-DESP_IDF_VERSION_MAJOR=5
-DLIBRARIES_NO_LOG=1
Expand Down
228 changes: 120 additions & 108 deletions src/src/DataStructs/ControllerSettingsStruct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,25 @@ void ControllerSettingsStruct::reset() {
// Otherwise the checksum will fail and settings will be saved too often.
memset(this, 0, sizeof(ControllerSettingsStruct));

UseDNS = DEFAULT_SERVER_USEDNS;
Port = DEFAULT_PORT;
MinimalTimeBetweenMessages = CONTROLLER_DELAY_QUEUE_DELAY_DFLT;
MaxQueueDepth = CONTROLLER_DELAY_QUEUE_DEPTH_DFLT;
MaxRetry = CONTROLLER_DELAY_QUEUE_RETRY_DFLT;
DeleteOldest = DEFAULT_CONTROLLER_DELETE_OLDEST;
ClientTimeout = CONTROLLER_CLIENTTIMEOUT_DFLT;
MustCheckReply = DEFAULT_CONTROLLER_MUST_CHECK_REPLY ;
SampleSetInitiator = INVALID_TASK_INDEX;
VariousFlags = 0;
UseDNS = DEFAULT_SERVER_USEDNS;
Port = DEFAULT_PORT;
MinimalTimeBetweenMessages = CONTROLLER_DELAY_QUEUE_DELAY_DFLT;
MaxQueueDepth = CONTROLLER_DELAY_QUEUE_DEPTH_DFLT;
MaxRetry = CONTROLLER_DELAY_QUEUE_RETRY_DFLT;
DeleteOldest = DEFAULT_CONTROLLER_DELETE_OLDEST;
ClientTimeout = CONTROLLER_CLIENTTIMEOUT_DFLT;
MustCheckReply = DEFAULT_CONTROLLER_MUST_CHECK_REPLY;
SampleSetInitiator = INVALID_TASK_INDEX;
VariousBits1.mqtt_cleanSession = 0;
VariousBits1.mqtt_not_sendLWT = 0;
VariousBits1.mqtt_not_willRetain = 0;
VariousBits1.mqtt_uniqueMQTTclientIdReconnect = 0;
VariousBits1.mqtt_retainFlag = 0;
VariousBits1.useExtendedCredentials = 0;
VariousBits1.sendBinary = 0;
VariousBits1.allowExpire = 0;
VariousBits1.deduplicate = 0;
VariousBits1.useLocalSystemTime = 0;

safe_strncpy(ClientID, F(CONTROLLER_DEFAULT_CLIENTID), sizeof(ClientID));
}
Expand Down Expand Up @@ -72,7 +81,6 @@ void ControllerSettingsStruct::validate() {
ZERO_TERMINATE(LWTMessageDisconnect);
}


String ControllerSettingsStruct::getHost() const {
if (UseDNS) {
return HostName;
Expand All @@ -90,6 +98,7 @@ bool ControllerSettingsStruct::checkHostReachable(bool quick) {
// No IP/hostname set
return false;
}

if (!NetworkConnected(10)) {
return false; // Not connected, so no use in wasting time to connect to a host.
}
Expand All @@ -111,7 +120,7 @@ bool ControllerSettingsStruct::connectToHost(WiFiClient& client) {
return false; // Host not reachable
}
uint8_t retry = 2;
bool connected = false;
bool connected = false;

while (retry > 0 && !connected) {
--retry;
Expand All @@ -125,16 +134,19 @@ bool ControllerSettingsStruct::connectToHost(WiFiClient& client) {
}
return false;
}

#endif // FEATURE_HTTP_CLIENT

bool ControllerSettingsStruct::beginPacket(WiFiUDP& client) {
if (!checkHostReachable(true)) {
return false; // Host not reachable
}
uint8_t retry = 2;
uint8_t retry = 2;

while (retry > 0) {
--retry;
FeedSW_watchdog();

if (client.beginPacket(getIP(), Port) == 1) {
return true;
}
Expand Down Expand Up @@ -181,101 +193,101 @@ bool ControllerSettingsStruct::updateIPcache() {
/*
bool ControllerSettingsStruct::mqtt_cleanSession() const
{
return bitRead(VariousFlags, 1);
}
void ControllerSettingsStruct::mqtt_cleanSession(bool value)
{
bitWrite(VariousFlags, 1, value);
}
bool ControllerSettingsStruct::mqtt_sendLWT() const
{
return !bitRead(VariousFlags, 2);
}
void ControllerSettingsStruct::mqtt_sendLWT(bool value)
{
bitWrite(VariousFlags, 2, !value);
}
bool ControllerSettingsStruct::mqtt_willRetain() const
{
return !bitRead(VariousFlags, 3);
}
void ControllerSettingsStruct::mqtt_willRetain(bool value)
{
bitWrite(VariousFlags, 3, !value);
}
bool ControllerSettingsStruct::mqtt_uniqueMQTTclientIdReconnect() const
{
return bitRead(VariousFlags, 4);
}
void ControllerSettingsStruct::mqtt_uniqueMQTTclientIdReconnect(bool value)
{
bitWrite(VariousFlags, 4, value);
}
bool ControllerSettingsStruct::mqtt_retainFlag() const
{
return bitRead(VariousFlags, 5);
}
void ControllerSettingsStruct::mqtt_retainFlag(bool value)
{
bitWrite(VariousFlags, 5, value);
}
bool ControllerSettingsStruct::useExtendedCredentials() const
{
return bitRead(VariousFlags, 6);
}
void ControllerSettingsStruct::useExtendedCredentials(bool value)
{
bitWrite(VariousFlags, 6, value);
}
bool ControllerSettingsStruct::sendBinary() const
{
return bitRead(VariousFlags, 7);
}
void ControllerSettingsStruct::sendBinary(bool value)
{
bitWrite(VariousFlags, 7, value);
}
bool ControllerSettingsStruct::allowExpire() const
{
return bitRead(VariousFlags, 9);
}
void ControllerSettingsStruct::allowExpire(bool value)
{
bitWrite(VariousFlags, 9, value);
}
bool ControllerSettingsStruct::deduplicate() const
{
return bitRead(VariousFlags, 10);
}
void ControllerSettingsStruct::deduplicate(bool value)
{
bitWrite(VariousFlags, 10, value);
}
bool ControllerSettingsStruct::useLocalSystemTime() const
{
return bitRead(VariousFlags, 11);
}
void ControllerSettingsStruct::useLocalSystemTime(bool value)
{
return bitRead(VariousFlags, 1);
}
void ControllerSettingsStruct::mqtt_cleanSession(bool value)
{
bitWrite(VariousFlags, 1, value);
}
bool ControllerSettingsStruct::mqtt_sendLWT() const
{
return !bitRead(VariousFlags, 2);
}
void ControllerSettingsStruct::mqtt_sendLWT(bool value)
{
bitWrite(VariousFlags, 2, !value);
}
bool ControllerSettingsStruct::mqtt_willRetain() const
{
return !bitRead(VariousFlags, 3);
}
void ControllerSettingsStruct::mqtt_willRetain(bool value)
{
bitWrite(VariousFlags, 3, !value);
}
bool ControllerSettingsStruct::mqtt_uniqueMQTTclientIdReconnect() const
{
return bitRead(VariousFlags, 4);
}
void ControllerSettingsStruct::mqtt_uniqueMQTTclientIdReconnect(bool value)
{
bitWrite(VariousFlags, 4, value);
}
bool ControllerSettingsStruct::mqtt_retainFlag() const
{
return bitRead(VariousFlags, 5);
}
void ControllerSettingsStruct::mqtt_retainFlag(bool value)
{
bitWrite(VariousFlags, 5, value);
}
bool ControllerSettingsStruct::useExtendedCredentials() const
{
return bitRead(VariousFlags, 6);
}
void ControllerSettingsStruct::useExtendedCredentials(bool value)
{
bitWrite(VariousFlags, 6, value);
}
bool ControllerSettingsStruct::sendBinary() const
{
return bitRead(VariousFlags, 7);
}
void ControllerSettingsStruct::sendBinary(bool value)
{
bitWrite(VariousFlags, 7, value);
}
bool ControllerSettingsStruct::allowExpire() const
{
return bitRead(VariousFlags, 9);
}
void ControllerSettingsStruct::allowExpire(bool value)
{
bitWrite(VariousFlags, 9, value);
}
bool ControllerSettingsStruct::deduplicate() const
{
return bitRead(VariousFlags, 10);
}
void ControllerSettingsStruct::deduplicate(bool value)
{
bitWrite(VariousFlags, 10, value);
}
bool ControllerSettingsStruct::useLocalSystemTime() const
{
return bitRead(VariousFlags, 11);
}
void ControllerSettingsStruct::useLocalSystemTime(bool value)
{
bitWrite(VariousFlags, 11, value);
}
*/
73 changes: 35 additions & 38 deletions src/src/DataStructs/ControllerSettingsStruct.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ struct ControllerSettingsStruct

String getHostPortString() const;

// VariousFlags defaults to 0, keep in mind when adding bit lookups.
// VariousBits1 defaults to 0, keep in mind when adding bit lookups.
bool mqtt_cleanSession() const { return VariousBits1.mqtt_cleanSession; }
void mqtt_cleanSession(bool value) { VariousBits1.mqtt_cleanSession = value; }

Expand Down Expand Up @@ -172,43 +172,40 @@ struct ControllerSettingsStruct
bool MustCheckReply; // When set to false, a sent message is considered always successful.
taskIndex_t SampleSetInitiator; // The first task to start a sample set.

union {
struct {
uint32_t unused_00 : 1; // Bit 00
uint32_t mqtt_cleanSession : 1; // Bit 01
uint32_t mqtt_not_sendLWT : 1; // Bit 02, !value, default enabled
uint32_t mqtt_not_willRetain : 1; // Bit 03, !value, default enabled
uint32_t mqtt_uniqueMQTTclientIdReconnect : 1; // Bit 04
uint32_t mqtt_retainFlag : 1; // Bit 05
uint32_t useExtendedCredentials : 1; // Bit 06
uint32_t sendBinary : 1; // Bit 07
uint32_t unused_08 : 1; // Bit 08
uint32_t allowExpire : 1; // Bit 09
uint32_t deduplicate : 1; // Bit 10
uint32_t useLocalSystemTime : 1; // Bit 11
uint32_t unused_12 : 1; // Bit 12
uint32_t unused_13 : 1; // Bit 13
uint32_t unused_14 : 1; // Bit 14
uint32_t unused_15 : 1; // Bit 15
uint32_t unused_16 : 1; // Bit 16
uint32_t unused_17 : 1; // Bit 17
uint32_t unused_18 : 1; // Bit 18
uint32_t unused_19 : 1; // Bit 19
uint32_t unused_20 : 1; // Bit 20
uint32_t unused_21 : 1; // Bit 21
uint32_t unused_22 : 1; // Bit 22
uint32_t unused_23 : 1; // Bit 23
uint32_t unused_24 : 1; // Bit 24
uint32_t unused_25 : 1; // Bit 25
uint32_t unused_26 : 1; // Bit 26
uint32_t unused_27 : 1; // Bit 27
uint32_t unused_28 : 1; // Bit 28
uint32_t unused_29 : 1; // Bit 29
uint32_t unused_30 : 1; // Bit 30
uint32_t unused_31 : 1; // Bit 31
} VariousBits1;
uint32_t VariousFlags; // Various flags
};
struct {
uint32_t unused_00 : 1; // Bit 00
uint32_t mqtt_cleanSession : 1; // Bit 01
uint32_t mqtt_not_sendLWT : 1; // Bit 02, !value, default enabled
uint32_t mqtt_not_willRetain : 1; // Bit 03, !value, default enabled
uint32_t mqtt_uniqueMQTTclientIdReconnect : 1; // Bit 04
uint32_t mqtt_retainFlag : 1; // Bit 05
uint32_t useExtendedCredentials : 1; // Bit 06
uint32_t sendBinary : 1; // Bit 07
uint32_t unused_08 : 1; // Bit 08
uint32_t allowExpire : 1; // Bit 09
uint32_t deduplicate : 1; // Bit 10
uint32_t useLocalSystemTime : 1; // Bit 11
uint32_t unused_12 : 1; // Bit 12
uint32_t unused_13 : 1; // Bit 13
uint32_t unused_14 : 1; // Bit 14
uint32_t unused_15 : 1; // Bit 15
uint32_t unused_16 : 1; // Bit 16
uint32_t unused_17 : 1; // Bit 17
uint32_t unused_18 : 1; // Bit 18
uint32_t unused_19 : 1; // Bit 19
uint32_t unused_20 : 1; // Bit 20
uint32_t unused_21 : 1; // Bit 21
uint32_t unused_22 : 1; // Bit 22
uint32_t unused_23 : 1; // Bit 23
uint32_t unused_24 : 1; // Bit 24
uint32_t unused_25 : 1; // Bit 25
uint32_t unused_26 : 1; // Bit 26
uint32_t unused_27 : 1; // Bit 27
uint32_t unused_28 : 1; // Bit 28
uint32_t unused_29 : 1; // Bit 29
uint32_t unused_30 : 1; // Bit 30
uint32_t unused_31 : 1; // Bit 31
} VariousBits1;
char ClientID[65]; // Used to define the Client ID used by the controller

private:
Expand Down
2 changes: 1 addition & 1 deletion src/src/DataStructs/PluginStats_Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

PluginStats_Config_t & PluginStats_Config_t::operator=(const PluginStats_Config_t& other)
{
stored = other.stored;
setStored(other.getStored());
return *this;
}

Expand Down
Loading

0 comments on commit 71a3290

Please sign in to comment.