2025-12-1205

This commit is contained in:
2025-12-11 01:19:39 +01:00
parent d57d91e83e
commit c2af9db648
11 changed files with 628 additions and 0 deletions

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

34
include/mess_Ub.h Normal file
View File

@@ -0,0 +1,34 @@
const float MinimalSpannung = 3.20;
float korectur = 1;
float getBattery(float ref = 0.00945)
{
float valA0 = analogRead(A0) * ref;
Serial.print("Batterie:\t");
Serial.print(valA0,4);
Serial.print(" V\n");
return valA0;
}
float readKorectur(){
float korectur;
File k = LittleFS.open("/kor.txt", "r");
if(!k){
//Serial.println("file open failed");
korectur = 0.01;
}else{
String data = k.readString();
korectur = data.toFloat();
k.close();
}
return korectur;
}
void saveKorektur(){
File k = LittleFS.open("/kor.txt", "w");
if(!k){
Serial.println("file open failed");
}else{
k.println(String(korectur,8));
k.close();
}
}

69
include/mess_bme280.h Normal file
View File

@@ -0,0 +1,69 @@
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme; // I2C
struct {
char temperature[15] = {0};
char pressure[15] = {0};
char approx_altitud[15] = {0};
char humity[15] = {0};
} BME280Data;
void Init_BME280(){
bool status = bme.begin();
if (!status) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}
}
void read_BME_280() {
Serial.print("Temperature:\t\t");
float t = bme.readTemperature();
dtostrf(t,10,4,BME280Data.temperature);
Serial.print(BME280Data.temperature);
Serial.println(" °C");
//Serial.print("Diff zu DS1820 \t\t");Serial.print(t-valTemp,4); Serial.println(" °C");
Serial.print("Humidity:\t\t");
float h = bme.readHumidity();
dtostrf(h,8,2,BME280Data.humity);
Serial.print(BME280Data.humity);
Serial.println(" %");
Serial.print("Pressure:\t\t");
float p = bme.readPressure() / 100.0F;
p = p + 22;
dtostrf(p,5,0,BME280Data.pressure);
Serial.print(BME280Data.pressure);
Serial.println(" hPa");
Serial.print("Approx. Altitude:\t");
float a = bme.readAltitude(SEALEVELPRESSURE_HPA);
dtostrf(a,5,0,BME280Data.approx_altitud);
Serial.print(BME280Data.approx_altitud);
Serial.println(" m über NN");
Serial.println();
}
void M2M_BME280(long deviceId = 4711) {
char topic[100];
sprintf(topic, "%s%ld%s", "hjk/devices/", deviceId, "/telemetry/temperature_BME_280" );
client.publish(topic, BME280Data.temperature, true);
sprintf(topic, "%s%ld%s", "hjk/devices/", deviceId, "/telemetry/pressure" );
client.publish(topic, BME280Data.pressure, true);
sprintf(topic, "%s%ld%s", "hjk/devices/", deviceId, "/telemetry/humity" );
client.publish(topic, BME280Data.humity, true);
sprintf(topic, "%s%ld%s", "hjk/devices/", deviceId, "/telemetry/approx_altitude" );
client.publish(topic, BME280Data.approx_altitud);
//
//delay(500);
}

29
include/mess_htu21.h Normal file
View File

@@ -0,0 +1,29 @@
#include "Adafruit_HTU21DF.h"
const float No_Valhtu = 999.99;
struct {
char temperature[15] = {0};
char humity[15] = {0};
float Temp = No_Valhtu;
float Feuchte = No_Valhtu;
} htu21Data;
Adafruit_HTU21DF htu = Adafruit_HTU21DF();
void init_HTU21(){
if (!htu.begin()) {
Serial.println("Couldn't find sensor HUT21D!");
while (1);
}
Serial.println("HUT21D gefunden");
}
void read_HTU21D() {
htu21Data.Temp = htu.readTemperature();
htu21Data.Feuchte = htu.readHumidity();
//htu21Data.Temp = htu21Data.Temp + HTU_Korrectur;
//htu21Data.Feuchte = htu21Data.Feuchte + HTUKorrekturFeuchte;
Serial.printf("HTU21D: Temperarur Innen %3.2f °C und\n Luftfeuchtigkeit %3.2f %%\n\n", htu21Data.Temp, htu21Data.Feuchte );
}

64
include/mess_mcp9808.h Normal file
View File

@@ -0,0 +1,64 @@
#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();
char Temperature[15] = {0};
void init_MCP9808(){
// 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("Couldn't find MCP9808! Check your connections and verify the address is correct.");
datenSave(-20);
while (1);
}
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
tempsensor.wake();
float temperature = tempsensor.readTempC();
tempsensor.shutdown();
dtostrf(temperature,10,4,Temperature);
Serial.print("Temperatur:\t\t");
Serial.print(Temperature);
Serial.println(" °C");
tempsensor.shutdown_wake(1); // shutdown MSP9808 - power consumption ~0.1 mikro Ampere, stops temperature sampling
return temperature;
}
void M2M_Temperatur_MCP9808(long deviceId = 4711) {
char topic[100];
dtostrf(valTemp,10,4,Temperature);
sprintf(topic, "%s%ld%s", "hjk/devices/", deviceId, "/telemetry/temperature" );
client.publish(topic, Temperature, true);
//delay(500);
}