2026-04-2502

This commit is contained in:
2026-04-25 16:15:24 +02:00
parent 10d2301686
commit c3888efbe2
2 changed files with 86 additions and 1 deletions
+17 -1
View File
@@ -8,7 +8,7 @@
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:esp32]
[env]
platform = espressif32
board = nodemcu-32s
framework = arduino
@@ -21,3 +21,19 @@ monitor_filters = time
lib_deps =
# The exact version
sensirion/Sensirion I2C SCD4x @ 1.1.0
adafruit/Adafruit NeoPixel @ 1.15.4
knolleary/PubSubClient @ 2.8
[env:debug] ; Entwicklungssystem
build_flags = ${env.build_flags}
-DDEBUG=1
-DGRENZWERT=3.70
-DSTASSID=\"MagentaWLAN-RGDO\"
-DSTAPSK=\"93329248424922704583\"
-DGATEWAY=\"192.168.127.1\"
-DDNS=\"192.168.127.1\"
-DSECONDARDNS=\"8.8.8.8\"
-DMYIP=\"192.168.127.52\"
-DSUBNET=\"255.255.255.0\"
-Dmqtt_server=\"192.168.127.251\"
-DMQTTPORT=1883
+69
View File
@@ -36,8 +36,10 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <Arduino.h>
#include <WiFi.h>
#include <SensirionI2cScd4x.h>
#include <Wire.h>
#include <PubSubClient.h>
// macro definitions
// make sure that we use the proper definition of NO_ERROR
@@ -46,23 +48,90 @@
#endif
#define NO_ERROR 0
WiFiClient espClient;
PubSubClient client(espClient);
SensirionI2cScd4x sensor;
static char errorMessage[64];
static int16_t error;
IPAddress ip;
IPAddress gateway;
IPAddress subnet;
IPAddress dns; // DNS-Server
IPAddress secondarDNS;
void PrintUint64(uint64_t& value) {
Serial.print("0x");
Serial.print((uint32_t)(value >> 32), HEX);
Serial.print((uint32_t)(value & 0xFFFFFFFF), HEX);
}
void setup_wifi() {
long ErrCount = 0;
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");
}
if (!secondarDNS.fromString(SECONDARDNS)) { // try to parse into the IPAddress
Serial.println("UnParsable GATEWAY");
}
if (!subnet.fromString(SUBNET)) { // try to parse into the IPAddress
Serial.println("UnParsable GATEWAY");
}
delay(10);
// We start by connecting to a WiFi network
Serial.println();
Serial.print("Connecting to ");
Serial.print(STASSID);
Serial.print(" ");
//WiFi.forceSleepWake();
delay( 1 );
#ifndef DHCP
WiFi.config( ip, gateway, subnet, dns, secondarDNS);
#endif
WiFi.begin(STASSID, STAPSK);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
ErrCount ++;
if (ErrCount >= 30){
delay(500);
ESP.restart();
}
}
//Serial.println(" WiFi connected");
client.setServer(mqtt_server, MQTTPORT);
client.setCallback(callback);
Serial.print("IP address: \t");
Serial.println(WiFi.localIP());
}
void setup() {
Serial.begin(115200);
while (!Serial) {
delay(100);
}
Wire.begin();
sensor.begin(Wire, SCD41_I2C_ADDR_62);