Add comprehensive setup guide and remove temperature validation

- Complete step-by-step setup guide for new devices
- ChirpStack configuration instructions with exact parameters
- Code modification guide with format conversion examples
- Remove temperature range validation (accept 0-255°C)
- Change send interval to 5 minutes
- Add troubleshooting section
This commit is contained in:
xlemmingx 2025-10-07 19:34:56 +02:00
parent 64f9d49448
commit 72c83fea4c
3 changed files with 259 additions and 21 deletions

252
README.md Normal file
View File

@ -0,0 +1,252 @@
# G2H LoRaWAN Heat Control
Intelligente Heizungssteuerung für STM32WL basierte LoRaWAN-Geräte mit dualer Temperaturüberwachung.
## Funktionsübersicht
### Sensoren
- **SHT4X**: Raumtemperatur und Luftfeuchtigkeit
- **MLX90614**: IR-Bodentemperatur (optional)
- **Relais**: Heizungssteuerung (Ein/Aus)
### Automatische Heizungsregelung
Das System schaltet die Heizung automatisch basierend auf zwei Temperaturschwellwerten:
1. **Raumtemperatur** (Standard: 21°C)
2. **Bodentemperatur** (Standard: 22°C, nur wenn Sensor verfügbar)
**Regel**: Heizung ist AN wenn **beide** Bedingungen erfüllt sind:
- Raumtemperatur < Schwellwert UND
- Bodentemperatur < Schwellwert (falls Sensor verfügbar)
**Fallback**: Wenn MLX90614-Sensor nicht verfügbar → nur Raumtemperatur wird überwacht.
## LoRaWAN-Konfiguration
### Netzwerk
- **Aktivierung**: ABP (Activation by Personalization)
- **Region**: EU868
- **Port**: 2
- **Sendeintervall**: 5 Minuten
## Downlink-Befehle
Alle Befehle als Base64 in ChirpStack eingeben:
### Relais-Steuerung
| Befehl | Base64 | Funktion |
|--------|--------|----------|
| r1:0 | `cjE6AA==` | Relais AUS + Automatik deaktiviert |
| r1:1 | `cjE6AQ==` | Automatik aktiviert |
### Temperatur-Schwellwerte
| Befehl | Beispiel Base64 | Funktion |
|--------|--------|----------|
| t1 + Wert | `dDESOQ==` (18°C) | Raumtemperatur-Schwellwert setzen |
| t1 + Wert | `dDFVUQ==` (21°C) | Raumtemperatur-Schwellwert setzen |
| t1 + Wert | `dDFZWQ==` (25°C) | Raumtemperatur-Schwellwert setzen |
| t2 + Wert | `dDIUFQ==` (20°C) | Bodentemperatur-Schwellwert setzen |
| t2 + Wert | `dDIWFg==` (22°C) | Bodentemperatur-Schwellwert setzen |
| t2 + Wert | `dDIZGQ==` (25°C) | Bodentemperatur-Schwellwert setzen |
**Hinweis**: Alle Temperaturwerte von 0-255°C sind möglich.
## Datenformat (Uplink)
Alle 5 Minuten wird ein 7-Byte Datenpaket gesendet:
| Byte | Inhalt | Format |
|------|--------|--------|
| 0-1 | Raumtemperatur | int16 × 100 (z.B. 2134 = 21.34°C) |
| 2-3 | Bodentemperatur | int16 × 100 |
| 4-5 | Luftfeuchtigkeit | int16 × 100 (z.B. 4520 = 45.20%) |
| 6 | Relais-Status | 0 = AUS, 1 = AN |
## Betriebsmodi
### 1. Automatik-Modus (Standard)
- Heizung wird automatisch basierend auf Temperaturschwellwerten gesteuert
- Beide Temperaturen werden überwacht (falls MLX-Sensor verfügbar)
### 2. Manueller Override
- Aktiviert durch `r1:0` → Heizung permanent AUS
- Deaktiviert durch `r1:1` oder neue Schwellwert-Befehle
### 3. Sensor-Fallback
- Wenn MLX90614 nicht verfügbar → nur Raumtemperatur wird überwacht
- Automatische Erkennung bei jedem Lesezyklus
## Status-Ausgabe
Über serielle Konsole (115200 baud):
```
hum: 45.20%
temp: 21.34 °C
floor_temp: 19.87 °C
relais: 1 (manual: 0, temp_th: 21°C, floor_th: 22°C)
```
- **relais**: 0=AUS, 1=AN
- **manual**: 0=Automatik, 1=Manueller Override
- **temp_th**: Raumtemperatur-Schwellwert
- **floor_th**: Bodentemperatur-Schwellwert
## Fehlerbehandlung
### MLX90614-Sensor nicht verfügbar
```
[ERR] MLX90614 reading sensor values failed 5 times with error 251!
```
→ System wechselt automatisch zu Raumtemperatur-only Modus
### LoRaWAN-Verbindungsfehler
```
[WRN] LoRaWAN busy (duty cycle), retrying in 1s...
```
→ Automatische Wiederholung nach 1 Sekunde
## Beispiel-Szenarien
### Szenario 1: Normale Heizung
- Raumtemp: 19°C (< 21°C)
- Bodentemp: 20°C (< 22°C)
- **Resultat**: Heizung AN
### Szenario 2: Überhitzungsschutz
- Raumtemp: 23°C (≥ 21°C) ✗
- Bodentemp: 20°C (< 22°C)
- **Resultat**: Heizung AUS
### Szenario 3: Bodentemperaturschutz
- Raumtemp: 19°C (< 21°C)
- Bodentemp: 25°C (≥ 22°C) ✗
- **Resultat**: Heizung AUS
### Szenario 4: Sensor-Ausfall
- Raumtemp: 19°C (< 21°C)
- MLX-Sensor: Nicht verfügbar
- **Resultat**: Heizung AN (nur Raumtemp wird geprüft)
## Setup & Installation
### 1. Framework Setup (Windows)
```bash
# Automatische PlatformIO-Konfiguration
setup_framework.bat
```
### 2. Neues Gerät einrichten
#### 2.1 ChirpStack Konfiguration
1. **Application erstellen** (falls nicht vorhanden):
- Name: `G2H-Heat-Control`
- Description: `LoRaWAN Heizungssteuerung`
2. **Device Profile erstellen** (falls nicht vorhanden):
- Name: `STM32WL-ABP`
- Region: `EU868`
- MAC Version: `1.0.4`
- Regional Parameters Revision: `RP002-1.0.3`
- Activation: `ABP`
- Class: `A`
- Supports OTAA: ❌
- ADR Algorithm: `Default`
3. **Device erstellen**:
- **General Tab**:
- Device name: `Heat-Controller-001` (eindeutig wählen)
- Device description: `Heizungssteuerung Raum XY`
- Device EUI: Neue eindeutige EUI generieren (z.B. `4633500400ABCD01`)
- Device Profile: `STM32WL-ABP`
- Skip FCnt check: ✅ (für Entwicklung/Test)
- **Activation Tab** (ABP):
- Device address: Neue Adresse generieren (z.B. `01234567`)
- Network session key: 32 Zeichen Hex (z.B. `268FDA933F4CAEBF96A30FE76027A41E`)
- Application session key: 32 Zeichen Hex (z.B. `408009CA1D9FE2B822F4684D76331300`)
#### 2.2 Firmware-Konfiguration
Öffne `src/lora/lorawan.h` und trage die ChirpStack-Werte ein:
```c
/* ABP Configuration */
#define LORAWAN_DEV_ADDR {0x01, 0x23, 0x45, 0x67} // Device Address (Big Endian!)
#define LORAWAN_NWKS_KEY {0x26, 0x8F, 0xDA, 0x93, \ // Network Session Key
0x3F, 0x4C, 0xAE, 0xBF, \
0x96, 0xA3, 0x0F, 0xE7, \
0x60, 0x27, 0xA4, 0x1E}
#define LORAWAN_APPS_KEY {0x40, 0x80, 0x09, 0xCA, \ // Application Session Key
0x1D, 0x9F, 0xE2, 0xB8, \
0x22, 0xF4, 0x68, 0x4D, \
0x76, 0x33, 0x13, 0x00}
```
**Wichtig**: DevEUI wird in `src/lora/lorawan.c` gesetzt:
```c
// Zeile ~113-120: Eindeutige DevEUI eintragen
dev_eui[0] = 0x46; // Entspricht ChirpStack DevEUI
dev_eui[1] = 0x33; // 4633500400ABCD01 wird zu:
dev_eui[2] = 0x50; // {0x46, 0x33, 0x50, 0x04,
dev_eui[3] = 0x04; // 0x00, 0xAB, 0xCD, 0x01}
dev_eui[4] = 0x00;
dev_eui[5] = 0xAB;
dev_eui[6] = 0xCD;
dev_eui[7] = 0x01; // Letztes Byte für Gerät eindeutig machen
```
#### 2.3 Format-Konvertierung ChirpStack → Code
| ChirpStack | Code Format | Beispiel |
|------------|-------------|----------|
| Device Address: `01234567` | `{0x01, 0x23, 0x45, 0x67}` | Big Endian Bytes |
| DevEUI: `4633500400ABCD01` | `dev_eui[0] = 0x46; ... dev_eui[7] = 0x01;` | Byte Array |
| Session Keys: `268F...A41E` | `{0x26, 0x8F, ..., 0x1E}` | 16 Byte Array |
### 3. Build & Flash
```bash
# Projekt kompilieren
pio run
# Firmware flashen (Device per USB verbinden)
pio run -t upload
```
### 4. Verification
1. **Serielle Konsole** öffnen (115200 baud):
```
=== Device starting ===
DevEUI: 46:33:50:04:00:AB:CD:01
DevAddr: 0x67452301
✓ Successfully activated LoRaWAN network via ABP
```
2. **ChirpStack Monitoring**:
- Device sollte nach ~30 Sekunden erste Uplinks senden
- LoRaWAN Frames Tab: Uplinks alle 5 Minuten
- Payload: 7 Bytes Sensordaten
3. **Test Downlink**:
- In ChirpStack: Queue Downlink
- Payload: `cjE6AA==` (Base64)
- Port: 2
- Confirmed: ❌
### 5. Troubleshooting
#### Keine Uplinks in ChirpStack
- [ ] DevEUI in Code korrekt gesetzt?
- [ ] DevAddr Big Endian konvertiert?
- [ ] Session Keys richtig formatiert?
- [ ] Gateway in Reichweite und online?
#### ABP Activation Failed
- [ ] Device Profile auf ABP konfiguriert?
- [ ] Skip FCnt Check aktiviert?
- [ ] Korrekte Region (EU868)?
#### Sensor Fehler
```
[ERR] MLX90614 reading sensor values failed 5 times
```
→ Normal wenn kein Bodensensor angeschlossen, System läuft trotzdem

