2024-12-0100 Start
This commit is contained in:
commit
ffc9bb7f58
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal 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
10
.vscode/extensions.json
vendored
Normal 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"
|
||||
]
|
||||
}
|
9
WetterDisplay.code-workspace
Normal file
9
WetterDisplay.code-workspace
Normal file
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"folders": [
|
||||
{
|
||||
"name": "WetterDisplay",
|
||||
"path": "."
|
||||
}
|
||||
],
|
||||
"settings": {}
|
||||
}
|
39
include/README
Normal file
39
include/README
Normal 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
|
80
include/mcp9808.h
Normal file
80
include/mcp9808.h
Normal file
|
@ -0,0 +1,80 @@
|
|||
#include <Arduino.h>
|
||||
/* Daten:
|
||||
* Temperaturbereich -40 bis 125°C
|
||||
* Genauigkeit: ± 0,25°C
|
||||
* Auflösung: 0,0625°C
|
||||
*/
|
||||
#include <Wire.h>
|
||||
#include "Adafruit_MCP9808.h"
|
||||
float valTemp;
|
||||
|
||||
// Create MCP9808 temperature sensor object
|
||||
Adafruit_MCP9808 tempsensor = Adafruit_MCP9808();
|
||||
|
||||
bool F_MCP9808;
|
||||
|
||||
char Temperature[15] = {0};
|
||||
|
||||
void init_MCP9808(){
|
||||
F_MCP9808 = true;
|
||||
// Make sure the sensor is found, you can also pass in a different i2c
|
||||
// address with tempsensor.begin(0x19) for example, also can be left in blank for default address use
|
||||
// Also there is a table with all addres possible for this sensor, you can connect multiple sensors
|
||||
// to the same i2c bus, just configure each sensor with a different address and define multiple objects for that
|
||||
// A2 A1 A0 address
|
||||
// 0 0 0 0x18 this is the default address
|
||||
// 0 0 1 0x19
|
||||
// 0 1 0 0x1A
|
||||
// 0 1 1 0x1B
|
||||
// 1 0 0 0x1C
|
||||
// 1 0 1 0x1D
|
||||
// 1 1 0 0x1E
|
||||
// 1 1 1 0x1F
|
||||
if (!tempsensor.begin(0x18)) {
|
||||
Serial.println("MCP9808 not connected!");
|
||||
//SystemStatus = SystemStatus | MCP9808noReady;
|
||||
F_MCP9808 = false;
|
||||
|
||||
}
|
||||
//Serial.println("Found MCP9808!");
|
||||
tempsensor.setResolution(3); // sets the resolution mode of reading, the modes are defined in the table bellow:
|
||||
// Mode Resolution SampleTime
|
||||
// 0 0.5°C 30 ms
|
||||
// 1 0.25°C 65 ms
|
||||
// 2 0.125°C 130 ms
|
||||
// 3 0.0625°C 250 ms
|
||||
}
|
||||
|
||||
|
||||
float getTemperature_MCP9808(){
|
||||
// Wake up MSP9808 - power consumption ~200 mikro Ampere
|
||||
int x = 170;
|
||||
tempsensor.wake();
|
||||
float temperature = tempsensor.readTempC();
|
||||
tempsensor.shutdown();
|
||||
dtostrf(temperature,7,1,Temperature);
|
||||
Serial.print("Temperatur (MCP9808):\t");
|
||||
Serial.print(Temperature);
|
||||
Serial.print(" °C\t");
|
||||
Serial.println(temperature,4);
|
||||
tft.drawString("Temperatur: ", 1, x, 4);
|
||||
tft.drawFloat(temperature, 1.0,190, x,4);
|
||||
tft.drawString("o", 252, x, 1);
|
||||
tft.drawString("C", 260, x, 4);
|
||||
tempsensor.shutdown_wake(1); // shutdown MSP9808 - power consumption ~0.1 mikro Ampere, stops temperature sampling
|
||||
return temperature;
|
||||
}
|
||||
|
||||
/* void M2M_Temperatur_MCP9808(String deviceId = "4711") {
|
||||
char topic[100];
|
||||
dtostrf(valTemp,7,1,Temperature);
|
||||
sprintf(topic, "%s%s%s", "hjk/devices/", deviceId.c_str(), "/telemetry/temperature_MCP9808");
|
||||
client.publish(topic, Temperature, true);
|
||||
}
|
||||
void Clear_MCP9808(String deviceId = "4711") {
|
||||
char topic[100];
|
||||
char test[1] = "";
|
||||
sprintf(topic, "%s%s%s", "hjk/devices/", deviceId.c_str(), "/telemetry/temperature_MCP9808");
|
||||
client.publish(topic, test, false);
|
||||
delay(100);
|
||||
} */
|
103
include/mess_BMP280.h
Normal file
103
include/mess_BMP280.h
Normal file
|
@ -0,0 +1,103 @@
|
|||
#include <SPI.h>
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_Sensor.h>
|
||||
#include <Adafruit_BMP280.h>
|
||||
|
||||
|
||||
#ifndef SEALEVELPRESSURE_HPA
|
||||
#define SEALEVELPRESSURE_HPA (1013.25f)
|
||||
#endif
|
||||
// Richen 219 m über NN
|
||||
// Eppingem 195 m über NN
|
||||
|
||||
Adafruit_BMP280 bmp; // I2C
|
||||
|
||||
|
||||
bool F_BMP280;
|
||||
|
||||
struct {
|
||||
char temperature[15] = {0};
|
||||
char pressure[15] = {0};
|
||||
char approx_altitud[15] = {0};
|
||||
char humity[15] = {0};
|
||||
} BMP280Data;
|
||||
|
||||
|
||||
|
||||
void Init_BMP280(){
|
||||
bool status = bmp.begin(0x76);
|
||||
F_BMP280 = true;
|
||||
if (!status) {
|
||||
Serial.println("BMP280 not connected!");
|
||||
F_BMP280 = false;
|
||||
//SystemStatus = SystemStatus | BMP280noReady;
|
||||
Serial.print("SensorID was: 0x"); Serial.println(bmp.sensorID(),16);
|
||||
//delay(5000);
|
||||
} else{
|
||||
/* Default settings from datasheet. */
|
||||
bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */
|
||||
Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */
|
||||
Adafruit_BMP280::SAMPLING_X16, /* Pressure oversampling */
|
||||
Adafruit_BMP280::FILTER_X16, /* Filtering. */
|
||||
Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */
|
||||
|
||||
//bmp_temp->printSensorDetails();
|
||||
Serial.println("BMP280 gefunden");
|
||||
}
|
||||
}
|
||||
|
||||
void read_BMP_280() {
|
||||
|
||||
int x = 30;
|
||||
Serial.print("Temperature (BMP280):\t");
|
||||
float t = bmp.readTemperature();
|
||||
//t = t + KorrekturTemperaturBMP;
|
||||
dtostrf(t,7,1,BMP280Data.temperature);
|
||||
Serial.print(BMP280Data.temperature);
|
||||
Serial.println(" °C");
|
||||
|
||||
Serial.print("Pressure:\t\t");
|
||||
float p = bmp.readPressure() / 100.0F;
|
||||
p = p + KorrekturLuftdruck;
|
||||
dtostrf(p,7,1,BMP280Data.pressure);
|
||||
Serial.print(BMP280Data.pressure);
|
||||
Serial.println(" hPa");
|
||||
|
||||
Serial.print("Approx. Altitude:\t");
|
||||
float a = bmp.readAltitude(SEALEVELPRESSURE_HPA);
|
||||
dtostrf(a,7,1,BMP280Data.approx_altitud);
|
||||
Serial.print(BMP280Data.approx_altitud);
|
||||
Serial.println(" m über NN");
|
||||
|
||||
Serial.println();
|
||||
tft.drawString("Temperatur: ", 1, x, 4);
|
||||
tft.drawFloat(t, 1.0,190, x,4);
|
||||
tft.drawString("o", 252, x, 1);
|
||||
tft.drawString("C", 260, x, 4);
|
||||
tft.drawString("Luftdruck ", 1, 60, 4);
|
||||
tft.drawFloat(p, 0.0,190, 60,4);
|
||||
//tft.drawString("o", 252, x, 1);
|
||||
tft.drawString("hPa", 260, 60, 4);
|
||||
}
|
||||
/* oid M2M_BMP280(String deviceId = "4711") {
|
||||
char topic[100];
|
||||
sprintf(topic, "%s%s%s", "hjk/devices/", deviceId.c_str(), "/telemetry/temperature_BMP_280" );
|
||||
client.publish(topic, BMP280Data.temperature, true);
|
||||
sprintf(topic, "%s%s%s", "hjk/devices/", deviceId.c_str(), "/telemetry/pressure" );
|
||||
client.publish(topic, BMP280Data.pressure, true);
|
||||
sprintf(topic, "%s%s%s", "hjk/devices/", deviceId.c_str(), "/telemetry/approx_altitude" );
|
||||
client.publish(topic, BMP280Data.approx_altitud);
|
||||
}
|
||||
void Clear_BMP280(String deviceId = "4711"){
|
||||
char topic[100];
|
||||
char test[1] = "";
|
||||
sprintf(topic, "%s%s%s", "hjk/devices/", deviceId.c_str(), "/telemetry/temperature_BMP_280" );
|
||||
client.publish(topic,test, false);
|
||||
delay(100);
|
||||
sprintf(topic, "%s%s%s", "hjk/devices/", deviceId.c_str(), "/telemetry/approx_altitude" );
|
||||
client.publish(topic,test, false);
|
||||
delay(100);
|
||||
sprintf(topic, "%s%s%s", "hjk/devices/", deviceId.c_str(), "/telemetry/pressure" );
|
||||
client.publish(topic,test, false);
|
||||
delay(100);
|
||||
} */
|
67
include/mess_htu21.h
Normal file
67
include/mess_htu21.h
Normal file
|
@ -0,0 +1,67 @@
|
|||
#include <Wire.h>
|
||||
#include <Adafruit_Sensor.h>
|
||||
#include <Adafruit_I2CDevice.h>
|
||||
#include <Adafruit_HTU21DF.h>
|
||||
|
||||
Adafruit_HTU21DF htu = Adafruit_HTU21DF();
|
||||
|
||||
#define I2C_SDA 22
|
||||
#define I2C_SCL 27
|
||||
|
||||
|
||||
bool F_HTU_21D;
|
||||
float K_HTU= -0.00;
|
||||
|
||||
struct {
|
||||
char temperature[15] = {0};
|
||||
char humity[15] = {0};
|
||||
} htuData;
|
||||
|
||||
void init_HTU21(){
|
||||
Wire.begin(I2C_SDA, I2C_SCL);
|
||||
F_HTU_21D = false;
|
||||
if (!htu.begin()) {
|
||||
Serial.println("Couldn't find sensor HUT21D!");
|
||||
//SystemStatus = SystemStatus | HTU21noReady;
|
||||
|
||||
}else{
|
||||
F_HTU_21D = true;
|
||||
Serial.println("HUT21D gefunden");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
float read_HTU21D() {
|
||||
float t = htu.readTemperature();
|
||||
//t = t + KorrekturTemperaturHTU;
|
||||
dtostrf(t,7,1,htuData.temperature);
|
||||
float h = htu.readHumidity();
|
||||
dtostrf(h,7,1,htuData.humity);
|
||||
Serial.print("Temperature (HTU21D):\t");
|
||||
Serial.print(htuData.temperature);
|
||||
Serial.print(" °C\t");
|
||||
tft.drawString("Temperatur: ", 1, x, 4);
|
||||
tft.drawFloat(t, 1.0,190, x,4);
|
||||
tft.drawString("o", 252, x, 1);
|
||||
tft.drawString("C", 260, x, 4);
|
||||
|
||||
Serial.println(t,8);
|
||||
Serial.print("Luftfeuchtigkeit:\t");
|
||||
Serial.print(htuData.humity);
|
||||
Serial.println(" %");
|
||||
tft.drawString("Luftfeuchtigkeit: ", 1, x +=25, 4);
|
||||
tft.drawFloat(h, 1.0,190, x, 4);
|
||||
tft.drawString("%", 252, x, 4);
|
||||
x = 100;
|
||||
return t;
|
||||
}
|
||||
|
||||
void M2M_HTU21D(String deviceId = "4711") {
|
||||
/* char topic[100];
|
||||
sprintf(topic, "%s%s%s", "hjk/devices/", deviceId.c_str(), "/telemetry/temperature_Htu_21" );
|
||||
client.publish(topic, htuData.temperature, true);
|
||||
sprintf(topic, "%s%s%s", "hjk/devices/", deviceId.c_str(), "/telemetry/humity" );
|
||||
client.publish(topic, htuData.humity, true); */
|
||||
/* Serial.printf("HTU21:\t\t %s °C\n", htuData.temperature);
|
||||
Serial.printf("HTU21:\t\t %s %%\n", htuData.humity); */
|
||||
}
|
46
lib/README
Normal file
46
lib/README
Normal 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 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
|
63
platformio.ini
Normal file
63
platformio.ini
Normal file
|
@ -0,0 +1,63 @@
|
|||
[platformio]
|
||||
src_dir = .
|
||||
default_envs = cyd
|
||||
|
||||
[env]
|
||||
platform = espressif32
|
||||
board = esp32dev
|
||||
framework = arduino
|
||||
lib_deps =
|
||||
bodmer/TFT_eSPI@^2.5.33
|
||||
;nitek/XPT2046_Bitbang_Slim@^2.0.0
|
||||
;https://github.com/PaulStoffregen/XPT2046_Touchscreen.git#v1.4
|
||||
adafruit/Adafruit HTU21DF Library @ 1.0.5
|
||||
;wollewald/ADS1115_WE @ 1.4.3
|
||||
adafruit/Adafruit MCP9808 Library @ 2.0.0
|
||||
adafruit/Adafruit BusIO @ 1.16.1
|
||||
;adafruit/Adafruit BME280 Library @ 2.2.4
|
||||
adafruit/Adafruit BMP280 Library @ 2.6.8
|
||||
adafruit/Adafruit Unified Sensor @ 1.1.14
|
||||
SD
|
||||
FS
|
||||
SPI
|
||||
|
||||
|
||||
monitor_speed = 115200
|
||||
monitor_filters = esp32_exception_decoder, time
|
||||
upload_speed = 921600
|
||||
board_build.partitions=min_spiffs.csv
|
||||
build_flags =
|
||||
-DUSER_SETUP_LOADED
|
||||
-DUSE_HSPI_PORT
|
||||
-DTFT_MISO=12
|
||||
-DTFT_MOSI=13
|
||||
-DTFT_SCLK=14
|
||||
-DTFT_CS=15
|
||||
-DTFT_DC=2
|
||||
-DTFT_RST=-1
|
||||
-DTFT_BL=21
|
||||
-DTFT_BACKLIGHT_ON=HIGH
|
||||
-DSPI_FREQUENCY=55000000
|
||||
-DSPI_READ_FREQUENCY=20000000
|
||||
-DSPI_TOUCH_FREQUENCY=2500000
|
||||
-DLOAD_GLCD
|
||||
-DLOAD_FONT2
|
||||
-DLOAD_FONT4
|
||||
-DLOAD_FONT6
|
||||
-DLOAD_FONT7
|
||||
-DLOAD_FONT8
|
||||
-DLOAD_GFXFF
|
||||
-DSAVE_INTERVAL=5
|
||||
-DKorrekturLuftdruck=27.1
|
||||
|
||||
[env:cyd]
|
||||
build_flags =
|
||||
${env.build_flags}
|
||||
-DILI9341_2_DRIVER
|
||||
|
||||
[env:cyd2usb]
|
||||
build_flags =
|
||||
${env.build_flags}
|
||||
-DST7789_DRIVER
|
||||
-DTFT_RGB_ORDER=TFT_BGR
|
||||
-DTFT_INVERSION_OFF
|
377
src/main.cpp
Normal file
377
src/main.cpp
Normal file
|
@ -0,0 +1,377 @@
|
|||
#include <ArduinoOTA.h>
|
||||
|
||||
#include <TFT_eSPI.h>
|
||||
|
||||
#include <Wire.h>
|
||||
|
||||
#include <WiFi.h>
|
||||
//#include <NTPClient.h>
|
||||
//#include <WiFiUdp.h>
|
||||
|
||||
// Replace with your network credentials
|
||||
const char* ssid = "MagentaWLAN-RGDO";
|
||||
const char* password = "93329248424922704583";
|
||||
|
||||
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;
|
||||
|
||||
char szZeit[20];
|
||||
|
||||
int x = 100;
|
||||
char sID[100];
|
||||
char ausgabe[100];
|
||||
|
||||
TFT_eSPI tft = TFT_eSPI();
|
||||
SPIClass spi2 = SPIClass(VSPI);
|
||||
|
||||
#include<mess_htu21.h>
|
||||
#include <mcp9808.h>
|
||||
#include <mess_BMP280.h>
|
||||
|
||||
// TEST
|
||||
#include "FS.h"
|
||||
#include "SD.h"
|
||||
#include "SPI.h"
|
||||
|
||||
bool getNTPtime(int sec);
|
||||
void showTime(tm localTime);
|
||||
void zeigeZeit(tm localTime, int x, int y);
|
||||
|
||||
void listDir(fs::FS &fs, const char * dirname, uint8_t levels) {
|
||||
Serial.printf("Listing directory: %s\n", dirname);
|
||||
|
||||
File root = fs.open(dirname);
|
||||
if (!root) {
|
||||
Serial.println("Failed to open directory");
|
||||
return;
|
||||
}
|
||||
if (!root.isDirectory()) {
|
||||
Serial.println("Not a directory");
|
||||
return;
|
||||
}
|
||||
|
||||
File file = root.openNextFile();
|
||||
while (file) {
|
||||
if (file.isDirectory()) {
|
||||
Serial.print(" DIR : ");
|
||||
Serial.println(file.name());
|
||||
if (levels) {
|
||||
listDir(fs, file.path(), levels - 1);
|
||||
}
|
||||
} else {
|
||||
Serial.print(" FILE: ");
|
||||
Serial.print(file.name());
|
||||
Serial.print(" SIZE: ");
|
||||
Serial.println(file.size());
|
||||
}
|
||||
file = root.openNextFile();
|
||||
}
|
||||
}
|
||||
|
||||
void createDir(fs::FS &fs, const char * path) {
|
||||
Serial.printf("Creating Dir: %s\n", path);
|
||||
if (fs.mkdir(path)) {
|
||||
Serial.println("Dir created");
|
||||
} else {
|
||||
Serial.println("mkdir failed");
|
||||
}
|
||||
}
|
||||
|
||||
void removeDir(fs::FS &fs, const char * path) {
|
||||
Serial.printf("Removing Dir: %s\n", path);
|
||||
if (fs.rmdir(path)) {
|
||||
Serial.println("Dir removed");
|
||||
} else {
|
||||
Serial.println("rmdir failed");
|
||||
}
|
||||
}
|
||||
|
||||
void readFile(fs::FS &fs, const char * path) {
|
||||
Serial.printf("Reading file: %s\n", path);
|
||||
|
||||
File file = fs.open(path);
|
||||
if (!file) {
|
||||
Serial.println("Failed to open file for reading");
|
||||
return;
|
||||
}
|
||||
|
||||
//Serial.print("Read from file: ");
|
||||
while (file.available()) {
|
||||
Serial.write(file.read());
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
void writeFile(fs::FS &fs, const char * path, const char * message) {
|
||||
Serial.printf("Writing file: %s\n", path);
|
||||
|
||||
File file = fs.open(path, FILE_WRITE);
|
||||
if (!file) {
|
||||
Serial.println("Failed to open file for writing");
|
||||
return;
|
||||
}
|
||||
if (file.print(message)) {
|
||||
//Serial.println("File written");
|
||||
} else {
|
||||
Serial.println("Write failed");
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
void appendFile(fs::FS &fs, const char * path, const char * message) {
|
||||
//Serial.printf("Appending to file: %s\n", path);
|
||||
|
||||
File file = fs.open(path, FILE_APPEND);
|
||||
if (!file) {
|
||||
Serial.println("Failed to open file for appending");
|
||||
return;
|
||||
}
|
||||
if (file.print(message)) {
|
||||
//Serial.println("Message appended");
|
||||
} else {
|
||||
Serial.println("Append failed");
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
void renameFile(fs::FS &fs, const char * path1, const char * path2) {
|
||||
Serial.printf("Renaming file %s to %s\n", path1, path2);
|
||||
if (fs.rename(path1, path2)) {
|
||||
Serial.println("File renamed");
|
||||
} else {
|
||||
Serial.println("Rename failed");
|
||||
}
|
||||
}
|
||||
|
||||
void deleteFile(fs::FS &fs, const char * path) {
|
||||
Serial.printf("Deleting file: %s\n", path);
|
||||
if (fs.remove(path)) {
|
||||
Serial.println("File deleted");
|
||||
} else {
|
||||
Serial.println("Delete failed");
|
||||
}
|
||||
}
|
||||
|
||||
void testFileIO(fs::FS &fs, const char * path) {
|
||||
File file = fs.open(path);
|
||||
static uint8_t buf[512];
|
||||
size_t len = 0;
|
||||
uint32_t start = millis();
|
||||
uint32_t end = start;
|
||||
if (file) {
|
||||
len = file.size();
|
||||
size_t flen = len;
|
||||
start = millis();
|
||||
while (len) {
|
||||
size_t toRead = len;
|
||||
if (toRead > 512) {
|
||||
toRead = 512;
|
||||
}
|
||||
file.read(buf, toRead);
|
||||
len -= toRead;
|
||||
}
|
||||
end = millis() - start;
|
||||
Serial.printf("%u bytes read for %u ms\n", flen, end);
|
||||
file.close();
|
||||
} else {
|
||||
Serial.println("Failed to open file for reading");
|
||||
}
|
||||
|
||||
|
||||
file = fs.open(path, FILE_WRITE);
|
||||
if (!file) {
|
||||
Serial.println("Failed to open file for writing");
|
||||
return;
|
||||
}
|
||||
|
||||
size_t i;
|
||||
start = millis();
|
||||
for (i = 0; i < 2048; i++) {
|
||||
file.write(buf, 512);
|
||||
}
|
||||
end = millis() - start;
|
||||
Serial.printf("%u bytes written for %u ms\n", 2048 * 512, end);
|
||||
file.close();
|
||||
}
|
||||
|
||||
// ENDE TEST
|
||||
|
||||
void setup() {
|
||||
// Start the tft display and set it to black
|
||||
tft.init();
|
||||
tft.setRotation(1); //This is the display in landscape
|
||||
|
||||
// Clear the screen before writing to it
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
|
||||
tft.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||
int x = 5;
|
||||
int y = 10;
|
||||
int fontNum = 2;
|
||||
tft.drawString("Hello", x, y, fontNum); // Left Aligned
|
||||
x = 320 /2;
|
||||
y += 16;
|
||||
tft.setTextColor(TFT_RED, TFT_BLACK);
|
||||
tft.drawCentreString("Warte auf verbindung", x, y, fontNum *= 2);
|
||||
Serial.begin(115200);
|
||||
WiFi.reconnect();
|
||||
delay( 1 );
|
||||
/* WiFi.persistent( false );
|
||||
WiFi.mode( WIFI_STA ); */
|
||||
|
||||
Serial.print("Connecting to ");
|
||||
Serial.println(ssid);
|
||||
WiFi.begin(ssid, password);
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(500);
|
||||
Serial.print(".");
|
||||
}
|
||||
// Print local IP address and start web server
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
Serial.println("");
|
||||
Serial.println("WiFi connected.");
|
||||
Serial.print("IP address: \t");
|
||||
Serial.println(WiFi.localIP());
|
||||
tft.setTextColor(TFT_YELLOW, TFT_BLACK);
|
||||
tft.setTextSize(2);
|
||||
tft.println(WiFi.localIP());
|
||||
tft.setTextSize(1);
|
||||
delay(5000);
|
||||
// Initialize a NTPClient to get time
|
||||
//timeClient.begin();
|
||||
// Set offset time in seconds to adjust for your timezone, for example:
|
||||
// GMT +1 = 3600
|
||||
// GMT +8 = 28800
|
||||
// GMT -1 = -3600
|
||||
// GMT 0 = 0
|
||||
//timeClient.setTimeOffset(3600);
|
||||
|
||||
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);
|
||||
|
||||
|
||||
//--------------------------------------------------------
|
||||
|
||||
init_HTU21();
|
||||
init_MCP9808();
|
||||
Init_BMP280();
|
||||
if (F_MCP9808 == true){
|
||||
valTemp = getTemperature_MCP9808();
|
||||
}
|
||||
|
||||
x = 320 /2;
|
||||
y += 32;
|
||||
tft.setTextColor(TFT_BLUE, TFT_BLACK);
|
||||
|
||||
if (!SD.begin(SS, spi2, 80000000)) {
|
||||
Serial.println("Card Mount Failed");
|
||||
return;
|
||||
}
|
||||
uint8_t cardType = SD.cardType();
|
||||
|
||||
if (cardType == CARD_NONE) {
|
||||
Serial.println("No SD card attached");
|
||||
return;
|
||||
}
|
||||
|
||||
Serial.print("SD Card Type: ");
|
||||
if (cardType == CARD_MMC) {
|
||||
Serial.println("MMC");
|
||||
} else if (cardType == CARD_SD) {
|
||||
Serial.println("SDSC");
|
||||
} else if (cardType == CARD_SDHC) {
|
||||
Serial.println("SDHC");
|
||||
} else {
|
||||
Serial.println("UNKNOWN");
|
||||
}
|
||||
uint64_t cardSize = SD.cardSize() / (1024 * 1024);
|
||||
Serial.printf("SD Card Size: %lluMB\n", cardSize);
|
||||
|
||||
listDir(SD, "/", 0);
|
||||
/* createDir(SD, "/mydir");
|
||||
listDir(SD, "/", 0);
|
||||
removeDir(SD, "/mydir");
|
||||
listDir(SD, "/", 2);
|
||||
testFileIO(SD, "/hello.txt");
|
||||
deleteFile(SD, "/hello.txt"); */
|
||||
|
||||
}
|
||||
|
||||
int Minuten, MintenOld = 99;
|
||||
float test;
|
||||
|
||||
void loop() {
|
||||
getNTPtime(10);
|
||||
tft.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||
zeigeZeit(timeinfo, 210, 0);
|
||||
Minuten = timeinfo.tm_min;
|
||||
if (Minuten != MintenOld){
|
||||
MintenOld = Minuten;
|
||||
tft.setTextColor(TFT_BLUE, TFT_BLACK);
|
||||
x = 100;
|
||||
test = read_HTU21D();
|
||||
getTemperature_MCP9808();
|
||||
read_BMP_280();
|
||||
if (Minuten % SAVE_INTERVAL == 0){
|
||||
sprintf(ausgabe, "%s;%f\n", szZeit, test);
|
||||
appendFile(SD, "/daten.csv", ausgabe);
|
||||
Serial.print("SAVE ----> "); Serial.println(szZeit);
|
||||
}
|
||||
}
|
||||
|
||||
delay(300);
|
||||
}
|
||||
|
||||
bool getNTPtime(int sec) {
|
||||
|
||||
{
|
||||
uint32_t start = millis();
|
||||
do {
|
||||
time(&now);
|
||||
localtime_r(&now, &timeinfo);
|
||||
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
|
||||
}
|
||||
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 zeigeZeit(tm localTime, int x = 0, int y = 0){
|
||||
sprintf(szZeit,"%02d:%02d:%02d\n",
|
||||
localTime.tm_hour,
|
||||
localTime.tm_min,
|
||||
localTime.tm_sec);
|
||||
tft.setCursor(x, y);
|
||||
tft.setTextSize(2);
|
||||
tft.println(szZeit);
|
||||
tft.setTextSize(1);
|
||||
}
|
||||
|
11
test/README
Normal file
11
test/README
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
This directory is intended for PlatformIO Test Runner 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/en/latest/advanced/unit-testing/index.html
|
Loading…
Reference in New Issue
Block a user