Chat freely about anything...

User avatar
By McChubby007
#79804 Your code needs to be reviewed and picked-over as there are various issues, some which are perhaps benign, and others which are masking other problems.

I see you have gone back to your bad old ways of adding wdt resets when your code is misbehaving - this is never a good idea, you are just papering over the cracks.

I looked at the magnet processing code :

Code: Select all     
while( magnet == 1 )
     {
          /* Wait for the ISR to set the
          * flag; reset it before
          * taking any action. */
          if (magnet)
          {
               if ((MINUTE % 15 == 0) && (SECOND == 0))
               {
                    listen();
               }
               else
               {
                    magnet = 0;
                    rainCounter();
               }
          }

Which makes no sense : you have a while followed by an if which is doing the same thing - the if is superfluous.

On the quarter hour you will furiously call listen function as fast as you can until the second ticks over. The listen function does a wifi connect and also spews out serial prints. That is assuming I understand it as the listen function is only (!) 500 lines long. How you imagine anyone can assist with code which is 'designed' like this is beyond me.

You see, I thought I would give you a hand this time, hoping you had taken on board what I said many months ago, but all that has happened is that I am irritated, as I think you are asking way too much when the code is in such a mess.
User avatar
By Sirquil
#79806 @ McChubby007

Having a disability, being 70 years old, self-learned in Arduino C++; I code to the best of my ability. I know it is not perfect and sometimes could be more thought out. I will admit, I do struggle in asking for help. Only after having spent much time with no resolution to an issue, do I ask for help.

I do appreciate you taking time; looking at my code and replying...

William
User avatar
By Sirquil
#80330 01/29/2019

Project sketch is executing without a wdt_reset; it is still a little "touchy" initiating a client "GET" request. Over-all much improved. File, fileRead function is once again fully functional.

Some of the problem was with the GPIO pins I was attempting to use. Current GPIO pin used for espsoftwaresaerial are GPIO5 for TX, GPIO4 for RX, DS3231 uses GPIO2 for SDA, and GPIO0 for SCL. Project board is a RobotDyn WiFi D1 R2. Board looks like a clone of the WeMos WiFi D1 R2.

Project uses a DS3231 for time keeping and will be updated by a Neo m8n GPS module. I am having a "false" value for unixtime in the function RTC_UPDAE. Unixtime value is almost double. Standalone sketch "Get_unixtime.ino" gives correct unixtime value. Intergrating it into project gives about twice the value for unixtime.

Get_unixtime.ino:

[code#include <time.h>
#include <stdio.h>

void setup() {

Serial.begin(115200);

struct tm timeinfo;
unsigned int unixtime;

printf("hello\n");
timeinfo.tm_year = 2017 - 1900;
timeinfo.tm_mon = 12 - 1;
timeinfo.tm_mday = 13;
timeinfo.tm_hour = 16;
timeinfo.tm_min = 46;
timeinfo.tm_sec = 45;

unixtime = mktime(&timeinfo);
printf("time = %u\n", unixtime);
// return 0;
}

void loop(){}][/code]

RTC_UPDATE function:
Code: Select allvoid RTC_UPDATE()
{

    ESP.wdtDisable();
       
    Serial.println("");
    Serial.print(F("GPS UTC Date/Time: "));
   
    if (gps.date.isValid())
    {
      Serial.print(gps.date.month());
      Serial.print(F("/"));
      Serial.print(gps.date.day());
      Serial.print(F("/"));
      Serial.print(gps.date.year());
    }
    else
    {
        Serial.print(F("INVALID"));
    }
 
    Serial.print(F(" "));
   
    if (gps.time.isValid())
    {
 
      if (gps.time.hour() < 10) Serial.print(F("0"));
      Serial.print(gps.time.hour());
      Serial.print(F(":"));
     
      if (gps.time.minute() < 10) Serial.print(F("0"));
      Serial.print(gps.time.minute());
      Serial.print(F(":"));
     
      if (gps.time.second() < 10) Serial.print(F("0"));
      Serial.print(gps.time.second());
      Serial.print(F("."));
     
      if (gps.time.centisecond() < 10) Serial.print(F("0"));
      Serial.print(gps.time.centisecond());
      Serial.println("");
     
    }
    else
    {
        Serial.print(F("INVALID"));
    }
   
       struct tm  timeinfo;
      unsigned long int unixtime;

      timeinfo.tm_year =  gps.date.year() - 1970;
      timeinfo.tm_mon = gps.date.month() - 1;
      timeinfo.tm_mday =  gps.date.day();
      timeinfo.tm_hour =  gps.time.hour();
      timeinfo.tm_min =  gps.time.minute();
      timeinfo.tm_sec = gps.time.second();

      unixtime = mktime(&timeinfo);
      Serial.println("");
      printf("unixtime = %u\n", unixtime);
     
      Clock.setDateTime(unixtime);

      Serial.println("RTC updated");
     
     ESP.wdtEnable(1000);



Any issues with the RTC_UPDATE function; that would cause the unixtime variable to be almost twice the expected value?

William
Attachments
Featuring web interface, graphs, rain gauge, and
GPS --still a work in progress. Working concept demo.

(21.83 KiB) Downloaded 170 times
Screen captures, text files and board pinout.
(1.65 MiB) Downloaded 163 times
Last edited by Sirquil on Wed Jan 30, 2019 4:09 pm, edited 1 time in total.