Hi, I wonder if someone can help me…
My project uses a Arduino mega and a ESP-01 wifi shield for doing some monitoring around the house. I am using a WDT to reset the mega if/when the connection is ever lost. I would like to log the time of the disconnect to EEPROM memory so that I have a record of when the project goes offline.
I am intending to save the time and date to EEPROM as the int32(?) which is given by now() from the Blynk RTC Widget. Therefore, in order to read the number back out from the EEPROM memory, I need to convert the number into the local time and date format.
I have searched in a number of places and I have found code to convert from raw time number to time date format but it doesn’t work in my script. I get an error message which I think may be caused by a conflict between the WidgetRTC.h, TimeLib.h and time.h libraries.
This is where I got the example code, but notice that this script doesn’t have the WidgetRTC.h library.
I am running on a Arduino mega and a ESP-01 wifi shield. I am running Blynk off the online server on iOS phone.
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266_hack.h>
// Real Time Clock library
#include <WidgetRTC.h>
#include <TimeLib.h>
#include <time.h>
// Blynk project authentication code
char auth[] = "xxxx";
// WiFi credentials.
char ssid[] = "xxxx";
char pass[] = "xxxx";
// Hardware Serial on Mega, Leonardo, Micro...
#define EspSerial Serial1
// Your ESP8266 baud rate:
#define ESP8266_BAUD 115200
ESP8266 wifi(&EspSerial);
BlynkTimer timer;
WidgetRTC rtc;
char dateBuffer[12];
String currentTime;
String currentDate;
String Recorded_time;
tmElements_t tm;
char time_stamp[80];
void setup()
{
// Debug console
Serial.begin(9600);
// Set ESP8266 baud rate
EspSerial.begin(ESP8266_BAUD);
Blynk.begin(auth, wifi, ssid, pass);
//Real time clock begin.
rtc.begin();
// Run Blynk.run a few times to allow rtc to sync correctly.
Blynk.run();
Blynk.run();
Blynk.run();
Blynk.run();
timer.setInterval(1000L, Uptime);
timer.setInterval(5001L, clockDisplay);
setSyncInterval(10 * 60); // Sync interval for RTC in seconds (interval is in seconds so this is 10 minutes)
}
void loop()
{
Blynk.run();
timer.run(); // Initiates BlynkTimer
}
//// Uptime counter
void Uptime()
{
Blynk.virtualWrite(V0, millis() / 1000);
}
void LogDisconnected()
{
// Print to serial monitor
Serial.print("Disconnected at: ");
Serial.print(currentTime);
Serial.print(" ");
Serial.print(currentDate);
Serial.println();
Serial.flush();
}
// Digital clock display of the time
void clockDisplay()
{
sprintf(dateBuffer, "%02d:%02d:%02d", hour(), minute(), second());
currentTime = dateBuffer;
sprintf(dateBuffer, "%04d/%02d/%02d", year(), month(), day());
currentDate = dateBuffer;
Serial.print("Current time: ");
Serial.print(currentTime);
Serial.print(" ");
Serial.print(currentDate);
Serial.println();
Recorded_time=now();
Serial.println(Recorded_time);
tm = localtime(Recorded_time); <------------------- This is where the problem is.
strftime (time_stamp,80,"%a %I:%M %p %d %b %G %Z.",tm); <------------------- This is where the problem is.
Serial.println(time_stamp);
}
This is the error message…
‘localtime’ was not declared in this scope
if I comment this line out then I get another one…
‘strftime’ was not declared in this scope