ESP8266-12E hängt sich auf

Gast #5367252
Lesenswert?

Hallo zusammen,

ich lese mit meinem ESP8266-12E den Temperatursensor BME280 aus.
Dabei stelle ich die Messwerte mithilfe der Blynk-App dar.

Mein Problem:
Der ESP8266 hängt sich meist nach 2-4 Tagen auf.
Habt Ihr eine Idee wie ich meinen Code stabieler programmieren kann?

Vielen Dank schon mal für die Tipps.
1
 
2
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
3
#include <SimpleTimer.h>
4
#include <ESP8266WiFi.h>
5
#include <Adafruit_Sensor.h>
6
#include <Adafruit_BME280.h>
7
#include <BlynkSimpleEsp8266.h>
8
#include <Ticker.h> //watchdog
9

10
Ticker secondTick; //watchdog
11
volatile int watchdogCount = 0; //watchdog
12
volatile int zaehler = 0; //Zähler Benachrichtigung
13

14
SimpleTimer timer;
15
Adafruit_BME280 bme; // I2C
16

17
char auth[] = "***";
18
char ssid[] = "***";
19
char pass[] = "***";
20

21
int connectTimer;
22

23
// Messwertvariablen
24
float h, t, p, pin, dp, tc;
25
char temperatureFString[6];
26
char dpString[6];
27
char humidityString[6];
28
char pressureString[7];
29
char pressureInchString[6];
30

31
void ISRwatchdog() { //ISR = Interrupt Service Routine
32
  watchdogCount++;
33
  if (watchdogCount >= 8) { // Einheit in Sekunden [s]!!!
34
    ESP.reset();
35
  }
36
}
37

38
void WLANconnect() {
39

40
  if (WiFi.status() != WL_CONNECTED) {
41
    yield();
42
    Serial.println("keine Verbindung vorhanden - Reset");
43
    watchdogCount = 8; // Einheit [s]!!!
44
     
45
  } else {
46
    Serial.println("verbunden");
47

48
    h = bme.readHumidity(); //Berechnung Messwert
49
    tc = bme.readTemperature();
50
    t = tc * 1.8 + 32.0;
51
    dp = t - 0.36 * (100.0 - h);
52
    yield();
53

54
    p = bme.readPressure() / 100.0F;
55
    //t = (t-32)*5/9; //[°C]
56
    pin = 0.02953 * p;
57
    dtostrf(tc, 5, 1, temperatureFString);
58
    dtostrf(h, 5, 1, humidityString);
59
    dtostrf(p, 6, 1, pressureString);
60
    dtostrf(pin, 5, 2, pressureInchString);
61
    dtostrf(dp, 5, 1, dpString);
62
    yield();
63

64
    Blynk.virtualWrite(V0, temperatureFString); //Senden Messwert an BlynkApp
65
    Blynk.virtualWrite(V1, humidityString);
66
    Blynk.virtualWrite(V2, pressureString);
67
    Serial.print(temperatureFString);
68
    Serial.println(" °C");
69
    Serial.print(humidityString);
70
    Serial.println(" %");
71
    Serial.print(pressureString);
72
    Serial.println(" hPA");
73
    Serial.println();
74

75
    if (tc > 27 && h > 30){
76
    zaehler = zaehler +1;
77
    }
78
    watchdogCount = 0; // Einheit [s]!!!
79
  }
80
}
81

82

83
void setup()
84
{
85
  Serial.begin(115200);
86
  Blynk.begin(auth, ssid, pass);
87
  Wire.begin(D3, D4); //Sensor
88
  Wire.setClock(115200);
89

90
  bme.begin();
91
  if (!bme.begin()) {
92
    Serial.println("Could not find a valid BME280 sensor, check wiring!");
93
    while (1); //(dient als Wachtdog!, falls Verkabelung defekt - Notfalls Kabel tauschen!)
94

95
    WiFi.begin(auth, ssid); //WiFi Verbindung
96
    Serial.print("Connecting");
97
    while (WiFi.status() != WL_CONNECTED)
98
    {
99
      delay(500);
100
      Serial.print(".");
101
    }
102
    Serial.println();
103
    Serial.print("Connected, IP address: ");
104
    Serial.println(WiFi.localIP());
105

106
  }
107

108
  connectTimer = timer.setInterval(1000L, WLANconnect); //Aurfur alle x Sekunden
109
  yield();
110
  secondTick.attach(1, ISRwatchdog);
111
  yield();
112
  delay(10);
113
}
114

115
void loop() {
116
  Blynk.run();
117
  timer.run();
118
}
Gast #5367360
Lesenswert?

Ein ESP hängt sich nicht auf.
Zumindest noch nie erlebt.
Er wirft eine Exception und startet dann neu.

Tipp:
Du solltest den ESP Exceptiondecoder in deine Arduino IDE integrieren 
und die Exception Meldung da mal rein werfen.

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren