From 8994baad3c6f4b7e85a7fead368a9822dae4a3a7 Mon Sep 17 00:00:00 2001 From: hans-jurgen Date: Tue, 24 Sep 2024 11:15:49 +0200 Subject: [PATCH] 2024-09-2400 --- platformio.ini | 4 ++-- src/main.cpp | 26 ++++++++++++++++++++------ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/platformio.ini b/platformio.ini index d334e85..74050f1 100644 --- a/platformio.ini +++ b/platformio.ini @@ -24,12 +24,12 @@ lib_deps = build_flags = ${env.build_flags} -DDEBUG=0 -DNOADS=0 - -DNAME=\"BLE_GATE\" + -DNAME=\"BLE-Praesenz\" -DSTASSID=\"MagentaWLAN-RGDO\" -DSTAPSK=\"93329248424922704583\" -DGATEWAY=\"192.168.127.1\" -DDNS=\"192.168.127.1\" - -DKMYIP=\"192.168.127.42\" + -DKMYIP=\"192.168.127.241\" -Dmqtt_server=\"192.168.127.193\" -Dmqtt_port=1883 diff --git a/src/main.cpp b/src/main.cpp index b0c72e2..09ede1c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -37,11 +37,13 @@ int scanTime = 5; //In seconds long int Feldstaerke; // WiFI -IPAddress ip( 192, 168, 127, 241 ); // 10 bis 29 für feste IP -IPAddress gateway( 192, 168, 127, 1 ); -IPAddress subnet( 255, 255, 255, 0 ); -IPAddress dns(192, 168, 127, 1); // DNS-Server +IPAddress ip; +IPAddress gateway; +IPAddress subnet(255,255,255,0); +IPAddress dns; +IPAddress secondaryDNS(8, 8, 8, 8); String hostname = NAME; +const char *MyIP = KMYIP; char msg[20]; char clientName[30]; char topic[50]; @@ -96,8 +98,20 @@ static void setup_wifi() { WiFi.persistent( false ); WiFi.setHostname(hostname.c_str()); //define hostname WiFi.mode( WIFI_STA ); - WiFi.config( ip, gateway, subnet, dns, dns ); - + if (!ip.fromString(MyIP)) { // try to parse into the IPAddress + Serial.println("UnParsable IP"); + } + if (!dns.fromString(DNS)) { // try to parse into the IPAddress + Serial.println("UnParsable DNS"); + } + if (!gateway.fromString(GATEWAY)) { // try to parse into the IPAddress + Serial.println("UnParsable GATEWAY"); + } + //WiFi.config( ip, dns, gateway, subnet ); + if (!WiFi.config(ip, gateway, subnet, dns, secondaryDNS)) + { + Serial.println("STA Failed to configure"); + } WiFi.begin (STASSID, STAPSK); while (WiFi.status() != WL_CONNECTED) {