netzwerk
This commit is contained in:
parent
31eefef9a2
commit
05d50c5ad7
@ -22,6 +22,19 @@
|
||||
<ParameterType Id="%AID%_PT-IpOctet" Name="IpOctet">
|
||||
<TypeNumber SizeInBit="8" Type="unsignedInt" minInclusive="0" maxInclusive="255" />
|
||||
</ParameterType>
|
||||
<ParameterType Id="%AID%_PT-WpaVersion" Name="WpaVersion">
|
||||
<TypeRestriction Base="Value" SizeInBit="8">
|
||||
<Enumeration Text="WPA2" Value="0" Id="%ENID%" />
|
||||
<Enumeration Text="WPA3" Value="1" Id="%ENID%" />
|
||||
<Enumeration Text="WPA2/WPA3" Value="2" Id="%ENID%" />
|
||||
</TypeRestriction>
|
||||
</ParameterType>
|
||||
<ParameterType Id="%AID%_PT-WlanSsid" Name="WlanSsid">
|
||||
<TypeText SizeInBit="256" />
|
||||
</ParameterType>
|
||||
<ParameterType Id="%AID%_PT-WlanPassword" Name="WlanPassword">
|
||||
<TypeText SizeInBit="512" />
|
||||
</ParameterType>
|
||||
</ParameterTypes>
|
||||
<Parameters>
|
||||
<!-- Byte 0: Flags -->
|
||||
@ -184,6 +197,24 @@
|
||||
ParameterType="%AID%_PT-IpOctet" Text="WLAN DNS 4. Oktett" Value="1">
|
||||
<Memory CodeSegment="%AID%_RS-04-00000" Offset="32" BitOffset="0" />
|
||||
</Parameter>
|
||||
|
||||
<!-- WLAN WPA Version: Byte 33 -->
|
||||
<Parameter Id="%AID%_P-%TT%00050" Name="pWlanWpa"
|
||||
ParameterType="%AID%_PT-WpaVersion" Text="WPA Version" Value="0">
|
||||
<Memory CodeSegment="%AID%_RS-04-00000" Offset="33" BitOffset="0" />
|
||||
</Parameter>
|
||||
|
||||
<!-- WLAN SSID: Bytes 34-65 (32 bytes) -->
|
||||
<Parameter Id="%AID%_P-%TT%00051" Name="pWlanSsid"
|
||||
ParameterType="%AID%_PT-WlanSsid" Text="WLAN SSID" Value="">
|
||||
<Memory CodeSegment="%AID%_RS-04-00000" Offset="34" BitOffset="0" />
|
||||
</Parameter>
|
||||
|
||||
<!-- WLAN Password: Bytes 66-129 (64 bytes) -->
|
||||
<Parameter Id="%AID%_P-%TT%00052" Name="pWlanPassword"
|
||||
ParameterType="%AID%_PT-WlanPassword" Text="WLAN Passwort" Value="">
|
||||
<Memory CodeSegment="%AID%_RS-04-00000" Offset="66" BitOffset="0" />
|
||||
</Parameter>
|
||||
</Parameters>
|
||||
<ParameterRefs>
|
||||
<!-- Flags -->
|
||||
@ -231,6 +262,10 @@
|
||||
<ParameterRef Id="%AID%_P-%TT%00043_R-%TT%0004301" RefId="%AID%_P-%TT%00043" />
|
||||
<ParameterRef Id="%AID%_P-%TT%00044_R-%TT%0004401" RefId="%AID%_P-%TT%00044" />
|
||||
<ParameterRef Id="%AID%_P-%TT%00045_R-%TT%0004501" RefId="%AID%_P-%TT%00045" />
|
||||
<!-- WLAN WPA, SSID, Password -->
|
||||
<ParameterRef Id="%AID%_P-%TT%00050_R-%TT%0005001" RefId="%AID%_P-%TT%00050" />
|
||||
<ParameterRef Id="%AID%_P-%TT%00051_R-%TT%0005101" RefId="%AID%_P-%TT%00051" />
|
||||
<ParameterRef Id="%AID%_P-%TT%00052_R-%TT%0005201" RefId="%AID%_P-%TT%00052" />
|
||||
</ParameterRefs>
|
||||
<ComObjectTable />
|
||||
<ComObjectRefs />
|
||||
@ -285,6 +320,10 @@
|
||||
|
||||
<choose ParamRefId="%AID%_UP-%TT%00003_R-%TT%0000301">
|
||||
<when test="1">
|
||||
<ParameterSeparator Id="%AID%_PS-nnn" Text="WLAN Zugangsdaten" UIHint="Headline" />
|
||||
<ParameterRefRef RefId="%AID%_P-%TT%00051_R-%TT%0005101" IndentLevel="1" />
|
||||
<ParameterRefRef RefId="%AID%_P-%TT%00052_R-%TT%0005201" IndentLevel="1" />
|
||||
<ParameterRefRef RefId="%AID%_P-%TT%00050_R-%TT%0005001" IndentLevel="1" />
|
||||
<ParameterRefRef RefId="%AID%_UP-%TT%00004_R-%TT%0000401" IndentLevel="1" />
|
||||
|
||||
<choose ParamRefId="%AID%_UP-%TT%00004_R-%TT%0000401">
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
#include "Wifi.hpp"
|
||||
#include "knx_facade.h"
|
||||
#include "esp_log.h"
|
||||
#include <cstring>
|
||||
|
||||
static const char* TAG = "NetworkConfig";
|
||||
|
||||
@ -32,6 +33,13 @@ static constexpr uint16_t NW_WLAN_SUBNET = NW_PARAM_BASE + 21;
|
||||
static constexpr uint16_t NW_WLAN_GATEWAY = NW_PARAM_BASE + 25;
|
||||
static constexpr uint16_t NW_WLAN_DNS = NW_PARAM_BASE + 29;
|
||||
|
||||
// WLAN credentials: bytes 33-129
|
||||
static constexpr uint16_t NW_WLAN_WPA = NW_PARAM_BASE + 33;
|
||||
static constexpr uint16_t NW_WLAN_SSID = NW_PARAM_BASE + 34;
|
||||
static constexpr uint16_t NW_WLAN_PASS = NW_PARAM_BASE + 66;
|
||||
static constexpr uint16_t NW_WLAN_SSID_LEN = 32;
|
||||
static constexpr uint16_t NW_WLAN_PASS_LEN = 64;
|
||||
|
||||
extern KnxFacade<Esp32IdfPlatform, Bau07B0> knx;
|
||||
|
||||
static void readIpOctets(uint16_t offset, uint8_t out[4]) {
|
||||
@ -40,6 +48,25 @@ static void readIpOctets(uint16_t offset, uint8_t out[4]) {
|
||||
}
|
||||
}
|
||||
|
||||
static std::string readParamString(uint16_t offset, uint16_t maxLen) {
|
||||
char buf[128] = {};
|
||||
uint16_t len = (maxLen < sizeof(buf) - 1) ? maxLen : sizeof(buf) - 1;
|
||||
for (uint16_t i = 0; i < len; i++) {
|
||||
buf[i] = (char)knx.paramByte(offset + i);
|
||||
if (buf[i] == '\0') break;
|
||||
}
|
||||
buf[len] = '\0';
|
||||
return std::string(buf);
|
||||
}
|
||||
|
||||
static wifi_auth_mode_t wpaVersionToAuthMode(uint8_t wpaVersion) {
|
||||
switch (wpaVersion) {
|
||||
case 1: return WIFI_AUTH_WPA3_PSK;
|
||||
case 2: return WIFI_AUTH_WPA2_WPA3_PSK;
|
||||
default: return WIFI_AUTH_WPA2_PSK;
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkConfig::applyFromKnx() {
|
||||
if (!knx.configured()) {
|
||||
ESP_LOGW(TAG, "KNX not configured, using default network settings");
|
||||
@ -92,5 +119,18 @@ void NetworkConfig::applyFromKnx() {
|
||||
|
||||
Wifi::instance().applyStaticIp(cfg);
|
||||
}
|
||||
|
||||
// Read WLAN credentials from KNX parameters
|
||||
std::string ssid = readParamString(NW_WLAN_SSID, NW_WLAN_SSID_LEN);
|
||||
std::string password = readParamString(NW_WLAN_PASS, NW_WLAN_PASS_LEN);
|
||||
uint8_t wpaVersion = knx.paramByte(NW_WLAN_WPA);
|
||||
wifi_auth_mode_t authMode = wpaVersionToAuthMode(wpaVersion);
|
||||
|
||||
if (!ssid.empty()) {
|
||||
ESP_LOGI(TAG, "WLAN connecting to SSID: %s (WPA=%d)", ssid.c_str(), wpaVersion);
|
||||
Wifi::instance().connect(ssid.c_str(), password.c_str(), authMode);
|
||||
} else {
|
||||
ESP_LOGW(TAG, "WLAN enabled but no SSID configured");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -137,17 +137,17 @@ void Wifi::scan(std::function<void(std::vector<wifi_ap_record_t>&)> callback) {
|
||||
}, "wifi_scan", 4096, nullptr, 5, nullptr);
|
||||
}
|
||||
|
||||
void Wifi::connect(const char* ssid, const char* password) {
|
||||
ESP_LOGI(TAG, "Connecting to %s", ssid);
|
||||
void Wifi::connect(const char* ssid, const char* password, wifi_auth_mode_t authMode) {
|
||||
ESP_LOGI(TAG, "Connecting to %s (auth=%d)", ssid, authMode);
|
||||
|
||||
xEventGroupClearBits(wifiEventGroup_, WIFI_CONNECTED_BIT | WIFI_FAIL_BIT);
|
||||
|
||||
wifi_config_t wifi_config = {};
|
||||
strncpy((char*)wifi_config.sta.ssid, ssid, sizeof(wifi_config.sta.ssid) - 1);
|
||||
strncpy((char*)wifi_config.sta.password, password, sizeof(wifi_config.sta.password) - 1);
|
||||
wifi_config.sta.threshold.authmode = WIFI_AUTH_WPA2_PSK;
|
||||
wifi_config.sta.threshold.authmode = authMode;
|
||||
wifi_config.sta.pmf_cfg.capable = true;
|
||||
wifi_config.sta.pmf_cfg.required = false;
|
||||
wifi_config.sta.pmf_cfg.required = (authMode == WIFI_AUTH_WPA3_PSK);
|
||||
|
||||
currentSSID_ = ssid;
|
||||
|
||||
|
||||
@ -18,7 +18,7 @@ public:
|
||||
void init();
|
||||
void applyStaticIp(const StaticIpConfig& cfg);
|
||||
void scan(std::function<void(std::vector<wifi_ap_record_t>&)> callback);
|
||||
void connect(const char* ssid, const char* password);
|
||||
void connect(const char* ssid, const char* password, wifi_auth_mode_t authMode = WIFI_AUTH_WPA2_PSK);
|
||||
void disconnect();
|
||||
bool isConnected();
|
||||
std::string getCurrentSSID();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user