2025-11-1002
This commit is contained in:
96
src/main.cpp
96
src/main.cpp
@@ -17,14 +17,10 @@
|
||||
#include <Fonts/Picopixel.h>
|
||||
|
||||
#include <PxMatrix.h>
|
||||
#include <Adafruit_HTU21DF.h>
|
||||
|
||||
#include <mess_BME280.h>
|
||||
#include <CO2.h>
|
||||
|
||||
#define I2C_SDA 17
|
||||
#define I2C_SCL 2
|
||||
|
||||
|
||||
// Pins for LED MATRIX
|
||||
#ifdef ESP32
|
||||
|
||||
@@ -55,10 +51,6 @@ Ticker display_ticker;
|
||||
|
||||
#endif
|
||||
|
||||
/* #define SDA 21
|
||||
#define SCL 22
|
||||
#define RX1 9
|
||||
#define TX1 10 */
|
||||
|
||||
#define MaxErrCount 30
|
||||
unsigned long startTime;
|
||||
@@ -69,8 +61,6 @@ unsigned long endTime;
|
||||
#define mqtt_port 61883
|
||||
WiFiClient espClient;
|
||||
PubSubClient client(espClient);
|
||||
Adafruit_HTU21DF htu = Adafruit_HTU21DF();
|
||||
|
||||
|
||||
|
||||
#define matrix_width 64
|
||||
@@ -78,7 +68,7 @@ Adafruit_HTU21DF htu = Adafruit_HTU21DF();
|
||||
|
||||
// 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 = 35; //30-70 is usually fine
|
||||
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);
|
||||
@@ -101,10 +91,17 @@ 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 ip( 192, 168, 127, 53);
|
||||
IPAddress gateway( 192, 168, 127, 1 );
|
||||
IPAddress subnet( 255, 255, 255, 0 );
|
||||
IPAddress dns1(192, 168, 127, 1); // DNS-Server 1
|
||||
@@ -161,6 +158,15 @@ 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_Hell = "hjk/devices/DisplayMarcel/telemetry/Lux";
|
||||
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";
|
||||
@@ -170,6 +176,7 @@ const char* topic_Akku = "hjk/devices/WETTERSTATIONMARCEL/telemetry/battery";
|
||||
const char* topic_Helligkeit = "hjk/devices/DisplayMarcel/telemetry/Lux";
|
||||
|
||||
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);
|
||||
@@ -220,6 +227,7 @@ void print_wifi_status() {
|
||||
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)
|
||||
@@ -317,11 +325,15 @@ void reconnect() {
|
||||
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_Helligkeit);
|
||||
/* client.subscribe(topic_Dunkel);
|
||||
client.subscribe(topic_ZeitEnde);
|
||||
client.subscribe(topic_ZeitStart); */
|
||||
client.subscribe(topic_Akku);
|
||||
} else {
|
||||
Serial.print("failed, rc=");
|
||||
@@ -337,6 +349,7 @@ 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);
|
||||
@@ -351,6 +364,8 @@ void ZeigeZeit(tm localTime, int xPos = 2, int yPos = 8)
|
||||
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);
|
||||
@@ -406,6 +421,7 @@ void ZeigeCO(int xPos = 1, int yPos = 19)
|
||||
}
|
||||
|
||||
}
|
||||
//display.setTextColor(myGREEN);
|
||||
display.fillRect(xPos, yPos-2, 64-xPos, 8+2, (myBLACK));
|
||||
display.print("CO :");
|
||||
display.print(szCO);
|
||||
@@ -430,6 +446,7 @@ void ZeigeDatum(tm localTime, int xPos = 2, int yPos = 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();
|
||||
@@ -537,6 +554,10 @@ void ZeigeInnenCO(int Co2){
|
||||
display.setTextColor(myRED);
|
||||
break;
|
||||
}
|
||||
/* case CO2_WARN_4 ... CO2_WARN_5 -1: {
|
||||
display.setTextColor(myRED);
|
||||
break;
|
||||
} */
|
||||
default: {
|
||||
display.setTextColor(myMAGENTA);
|
||||
break;
|
||||
@@ -612,7 +633,7 @@ void BlinkSec(bool blink){
|
||||
}
|
||||
}
|
||||
|
||||
void readHtu(){
|
||||
/* void readHtu(){
|
||||
if (!NOHTU){
|
||||
FeuchteInnen = htu.readHumidity();
|
||||
TemparaturInnen = htu.readTemperature();
|
||||
@@ -622,7 +643,7 @@ void readHtu(){
|
||||
FeuchteInnen = 20.00;
|
||||
TemparaturInnen = 30.00;
|
||||
}
|
||||
}
|
||||
} */
|
||||
|
||||
void Test()
|
||||
{
|
||||
@@ -636,15 +657,14 @@ void Test()
|
||||
void setup() {
|
||||
startTime = millis();
|
||||
Serial.begin(115200);
|
||||
//Wire.begin(I2C_SDA, I2C_SCL);
|
||||
beginC02();
|
||||
if (!htu.begin()){
|
||||
Serial.println("Couldn't find sensor!");
|
||||
NOHTU = true;
|
||||
delay(5000);
|
||||
|
||||
Sensor_BME280();
|
||||
;
|
||||
Serial.println(Temp[0]);
|
||||
|
||||
}
|
||||
readHtu();
|
||||
|
||||
delay(10000);
|
||||
beginC02();
|
||||
WiFi.mode( WIFI_OFF );
|
||||
// WiFi.forceSleepBegin();
|
||||
delay( 10 );
|
||||
@@ -657,17 +677,21 @@ void setup() {
|
||||
|
||||
// Set the color order {RRGGBB, RRBBGG, GGRRBB, GGBBRR, BBRRGG, BBGGRR} (default is RRGGBB)
|
||||
display.setColorOrder(RRBBGG);
|
||||
|
||||
|
||||
// Set the brightness of the panels (default is 255)
|
||||
display.setBrightness(255);
|
||||
display.clearDisplay();
|
||||
display.setTextColor(myRED);
|
||||
|
||||
/* display.setTextColor(myRED);
|
||||
display.setCursor(0,0);
|
||||
display.print("Pixel");
|
||||
display.setTextColor(myGREEN);
|
||||
display.setCursor(30,0);
|
||||
display.print("Time");
|
||||
display.print("Time"); */
|
||||
display_update_enable(true);
|
||||
delay(5000);
|
||||
//--------------------------------------------------
|
||||
//--------------------------------------------------
|
||||
|
||||
|
||||
print_wifi_status();
|
||||
configTime(0, 0, NTP_SERVER);
|
||||
@@ -874,7 +898,7 @@ void loop() {
|
||||
readCo2Flag = true;
|
||||
}
|
||||
|
||||
if ((timeinfo.tm_min % 2) == 0)
|
||||
/* if ((timeinfo.tm_min % 2) == 0)
|
||||
{
|
||||
if (readHtuFlag == true)
|
||||
{
|
||||
@@ -883,12 +907,12 @@ void loop() {
|
||||
}
|
||||
}else{
|
||||
readHtuFlag = true;
|
||||
}
|
||||
|
||||
} */
|
||||
switch (timeinfo.tm_sec)
|
||||
{
|
||||
case 0 ... 14:
|
||||
{
|
||||
//ZeigeInnenTemp(TemparaturInnen);
|
||||
ZeigeTemperatur(TemparaturInnen, myGREEN);
|
||||
ZeigeInnenFeuchtigkeit(FeuchteInnen);
|
||||
ZeigeInnenCO(CO2Wert);
|
||||
@@ -896,6 +920,7 @@ void loop() {
|
||||
}
|
||||
case 15 ... 29:
|
||||
{
|
||||
//ZeigeAussenTemp(Aussentemp);
|
||||
ZeigeTemperatur(Aussentemp, myHimmelblau);
|
||||
ZeigeAussenFeuchtigkeit(Luftfeuchtigkeit);
|
||||
ZeigeLuftdruck(Pressure);
|
||||
@@ -903,6 +928,7 @@ void loop() {
|
||||
}
|
||||
case 30 ... 44:
|
||||
{
|
||||
//ZeigeInnenTemp(TemparaturInnen);
|
||||
ZeigeTemperatur(TemparaturInnen, myGREEN);
|
||||
ZeigeInnenFeuchtigkeit(FeuchteInnen);
|
||||
ZeigeInnenCO(CO2Wert);
|
||||
@@ -910,6 +936,7 @@ void loop() {
|
||||
}
|
||||
case 45 ... 59:
|
||||
{
|
||||
//ZeigeAussenTemp(Aussentemp);
|
||||
ZeigeTemperatur(Aussentemp, myHimmelblau);
|
||||
ZeigeAussenFeuchtigkeit(Luftfeuchtigkeit);
|
||||
ZeigeLuftdruck(Pressure);
|
||||
@@ -917,12 +944,11 @@ void loop() {
|
||||
}
|
||||
}
|
||||
}
|
||||
client.loop();
|
||||
|
||||
}
|
||||
|
||||
bool getNTPtime(int sec) {
|
||||
|
||||
{
|
||||
uint32_t start = millis();
|
||||
do {
|
||||
time(&now);
|
||||
@@ -931,12 +957,6 @@ bool getNTPtime(int sec) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user