2023-06-04

Dieverse Änderungen (Boris)
This commit is contained in:
hans-jurgen 2023-06-04 13:50:28 +02:00
commit cfc51c853e
8 changed files with 961 additions and 0 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch

10
.vscode/extensions.json vendored Normal file
View File

@ -0,0 +1,10 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
],
"unwantedRecommendations": [
"ms-vscode.cpptools-extension-pack"
]
}

4
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,4 @@
{
"C_Cpp.errorSquiggles": "Disabled",
"cmake.configureOnOpen": true
}

39
include/README Normal file
View File

@ -0,0 +1,39 @@
This directory is intended for project header files.
A header file is a file containing C declarations and macro definitions
to be shared between several project source files. You request the use of a
header file in your project source file (C, C++, etc) located in `src` folder
by including it, with the C preprocessing directive `#include'.
```src/main.c
#include "header.h"
int main (void)
{
...
}
```
Including a header file produces the same results as copying the header file
into each source file that needs it. Such copying would be time-consuming
and error-prone. With a header file, the related declarations appear
in only one place. If they need to be changed, they can be changed in one
place, and programs that include the header file will automatically use the
new version when next recompiled. The header file eliminates the labor of
finding and changing all the copies as well as the risk that a failure to
find one copy will result in inconsistencies within a program.
In C, the usual convention is to give header files names that end with `.h'.
It is most portable to use only letters, digits, dashes, and underscores in
header file names, and at most one dot.
Read more about using header files in official GCC documentation:
* Include Syntax
* Include Operation
* Once-Only Headers
* Computed Includes
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html

46
lib/README Normal file
View File

@ -0,0 +1,46 @@
This directory is intended for project specific (private) libraries.
PlatformIO will compile them to static libraries and link into executable file.
The source code of each library should be placed in a an own separate directory
("lib/your_library_name/[here are source files]").
For example, see a structure of the following two libraries `Foo` and `Bar`:
|--lib
| |
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
| |
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |
| |- README --> THIS FILE
|
|- platformio.ini
|--src
|- main.c
and a contents of `src/main.c`:
```
#include <Foo.h>
#include <Bar.h>
int main (void)
{
...
}
```
PlatformIO Library Dependency Finder will find automatically dependent
libraries scanning project source files.
More information about PlatformIO Library Dependency Finder
- https://docs.platformio.org/page/librarymanager/ldf.html

50
platformio.ini Normal file
View File

@ -0,0 +1,50 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env]
platform = espressif32
board = nodemcu-32s
framework = arduino
monitor_speed = 115200
monitor_port = COM4
monitor_filters = time
upload_port = COM4
lib_deps =
knolleary/PubSubClient @ 2.8
adafruit/Adafruit GFX Library @ 1.11.3
2dom/PxMatrix LED MATRIX library @ 1.8.2
adafruit/Adafruit BusIO @ 1.7.2
build_flags =
-DSCAN=32
[env:debug] ; Entwicklungssystem
build_flags = ${env.build_flags}
-DDEBUG=1
-DGRENZWERT=3.80
-DINNEN=\"hjk/devices/WETTERSTATION/telemetry/temperature_BMP_280\"
-DCO2=\"hjk/devices/WETTERSTATION/telemetry/co2\"
-DAKKU=\"hjk/devices/WETTERSTATION/telemetry/battery\"
-DWETTER=\"hjk/devices/WETTERSTATION/telemetry/temperature_Htu_21\"
-DLUFTDRUCK=\"hjk/devices/WETTERSTATION/telemetry/pressure\"
-DFEUCHTIGKEIT=\"hjk/devices/WETTERSTATION/telemetry/humity\"
-DHELLIGKEIT=\"hjk/devices/WETTERSTATION/telemetry/Lux\"
[env:boris]
build_flags = ${env.build_flags}
-DDEBUG=1
-DGRENZWERT=2.80
-DINNEN=\"hjk/devices/WETTERSTATIONBORIS/telemetry/temperature_BMP_280\"
-DCO2=\"hjk/devices/WETTERSTATIONBORIS/telemetry/co2\"
-DAKKU=\"hjk/devices/WETTERSTATIONBORIS/telemetry/battery\"
-DWETTER=\"hjk/devices/WETTERSTATIONBORIS/telemetry/temperature_Htu_21\"
-DLUFTDRUCK=\"hjk/devices/WETTERSTATIONBORIS/telemetry/pressure\"
-DFEUCHTIGKEIT=\"hjk/devices/WETTERSTATIONBORIS/telemetry/humity\"
-DHELLIGKEIT=\"hjk/devices/WETTERSTATIONBORIS/telemetry/Lux\"

796
src/main.cpp Normal file
View File

@ -0,0 +1,796 @@
#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>
#define mqtt_port 61883
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[] = "St.-Peters-Gasse"; // your network SSID (name)
char pass[] = "1952994784599317"; // your network password
IPAddress ip( 192, 168, 127, 247);
IPAddress gateway( 192, 168, 127, 1 );
IPAddress subnet( 255, 255, 255, 0 );
IPAddress dns(192, 168, 127, 1); // DNS-Server
String hostname = "GROSSZEICHENDISPLAY2";
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 FlurTemp = -99.90;
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 1883
const char* mqtt_server = "hjkmqtt.dedyn.io";
char topic_0[50];
char msg[20];
char clientName[30];
const char* topic_Innen = INNEN;
const char* topic_Akku = AKKU;
const char* topic_Co2 = CO2;
const char* topic_Wetter = WETTER;
const char* topic_Pressure = LUFTDRUCK;
const char* topic_Luftfeuchtigkeit = FEUCHTIGKEIT;
const char* topic_Helligkeit = HELLIGKEIT;
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);
// CO2 Wert vom Sensor
if(strcmp(topic1, topic_Co2)== 0){
Serial.print("Co2 Sensor: ");
Serial.print(msg);
Serial.println();
Co2 = atoi(msg);
}
// 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");
FlurTemp = atof(msg);
}
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", "_Zentrale3" );
// 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);Ja
client.subscribe(topic_Wetter);
client.subscribe(topic_Pressure);
client.subscribe(topic_Innen);
client.subscribe(topic_Luftfeuchtigkeit);
client.subscribe(topic_Akku);
client.subscribe(topic_Helligkeit);
} 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(myTEMP);
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(RRGGBB);
// 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("Time");
//--------------------------------------------------
//--------------------------------------------------
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(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
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, dns, dns );
//WiFi.begin( WLAN_SSID, WLAN_PASSWD );
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
ErrCount ++;
if (ErrCount >= MaxErrCount){
// ---------------------------------
// Status ändern !!! -1
//datenSave(-1);
// ---------------------------------
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() {
if (!client.connected()) {
reconnect();
}
getNTPtime(10);
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(FlurTemp), WetterY,WetterX);
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) + " %", 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);
}
}
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")
);
}

11
test/README Normal file
View File

@ -0,0 +1,11 @@
This directory is intended for PlatformIO Unit Testing and project tests.
Unit Testing is a software testing method by which individual units of
source code, sets of one or more MCU program modules together with associated
control data, usage procedures, and operating procedures, are tested to
determine whether they are fit for use. Unit testing finds problems early
in the development cycle.
More information about PlatformIO Unit Testing:
- https://docs.platformio.org/page/plus/unit-testing.html