2025-03-2505
This commit is contained in:
847
src/main.cpp
Normal file
847
src/main.cpp
Normal file
@ -0,0 +1,847 @@
|
||||
#include <Arduino.h>
|
||||
|
||||
// This is how many color levels the display shows - the more the slower the update
|
||||
//#define PxMATRIX_COLOR_DEPTH 4
|
||||
|
||||
// Defines the speed of the SPI bus (reducing this may help if you experience noisy images)
|
||||
//#define PxMATRIX_SPI_FREQUENCY 20000000
|
||||
|
||||
// Creates a second buffer for backround drawing (doubles the required RAM)
|
||||
//#define PxMATRIX_double_buffer true
|
||||
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Fonts/FreeMonoBold12pt7b.h>
|
||||
#include <Fonts/FreeMono12pt7b.h>
|
||||
#include <Fonts/FreeMono9pt7b.h>
|
||||
#include <Fonts/Picopixel.h>
|
||||
|
||||
#include <PxMatrix.h>
|
||||
|
||||
// Pins for LED MATRIX
|
||||
#ifdef ESP32
|
||||
|
||||
#define P_LAT 22
|
||||
#define P_A 19
|
||||
#define P_B 23
|
||||
#define P_C 18
|
||||
#define P_D 5
|
||||
#define P_E 15
|
||||
#define P_OE 16
|
||||
hw_timer_t * timer = NULL;
|
||||
portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef ESP8266
|
||||
|
||||
#include <Ticker.h>
|
||||
Ticker display_ticker;
|
||||
#define P_LAT 16
|
||||
#define P_A 5
|
||||
#define P_B 4
|
||||
#define P_C 15
|
||||
#define P_D 12
|
||||
#define P_E 0
|
||||
#define P_OE 2
|
||||
|
||||
#endif
|
||||
|
||||
#define MaxErrCount 30
|
||||
const unsigned long stoerung = 15 * 60000000UL; // Minuten * Mikrosekunden für Sleep Mode
|
||||
unsigned long startTime;
|
||||
unsigned long endTime;
|
||||
#include <Wire.h>
|
||||
#include <WiFi.h>
|
||||
#include <PubSubClient.h>
|
||||
WiFiClient espClient;
|
||||
PubSubClient client(espClient);
|
||||
|
||||
// co2 Werte
|
||||
#define CO2_WARN_1 650
|
||||
#define CO2_WARN_2 950
|
||||
#define CO2_WARN_3 1250
|
||||
#define CO2_WARN_4 1500
|
||||
#define CO2_CRITICAL_PPM 1850
|
||||
|
||||
#define matrix_width 64
|
||||
#define matrix_height 64
|
||||
|
||||
// This defines the 'on' time of the display is us. The larger this number,
|
||||
// the brighter the display. If too large the ESP will crash
|
||||
uint8_t display_draw_time=10; //30-70 is usually fine
|
||||
|
||||
//PxMATRIX display(32,16,P_LAT, P_OE,P_A,P_B,P_C);
|
||||
//PxMATRIX display(64,32,P_LAT, P_OE,P_A,P_B,P_C,P_D);
|
||||
PxMATRIX display(64,64,P_LAT, P_OE,P_A,P_B,P_C,P_D,P_E);
|
||||
|
||||
// Some standard colors
|
||||
uint16_t myRED = display.color565(255, 0, 0);
|
||||
uint16_t myGREEN = display.color565(0, 255, 0);
|
||||
uint16_t myBLUE = display.color565(0, 0, 255);
|
||||
uint16_t myWHITE = display.color565(255, 255, 255);
|
||||
uint16_t myYELLOW = display.color565(255, 255, 0);
|
||||
uint16_t myCYAN = display.color565(0, 255, 255);
|
||||
uint16_t myMAGENTA = display.color565(255, 0, 255);
|
||||
uint16_t myBLACK = display.color565(0, 0, 0);
|
||||
uint16_t myDATUM = display.color565(64, 64, 64);
|
||||
uint16_t myTEMP = display.color565(255, 255, 255);
|
||||
uint16_t myCo = display.color565(0, 64, 0);
|
||||
|
||||
uint16_t myTEST = display.color565(30, 30, 0);
|
||||
|
||||
uint16_t myCOLORS[8]={myRED,myGREEN,myBLUE,myWHITE,myYELLOW,myCYAN,myMAGENTA,myBLACK};
|
||||
|
||||
// Wifi
|
||||
char ssid[] = STASSID; // your network SSID (name)
|
||||
char pass[] = STAPSK; // your network password
|
||||
IPAddress ip;
|
||||
IPAddress gateway;
|
||||
IPAddress subnet;
|
||||
IPAddress dns; // DNS-Server
|
||||
IPAddress secondarDNS;
|
||||
String hostname = "GROSSZEICHBORIS";
|
||||
int status = WL_IDLE_STATUS;
|
||||
const char* NTP_SERVER = "de.pool.ntp.org";
|
||||
const char* TZ_INFO = "CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00"; // enter your time zone (https://remotemonitoringsystems.ca/time-zone-abbreviations.php)
|
||||
|
||||
tm timeinfo;
|
||||
time_t now;
|
||||
long unsigned lastNTPtime;
|
||||
unsigned long lastEntryTime;
|
||||
|
||||
const int TimeY = 20;
|
||||
const int TimeX = 1;
|
||||
|
||||
const int WetterY = 32;
|
||||
const int WetterX = 18;
|
||||
|
||||
const int CoY = 43;
|
||||
|
||||
|
||||
|
||||
int Co2 = 0.00;
|
||||
float Covid19 = 0.00;
|
||||
float Aussentemp = -99.90;
|
||||
int Pressure = 0;
|
||||
float TempWohn = -99.90;
|
||||
float TempFlur = -99.99;
|
||||
float Luftfeuchtigkeit = 0.00;
|
||||
float Akku = -99.00;
|
||||
int Helligkeit = 255;
|
||||
|
||||
|
||||
const char* const PROGMEM DAY_NAMES[] = {"Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag"};
|
||||
const char* const PROGMEM DAY_SHORT[] = {"So", "Mo", "Di", "Mi", "Do", "Fr", "Sa", "So"};
|
||||
|
||||
//MQTT
|
||||
//define mqtt_port mqtt_port
|
||||
//const char* mqtt_server = mqtt_server;
|
||||
char topic_0[50];
|
||||
char msg[20];
|
||||
char clientName[30];
|
||||
|
||||
const char* topic_Innen = INNEN;
|
||||
const char* topic_Akku = AKKU;
|
||||
#ifdef CO2
|
||||
const char* topic_Co2 = CO2;
|
||||
#endif
|
||||
const char* topic_Wetter = WETTER;
|
||||
const char* topic_Pressure = LUFTDRUCK;
|
||||
const char* topic_Luftfeuchtigkeit = FEUCHTIGKEIT;
|
||||
const char* topic_Helligkeit = HELLIGKEIT;
|
||||
#ifdef FLUR
|
||||
const char* topic_Flur = FLUR;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
void callback(char* topic1, byte* payload, unsigned int length);
|
||||
void scroll_text(uint8_t ypos, unsigned long scroll_delay, String text, uint8_t colorR, uint8_t colorG, uint8_t colorB, boolean blink);
|
||||
void scroll_text2(uint8_t ypos, unsigned long scroll_delay, String text, uint8_t colorR, uint8_t colorG, uint8_t colorB, boolean blink);
|
||||
void scroll_Grad(uint8_t ypos, unsigned long scroll_delay, String text, uint8_t colorR, uint8_t colorG, uint8_t colorB, boolean blink);
|
||||
bool getNTPtime(int sec);
|
||||
void showTime(tm localTime);
|
||||
static uint32_t lastTime = 0; // millis() memory
|
||||
static void setup_wifi();
|
||||
|
||||
#ifdef ESP8266
|
||||
// ISR for display refresh
|
||||
void display_updater()
|
||||
{
|
||||
display.display(display_draw_time);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ESP32
|
||||
void IRAM_ATTR display_updater(){
|
||||
// Increment the counter and set the time of ISR
|
||||
portENTER_CRITICAL_ISR(&timerMux);
|
||||
display.display(display_draw_time);
|
||||
portEXIT_CRITICAL_ISR(&timerMux);
|
||||
}
|
||||
#endif
|
||||
|
||||
void print_wifi_status() {
|
||||
// SSID des WiFi Netzwerkes ausgeben:
|
||||
/* Serial.print("SSID: ");
|
||||
Serial.println(WiFi.SSID()); */
|
||||
// WiFi IP Adresse des ESP32 ausgeben:
|
||||
/* IPAddress ip = WiFi.localIP();
|
||||
Serial.print("IP Address: ");
|
||||
Serial.println(ip); */
|
||||
// WiFi Signalstärke ausgeben:
|
||||
long rssi = WiFi.RSSI();
|
||||
Serial.print("signal strength (RSSI):");
|
||||
Serial.print(rssi);
|
||||
Serial.println(" dBm");
|
||||
display.clearDisplay();
|
||||
scroll_text(64-16,40,"IP Adress: " + WiFi.localIP().toString()+ " signal strength (RSSI): " + String(rssi, DEC) + " dBm", 96,96,0, false);
|
||||
}
|
||||
|
||||
void display_update_enable(bool is_enable)
|
||||
{
|
||||
|
||||
#ifdef ESP8266
|
||||
if (is_enable)
|
||||
display_ticker.attach(0.004, display_updater);
|
||||
else
|
||||
display_ticker.detach();
|
||||
#endif
|
||||
|
||||
#ifdef ESP32
|
||||
if (is_enable)
|
||||
{
|
||||
timer = timerBegin(0, 80, true);
|
||||
timerAttachInterrupt(timer, &display_updater, true);
|
||||
timerAlarmWrite(timer, 4000, true);
|
||||
timerAlarmEnable(timer);
|
||||
}
|
||||
else
|
||||
{
|
||||
timerDetachInterrupt(timer);
|
||||
timerAlarmDisable(timer);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
String TimeOld = "";
|
||||
int MinuteOld = 99;
|
||||
static bool blinkSek = false; // seconds passing flasher
|
||||
|
||||
void callback(char* topic1, byte* payload, unsigned int length) {
|
||||
// float wert;
|
||||
// int st; // Hilfsvariable zum ansteuern der Page zum einstellen der Solltemperatur
|
||||
Serial.print("Message arrived [");
|
||||
Serial.print(topic1);
|
||||
Serial.print("] ");
|
||||
for (int i = 0; i < length; i++) {
|
||||
msg[i] = (char)payload[i];
|
||||
}
|
||||
msg[length] = '\0';
|
||||
//Serial.println(msg);
|
||||
|
||||
#ifdef CO2
|
||||
// CO2 Wert vom Sensor
|
||||
if(strcmp(topic1, topic_Co2)== 0){
|
||||
Serial.print("Co2 Sensor !!!: ");
|
||||
Serial.print(msg);
|
||||
Serial.println();
|
||||
Co2 = atoi(msg);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Covid19 Wert
|
||||
/* if(strcmp(topic1, topic_Covid)== 0){
|
||||
Serial.print("Covid: ");
|
||||
Serial.print(msg);
|
||||
Serial.println();
|
||||
Covid19 = atof(msg);
|
||||
} */
|
||||
|
||||
// Wetter Wert
|
||||
if(strcmp(topic1, topic_Wetter)== 0){
|
||||
Serial.print("Aussentemperatur: ");
|
||||
Serial.print(msg);
|
||||
Serial.println(" °C");
|
||||
Aussentemp = atof(msg);
|
||||
}
|
||||
if(strcmp(topic1, topic_Pressure)== 0){
|
||||
Serial.print("Luftdruck: ");
|
||||
Serial.print(msg);
|
||||
Serial.println(" hPa");
|
||||
Pressure = atoi(msg);
|
||||
}
|
||||
if(strcmp(topic1, topic_Innen)== 0){
|
||||
Serial.print("Temperatur Innen: ");
|
||||
Serial.print(msg);
|
||||
Serial.println(" °C");
|
||||
TempWohn = atof(msg);
|
||||
}
|
||||
#ifdef FLUR
|
||||
if(strcmp(topic1, topic_Flur)== 0){
|
||||
Serial.print("Temperatur Flur: ");
|
||||
Serial.print(msg);
|
||||
Serial.println(" °C");
|
||||
TempFlur = atof(msg);
|
||||
}
|
||||
#endif
|
||||
if(strcmp(topic1, topic_Luftfeuchtigkeit)== 0){
|
||||
Serial.print("Luftfeuchtigkeit: ");
|
||||
Serial.print(msg);
|
||||
Serial.println(" %");
|
||||
Luftfeuchtigkeit = atof(msg);
|
||||
}
|
||||
if(strcmp(topic1, topic_Akku)== 0){
|
||||
Serial.print("Wetterstation Akku: ");
|
||||
Serial.print(msg);
|
||||
Serial.println(" V");
|
||||
Akku = atof(msg);
|
||||
}
|
||||
if(strcmp(topic1, topic_Helligkeit)== 0){
|
||||
Serial.print("Helligkeit: ");
|
||||
Serial.print(msg);
|
||||
Serial.println(" Lux");
|
||||
Helligkeit = atoi(msg);
|
||||
if (Helligkeit > 255) Helligkeit = 255;
|
||||
if (Helligkeit < 0) Helligkeit = 0;
|
||||
display.setBrightness(Helligkeit);
|
||||
}
|
||||
}
|
||||
void reconnect() {
|
||||
sprintf(clientName, "%s%s", "Uhr", "Zentrale4" );
|
||||
// Loop until we're reconnected
|
||||
while (!client.connected()) {
|
||||
Serial.print("Attempting MQTT connection...");
|
||||
if (client.connect(clientName)) {
|
||||
/* MQTTStatus.setPic(3); */
|
||||
Serial.println("connected");
|
||||
#ifdef CO2
|
||||
client.subscribe(topic_Co2);
|
||||
#endif
|
||||
//client.subscribe(topic_Covid);Ja
|
||||
client.subscribe(topic_Wetter);
|
||||
client.subscribe(topic_Pressure);
|
||||
client.subscribe(topic_Innen);
|
||||
#ifdef FLUR
|
||||
client.subscribe(topic_Flur);
|
||||
#endif
|
||||
client.subscribe(topic_Luftfeuchtigkeit);
|
||||
client.subscribe(topic_Akku);
|
||||
client.subscribe(topic_Helligkeit);
|
||||
//client.subscribe("hjk/devices/WETTERSTATIONBORIS/telemetry/#");
|
||||
//client.subscribe("hjk/devices/MESSUNITTEMPBORIS/telemetry/#");
|
||||
} else {
|
||||
Serial.print("failed, rc=");
|
||||
Serial.print(client.state());
|
||||
Serial.println(" try again in 5 seconds");
|
||||
// Wait 5 seconds before retrying
|
||||
delay(5000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ZeigeZeit(tm localTime, int xPos = 2, int yPos = 8)
|
||||
{
|
||||
if (xPos < 4) xPos = 4;
|
||||
if (yPos < 4) yPos = 4;
|
||||
//Serial.print(timeClient.getFormattedTime()); Serial.println();
|
||||
char szTime[4];
|
||||
sprintf(szTime, "%02d", localTime.tm_hour);
|
||||
display.setCursor(xPos-1, yPos);
|
||||
display.setFont(&FreeMonoBold12pt7b);
|
||||
display.setTextColor(myMAGENTA);
|
||||
display.fillRect(xPos, yPos - 8, 27, 15, myBLACK);
|
||||
display.print(szTime);
|
||||
display.setFont();
|
||||
// Doppelpunkt zeichnen
|
||||
display.fillRect(xPos + 27, yPos -8, 2, 15, myBLACK);
|
||||
if (blinkSek == true) {
|
||||
display.fillRect(xPos + 27, yPos - 3, 2, 2, myMAGENTA);
|
||||
display.fillRect(xPos + 27, yPos + 1, 2, 2, myMAGENTA);
|
||||
}
|
||||
/* display.fillRect(xPos + 27, yPos - 3, 2, 2, myMAGENTA);
|
||||
display.fillRect(xPos + 27, yPos + 1, 2, 2, myMAGENTA); */
|
||||
sprintf(szTime, "%02d", localTime.tm_min);
|
||||
display.setCursor(xPos + 29, yPos);
|
||||
display.setFont(&FreeMonoBold12pt7b);
|
||||
display.setTextColor(myMAGENTA);
|
||||
display.fillRect(xPos + 29, yPos - 8, 27, 15, myBLACK);
|
||||
display.print(szTime);
|
||||
display.setFont();
|
||||
}
|
||||
|
||||
void ZeigeCO(int xPos = 1, int yPos = 19)
|
||||
{
|
||||
if (xPos < 1) xPos = 1;
|
||||
if (yPos < 19) yPos = 19;
|
||||
if (Co2 > 300.00){
|
||||
char szCO[10];
|
||||
sprintf(szCO, "%4d", Co2);
|
||||
//Serial.print("CO = "); Serial.println(szCO);
|
||||
display.setCursor(xPos, yPos);
|
||||
display.setFont();
|
||||
switch (Co2){
|
||||
case 0 ... CO2_WARN_3 -1: {
|
||||
display.setTextColor(myCo); // green
|
||||
break;
|
||||
}
|
||||
case CO2_WARN_3 ... CO2_WARN_4 -1: {
|
||||
display.setTextColor(myYELLOW);
|
||||
break;
|
||||
}
|
||||
case CO2_WARN_4 ... CO2_CRITICAL_PPM: {
|
||||
display.setTextColor(myRED);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
display.setTextColor(myBLUE);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
//display.setTextColor(myGREEN);
|
||||
display.fillRect(xPos, yPos-2, 64-xPos, 8+2, (myBLACK));
|
||||
display.print("CO :");
|
||||
display.print(szCO);
|
||||
// Hochzeichen zeichen CO²
|
||||
display.setFont(&Picopixel);
|
||||
display.setCursor(xPos+12, yPos+2);
|
||||
display.print("2");
|
||||
display.setCursor(xPos+48, yPos+6);
|
||||
display.print("ppm");
|
||||
display.setFont();
|
||||
}
|
||||
}
|
||||
|
||||
void ZeigeDatum(tm localTime, int xPos = 2, int yPos = 1)
|
||||
{
|
||||
//if (xPos < 2) xPos = 2;
|
||||
if (yPos < 0) yPos = 0;
|
||||
char szDATUM[20];
|
||||
/* sprintf(szDATUM, "%s%2d.%02d.%02d", DAY_SHORT[(localTime.tm_wday > 0 ? localTime.tm_wday : 7 )],
|
||||
localTime.tm_mday,
|
||||
localTime.tm_mon + 1,
|
||||
(localTime.tm_year+1900)-2000); */
|
||||
display.setCursor(xPos, yPos);
|
||||
display.fillRect(xPos, yPos-2, 64-xPos, 8+2, (myBLACK));
|
||||
sprintf(szDATUM, "%s", DAY_SHORT[(localTime.tm_wday > 0 ? localTime.tm_wday : 7 )]);
|
||||
// display.setFont(&Picopixel);
|
||||
display.setTextColor(myDATUM);
|
||||
display.print(szDATUM); // Tag
|
||||
display.setCursor(xPos+15, yPos);
|
||||
sprintf(szDATUM, "%2d.%02d.%02d",
|
||||
localTime.tm_mday,
|
||||
localTime.tm_mon + 1,
|
||||
(localTime.tm_year+1900)-2000);
|
||||
display.print(szDATUM); // Zeit
|
||||
display.setFont();
|
||||
|
||||
}
|
||||
|
||||
void ZeigeWetter(double Wetter1, int yPos = 2, int xPos = 1)
|
||||
{
|
||||
if (xPos < 2) xPos = 2;
|
||||
if (yPos < 0) yPos = 0;
|
||||
if (Wetter1 > -99.9){
|
||||
char szWetter[10];
|
||||
//Serial.print("Aussentemperatur: "); Serial.println(Wetter1,3);
|
||||
dtostrf(Wetter1, 4, 1, szWetter);
|
||||
display.setCursor(xPos, yPos);
|
||||
display.fillRect(xPos, yPos-2, 64-xPos, 8+2, (myBLACK));
|
||||
display.setTextColor(myWHITE);
|
||||
display.print(szWetter);
|
||||
// Erzeuge Grad Zeichen ......
|
||||
display.setCursor(xPos+24, yPos-5);
|
||||
display.setFont(&Picopixel);
|
||||
display.print("o");
|
||||
display.setCursor(xPos+28, yPos+6);
|
||||
display.setFont();
|
||||
// ...........
|
||||
display.print("C");
|
||||
}
|
||||
}
|
||||
void Test()
|
||||
{
|
||||
display.setCursor(1, 40);
|
||||
display.print("Hallo");
|
||||
display.setFont(&Picopixel);
|
||||
display.print("0o");
|
||||
display.setFont();
|
||||
}
|
||||
|
||||
void setup() {
|
||||
startTime = millis();
|
||||
Serial.begin(115200);
|
||||
//WiFi.mode( WIFI_OFF );
|
||||
delay( 10 );
|
||||
Serial.println("Start");
|
||||
// initialise_wifi();
|
||||
setup_wifi();
|
||||
|
||||
// Define your display layout here, e.g. 1/8 step, and optional SPI pins begin(row_pattern, CLK, MOSI, MISO, SS)
|
||||
display.begin(SCAN); // Rows-scan pattern 1/32
|
||||
//display.begin(8, 14, 13, 12, 4);
|
||||
|
||||
// Define multiplex implemention here {BINARY, STRAIGHT} (default is BINARY)
|
||||
display.setMuxPattern(BINARY);
|
||||
|
||||
// Set the multiplex pattern {LINE, ZIGZAG,ZZAGG, ZAGGIZ, WZAGZIG, VZAG, ZAGZIG} (default is LINE)
|
||||
display.setScanPattern(LINE);
|
||||
|
||||
|
||||
// Rotate display
|
||||
//display.setRotate(true);
|
||||
|
||||
// Flip display
|
||||
//display.setFlip(true);
|
||||
|
||||
// Control the minimum color values that result in an active pixel
|
||||
//display.setColorOffset(5, 5,5);
|
||||
|
||||
// Set the multiplex implemention {BINARY, STRAIGHT} (default is BINARY)
|
||||
display.setMuxPattern(BINARY);
|
||||
|
||||
// Set the color order {RRGGBB, RRBBGG, GGRRBB, GGBBRR, BBRRGG, BBGGRR} (default is RRGGBB)
|
||||
display.setColorOrder(BBRRGG);
|
||||
|
||||
// Set the time in microseconds that we pause after selecting each mux channel
|
||||
// (May help if some rows are missing / the mux chip is too slow)
|
||||
//display.setMuxDelay(0,1,0,0,0);
|
||||
|
||||
// Set the number of panels that make up the display area width (default is 1)
|
||||
//display.setPanelsWidth(2);
|
||||
|
||||
// Set the brightness of the panels (default is 255)
|
||||
display.setBrightness(Helligkeit);
|
||||
display_update_enable(true);
|
||||
|
||||
display.clearDisplay();
|
||||
display.setTextColor(myRED);
|
||||
display.setCursor(0,0);
|
||||
display.print("Pixel");
|
||||
display.setTextColor(myGREEN);
|
||||
display.setCursor(30,0);
|
||||
display.print("Time");
|
||||
//----------------------
|
||||
display.setTextColor(myBLUE);
|
||||
display.setCursor(2,50);
|
||||
display.print("Pixel");
|
||||
display.setTextColor(myYELLOW);
|
||||
display.setCursor(30,50);
|
||||
display.print("1234");
|
||||
//--------------------------------------------------
|
||||
//--------------------------------------------------
|
||||
|
||||
delay(1000);
|
||||
print_wifi_status();
|
||||
configTime(0, 0, NTP_SERVER);
|
||||
// See https://github.com/nayarsystems/posix_tz_db/blob/master/zones.csv for Timezone codes for your region
|
||||
setenv("TZ", TZ_INFO, 1);
|
||||
|
||||
if (getNTPtime(10)) { // wait up to 10sec to sync
|
||||
} else {
|
||||
Serial.println("Time not set");
|
||||
delay(5000);
|
||||
ESP.restart();
|
||||
}
|
||||
lastNTPtime = time(&now);
|
||||
lastEntryTime = millis();
|
||||
|
||||
|
||||
}
|
||||
union single_double{
|
||||
uint8_t two[2];
|
||||
uint16_t one;
|
||||
} this_single_double;
|
||||
|
||||
unsigned long last_draw=0;
|
||||
void scroll_text(uint8_t ypos, unsigned long scroll_delay, String text, uint8_t colorR, uint8_t colorG, uint8_t colorB, boolean blink)
|
||||
{
|
||||
uint16_t text_length = text.length();
|
||||
display.setTextWrap(false); // we don't wrap text so it scrolls nicely
|
||||
display.setTextSize(1);
|
||||
display.setRotation(0);
|
||||
display.setTextColor(display.color565(colorR,colorG,colorB));
|
||||
|
||||
// Asuming 5 pixel average character width
|
||||
for (int xpos=matrix_width; xpos>-(matrix_width+text_length*5); xpos--)
|
||||
{
|
||||
if (millis() - lastTime >= 1000)
|
||||
{
|
||||
lastTime = millis();
|
||||
blinkSek = !blinkSek;
|
||||
}
|
||||
if (blink){
|
||||
if (blinkSek) {
|
||||
display.fillRect(TimeX + 30, TimeY - 3, 2, 2, myMAGENTA);
|
||||
display.fillRect(TimeX + 30, TimeY + 1, 2, 2, myMAGENTA);
|
||||
}else{
|
||||
display.fillRect(TimeX + 30, TimeY - 8, 2, 15, myBLACK);
|
||||
}
|
||||
}
|
||||
|
||||
display.setTextColor(display.color565(colorR,colorG,colorB));
|
||||
//display.clearDisplay();
|
||||
display.fillRect(xpos, ypos, 64-xpos, 8, (myBLACK));
|
||||
display.setCursor(xpos,ypos);
|
||||
display.println(text);
|
||||
delay(scroll_delay);
|
||||
yield();
|
||||
|
||||
// This might smooth the transition a bit if we go slow
|
||||
// Dies könnte den Übergang etwas glätten, wenn wir langsam vorgehen
|
||||
/* display.setTextColor(display.color565(colorR/4,colorG/4,colorB/4));
|
||||
display.setCursor(xpos-1,ypos);
|
||||
display.println(text);
|
||||
|
||||
delay(scroll_delay/5);
|
||||
yield(); */
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void scroll_text2(uint8_t ypos, unsigned long scroll_delay, String text, uint8_t colorR, uint8_t colorG, uint8_t colorB, boolean blink)
|
||||
{
|
||||
uint16_t text_length = text.length();
|
||||
display.setTextWrap(false); // we don't wrap text so it scrolls nicely
|
||||
display.setTextSize(2);
|
||||
display.setRotation(0);
|
||||
display.setTextColor(display.color565(colorR,colorG,colorB));
|
||||
|
||||
// Asuming 5 pixel average character width
|
||||
for (int xpos=matrix_width; xpos>-(matrix_width+text_length*10); xpos--)
|
||||
{
|
||||
if (millis() - lastTime >= 1000)
|
||||
{
|
||||
lastTime = millis();
|
||||
blinkSek = !blinkSek;
|
||||
}
|
||||
if (blinkSek && blink) {
|
||||
display.fillRect(4 + 27, 20 - 3, 2, 2, myMAGENTA);
|
||||
display.fillRect(4 + 27, 20 + 1, 2, 2, myMAGENTA);
|
||||
}else{
|
||||
display.fillRect(4 + 27, 20 - 3, 2, 2, myBLACK);
|
||||
display.fillRect(4 + 27, 20 + 1, 2, 2, myBLACK);
|
||||
}
|
||||
display.setTextColor(display.color565(colorR,colorG,colorB));
|
||||
//display.clearDisplay();
|
||||
display.fillRect(xpos, ypos, 64-xpos, 16, (myBLACK));
|
||||
display.setCursor(xpos,ypos);
|
||||
display.println(text);
|
||||
delay(scroll_delay);
|
||||
yield();
|
||||
}
|
||||
display.setTextSize(1);
|
||||
}
|
||||
|
||||
void scroll_Grad(uint8_t ypos, unsigned long scroll_delay, String text, uint8_t colorR, uint8_t colorG, uint8_t colorB, boolean blink)
|
||||
{
|
||||
uint16_t text_length = text.length() +2;
|
||||
display.setTextWrap(false); // we don't wrap text so it scrolls nicely
|
||||
display.setTextSize(1);
|
||||
display.setRotation(0);
|
||||
display.setTextColor(display.color565(colorR,colorG,colorB));
|
||||
|
||||
// Asuming 5 pixel average character width
|
||||
for (int xpos=matrix_width; xpos>-(matrix_width+text_length*5); xpos--)
|
||||
{
|
||||
if (millis() - lastTime >= 1000)
|
||||
{
|
||||
lastTime = millis();
|
||||
blinkSek = !blinkSek;
|
||||
}
|
||||
if (blink){
|
||||
if (blinkSek) {
|
||||
display.fillRect(TimeX + 30, TimeY - 3, 2, 2, myMAGENTA);
|
||||
display.fillRect(TimeX + 30, TimeY + 1, 2, 2, myMAGENTA);
|
||||
}else{
|
||||
display.fillRect(TimeX + 30, TimeY - 8, 2, 15, myBLACK);
|
||||
}
|
||||
}
|
||||
|
||||
display.setTextColor(display.color565(colorR,colorG,colorB));
|
||||
display.fillRect(xpos, ypos-1, 64-xpos, 9, (myBLACK));
|
||||
display.setCursor(xpos,ypos);
|
||||
display.print(text);
|
||||
display.setCursor(xpos+132, ypos-5);
|
||||
display.setFont(&Picopixel);
|
||||
display.print("o");
|
||||
display.setCursor(xpos+136, ypos+6);
|
||||
display.setFont();
|
||||
// ...........
|
||||
display.println("C");
|
||||
delay(scroll_delay);
|
||||
yield();
|
||||
|
||||
}
|
||||
}
|
||||
uint8_t icon_index=0;
|
||||
|
||||
static void setup_wifi() {
|
||||
|
||||
long ErrCount = 0;
|
||||
|
||||
delay(10);
|
||||
// We start by connecting to a WiFi network
|
||||
if (!ip.fromString(MYIP)) { // try to parse into the IPAddress
|
||||
Serial.println("UnParsable IP");
|
||||
}
|
||||
if (!dns.fromString(DNS)) { // try to parse into the IPAddress
|
||||
Serial.println("UnParsable DNS");
|
||||
}
|
||||
if (!gateway.fromString(GATEWAY)) { // try to parse into the IPAddress
|
||||
Serial.println("UnParsable GATEWAY");
|
||||
}
|
||||
if (!secondarDNS.fromString(SECONDARDNS)) { // try to parse into the IPAddress
|
||||
Serial.println("UnParsable GATEWAY");
|
||||
}
|
||||
if (!subnet.fromString(SUBNET)) { // try to parse into the IPAddress
|
||||
Serial.println("UnParsable GATEWAY");
|
||||
}
|
||||
if (!WiFi.config(ip, gateway, subnet, dns, secondarDNS))
|
||||
{
|
||||
Serial.println("STA Failed to configure");
|
||||
}
|
||||
Serial.println();
|
||||
Serial.print("Connecting to ");
|
||||
Serial.println(ssid);
|
||||
WiFi.begin(ssid, pass);
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(500);
|
||||
Serial.print(".");
|
||||
ErrCount ++;
|
||||
if (ErrCount >= MaxErrCount){
|
||||
endTime = millis();
|
||||
unsigned long Pause = stoerung -((endTime - startTime) * 1000); // Pause
|
||||
ESP.deepSleep(Pause); // Pause
|
||||
delay(100);
|
||||
}
|
||||
}
|
||||
Serial.println(" WiFi connected");
|
||||
client.setServer(mqtt_server, mqtt_port);
|
||||
client.setCallback(callback);
|
||||
Serial.print("IP Address: \t");
|
||||
Serial.println(WiFi.localIP());
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
|
||||
getNTPtime(10);
|
||||
if (!client.connected()) {
|
||||
reconnect();
|
||||
}
|
||||
client.loop();
|
||||
|
||||
if (millis() - lastTime >= 1000)
|
||||
{
|
||||
lastTime = millis();
|
||||
blinkSek = !blinkSek;
|
||||
ZeigeDatum(timeinfo, 1, 1);
|
||||
ZeigeZeit(timeinfo, TimeX, TimeY);
|
||||
//ZeigeZeit(timeinfo, 1,40);
|
||||
ZeigeCO(1,CoY);
|
||||
/* if ((timeinfo.tm_min % 10) == 0){
|
||||
/* if (Covid19 != 0){
|
||||
scroll_text(matrix_height-8,20,"Landkreis Heilbronn", 30,30,30, true);
|
||||
if (Covid19 <= 500){
|
||||
// ------------------------------------ \204 für ä
|
||||
scroll_text(matrix_height-8,25,"Covid 19 F\204lle in den letzte 7 Tage pro 100000 EW: " + String(Covid19, 1), 40,40,40, true);
|
||||
} else if (Covid19 <= 1000){
|
||||
// ------------------------------------ \204 für ä
|
||||
scroll_text(matrix_height-8,25,"Covid 19 F\204lle in den letzte 7 Tage pro 100000 EW: " + String(Covid19, 1), 64,64,0, true);
|
||||
} else {
|
||||
// ------------------------------------ \204 für ä
|
||||
scroll_text(matrix_height-8,25,"Covid 19 F\204lle in den letzte 7 Tage pro 100000 EW: " + String(Covid19, 1), 64,0,0, true);
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
if (Aussentemp > -99.9){
|
||||
scroll_text(matrix_height-8,30,"Luftdruck: " + String(Pressure) + " hPa", 255,255,255, true);
|
||||
char szWetter[10];
|
||||
dtostrf(Aussentemp, 4, 1, szWetter);
|
||||
//Serial.print(Aussentemp); Serial.print(" "); Serial.println(szWetter);
|
||||
scroll_Grad(matrix_height-8,30,"Aussentemperatur: " + String(szWetter), 64,64,64, true);
|
||||
dtostrf(Luftfeuchtigkeit, 4, 1, szWetter);
|
||||
scroll_text(matrix_height-8,30,"Luftfeuchtigkeit: " + String(szWetter) + " %", 48,48,48, true);
|
||||
}
|
||||
} */
|
||||
//scroll_text(matrix_height-16,20,"Temperatur: " + String(Wetter,1) +" °C", 128,30,30, true);
|
||||
/* scroll_text2(matrix_height-24,20,"Liebe Frunde, liebe Nachbarn,", 128,128,0, true);
|
||||
scroll_text2(matrix_height-24,20,"ich w\201nsche Euch allen ein", 128,128,0, true);
|
||||
scroll_text2(matrix_height-24,20,"Frohes neues Jahr 2022.", 128,255,0, true); */
|
||||
|
||||
ZeigeWetter(double(TempWohn), WetterY,WetterX);
|
||||
//Serial.println("START");
|
||||
if (Aussentemp > -99.9){
|
||||
char szWetter[10];
|
||||
dtostrf(TempFlur, 4, 1, szWetter);
|
||||
//Serial.print(Aussentemp); Serial.print(" "); Serial.println(szWetter);
|
||||
scroll_Grad(matrix_height-8,30," Flur: " + String(szWetter), 64,64,64, true);
|
||||
/* Achtung sehr wichtig,
|
||||
wenn das gesamt Laufschrift mehr
|
||||
als 30 Sekunden Dauert muss ein .... */
|
||||
client.loop();
|
||||
/* eingeführt werden, sonst kommt es zu
|
||||
einen Socket Fehler !!!! */
|
||||
scroll_text(matrix_height-8,30,"Luftdruck: " + String(Pressure) + " hPa", 255,255,255, true);
|
||||
dtostrf(Aussentemp, 4, 1, szWetter);
|
||||
//Serial.print(Aussentemp); Serial.print(" "); Serial.println(szWetter);
|
||||
/* Achtung sehr wichtig,
|
||||
wenn das gesamt Laufschrift mehr
|
||||
als 30 Sekunden Dauert muss ein .... */
|
||||
client.loop();
|
||||
/* eingeführt werden, sonst kommt es zu
|
||||
einen Socket Fehler !!!! */
|
||||
scroll_Grad(matrix_height-8,30,"Aussentemperatur: " + String(szWetter), 64,64,64, true);
|
||||
/* Achtung sehr wichtig,
|
||||
wenn das gesamt Laufschrift mehr
|
||||
als 30 Sekunden Dauert muss ein .... */
|
||||
client.loop();
|
||||
/* eingeführt werden, sonst kommt es zu
|
||||
einen Socket Fehler !!!! */
|
||||
dtostrf(Luftfeuchtigkeit, 4, 1, szWetter);
|
||||
scroll_text(matrix_height-8,30,"Luftfeuchtigkeit: " + String(szWetter) + " %", 64,64,64, true);
|
||||
}
|
||||
if ((Akku <= GRENZWERT) && (Akku > 0)){
|
||||
scroll_text(matrix_height-8,40,"Akku: " + String(Akku) + " Volt", 255, 0, 0, true);
|
||||
scroll_text(matrix_height-8,40,"Akku aufladen!", 255, 0, 0, true);
|
||||
}
|
||||
//Serial.println("STOP");
|
||||
}
|
||||
}
|
||||
|
||||
bool getNTPtime(int sec) {
|
||||
|
||||
{
|
||||
uint32_t start = millis();
|
||||
do {
|
||||
time(&now);
|
||||
localtime_r(&now, &timeinfo);
|
||||
//Serial.print(".");
|
||||
delay(10);
|
||||
} while (((millis() - start) <= (1000 * sec)) && (timeinfo.tm_year < (2016 - 1900)));
|
||||
if (timeinfo.tm_year <= (2016 - 1900)) return false; // the NTP call was not successful
|
||||
//Serial.print("now "); Serial.println(now);
|
||||
/* char time_output[30];
|
||||
strftime(time_output, 30, "%a %d-%m-%y %T", localtime(&now));
|
||||
Serial.println(time_output);
|
||||
Serial.println(12); */
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void showTime(tm localTime) {
|
||||
Serial.printf(
|
||||
"%04d-%02d-%02d %02d:%02d:%02d, day %d, %s time\n",
|
||||
localTime.tm_year + 1900,
|
||||
localTime.tm_mon + 1,
|
||||
localTime.tm_mday,
|
||||
localTime.tm_hour,
|
||||
localTime.tm_min,
|
||||
localTime.tm_sec,
|
||||
(localTime.tm_wday > 0 ? localTime.tm_wday : 7 ),
|
||||
(localTime.tm_isdst == 1 ? "summer" : "standard")
|
||||
);
|
||||
}
|
Reference in New Issue
Block a user