Hello freinds!
I leanrned from my last posts, that i must be more specfic about my probelms to help you guys.
What i am using:
ESP32
NEXTION 7 inch display
#include <Arduino.h>
#include <Wire.h>
#include "RTClib.h"
#include <Nextion.h>
#include "EEPROM.h"
#include "DFRobot_ESP_PH.h"
// SD card
#include "FS.h"
#include "SD.h"
#include "SPI.h"
//RTC-clock
#include <Wire.h>
#include "RTClib.h"
//#include <functions.cpp>
#include "functions.h"
#define RXD2 16
#define TXD2 17
//Classobjects
Initialize init_1;
File file;
RTC_DS3231 rtc;
uint32_t setup_start;
/********************************************************************************************************
***********************SETUP****************************************************************************
********************************************************************************************************/
// put your setup code here, to run once:
void setup() {
nexInit();
Serial.begin(9600);
Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2);
EEPROM.begin(64);
ph.begin();
init_1.beginInitialize();
init_1.beginInitializeSendToNextion();
DateTime now = rtc.now();
setup_start = now.hour();
//Serial COM
Wire.begin();
// while the serial stream is not open, do nothing:
while (!Serial) ;
/***********************************************
****************SD Initializing process**********
*************************************************/
SD.begin(5);
Serial.print("Initializing SD card...");
if (!SD.begin(5))
{
Serial.println("initialization failed!");
//return;
}
uint8_t cardType = SD.cardType();
if(cardType == CARD_NONE) {
Serial.println("No SD card attached");
//return;
}
/*
file = SD.open("/data.txt");
if(!file) {
Serial.println("File doens't exist");
Serial.println("Creating file...");
writeFile(SD, "/data.txt", "ID, Date, Time, Value_raw, Value_maped \r\n");
}
else {
Serial.println("File already exists");
}
file.close(); */
/***********************************************
****************RTC Initializing process**********
*************************************************/
#ifndef ESP8266
while (!Serial); // for Leonardo/Micro/Zero
#endif
delay(1000); // wait for console opening
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (rtc.lostPower()) {
Serial.println("RTC lost power, lets set the time!");
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
//rtc.adjust(DateTime(2014(Jahr), 1(Monat), 21(Tag), 3(Stunde), 0(Minute), 0(Sekunde)));
//rtc.adjust(DateTime(2019, 10, 31, 11, 19, 0));
//rtc.adjust(DateTime(2019, 11, 1,11,48,00));
}
}
/********************************************************************************************************
***********************Loop****************************************************************************
********************************************************************************************************/
// put your main code here, to run repeatedly:
void loop() {
//DateTime hol;
DateTime now = rtc.now();
String current_line = "";
//Interval for measurements
if (millis() - startChrono >=(init_1._measrueIntvl)*1000)
{
voltage = mapf(analogRead(PH_PIN),A1.low_x1,A1.low_y1,A1.low_x2,A1.low_y2);
phValue = ph.readPH(voltage);
A1.phValue=phValue; //Ausgerechneter Ph Value von lib DFRobot wird in struct gespeichert
writeTextIntoNextion();
init_1.logSDCard();
startChrono=millis();
}
//Intervall for time. Usually its set to 1 sec
if (millis() - startChrono_clock >= Clocktimer)
{
sprintf(tempString, "%02d.%02d.%02d/%02d:%02d:%02d",now.day(),now.month(),now.year(),now.hour(), now.minute(),now.second());
Serial2.print("time.txt=\"");
Serial2.print(tempString);
Serial2.write('"');
Serial2.write(0xFF);
Serial2.write(0xFF);
Serial2.write(0xFF);
DateTime now = rtc.now();
DateTime future (now + TimeSpan(0,0,1,0));
Serial.println("now.unixtime()");
Serial.println(now.unixtime());
Serial.println("future.unixtime()");
Serial.println(future.unixtime());
Serial.print("setup_start ");
Serial.println(setup_start);
checkRoutine();
writeGeneralInfo();
startChrono_clock=millis();
}
nexLoop(nex_listen_list);
}
The output that i get is:
now.unixtime(): 17
future.unixtime(): 17
setup_start: 165
What i dont understand: isnt the now object not always the same? The object DateTime now = rtc.now(); that i created in Setup, shouldnt that store the current "hours" when the sectch was uploaded? Why is it 165? I expected 17. The hours the RTC is set
thank you