Programm stopps after a few minutes...

7 years 11 months ago - 7 years 11 months ago #3286 by sutter.michi
Hi @ all.

I would use the ESP and the DHT22 humitidy Sensor.

But i have the follow problem:

I can programm the ESP and it works fine for a time of ca 30 minutes. But after this time i think the ESP do a reset or what ever....
The programm works no more and the temperature are is longer updated in the cloud.
When i do a maual reset or reconect the power then it works for the same time as before and after this time i have the same issue...

Is that eventually a problem with the watchdog?

Has anyone the same problem?

Best regards

Michi

Please Log in or Create an account to join the conversation.

7 years 11 months ago #3307 by imsony
try to place some log in your code in both loop and set up, in this way you can be sure that if it resets or block.
If you share your code you may get more help.

Please Log in or Create an account to join the conversation.

7 years 11 months ago #3308 by sutter.michi
Hi.

There`s my code:
//********************************************************//
//Bibliotheken:

#include <ESP8266WiFi.h>                                  
#include "EIoTCloudRestApiV1.0.h"
#include "DHT.h"

EIoTCloudRestApi eiotcloud;
DHT dht;

#define DEBUG_PROG 1

#ifdef DEBUG_PROG
  #define DEBUG_PRINTLN(x)  Serial.println(x)
  #define DEBUG_PRINT(x)    Serial.print(x)
#endif

//********************************************************//
//WLAN und EIoTCloud Parameter:

#define AP_USERNAME "Sutter_2.4GHz"                       //WLAN SSID und Passwort eingeben!!
#define AP_PASSWORD "Sutter6Leute2003"

#define INSTANCE_ID "5676f4e4cf045c1fce74d443"            //EIoTCloud Instance ID -> unter Configure -> User Info
#define TOKEN "BWSO0qAeY9aqukietBbOzuFegUbSSUR8El5kBkJO"  //Token -> unter Configure -> Tokens ... !!sehr wichtig ohne geht nichts!!

String moduleId_Raumklima = "1";                          //Temperatur und Luftfeuchtigkeit ID Daten
String parameterId_Temperatur = "dCuTTLGPR3eR6t82";       
String parameterId_Luftfeuchtigkeit = "HnmIKwcBJMIROMZL"; //Configure -> Modules -> SensorParameter -> ParameterID

String parameterId_Schalter = "tJfyC1GLNf8O2Jpw";         //Schalter ID Daten
//********************************************************//
//Pins und Variablen definieren:

//#define INTERVALL 50                                      //Zeit bis zur nächsten Übermittlung der Klimadaten (Wert 10 entspricht ca 14s/ 70 = ca. 60s ...)
int Aktualisierung = 0;

#define SchalterPIN 4                                     //Ausgangs Pin für Schalter

#define TasterPIN 0                                       //Taster Eingangs Pin, für manuelles Ein- und Ausschalten
int TasterStatus_alt = 0;                                 

String Schalter_EIoT = "";                                //Schalter Zustand in der EIoT Cloud
//********************************************************//
//Initialisieren:

void setup() 
{  
      Serial.begin(115200);
    DEBUG_PRINTLN("Start...");

    
  eiotcloud.begin(AP_USERNAME, AP_PASSWORD);              //Ins WLAN einloggen...
  eiotcloud.SetToken(TOKEN);                              //Token setzen!! 

  pinMode(SchalterPIN, OUTPUT);                           //Schalter AusgangsPin
  
  pinMode(TasterPIN,INPUT);
  digitalWrite(TasterPIN, HIGH);
  
  dht.setup(2);                                           //DHT22 Sensor EingangsPin setzen, und Sensor Daten laden...

  eiotcloud.SetParameterValue(parameterId_Schalter,"0");  //Bei ESP Programmstart -> Schalter in der Cloud: AUS!
}
//********************************************************//
//Hauptprogramm:

void loop() 
{
  yield();
  Serial.println("Hauptprogramm");
  delay(1);
//Taster für manuelles ändern des Schalterzustandes: 

  int TasterStatus_neu = digitalRead(TasterPIN);          //Taster für manuelles Ein- und Ausschalten einlesen
  if(TasterStatus_neu != TasterStatus_alt)                //Wenn Taster gedrückt -> Schalter invertieren
  {
    TasterStatus_alt = TasterStatus_neu;
    
    if(TasterStatus_neu == 0)                             //Schalterzustand aus der Cloud abfragen und Ausgang entsprechend invertieren
    {
      Serial.println("Taster gedrückt!!");
      yield();
      if(Schalter_EIoT == "0")
      {
        eiotcloud.SetParameterValue(parameterId_Schalter,"1");
      }
      if(Schalter_EIoT == "1")
      {
        eiotcloud.SetParameterValue(parameterId_Schalter,"0");
      }
    }
  }

//Schalter aus Cloud abfragen und Pin ansteuern:

  Schalter_EIoT = eiotcloud.GetParameterValue(parameterId_Schalter);  //Schalterzustand aus der Cloud abfragen und Ausgang entsprechend setzen
  if (Schalter_EIoT == "1")                                           //Zustand wird als String gespeichert: 0 -> AUSGESCHALTET / 1 -> EINGESCHALTET
  {
    digitalWrite (SchalterPIN, 0);
  }
  if (Schalter_EIoT == "0")
  {
    digitalWrite (SchalterPIN, 1);
  }
  Serial.println("Schalter aktualisiert");
 delay(1);
//DHT22 Sensor auslesen und Daten an Cloud senden:

  if(Aktualisierung == 0)
  {
    yield();
    Serial.println("Temp:");
    delay(dht.getMinimumSamplingPeriod());
  
    float luftf = dht.getHumidity();
    float temp = dht.getTemperature();

    eiotcloud.SetParameterValues("[{\"Id\": \""+parameterId_Temperatur+"\", \"Value\": \""+String(temp)+"\" },{\"Id\": \""+parameterId_Luftfeuchtigkeit+"\", \"Value\": \""+String(luftf)+"\" }]");
    Aktualisierung = 50;
 Serial.println(temp);
  }
  Aktualisierung --;
 Serial.println(Aktualisierung);

  
}

It sends the DHT22 data to the Cloud and recive the switch state form the Cloud...

Is there anything wrong in the code?

Best regards

Michi

Please Log in or Create an account to join the conversation.

Time to create page: 0.185 seconds

Forum latest

  • No posts to display.