b707:
Can you show your code?
#define USE_DS1307
// ============= =======================================================
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#include <MD_DS1307.h>
#include "Font_Data.h"
#include <microDS18B20.h>
// ============= =======================================================
#include <GyverPortal.h>
#include <EEPROM.h>
#include <ESP8266WiFi.h>
#include <EEManager.h>
#include "Timer.h"
GyverPortal portal;
const char* ssid = ""; //“your_wifi_ssid”
const char* password = ""; //"your_wifi_password"
uint8_t retries=0;
// ============= ========================================================
//#include <NTPClient.h>
#include <WiFiUdp.h>
#include <GyverNTP.h>
const long timeZone = 3;
const long UpdateInterval = 43200;
//WiFiUDP ntpUDP;
//NTPClient timeClient(ntpUDP, "ua.pool.ntp.org", timeZone, UpdateInterval);
GyverNTP ntp(timeZone, UpdateInterval);
// ================================================================
MicroDS18B20<0> sensor; // ESP8266 D3/0 // Arduino Nano D2/2
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW //ICSTATION_HW
#define MAX_ZONES 3 //
#define ZONE_SIZE 4 //
#define MAX_DEVICES (MAX_ZONES * ZONE_SIZE)
#define ZONE_UPPER 1 //
#define ZONE_LOWER 0 //
#define CLK_PIN 14 //
#define DATA_PIN 13 //
#define CS_PIN 15 //
MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
// Global variables
char szTimeL[9]; // hh:mm\0
char szTempC[9];
char szTempP[2];
char szTempS[2];
//======================================
uint8_t brDisp = 0;
uint8_t dsTimeH1 = 23;
uint8_t dsTimeH2 = 4;
uint8_t brTimeH1 = 5;
uint8_t brTimeH2 = 8;
uint8_t brTimeH3 = 20;
//======================================
/*GPtime valTime = {
(uint16_t)21, (uint8_t)28,(uint8_t)0
};
*/
GPtime valTime1 = {
(uint16_t)21, (uint8_t)28
};
GPtime valTime2 = {
(uint16_t)22, (uint8_t)14
};
//======================================
void getTime(char *psz, bool f = true)
{
RTC.readTime();
sprintf(psz, "%02d%c%02d", RTC.h, (f ? ':' : ' '), RTC.m);
}
void getTemperature(char *psz)
{
float temperature = 0;
int t = 0;
if (sensor.readTemp()) temperature = sensor.getTemp();
else Serial.println("error");
sensor.requestTemp();
t = (abs(temperature) - (byte)abs(temperature)+0.01)*10;
if (temperature > 0 ) {
sprintf(szTempP, "+");
}
else {
sprintf(szTempP, "-");
}
sprintf(szTempS, "%1d", t);
sprintf(psz, "%2d%c", (byte)abs(temperature), '.');
}
void getDisplayShutdown2()
{
RTC.readTime();
if (dsTimeH2 >= dsTimeH1) {
if (RTC.h >= dsTimeH1 && RTC.h <= dsTimeH2) {
P.displayShutdown(true);
}
else {
P.displayShutdown(false);
}
}
else {
if (RTC.h >= dsTimeH2 && RTC.h <= dsTimeH1) {
P.displayShutdown(false);
}
else {
P.displayShutdown(true);
}
}
}
void getDisplayBright()
{
RTC.readTime();
if (RTC.h >= brTimeH1 && RTC.h < brTimeH2) {
brDisp = 1;
}
else if (RTC.h >= brTimeH2 && RTC.h < brTimeH3) {
brDisp = 15;
}
else {
brDisp = 0;
}
}
void action() {
if (portal.form()) {
if (portal.form("/save")) {
brDisp = portal.getInt("br");
valTime1 = portal.getTime("time1");
valTime2 = portal.getTime("time2");
Serial.print(brDisp);
Serial.print(',');
Serial.print(encodeTime(valTime1));
Serial.print(',');
Serial.print(encodeTime(valTime2));
}
}
}
void timeUpdate()
{
//timeClient.update();
if (ntp.tick() && ntp.synced()&& ntp.status()==0)
{
//RTC.adjust(DateTime(ntp.year(), ntp.month(), ntp.day(), ntp.hour(), ntp.minute(), ntp.second()));
RTC.yyyy = ntp.year();
RTC.mm = ntp.month();
RTC.dd = ntp.day();
RTC.h = ntp.hour();
RTC.m = ntp.minute();
RTC.s = ntp.second();
RTC.writeTime();
Serial.println(ntp.timeString());
Serial.println(ntp.dateString());
}
}
void setup()
{
P.begin(5);
// Serial.begin(9600);
//setupWeb();
//============================================================================
//Start the serial communication with the computer
Serial.begin(115200);
delay(100);
Serial.println();
//Try and Connect to the Network
WiFi.begin(ssid,password);
Serial.print("Connecting to ");
Serial.print(ssid);
Serial.println("...");
//Wait for WiFi to connect for a maximum timeout of 20 seconds
while(WiFi.status()!=WL_CONNECTED && retries<20)
{
Serial.print(".");
retries++;
delay(1000);
}
Serial.println();
//Inform the user whether the timeout has occured, or the ESP8266 is connected to the internet
if(retries==20)//Timeout has occured
{
Serial.print("Unable to Connect to ");
Serial.println(ssid);
}
if(WiFi.status()==WL_CONNECTED)//WiFi has succesfully Connected
{
Serial.print("Successfully connected to ");
Serial.println(ssid);
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
}
//============================================================================
ntp.begin();
//============================================================================
portal.attachBuild(build);
portal.attach(action);
portal.start();
P.setZone(0, 0, 3);
P.setZone(1, 4, 6);
P.setZone(2, 7, 7);
P.setZone(3, 8, 8);
P.setZone(4, 9, 11);
P.setFont(0, clockFont3);
P.setFont(1, BigFontLower);
P.setFont(2, clockFont2);
P.setFont(3, clockFont2);
P.setFont(4, BigFontUpper);
P.setCharSpacing(P.getCharSpacing()*1);
P.setZoneEffect(1, true, PA_FLIP_UD);
P.setZoneEffect(1, true, PA_FLIP_LR);
P.setZoneEffect(2, true, PA_FLIP_UD);
P.setZoneEffect(2, true, PA_FLIP_LR);
P.displayZoneText(0, szTimeL, PA_CENTER, 75, 0, PA_PRINT, PA_NO_EFFECT);
P.displayZoneText(1, szTempC, PA_LEFT, 75, 0, PA_PRINT, PA_NO_EFFECT);
P.displayZoneText(2, szTempS, PA_CENTER, 75, 0, PA_PRINT, PA_NO_EFFECT);
P.displayZoneText(3, szTempP, PA_CENTER, 75, 0, PA_PRINT, PA_NO_EFFECT);
P.displayZoneText(4, szTempC, PA_RIGHT, 75, 0, PA_PRINT, PA_NO_EFFECT);
RTC.control(DS1307_CLOCK_HALT, DS1307_OFF);
RTC.control(DS1307_12H, DS1307_OFF);
getTime(szTimeL);
}
void loop()
{
static uint32_t lastTime = 0; // millis() memory
static bool flasher = false; // seconds passing flasher
P.displayAnimate();
P.setIntensity(brDisp);
portal.tick();
timeUpdate();
if (P.getZoneStatus(0) && P.getZoneStatus(1) && P.getZoneStatus(2) && P.getZoneStatus(3) && P.getZoneStatus(4))
{
// Adjust the time string if we have to. It will be adjusted
// every second at least for the flashing colon separator.
if (millis() - lastTime >= 1000)
{
lastTime = millis();
getTemperature(szTempC);
getTime(szTimeL, flasher);
getDisplayShutdown2();
getDisplayBright();
flasher = !flasher;
P.displayReset();
// synchronise the start
P.synchZoneStart();
}
}
}