View File

@ -67,31 +67,17 @@ static void dl_callback(uint8_t port, uint8_t flags, int16_t rssi, int8_t snr, u
else if (len > 3 && hex_data[0] == 't' && hex_data[1] == '1')
{
uint8_t new_threshold = hex_data[2];
if (new_threshold >= 10 && new_threshold <= 35) // Valid range 10-35°C
{
temperature_threshold = new_threshold;
relais_manual_override = false; // Re-enable automatic control
LOG_INF("Room temperature threshold updated to %d°C, automatic control enabled", temperature_threshold);
}
else
{
LOG_WRN("Invalid room temperature threshold %d°C (valid range: 10-35°C)", new_threshold);
}
temperature_threshold = new_threshold;
relais_manual_override = false; // Re-enable automatic control
LOG_INF("Room temperature threshold updated to %d°C, automatic control enabled", temperature_threshold);
}
/* Floor temperature threshold command: t2[temp] (e.g., "t2" + 22 for 22°C) */
else if (len > 3 && hex_data[0] == 't' && hex_data[1] == '2')
{
uint8_t new_threshold = hex_data[2];
if (new_threshold >= 15 && new_threshold <= 40) // Valid range 15-40°C
{
floor_temp_threshold = new_threshold;
relais_manual_override = false; // Re-enable automatic control
LOG_INF("Floor temperature threshold updated to %d°C, automatic control enabled", floor_temp_threshold);
}
else
{
LOG_WRN("Invalid floor temperature threshold %d°C (valid range: 15-40°C)", new_threshold);
}
floor_temp_threshold = new_threshold;
relais_manual_override = false; // Re-enable automatic control
LOG_INF("Floor temperature threshold updated to %d°C, automatic control enabled", floor_temp_threshold);
}
}

View File

@ -20,7 +20,7 @@
0x0F, 0x0F}
#define RETRY_DELAY K_MSEC(1000)
#define SEND_INTERVALL K_SECONDS(20)
#define SEND_INTERVALL K_MINUTES(5)
void init_lorawan();