ESP32 WROOM 32 hängt sich immer auf

Guten Tag,

dies ist hier mein erster Beitrag. Habe hier schon öffters etwas gestöbert und Hilfe gefunden.
Bei meinem jetzigen Problem komme ich aber nicht weiter…

Wie der titel schon sagt, hängt sich der ESP32 in unregelmäßigen Abständen ständig auf. Es handelt sich dabei um dieses Modul ESP32-WROOM-32.

Verdrahtet wie auf dem Bild:

und hier der Code:

#include <Wire.h>
#include <cactus_io_BME280_I2C.h>
#include <WiFi.h>

#define uS_TO_S_FACTOR 1000000  // Konvertiert Mikrosekunden zu Sekunden
#define TIME_TO_SLEEP 900       // Zeit in Sekunden

const char* ssid     = "SSID";
const char* password = "PW";
const int httpPort   = 80;
const char* host     = "Server_IP";
float t;
float h;
float p;
float raw1;
float raw2;
float volt;
float R1 = 100.00;
float R2 = 40.00;
const int voltpin = 36;
const int LED = 12;
//const int LED_BUILTIN = 2;

// Create BME280 object
// BME280_I2C bme(0x77); // I2C using address 0x77
BME280_I2C bme(0x76); // I2C using address 0x76

RTC_DATA_ATTR int bootCount = 0;

void print_wakeup_reason(){
  esp_sleep_wakeup_cause_t wakeup_reason;

  wakeup_reason = esp_sleep_get_wakeup_cause();

  switch(wakeup_reason)
  {
    case 1  : Serial.println("Wakeup caused by external signal using RTC_IO"); break;
    case 2  : Serial.println("Wakeup caused by external signal using RTC_CNTL"); break;
    case 3  : Serial.println("Wakeup caused by timer"); break;
    case 4  : Serial.println("Wakeup caused by touchpad"); break;
    case 5  : Serial.println("Wakeup caused by ULP program"); break;
    default : Serial.println("Wakeup was not caused by deep sleep"); break;
  }
}

void setup() {
  Serial.begin(115200);
  
  pinMode(voltpin, INPUT);
  pinMode(LED , OUTPUT);
  //pinMode(LED_BUILTIN, OUTPUT);
  delay(500);

  Serial.println("Bosch BME280 Druck - Feuchte - Temp Sensor");

  digitalWrite(LED, HIGH);
  //digitalWrite(LED_BUILTIN, HIGH);

  ++bootCount;
  Serial.print("Boot number: ");
  Serial.println(bootCount);
  print_wakeup_reason();
  esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);

  bme.setTempCal(-1);// Temp was reading high so subtract 1 degree

  raw1 = analogRead(A0);
  raw2 = raw1 * (4.4 * (R1/(R1+R2)));
  volt = raw2 / 1000;
  
  //raw1 = analogRead(voltpin);
  //raw2 = (raw1 / 1000.0) / 4096.0;
  //volt = raw2 * 5;

  //raw = analogRead(A0);
  //volt = raw / 229.2;

  Serial.print(raw1);
  Serial.print(" | ");
  Serial.print(raw2);
  Serial.print(" | ");
  Serial.println(volt);

  if (!bme.begin()) {
    Serial.println("Kein BME280 Sensor gefunden, Verkabelung überprüfen!");
    delay(5000);
    ESP.restart();
  }
  
  bme.readSensor();
  Serial.print(bme.getHumidity()); Serial.print(" %\t\t");
  h = bme.getHumidity();
  Serial.print(bme.getTemperature_C()); Serial.print(" *C\t");
  t = bme.getTemperature_C();
  Serial.print(bme.getPressure_MB()); Serial.print(" mb\t"); // Druck in Millibar
  p = bme.getPressure_MB();
  Serial.print(bme.getTemperature_F()); Serial.println(" *F");
  if (isnan(h) || isnan(t) || isnan(p)) {
    Serial.println("Fehler beim lesen des BME280 Sensor!");
    delay(5000);
    ESP.restart();
  }

  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(300);
    Serial.println(".");
  }
  
    Serial.println("");
    Serial.println("WiFi Verbunden");
    Serial.println("IP Addresse: ");
    Serial.println(WiFi.localIP());
  
  WiFiClient client;
  if (!client.connect(host, httpPort)) {
    Serial.println("Verbundung fehlgeschlagen");
    delay(5000);
    ESP.restart();
  }
  
  String url = "/arduino/Wetterstation.php?";
  url += "id=1";
  url += "&t=";
  url += t;
  url += "&h=";
  url += h;
  url += "&p=";
  url += p;
  url += "&v=";
  url += volt;
  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" +
               "Connection: close\r\n\r\n");
  Serial.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" +
               "Connection: close\r\n\r\n");

  Serial.print("Schlafe für ");
  Serial.print(TIME_TO_SLEEP);
  Serial.println(" Sekunden");
  Serial.println("Geh jetz Schlafen!");
  digitalWrite(LED, LOW);
  //digitalWrite(LED_BUILTIN, LOW);
  esp_deep_sleep_start();
}

