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