Unix time not syncing with server?

Hi all, and thank you for your time.

I have been having trouble getting my code to show the current time in the serial monitor and it is holding me up from completing my project. I have rebuilt this from the ground up, but still face the same issue.

this is the output to the serial monitor:

 ets Jan  8 2013,rst cause:2, boot mode:(3,7)

load 0x4010f000, len 1384, room 16 
tail 8
chksum 0x2d
csum 0x2d
v3de0c112
~ld
ü.........
WiFi connected
IP address: 
192.168.0.13
[4823] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.4.3 on Arduino

[5001] Connecting to blynk-cloud.com:8442
[5241] Ready (ping: 0ms).
[10242] Connecting to blynk-cloud.com:8442
[21284] Connecting to blynk-cloud.com:8442
[21392] Ready (ping: 0ms).
Connected to Blynk server
Current time: 0:0:31 1 1 1970
Connected to Blynk server
Current time: 0:0:41 1 1 1970
Connected to Blynk server

My code:

#define BLYNK_PRINT Serial

#include "Blynk.h"
#include "rtc.h"

void setup()
{
  wifiServerConnect();
  
  rtc.begin();

  timer.setInterval(10000L, clockDisplay);
}

void loop()
{
  Blynk.run();
  timer.run();
}

rtc.h:

#include <TimeLib.h>
#include <WidgetRTC.h>

WidgetRTC rtc;

void clockDisplay()
{
  // You can call hour(), minute(), ... at any time
  // Please see Time library examples for details

  String currentTime = String(hour()) + ":" + minute() + ":" +     second();
  String currentDate = String(day()) + " " + month() + " " + year();
  Serial.print("Current time: ");
  Serial.print(currentTime);
  Serial.print(" ");
  Serial.print(currentDate);
  Serial.println();

  // Send time to the App
  Blynk.virtualWrite(V1, currentTime);
  // Send date to the App
  Blynk.virtualWrite(V2, currentDate);
}

and in case it is relevant, Blynk.h:

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>

SimpleTimer timer;

char auth[] = "6f5664c6d70f499e9d6f87e63f669bac";
char ssid[] = "virginmedia6125068";
char pass[] = "jnaascuw";

bool Connected = false;

void CheckConnection(){
  Connected = Blynk.connected();
  if(!Connected){
    Serial.println("Not connected to Blynk server"); 
    Blynk.connect(3333);  // timeout set to 10 seconds and then continue without Blynk  
  }
  else{
    Serial.println("Connected to Blynk server");     
  }
};

void wifiServerConnect (){
    Serial.begin(74880);
  WiFi.begin(ssid, pass);  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");  
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());  
  
  Blynk.config(auth);  // in place of Blynk.begin(auth, ssid, pass);
  Blynk.connect(3333);  // timeout set to 10 seconds and then continue without Blynk
  while (Blynk.connect() == false) {
    // Wait until connected
  }
  Serial.println("Connected to Blynk server");
  timer.setInterval(11000L, CheckConnection); // check if still connected every 11 seconds 

};

Any help would be really valued! I’ve been fussing about trying to fix this for long enough that the animal who will be the beneficiary of this environmental control system is becoming uncomfortably cramped in his/her current quarters waiting for me to finish!

hardware is Wemos D1 Mini Pro (ESP8266).

Wait 5 min for the re-sync or set the setSyncInterval() shorter… I use 5 seconds after boot then change it back to 5min once the year != 1970

setSyncInterval(interval);         // set the number of seconds between re-sync

Ref: https://github.com/PaulStoffregen/Time

Sadly this isn’t changing the serial output :confused:

edit: For that matter it also doesn’t seem to be syncing each 5 minute period.

Try latest library.

v0.4.6

No change on the output sadly.

Following a reset or five, the code is now syncing. Absolutely no idea why tbh. Anyway, thanks for the help all :slight_smile:

1 Like