Go Down

Topic: NODEMCU v2.0 with esp8266 stops working after some time (Read 2188 times) previous topic - next topic

tuadru

I have made a project that consists of outdoor modules that gather some parameters of the air using the nodemcu v2.0 board with esp8266 chip and some sensors connected to it (DHT11 for temperature and humidity, cjmcu 8118 for co2 and tvoc). I have managed to send the data from the modules to remote server and fill MySQL database on that server with the data from sensors. Since I don't need readings every second and for power saving in further phases of the project Ive put the esp in sleep for cca. 5minutes after every reading is sent. Everything works fine for few days (2,3,4) and then the reading stop coming to the database, I just reset the modules and they again work for couple of days before stopping again. I have 2 modules for now and they are easily accessible to me at this point so I can restart them manually, but in further phase of this project I was planning to put them on less accessible places with external power supply (solar panel + battery) so its not feasible to climb up there and restart them manually every 2-3-4 days. Does anyone know what could be causing this blockage? It happens to both of my modules so I don't think its a specific board problem. The code is posted below:
Code: [Select]

#include <ESP8266WiFi.h>
#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>
#include <Adafruit_CCS811.h>
#include <DHT.h>

Adafruit_CCS811 ccs;
IPAddress server_addr(xxxxx);  // IP of the MySQL server here
char user[] = "xxxxx";              // MySQL user login username
char password[] = "xxxxx";        // MySQL user login password
char ssid[] = "xxxxx";    // your SSID
char pass[] = "xxxxx";       // your SSID Password
char INSERT_DATA[] = "INSERT INTO database.table(temperature, humidity, co2, voc) VALUES ('%s', '%s', '%s', '%s')";
char query[128];
char temperature[10];
char humidity[10];
char co2[10];
char voc[10];
float t,h,carb2,Voc;
WiFiClient client;
MySQL_Connection conn((Client *)&client);

#define DHTPIN 14
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

void setup() {
  pinMode(D0, WAKEUP_PULLUP);
  Serial.begin(115200);
  while (!Serial); // wait for serial port to connect
  WiFi.begin(ssid, pass);             // connects to the WiFi router
  while (WiFi.status() != WL_CONNECTED) {    delay(500);
  }
  dht.begin();
  ccs.begin();
}

void loop() {
  delay(10000);
  h = dht.readHumidity();
  t = dht.readTemperature();
  if(ccs.available()){
    if(!ccs.readData ()){
       carb2 = ccs.geteCO2();
       Voc = ccs.getTVOC();
             }}
    if(isnan(h))
      {Serial.println("nan"); delay(500);}
    else{
        if (conn.connect(server_addr, 3306, user, password)) {
   
          // Initiate the query class instance
          MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);

          dtostrf(t, 5, 2, temperature);
          dtostrf(h, 5, 2, humidity);
          dtostrf(carb2, 6, 2, co2);
          dtostrf(Voc, 7, 2, voc);
   
   
          sprintf(query, INSERT_DATA, temperatura, vlaga, co2, voc);
          // Execute the query
          cur_mem->execute(query);
     
          // Deleting the cursor also frees up memory used
          delete cur_mem;
   }
   conn.close();
   
   ESP.deepSleep(286e6);
   
   }
}

sterretje

Just a possibility
Code: [Select]
    if (conn.connect(server_addr, 3306, user, password))
    {
      ...
      ...
    }
    conn.close();

It does not sound right to me that you close the connection regardless if it was successfully opened or not.
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

tuadru

Youre right it should probably be within the if loop...Do you think that's could have caused the problems of stoppage?

sterretje

I already stated that it can be a possibility. Just try and see if it solves the issue ;)
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

tuadru

I already stated that it can be a possibility. Just try and see if it solves the issue ;)
Havent seen that part sorry about that.
Ive changed it and now all that's left is waiting for few days to see what happens lol

tuadru

It hasn't worked, its been on for 4 hours sending data and then stopped again.

PerryBebbington

Tuadru,

I'm following this with interest. I have an ESP8266, which I am playing with to learn about it. I left it for several days with a real time clock running using Millis and synchronised to an NTP server every few minutes. The output is sent over serial to a Nextion display. After a few days the clock started incrementing erratically, it would stop for, maybe, 30 seconds then increment normally for a few seconds then stop again. It was not getting timestamps from the NTP server either. I've reset it, I will leave it running for a few more days...

tuadru

Ive tried to remove deep sleep part and just put delay for 5min instead (not a single one but 10 times delay(30000) in for loop ) and same thing happened, it sends data for some time and then stops. Im thinking its the board problem and not sure how to fix it.

P.S.
Nevermind I just found out there was a power outage, its working again. Ill continue to monitor and let you know if it changes in few days.

tuadru

UPDATE:
So far so good. The first module has been working for 4 days now without a glitch after Ive removed the deep sleep part, and second one is working for 24h also without a problem. The problem now is power consumption but if I get big enough battery and solar panel to charge it I should eliminate that problem. Not sure what the issue with deep sleep was, probably wouldn't wake up after some time for whatever the reason.

javierfer

hi tuadru,

Have you been able to solve your problem? Am I experiencing the same issues!

Go Up