1121 lines
32 KiB
C++
1121 lines
32 KiB
C++
#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/FreeMonoBold9pt7b.h>
|
|
#include <Fonts/Picopixel.h>
|
|
|
|
#include <PxMatrix.h>
|
|
#include <Adafruit_HTU21DF.h>
|
|
|
|
#include <CO2.h>
|
|
|
|
|
|
// Pins for LED MATRIX
|
|
#ifdef ESP32
|
|
|
|
//#define P_LAT 22
|
|
#define P_LAT 15
|
|
#define P_A 19
|
|
#define P_B 23
|
|
#define P_C 18
|
|
#define P_D 5
|
|
#define P_E -1
|
|
#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 SDA 21
|
|
#define SCL 22
|
|
#define RX1 9
|
|
#define TX1 10 */
|
|
|
|
#define MaxErrCount 30
|
|
unsigned long startTime;
|
|
unsigned long endTime;
|
|
#include <Wire.h>
|
|
#include <WiFi.h>
|
|
#include <PubSubClient.h>
|
|
#define mqtt_port 61883
|
|
WiFiClient espClient;
|
|
PubSubClient client(espClient);
|
|
Adafruit_HTU21DF htu = Adafruit_HTU21DF();
|
|
|
|
|
|
|
|
#define matrix_width 64
|
|
#define matrix_height 32
|
|
|
|
// 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 myCo = display.color565(0, 255, 0);
|
|
uint16_t myBraun = display.color565(165, 74, 55);
|
|
uint16_t myTEST = display.color565(30, 30, 0);
|
|
uint16_t myHimmelblau = display.color565(0, 191, 255);
|
|
|
|
uint16_t myCOLORS[8]={myRED,myGREEN,myBLUE,myWHITE,myYELLOW,myCYAN,myMAGENTA,myBLACK};
|
|
|
|
//------- Helligkeit des Display -------
|
|
uint8_t dunkel = 25;
|
|
uint8_t hell = 255;
|
|
//---- Zeitsteuerung der Helligkeit ----
|
|
u_int16_t StartderAbdunklung = 20;
|
|
u_int16_t EndederAbdunklung = 7;
|
|
|
|
// Wifi
|
|
/* char ssid[] = "MagentaWLAN-RGDO"; // your network SSID (name)
|
|
char pass[] = "93329248424922704583"; // your network password
|
|
IPAddress ip( 192, 168, 127, 52);
|
|
IPAddress gateway( 192, 168, 127, 1 );
|
|
IPAddress subnet( 255, 255, 255, 0 );
|
|
IPAddress dns1(192, 168, 127, 1); // DNS-Server 1
|
|
IPAddress dns2(192, 168, 127, 1); // DNS-Server 2 */
|
|
|
|
char ssid[] = "EasyBox-838169"; // your network SSID (name)
|
|
char pass[] = "RcZmua6Xv4R4V5Kf"; // your network password
|
|
IPAddress ip( 192, 168, 2, 80);
|
|
IPAddress gateway( 192, 168, 2, 1 );
|
|
IPAddress subnet( 255, 255, 255, 0 );
|
|
IPAddress dns1(192, 168, 2, 1); // DNS-Server 1
|
|
IPAddress dns2(192, 168, 2, 1); // DNS-Server 2
|
|
String hostname = "DISPLAY";
|
|
int status = WL_IDLE_STATUS;
|
|
const char* NTP_SERVER = "de.pool.ntp.org"; // Vodafone ???? (de.pool.ntp.arcor-ip.net)
|
|
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 FlurTemp = -99.90;
|
|
float Luftfeuchtigkeit = 0.00;
|
|
float FeuchteInnen = 0.00;
|
|
float TemparaturInnen = 0.00;
|
|
bool NOHTU = false;
|
|
bool readHtuFlag = true;
|
|
float akku = 2.87;
|
|
|
|
|
|
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 61883
|
|
const char* mqtt_server = "hjkmqtt.dedyn.io";
|
|
char topic_0[50];
|
|
char msg[20];
|
|
char clientName[30];
|
|
/* const char* topic_1 = "hjk/devices/WETTERSTATIONMARCEL/telemetry/temperature"; // Wohnzimmer 3933178
|
|
const char* topic_Flur = "hjk/devices/267014/telemetry/temperature"; // Flur
|
|
const char* topic_3 = "hjk/devices/11277819/telemetry/temperature"; // Büro 11277819 */
|
|
const char* topic_ZeitStart = "hjk/devices/DisplayMarcel/telemetry/Start";
|
|
const char* topic_ZeitEnde = "hjk/devices/DisplayMarcel/telemetry/Ende";
|
|
const char* topic_Hell = "hjk/devices/DisplayMarcel/telemetry/Hell";
|
|
const char* topic_Dunkel = "hjk/devices/DisplayMarcel/telemetry/Dunkel";
|
|
//const char* topic_Co2 = "hjk/devices/257923/telemetry/co2"; // Co2 Sensor
|
|
const char* topic_Covid = "hjk/devices/Covid19/telemetry/Covid19";
|
|
const char* topic_Wetter = "hjk/devices/WETTERSTATIONMARCEL/telemetry/temperature_Htu_21";
|
|
const char* topic_Pressure = "hjk/devices/WETTERSTATIONMARCEL/telemetry/pressure";
|
|
const char* topic_Luftfeuchtigkeit = "hjk/devices/WETTERSTATIONMARCEL/telemetry/humity";
|
|
const char* topic_Akku = "hjk/devices/WETTERSTATIONMARCEL/telemetry/battery";
|
|
|
|
void callback(char* topic1, byte* payload, unsigned int length);
|
|
//void ZeigeZeit(int xPos);
|
|
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);
|
|
void BlinkSec(bool blink);
|
|
static uint32_t lastTime = 0; // millis() memory
|
|
static uint32_t oldsec = 99;
|
|
static void setup_wifi();
|
|
void ZeigeTestTime(tm localTime);
|
|
void ZeigeInnenTemp(float Aussentemp);
|
|
void ZeigeTemperatur(float Temperatur, uint16_t Color);
|
|
|
|
void ZeigeInnenFeuchtigkeit(float Luftfeuchtigkeit);
|
|
void ZeigeLuftdruck(float Pressure);
|
|
void readHtu();
|
|
void AkkuAlarm();
|
|
|
|
#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(32-16,40,"IP Adress: " + WiFi.localIP().toString()+ " signal strength (RSSI): " + String(rssi, DEC) + " dBm", 96,96,0, false);
|
|
//delay(2000);
|
|
}
|
|
|
|
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) {
|
|
#ifdef DEBUG
|
|
Serial.print("Message arrived [");
|
|
Serial.print(topic1);
|
|
Serial.print("] ");
|
|
#endif
|
|
for (int i = 0; i < length; i++) {
|
|
msg[i] = (char)payload[i];
|
|
}
|
|
msg[length] = '\0';
|
|
|
|
// CO2 Wert vom Sensor
|
|
/* if(strcmp(topic1, topic_Co2)== 0){
|
|
#ifdef DEBUG
|
|
Serial.print("Co2 Sensor: ");
|
|
Serial.print(msg);
|
|
Serial.println();
|
|
#endif
|
|
Co2 = atoi(msg);
|
|
} */
|
|
// Wetter Wert
|
|
if(strcmp(topic1, topic_Wetter)== 0){
|
|
#ifdef DEBUG
|
|
Serial.print("Aussentemperatur: ");
|
|
Serial.print(msg);
|
|
Serial.println();
|
|
#endif
|
|
Aussentemp = atof(msg);
|
|
}
|
|
if(strcmp(topic1, topic_Pressure)== 0){
|
|
#ifdef DEBUG
|
|
Serial.print("Luftdruck: ");
|
|
Serial.print(msg);
|
|
Serial.println();
|
|
#endif
|
|
Pressure = atoi(msg);
|
|
}
|
|
if(strcmp(topic1, topic_Luftfeuchtigkeit)== 0){
|
|
#ifdef DEBUG
|
|
Serial.print("Luftfeuchtigkeit: ");
|
|
Serial.print(msg);
|
|
Serial.println();
|
|
#endif
|
|
Luftfeuchtigkeit = atof(msg);
|
|
}
|
|
if(strcmp(topic1, topic_Hell)== 0){
|
|
#ifdef DEBUG
|
|
Serial.print("Helligkeit: ");
|
|
Serial.print(msg);
|
|
Serial.println();
|
|
#endif
|
|
hell = atoi(msg);
|
|
}
|
|
if(strcmp(topic1, topic_Dunkel)== 0){
|
|
#ifdef DEBUG
|
|
Serial.print("Dunkel: ");
|
|
Serial.print(msg);
|
|
Serial.println();
|
|
#endif
|
|
dunkel = atoi(msg);
|
|
}
|
|
if(strcmp(topic1, topic_ZeitStart)== 0){
|
|
#ifdef DEBUG
|
|
Serial.print("ZeitStart: ");
|
|
Serial.print(msg);
|
|
Serial.println();
|
|
#endif
|
|
StartderAbdunklung = atoi(msg);
|
|
}
|
|
if(strcmp(topic1, topic_ZeitEnde)== 0){
|
|
#ifdef DEBUG
|
|
Serial.print("ZeitEnde: ");
|
|
Serial.print(msg);
|
|
Serial.println();
|
|
#endif
|
|
EndederAbdunklung = atoi(msg);
|
|
}
|
|
if(strcmp(topic1, topic_Akku)== 0){
|
|
#ifdef DEBUG
|
|
Serial.print("AKKU: ");
|
|
Serial.print(msg);
|
|
Serial.println();
|
|
#endif
|
|
akku = atof(msg);
|
|
}
|
|
}
|
|
void reconnect() {
|
|
sprintf(clientName, "%s%s", "Uhr", "_Zentrale" );
|
|
// Loop until we're reconnected
|
|
while (!client.connected()) {
|
|
Serial.print("Attempting MQTT connection...");
|
|
if (client.connect(clientName)) {
|
|
/* MQTTStatus.setPic(3); */
|
|
Serial.println("connected");
|
|
/* client.subscribe(topic_Co2); */
|
|
client.subscribe(topic_Covid);
|
|
client.subscribe(topic_Wetter);
|
|
client.subscribe(topic_Pressure);
|
|
client.subscribe(topic_Luftfeuchtigkeit);
|
|
client.subscribe(topic_Hell);
|
|
client.subscribe(topic_Dunkel);
|
|
client.subscribe(topic_ZeitEnde);
|
|
client.subscribe(topic_ZeitStart);
|
|
client.subscribe(topic_Akku);
|
|
} 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(myWHITE);
|
|
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, myWHITE);
|
|
display.fillRect(xPos + 27, yPos + 1, 2, 2, myWHITE);
|
|
}
|
|
/* 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(myWHITE);
|
|
display.fillRect(xPos + 29, yPos - 8, 27, 15, myBLACK);
|
|
display.print(szTime);
|
|
display.setFont();
|
|
}
|
|
|
|
void ZeigeTestTime(tm localTime)
|
|
{
|
|
char szTime[15];
|
|
if (blinkSek == true){
|
|
sprintf(szTime, "%02d:%02d", localTime.tm_hour, localTime.tm_min);
|
|
}
|
|
else{
|
|
sprintf(szTime, "%02d %02d", localTime.tm_hour, localTime.tm_min);
|
|
}
|
|
display.setFont(&FreeMonoBold9pt7b);
|
|
display.setCursor(6, 11);
|
|
display.setTextColor(myMAGENTA);
|
|
display.fillRect(0, 0, 64, 12, myBLACK);
|
|
display.print(szTime);
|
|
display.setFont(0);
|
|
}
|
|
|
|
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", CO2Wert);
|
|
Serial.print("CO = "); Serial.println(szCO);
|
|
display.setCursor(xPos, yPos);
|
|
display.setFont();
|
|
switch (Co2){
|
|
case 0 ... CO2_WARN_1 -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+14, yPos+2);
|
|
display.print("2");
|
|
display.setCursor(xPos+50, 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));
|
|
// display.setFont(&Picopixel);
|
|
display.setTextColor(myDATUM);
|
|
display.print(szDATUM);
|
|
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];
|
|
dtostrf(Wetter1, 4, 1, szWetter);
|
|
display.setCursor(xPos, yPos);
|
|
display.fillRect(xPos, yPos-2, 64-xPos, 8+2, (myBLACK));
|
|
display.setTextColor(myDATUM);
|
|
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 ZeigeInnenTemp(float Aussentemp){
|
|
char szWetter[15];
|
|
if (Aussentemp > -99)
|
|
{
|
|
dtostrf(Aussentemp, 5, 1, szWetter);
|
|
display.setFont();
|
|
display.setCursor(1, 14);
|
|
display.setTextColor(myGREEN);
|
|
display.fillRect(0, 13, 40, 9, myRED);
|
|
display.print(szWetter);
|
|
display.setCursor(30, 9);
|
|
display.setFont(&Picopixel);
|
|
display.print("o");
|
|
display.setCursor(34, 20);
|
|
display.setFont();
|
|
display.print("C");
|
|
display.setFont(0);
|
|
}
|
|
}
|
|
void ZeigeTemperatur(float temperatur, uint16_t Color){
|
|
char szWetter[15];
|
|
if (Aussentemp > -99)
|
|
{
|
|
dtostrf(temperatur, 5, 1, szWetter);
|
|
display.setFont();
|
|
display.setCursor(1, 16);
|
|
display.setTextColor(Color);
|
|
display.fillRect(0, 15, 40, 9, myBLACK);
|
|
display.print(szWetter);
|
|
display.setCursor(31, 11);
|
|
display.setFont(&Picopixel);
|
|
display.print("o");
|
|
display.setCursor(34, 22);
|
|
display.setFont();
|
|
display.print("C");
|
|
display.setFont(0);
|
|
}
|
|
}
|
|
|
|
void ZeigeInnenFeuchtigkeit(float Luftfeuchtigkeit){
|
|
char szWetter[15];
|
|
if (Aussentemp > -99)
|
|
{
|
|
dtostrf(Luftfeuchtigkeit, 2, 0, szWetter);
|
|
display.setFont();
|
|
display.setCursor(45, 16);
|
|
display.setTextColor(myGREEN);
|
|
display.fillRect(45, 16, 64, 7, myBLACK);
|
|
display.print(szWetter);
|
|
display.print("%");
|
|
display.setFont(0);
|
|
}
|
|
}
|
|
|
|
void ZeigeInnenCO(int Co2){
|
|
char szWetter[15];
|
|
display.fillRect(0, 34-10, 64, 8, myBLACK);
|
|
if (Co2 > 0)
|
|
{
|
|
sprintf(szWetter, "%5d", CO2Wert);
|
|
//Serial.print("CO = "); Serial.println(Co2);
|
|
display.setFont();
|
|
display.setCursor(1, 35-10);
|
|
switch (CO2Wert){
|
|
case 400 ... CO2_WARN_1: {
|
|
display.setTextColor(myGREEN);
|
|
break;
|
|
}
|
|
case CO2_WARN_1+1 ... CO2_WARN_2: {
|
|
display.setTextColor(myYELLOW);
|
|
break;
|
|
}
|
|
case CO2_WARN_2+1 ... CO2_WARN_3: {
|
|
display.setTextColor(myBraun);
|
|
break;
|
|
}
|
|
case CO2_WARN_3+1 ... CO2_WARN_5: {
|
|
display.setTextColor(myRED);
|
|
break;
|
|
}
|
|
/* case CO2_WARN_4 ... CO2_WARN_5 -1: {
|
|
display.setTextColor(myRED);
|
|
break;
|
|
} */
|
|
default: {
|
|
display.setTextColor(myMAGENTA);
|
|
break;
|
|
}
|
|
}
|
|
display.print("CO");
|
|
display.setFont(&Picopixel);
|
|
display.setCursor(13, 35-10+3);
|
|
display.print("2");
|
|
display.setCursor(15, 35-10+6);
|
|
display.setFont(0);
|
|
display.print(szWetter);
|
|
display.setFont(&Picopixel);
|
|
display.setCursor(45, 35-10+5);
|
|
display.print("ppm");
|
|
display.setFont(0);
|
|
}
|
|
}
|
|
void ZeigeAussenTemp(float Aussentemp){
|
|
char szWetter[15];
|
|
if (Aussentemp > -99)
|
|
{
|
|
dtostrf(Aussentemp, 4, 1, szWetter);
|
|
display.setFont();
|
|
display.setCursor(1, 14);
|
|
display.setTextColor(myHimmelblau);
|
|
display.fillRect(0, 14, 33, 7, myBLACK);
|
|
display.print(szWetter);
|
|
display.setCursor(24, 9);
|
|
display.setFont(&Picopixel);
|
|
display.print("o");
|
|
display.setCursor(28, 20);
|
|
display.setFont();
|
|
display.print("C");
|
|
display.setFont(0);
|
|
}
|
|
}
|
|
|
|
void ZeigeAussenFeuchtigkeit(float Luftfeuchtigkeit){
|
|
char szWetter[15];
|
|
if (Aussentemp > -99)
|
|
{
|
|
dtostrf(Luftfeuchtigkeit, 2, 0, szWetter);
|
|
display.setFont();
|
|
display.setCursor(45, 16);
|
|
display.setTextColor(myHimmelblau);
|
|
display.fillRect(45, 16, 64, 7, myBLACK);
|
|
display.print(szWetter);
|
|
display.print("%");
|
|
display.setFont(0);
|
|
}
|
|
}
|
|
|
|
void ZeigeLuftdruck(float Pressure){
|
|
char szWetter[15];
|
|
dtostrf(Pressure, 4, 0, szWetter);
|
|
display.setFont();
|
|
display.fillRect(0, 33-10, 64, 10, myBLACK);
|
|
display.setCursor(10, 33-8);
|
|
display.setTextColor(myHimmelblau);
|
|
display.print(szWetter);
|
|
display.print(" hPa");
|
|
display.setFont(0);
|
|
|
|
}
|
|
void BlinkSec(bool blink){
|
|
if (blink) {
|
|
display.fillRect(32, 4, 2, 2, myGREEN);
|
|
display.fillRect(32, 10, 2, 2, myMAGENTA);
|
|
|
|
}else{
|
|
display.fillRect(32, 0, 2, 12, myBLACK);
|
|
}
|
|
}
|
|
|
|
void readHtu(){
|
|
if (!NOHTU){
|
|
FeuchteInnen = htu.readHumidity();
|
|
TemparaturInnen = htu.readTemperature();
|
|
TemparaturInnen = TemparaturInnen + HTU_Korrectur;
|
|
Serial.printf("\n\nTemperarur Innen %f °C und\nLuftfeuchtigkeit %f %%\n\n", TemparaturInnen, FeuchteInnen );
|
|
}else{
|
|
FeuchteInnen = 20.00;
|
|
TemparaturInnen = 30.00;
|
|
}
|
|
}
|
|
|
|
void Test()
|
|
{
|
|
display.setCursor(1, 40);
|
|
display.print("Hallo");
|
|
display.setFont(&Picopixel);
|
|
display.print("0o");
|
|
display.setFont();
|
|
}
|
|
|
|
void setup() {
|
|
startTime = millis();
|
|
Serial.begin(115200);
|
|
beginC02();
|
|
if (!htu.begin()) {
|
|
Serial.println("Couldn't find sensor!");
|
|
NOHTU = true;
|
|
delay(500);
|
|
|
|
}
|
|
readHtu();
|
|
WiFi.mode( WIFI_OFF );
|
|
// WiFi.forceSleepBegin();
|
|
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(16); // 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(RRBBGG);
|
|
|
|
// 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(50);
|
|
display.setBrightness(255);
|
|
display.clearDisplay();
|
|
// Set driver chip type
|
|
//display.setDriverChip(FM6124);
|
|
|
|
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("Time"); */
|
|
display_update_enable(true);
|
|
//delay(5000);
|
|
//--------------------------------------------------
|
|
//--------------------------------------------------
|
|
|
|
|
|
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(100)) { // wait up to 10sec to sync
|
|
} else {
|
|
Serial.println("Time not set");
|
|
delay(5000);
|
|
ESP.restart();
|
|
}
|
|
showTime(timeinfo);
|
|
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 >= 200)
|
|
{
|
|
lastTime = millis();
|
|
blinkSek = !blinkSek;
|
|
}
|
|
if (blink){
|
|
BlinkSec(blinkSek);
|
|
}
|
|
|
|
display.setTextColor(display.color565(colorR,colorG,colorB));
|
|
//display.clearDisplay();
|
|
display.fillRect(xpos, ypos-2, 64-xpos, 10, (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 >= 200)
|
|
{
|
|
lastTime = millis();
|
|
blinkSek = !blinkSek;
|
|
}
|
|
if (blink){
|
|
BlinkSec(blinkSek);
|
|
}
|
|
|
|
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
|
|
Serial.println();
|
|
Serial.print("Connecting to ");
|
|
Serial.print(ssid);
|
|
Serial.print(" ");
|
|
|
|
//WiFi.forceSleepWake();
|
|
delay( 1 );
|
|
/* WiFi.persistent( false );
|
|
WiFi.setHostname(hostname.c_str()); //define hostname
|
|
WiFi.mode( WIFI_STA ); */
|
|
WiFi.config( ip, gateway, subnet, dns1, dns2);
|
|
|
|
WiFi.begin(ssid, pass);
|
|
|
|
while (WiFi.status() != WL_CONNECTED) {
|
|
delay(500);
|
|
Serial.print(".");
|
|
ErrCount ++;
|
|
if (ErrCount >= MaxErrCount){
|
|
delay(500);
|
|
ESP.restart();
|
|
}
|
|
}
|
|
Serial.println(" WiFi connected");
|
|
client.setServer(mqtt_server, mqtt_port);
|
|
client.setCallback(callback);
|
|
Serial.print("IP address: \t");
|
|
Serial.println(WiFi.localIP());
|
|
|
|
/* Serial.begin(115200);
|
|
Serial.print("Connecting to: ");
|
|
Serial.println(ssid);
|
|
WiFi.begin(ssid, pass);
|
|
|
|
while(WiFi.status() != WL_CONNECTED){
|
|
delay(500);
|
|
Serial.print(".");
|
|
}
|
|
Serial.println("");
|
|
Serial.println("WiFi connected");
|
|
Serial.print("IP-Address of ESP8266 module: ");
|
|
Serial.println(WiFi.localIP()); */
|
|
}
|
|
|
|
|
|
void loop() {
|
|
Serial1.println("Hallo Co2");
|
|
if (!client.connected()) {
|
|
reconnect();
|
|
}
|
|
|
|
|
|
getNTPtime(10);
|
|
|
|
|
|
if (millis() - lastTime >= 1000)
|
|
{
|
|
lastTime = millis();
|
|
//Co2 = readCO2();
|
|
blinkSek = !blinkSek;
|
|
//ZeigeTestTime(timeinfo);
|
|
ZeigeZeit(timeinfo,1,8);
|
|
|
|
if (akku < 2.85)
|
|
{
|
|
AkkuAlarm();
|
|
}
|
|
|
|
if ((timeinfo.tm_sec % 30) == 0)
|
|
{
|
|
if (readCo2Flag == true) //eadCo2Flag
|
|
{
|
|
CO2Wert = readCO2();
|
|
Serial.print("CO = \t"); Serial.println(CO2Wert);
|
|
readCo2Flag = false;
|
|
}
|
|
}else{
|
|
readCo2Flag = true;
|
|
}
|
|
|
|
if ((timeinfo.tm_min % 2) == 0)
|
|
{
|
|
if (readHtuFlag == true)
|
|
{
|
|
readHtu();
|
|
readHtuFlag = false;
|
|
}
|
|
}else{
|
|
readHtuFlag = true;
|
|
}
|
|
if ((timeinfo.tm_hour >= StartderAbdunklung) && timeinfo.tm_hour < EndederAbdunklung)
|
|
{
|
|
display.setBrightness(dunkel);
|
|
#ifdef HELLIGKEIT
|
|
Serial.printf("Die Helligkeit wird von %0d Uhr bis %0d Uhr auf %00d reduziert\n", StartderAbdunklung, EndederAbdunklung, dunkel);
|
|
#endif
|
|
} else
|
|
{
|
|
display.setBrightness(hell);
|
|
}
|
|
switch (timeinfo.tm_sec)
|
|
{
|
|
case 0 ... 29:
|
|
{
|
|
//ZeigeInnenTemp(TemparaturInnen);
|
|
ZeigeTemperatur(TemparaturInnen, myGREEN);
|
|
ZeigeInnenFeuchtigkeit(FeuchteInnen);
|
|
ZeigeInnenCO(CO2Wert);
|
|
break;
|
|
}
|
|
case 30 ... 59:
|
|
{
|
|
//ZeigeAussenTemp(Aussentemp);
|
|
ZeigeTemperatur(Aussentemp, myHimmelblau);
|
|
ZeigeAussenFeuchtigkeit(Luftfeuchtigkeit);
|
|
ZeigeLuftdruck(Pressure);
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
//ZeigeLuftdruck(Pressure);
|
|
|
|
/* if (Aussentemp > -99.9){
|
|
scroll_text(matrix_height-8,30,"Luftdruck: " + String(Pressure) + " hPa", 30,30,30, 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);
|
|
} */
|
|
//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", 30,30,30, 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(FlurTemp), WetterY,WetterX);
|
|
}
|
|
client.loop();
|
|
}
|
|
|
|
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(); */
|
|
}
|
|
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")
|
|
);
|
|
}
|
|
|
|
|
|
void AkkuAlarm()
|
|
{
|
|
if (((timeinfo.tm_min % 5) == 0))
|
|
{
|
|
char szAkku[10];
|
|
dtostrf(akku, 5, 2, szAkku);
|
|
String myAkku = "ACHTUNG!! Akku : " + String(szAkku) + " V. Bitte aufladen!";
|
|
scroll_text(32-8,40, myAkku, 255,0,0, true);
|
|
}
|
|
} |