void loop() {

}

Würde es helfen, wenn ich diese abgeänderete Version nutze?

#include <Wire.h>
#include <cactus_io_BME280_I2C.h>
#include <WiFi.h>

#define uS_TO_S_FACTOR 1000000  // Konvertiert Mikrosekunden zu Sekunden
#define TIME_TO_SLEEP 900       // Zeit in Sekunden

const char* ssid     = "SSID";
const char* password = "PW";
const int httpPort   = 80;
const char* host     = "Server_IP";
float t;
float h;
float p;
float raw1;
float raw2;
float volt;
float R1 = 100.00;
float R2 = 40.00;
const int voltpin = 36;
const int LED = 12;
//const int LED_BUILTIN = 2;

// Create BME280 object
// BME280_I2C bme(0x77); // I2C using address 0x77
BME280_I2C bme(0x76); // I2C using address 0x76

void setup() {
  pinMode(voltpin, INPUT);
  pinMode(LED , OUTPUT);
  //pinMode(LED_BUILTIN, OUTPUT);
  delay(500);

  digitalWrite(LED, HIGH);
  //digitalWrite(LED_BUILTIN, HIGH);

  raw1 = analogRead(A0);
  raw2 = raw1 * (4.4 * (R1/(R1+R2)));
  volt = raw2 / 1000;
  
  if (!bme.begin()) {
    bme.setTempCal(-1);// Temp was reading high so subtract 1 degree
  
    bme.readSensor();
    h = bme.getHumidity();
    t = bme.getTemperature_C();
    p = bme.getPressure_MB();
    if (isnan(h) || isnan(t) || isnan(p)) {
    }
    else {
      delay(5000);
      ESP.restart();
    }
  }
  else{
    delay(5000);
    ESP.restart();
  }

  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
  }
  
  WiFiClient client;
  if (!client.connect(host, httpPort)) {
    String url = "/arduino/Wetterstation.php?";
    url += "id=1";
    url += "&t=";
    url += t;
    url += "&h=";
    url += h;
    url += "&p=";
    url += p;
    url += "&v=";
    url += volt;
    client.print(String("GET ") + url + " HTTP/1.1\r\n" +
                 "Host: " + host + "\r\n" +
                 "Connection: close\r\n\r\n");
  }
  else{
    delay(5000);
    ESP.restart();
  }

  digitalWrite(LED, LOW);
  //digitalWrite(LED_BUILTIN, LOW);
  esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
  esp_deep_sleep_start();
}

void loop() {

}

Auf einem WEMOS D1 Mini funktioniert folgender Code Problemlos seit ca. 2 Jahren:

#include <Wire.h>
#include <cactus_io_BME280_I2C.h>     
#include <ESP8266WiFi.h>

const char* ssid = "SSID";
const char* password = "PW";
const int httpPort = 80;
const char* host = "Server_IP";
float t;
float h;
float p;

// Create BME280 object
BME280_I2C bme; // I2C using address 0x77
// BME280_I2C bme(0x76); // I2C using address 0x76

void setup() {
  Serial.begin(115200);
  WiFi.begin(ssid, password);  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
Serial.println(WiFi.localIP());

  pinMode(A0, INPUT);
  
Serial.println("Bosch BME280 Druck - Feuchte - Temp Sensor");

if (!bme.begin()) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}

bme.setTempCal(-1);// Temp was reading high so subtract 1 degree

}
void loop() {

  int raw = analogRead(A0);
  float volt = raw / 229.2;
    
  Serial.print(raw);
  Serial.print(" | ");
  Serial.println(volt);
  
  bme.readSensor();
   Serial.print(bme.getHumidity()); Serial.print(" %\t\t");
   h = bme.getHumidity();
   Serial.print(bme.getTemperature_C()); Serial.print(" *C\t");   
   t = bme.getTemperature_C();
   Serial.print(bme.getPressure_MB()); Serial.print(" mb\t"); // Druck in Millibar
   p = bme.getPressure_MB();
   Serial.print(bme.getTemperature_F()); Serial.println(" *F");
    if (isnan(h) || isnan(t) || isnan(p)) {
    Serial.println("Fehler beim lesen des BME280 Sensor!");
    return;
  }  
   WiFiClient client;
   if (!client.connect(host, httpPort)) {
    Serial.println("Verbundung fehlgeschlagen");
    return;
  }
String url = "/arduino/Wetterstation.php?";
    url += "id=1"; 
    url += "&t="; 
    url += t;
    url += "&h="; 
    url += h;
    url += "&p="; 
    url += p;
    url += "&v=";
    url += volt;
  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" + 
               "Connection: close\r\n\r\n");
   
          
    Serial.end();
    client.stop();
    WiFi.disconnect(); 
    ESP.deepSleep(900000000); 
    delay(200);
  }