(SOLVED) ESP8266mcu and ds3231

Hi. I need show clock in blynk. But this sketch show bad value… ?
THanks…

#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <DHT.h>
#include <TimeLib.h>
#include <WidgetRTC.h>
#include <Wire.h>


#define DHTPIN 12 //pin gpio 12 in sensor
#define DHTTYPE DHT22   // DHT 22 Change this if you have a DHT11
DHT dht(DHTPIN, DHTTYPE);

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "";  // Put your Auth Token here. (see Step 3 above)

SimpleTimer timer;

WidgetRTC rtc;

void setup()
{
  Serial.begin(9600); // See the connection status in Serial Monitor
   Blynk.begin(auth, "", ""); //insert here your SSID and password
 
  // Setup a function to be called every second
  timer.setInterval(10000L, sendUptime);
  timer.setInterval(10000L, clockDisplay);
   Wire.begin(4,5);             //ds3231: 4-D2 SDA. 5-D1 SCL
   rtc.begin(); 
}

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);
}


void sendUptime()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
   //Read the Temp and Humidity from DHT
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  
  Blynk.virtualWrite(12, t); // virtual pin 
  Blynk.virtualWrite(13, h); // virtual pin 
}

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

Which library version are you using? I believe your need 0.4.4 or later but it would make sense to use the latest, currently 0.4.6.

iOS or Android?

I have 0.4.4 and iOS… Thanks…

Now i have 0.4.6 and is it same…
Is possible something wrong in sketch??

@Jiri_Bam try rtc.begin() directly after Blynk.begin() like in the Sketch Builder example.

There are some other hacks like if year == 1970 don’t show time and setInterval() for rtc updates but they shouldn’t be needed.

I tryed :

Serial.begin(9600); // See the connection status in Serial Monitor
   Blynk.begin(auth, "ASUS", "Jersin72"); //insert here your SSID and password
   rtc.begin();
   Wire.begin(4,5);             //ds3231: 4-D2 SDA. 5-D1 SCL
   

but is it same

Have you added the RTC widget to your project as I don’t see it on the tab that is visible, could be on the GRAF tab.

No i dont have. Do you mean this?:

So yes that was wrong… Now is it good… THanks

A post was split to a new topic: Real Time question