Compare commits
8
Commits
71a01cc63e
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f639f14427 | ||
|
|
e88623cf6e | ||
|
|
dde4736cc2 | ||
|
|
62e9d249cb | ||
|
|
69bb47dda1 | ||
|
|
45b05d045a | ||
|
|
3dcfdedc18 | ||
|
|
b10b96f1ae |
@@ -0,0 +1,225 @@
|
|||||||
|
# ESP32 Hardware Development Workflow
|
||||||
|
|
||||||
|
## Entwicklungsumgebung
|
||||||
|
|
||||||
|
Dieses Projekt wird mit Codex in einem Docker-Container auf einem VPS entwickelt.
|
||||||
|
|
||||||
|
- Versionsverwaltung: Gitea
|
||||||
|
- Build-System: PlatformIO
|
||||||
|
- Framework: ESP-IDF 5.5.0 (aktueller getesteter Build)
|
||||||
|
- PlatformIO-Plattform: `espressif32@6.12.0`
|
||||||
|
- SDK-Paket: `platformio/framework-espidf@3.50500.0`
|
||||||
|
- Hardwarezugriff: WireGuard + eingeschränktes SSH-Gateway
|
||||||
|
- SSH-Alias im Codex-Container: `esp32`
|
||||||
|
- Gateway-Rechner: Debian 13
|
||||||
|
|
||||||
|
Der ESP32 ist physisch am Debian-Rechner angeschlossen. Codex führt sämtliche Builds auf dem VPS aus und verwendet ausschließlich das SSH-Gateway zur Hardwarekommunikation.
|
||||||
|
|
||||||
|
## Board-Erkennung
|
||||||
|
|
||||||
|
Vor jeder Hardwareoperation das Zielboard eindeutig bestimmen.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ssh esp32 list
|
||||||
|
```
|
||||||
|
|
||||||
|
Bekanntes Testboard:
|
||||||
|
|
||||||
|
- Chip: ESP32-C6FH8
|
||||||
|
- USB-Seriennummer: `CC:BA:97:F2:52:80`
|
||||||
|
- Flash: 8 MB
|
||||||
|
- Revision: v0.2
|
||||||
|
|
||||||
|
Weitere bekannte Hardware:
|
||||||
|
|
||||||
|
- ESP32-C6FH8, 8 MB, Revision v0.2, USB-Seriennummer `CC:BA:97:F2:5F:7C`; SEN66 und Display-Profil am 09.11.2026 geprüft, aktuelles OTA-Layout statt früherer 1-MiB-Factory-Partition.
|
||||||
|
- ESP32-C6FH4
|
||||||
|
- USB-Seriennummer: `9C:9E:6E:7B:5D:C0`
|
||||||
|
- Flash: 4 MB
|
||||||
|
|
||||||
|
Niemals anhand von `/dev/ttyACM0` oder `/dev/ttyUSB0` allein ein Board auswählen, da sich diese Gerätenamen ändern können.
|
||||||
|
|
||||||
|
## Gateway-Befehle
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ssh esp32 list
|
||||||
|
ssh esp32 "info BOARD_ID"
|
||||||
|
ssh esp32 "flash-id BOARD_ID"
|
||||||
|
ssh esp32 "monitor BOARD_ID 30"
|
||||||
|
ssh esp32 "send BOARD_ID HEXDATEN"
|
||||||
|
ssh esp32 "read BOARD_ID OFFSET GROESSE"
|
||||||
|
ssh esp32 "write BOARD_ID OFFSET GROESSE SHA256"
|
||||||
|
ssh esp32 "erase BOARD_ID CONFIRM"
|
||||||
|
```
|
||||||
|
|
||||||
|
Alle boardbezogenen Hardwareoperationen müssen eine explizite Boardkennung verwenden. `list` dient ausschließlich der Erkennung und benötigt keine Boardkennung.
|
||||||
|
|
||||||
|
Die `read`-Funktion liefert rohe Binärdaten über stdout.
|
||||||
|
|
||||||
|
Die `write`-Funktion erhält die Firmwaredatei über stdin. Die erwartete Dateigröße und SHA-256-Prüfsumme werden vom Gateway geprüft.
|
||||||
|
|
||||||
|
## Build-Workflow
|
||||||
|
|
||||||
|
Das PlatformIO-Projekt liegt unter `firmware/`. Das aktuelle Environment `esp32-c6-devkitc-1` ist für ESP32-C6 mit **8 MB Flash** konfiguriert. Diesen Build nicht auf das bekannte 4-MB-Board übertragen. Die aktive SDK-Konfiguration ist `firmware/sdkconfig.esp32-c6-devkitc-1`; Defaults stehen in `firmware/sdkconfig.defaults`, die Partitionstabelle in `firmware/partitions.csv`.
|
||||||
|
|
||||||
|
Sensor und Peripherieprofil werden zentral in `firmware/components/hardware_config/hardware_config.h` gewählt. Unterstützte Sensoren: SEN54 und SEN66; vorhandene Profile: ESP32-C6 mit Display (Touch auf Hardware-I²C GPIO18/19) und ESP32-C6 ohne Display (Hardware-I²C GPIO7/8), jeweils 8 MB. SEN54 nutzt den Hardware-Bus des Profils. SEN66 bleibt immer auf GPIO7/8 und verwendet beim Display-Profil einen separaten Software-I²C-Bus; ohne Display verwendet er den Hardware-Controller. Die aktuelle Standardauswahl ist SEN66 mit Display. Die Software-I²C-Implementierung hat ACK/NACK-, Clock-Stretching- und Timeout-Tests; keine weiteren Sensorgeräte ohne Prüfung auf diesem Bus hinzufügen. Auswahl und Verdrahtung vor jedem Build prüfen; nicht vom angeschlossenen Port oder einer früheren Auswahl ableiten. Die Auswahl ersetzt keine Prüfung von PlatformIO-Chip, Flash-Größe und Partitionstabelle. Anleitung und Tests: `firmware/HARDWARE.md`. Der SEN66 verwendet den gepinnten offiziellen Sensirion-Treiber; Herkunft und Lizenz sind in `firmware/components/sen5x/SENSIRION-UPSTREAM.md` dokumentiert. Die gemeinsame Sensoranwendung heißt `air_sensor_app`; SEN66 ergänzt das Influx-Feld `co2`, SEN54 darf keine künstlichen CO₂-Werte erzeugen. Die bisherige Messwertseite mit Schriftzug, PM, Temperatur, Feuchte, VOC und Statussymbolen bleibt erhalten. Der neue Benutzerauftrag vom 11.11.2026 erweitert das Display um Raumluft mit CO₂/VOC-/NOx-Index, lokalen Verlauf und Gerätestatus/Einstellungen. EEZ-Projekt und Firmware zusammen pflegen; PlatformIO synchronisiert die Bildschirmdateien vor dem Build automatisch. Details und native UI-Tests stehen in `firmware/HARDWARE.md`.
|
||||||
|
|
||||||
|
1. Projektkonfiguration in `platformio.ini` prüfen.
|
||||||
|
2. PlatformIO-Environment für das Zielboard bestimmen.
|
||||||
|
3. Firmware kompilieren.
|
||||||
|
4. Build-Fehler beheben.
|
||||||
|
5. Firmware-Image und Flash-Layout prüfen.
|
||||||
|
6. Zielboard über das Gateway identifizieren.
|
||||||
|
|
||||||
|
Build aus dem Repository-Hauptverzeichnis:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pio run -d firmware -e esp32-c6-devkitc-1 -j 2
|
||||||
|
```
|
||||||
|
|
||||||
|
`firmware/CMakeLists.txt` setzt `IDF_COMPONENT_CHECK_NEW_VERSION=0` vor dem Laden des ESP-IDF-Buildsystems. Dadurch bleibt die optionale Suche nach neueren Komponenten-Versionen auch bei Builds über VS Code deaktiviert; ein manuelles `export` ist nicht erforderlich. Die reguläre Abhängigkeitsauflösung und die Verwendung von `dependencies.lock` bleiben aktiv. Hintergrund ist ein bestätigter Build-Abbruch durch fehlende LVGL-Kconfig-Optionen bei eingeschalteter Update-Suche auf einem weiteren Entwicklungsrechner. Abhängigkeitsupdates getrennt und gezielt durchführen, nicht diese Einstellung ungeprüft entfernen.
|
||||||
|
|
||||||
|
Die festgelegten Plattform-/SDK-Versionen erhalten. Der frühere Build mit ESP-IDF 6.1.0 scheiterte, weil `REQUIRES driver` dort `esp_driver_ledc` nicht mehr automatisch einbindet. Ein SDK-Upgrade ist eine gesonderte Migration; Versionen nicht ungeprüft anheben.
|
||||||
|
|
||||||
|
Die aktuellen OTA-Partitionen reichen bis `0x740000` und passen in 8 MB. Image-Dateinamen und Flash-Adressen aus den tatsächlichen PlatformIO-Artefakten, `flasher_args.json` und gegebenenfalls `envdump` ermitteln. CMake kann logische Dateinamen angeben, während PlatformIO `firmware.bin`, `bootloader.bin` und `partitions.bin` erzeugt.
|
||||||
|
|
||||||
|
## Flash-Workflow
|
||||||
|
|
||||||
|
Vor jedem Upload:
|
||||||
|
|
||||||
|
1. Board-Seriennummer überprüfen.
|
||||||
|
2. Chiptyp und Flash-Größe prüfen.
|
||||||
|
3. Firmware-SHA-256 berechnen.
|
||||||
|
4. Partitionstabelle und OTA-Auswahl prüfen.
|
||||||
|
5. Schreibadresse aus dem tatsächlichen Build und der aktiven Partitionierung ableiten.
|
||||||
|
6. Verifizieren, dass der gesamte Schreibbereich einschließlich betroffener Flash-Sektoren innerhalb der vorgesehenen Partition liegt.
|
||||||
|
7. Sicherstellen, dass ein gültiges Backup verfügbar ist.
|
||||||
|
|
||||||
|
Nur notwendige Flash-Bereiche schreiben.
|
||||||
|
|
||||||
|
Bootloader, Partitionstabelle, NVS und OTA-Auswahldaten nicht ohne technische Notwendigkeit überschreiben. PHY-Daten ebenfalls erhalten, sofern der konkrete Auftrag keine begründete Änderung vorsieht.
|
||||||
|
|
||||||
|
Nach dem Flashen:
|
||||||
|
|
||||||
|
1. Geschriebenen Bereich vollständig zurücklesen.
|
||||||
|
2. Binärdaten bytegenau vergleichen.
|
||||||
|
3. SHA-256 verifizieren.
|
||||||
|
4. Bootverhalten kontrollieren.
|
||||||
|
5. Seriellen Monitor mindestens 60 Sekunden auswerten.
|
||||||
|
6. WLAN, Netzwerkdienste und Hardwareperipherie prüfen.
|
||||||
|
|
||||||
|
Ein erfolgreicher Flash-Vorgang gilt erst nach bestandener Rückleseverifikation als technisch bestätigt. Die Anwendungsfunktion muss separat geprüft werden.
|
||||||
|
|
||||||
|
## Sicherheitsregeln
|
||||||
|
|
||||||
|
- Keine normale SSH-Shell auf dem Debian-Rechner verwenden.
|
||||||
|
- Keine Änderungen an WireGuard, SSH-Konfiguration oder Gateway vornehmen, außer wenn ausdrücklich beauftragt.
|
||||||
|
- Kein vollständiges `erase` ohne ausdrückliche Freigabe.
|
||||||
|
- Vor destruktiven Operationen Zielboard und Flash-Bereich erneut prüfen.
|
||||||
|
- Operationen, die sämtliche gespeicherten Daten oder unbekannte persistente Bereiche unwiederbringlich zerstören können, benötigen eine ausdrückliche Benutzerfreigabe.
|
||||||
|
- Keine automatischen wiederholten Flash-Versuche bei ungeklärten Fehlern.
|
||||||
|
- Keine privaten SSH-Schlüssel oder Zugangsdaten ausgeben oder committen.
|
||||||
|
- Private SSH-Schlüssel niemals in das Repository aufnehmen oder ohne gesonderten ausdrücklichen Sicherungsauftrag kopieren.
|
||||||
|
- Keine Firmware auf ein anderes als das ausgewählte Board schreiben.
|
||||||
|
- Hardwaretests und Schreiboperationen nicht parallel auf demselben seriellen Gerät ausführen.
|
||||||
|
- Keine nicht dokumentierten Gateway-Befehle ausprobieren und keine Sicherheitsmechanismen umgehen.
|
||||||
|
|
||||||
|
## Erfolgreich getestetes Deployment
|
||||||
|
|
||||||
|
Am 04.11.2026 wurde ein Firmware-Upload auf das Board `CC:BA:97:F2:52:80` erfolgreich durchgeführt.
|
||||||
|
|
||||||
|
- Chip: ESP32-C6FH8
|
||||||
|
- Flash: 8 MB
|
||||||
|
- Build-Environment: `esp32-c6-devkitc-1`
|
||||||
|
- Framework: ESP-IDF 5.5.0
|
||||||
|
- Anwendungspartition: `ota_0`
|
||||||
|
- Schreibadresse: `0x020000`
|
||||||
|
- Firmwaregröße: 1.741.040 Bytes
|
||||||
|
- Schreibvorgänge: 1
|
||||||
|
- Rückleseverifikation: erfolgreich
|
||||||
|
- SHA-256: `ae6d2892c16e3ac7ced681ca4112a4dc8b5168af4a7b2c9d029db9c095be6fdd`
|
||||||
|
- Boot: erfolgreich
|
||||||
|
- WLAN: erfolgreich
|
||||||
|
- Bootloader, Partitionstabelle, OTA-Auswahl und PHY-Daten: beim Upload unverändert
|
||||||
|
- Serieller Monitor: 60 Sekunden, keine erkannten Panics oder Neustartschleifen
|
||||||
|
|
||||||
|
Dieser Upload ist ein dokumentierter Referenzfall. Die genannten Adressen und Hashwerte dürfen nicht ungeprüft für zukünftige Firmware-Versionen wiederverwendet werden.
|
||||||
|
|
||||||
|
## Getestete SEN66-Migration (09.11.2026)
|
||||||
|
|
||||||
|
- Ziel: `CC:BA:97:F2:5F:7C`, ESP32-C6FH8, 8 MB; Sensor SEN66 an SDA GPIO7/SCL GPIO8, mit Display und Touch auf separatem Hardware-I²C-Bus GPIO18/19.
|
||||||
|
- Benutzer hat die Migration und neue Partitionierung ausdrücklich freigegeben. Nach vollständigem geprüftem Backup wurde ohne vollständiges Löschen auf das bestehende nanoPSX-8-MB-Layout mit zwei OTA-Partitionen migriert. Vorhandener gültiger IDF-5.5-Bootloader blieb unverändert.
|
||||||
|
- Vier Schreibvorgänge, jeweils vollständiges bytegenaues Rücklesen und SHA256 erfolgreich: Anwendung `0x20000` (1.736.144 Bytes, SHA256 `59ee4120dbcdf2edda17bcf57c1f7a81d18b197e8d4413f0a28e283a7871eba9`), Inhalt der bisherigen PHY-Partition nach `0x11000` kopiert (4096 Bytes), OTA-Auswahl bei `0xF000` initialisiert (8192 Bytes), neue Partitionstabelle bei `0x8000` zuletzt aktiviert (3072 Bytes).
|
||||||
|
- Abschließend vollständige 8 MB ausgelesen: keine Änderungen außerhalb geplanter Sektoren und regulärer NVS-/OTA-Laufzeitbereiche; Bootloader und kopierter PHY-Partitionsinhalt bytegenau erhalten. OTA-Auswahl gültig, Sequenz 1, Zustand 2, Auswahl `ota_0`.
|
||||||
|
- NVS war vor Aktivierung bytegenau erhalten. Nach Start waren 2032 Rohbytes verändert; der offizielle SDK-NVS-Parser ordnet die logischen Änderungen ausschließlich `phy:cal_data` (Radio-Kalibrierungsblob) zu. Alle anderen vorhandenen logischen Einträge behalten identische Inhaltsfingerprints. Kein NVS-Reset durchgeführt.
|
||||||
|
- Alle vier Sensor-/Board-Builds und native Hersteller-/Software-I²C-Tests erfolgreich. 60 Sekunden Monitor ohne erkannte Panic oder Sensor-I²C-Fehler; SEN66 erkannt und Messung gestartet, u.a. CO₂ 1149 ppm und PM2.5 7,2 µg/m³. Display initialisiert, kein Touch-Ausfall gemeldet. Eine sichtbare Prüfung des physischen Displays ist über das Gateway nicht möglich.
|
||||||
|
- Setup-AP `nanoPSX`, Portal `http://192.168.4.1`; auf diesem Board wurde im Test noch keine STA-IP oder erfolgreiche Influx-Übertragung beobachtet. WLAN sowie Organisation/Bucket gegebenenfalls im Portal einrichten. SD-Karten-Timeout besteht weiter.
|
||||||
|
- Diese Einzelfreigabe ist abgeschlossen und gilt nicht automatisch für erneute Migrationen oder andere Boards. Künftige App-Updates nach erneuter Layout-/OTA-Prüfung planen; keine erneute Migration anhand dieses historischen Eintrags ausführen.
|
||||||
|
|
||||||
|
Nachfolgende Benutzerkorrektur am selben Tag: Die zusätzliche CO₂-Anzeige wurde wieder entfernt. Die EEZ-Displaydateien entsprechen bytegenau dem ursprünglichen Git-Stand; keine NOx-/CO₂-Widgets ergänzen, solange kein neuer Auftrag vorliegt. Die entsprechende SEN66-Anwendung wurde ausschließlich bei `0x20000` aktualisiert (1.735.776 Bytes, SHA256 `ed9cec4854c5c19eaaecf69c4a1f5c9740014caf8a2bcd88976bb0bbe7fba4dd`) und vollständig bytegenau/SHA256-verifiziert. Bootloader, Partitionstabelle, OTA-Auswahl und PHY-Partitionsinhalt unverändert. Anwendungseinstellungen in NVS behalten ihre Inhaltsfingerprints; normale Radio-Kalibrierungsänderungen wurden getrennt erfasst. Der anschließende 60-Sekunden-Monitor bestätigte laufende SEN66-Messungen und **55 erfolgreiche Influx-Schreibantworten mit HTTP 204**, keine Schreib-/Sensorfehler und keine Panic. NOx und CO₂ bleiben für InfluxDB erhalten. Der vorherige Setup-AP-Hinweis beschreibt den Zustand vor der inzwischen vom Benutzer eingerichteten WLAN-Verbindung.
|
||||||
|
|
||||||
|
## Getestetes Displayseiten-Update (11.11.2026)
|
||||||
|
|
||||||
|
- Benutzerauftrag: neue EEZ-Seite übernehmen, Wischen zur zweiten Seite und zurück ermöglichen, bauen und flashen. Git-Stand `62e9d24` enthält die leere `Page_2`; die Firmware-Displayobjekte wurden entsprechend ergänzt. Navigation liegt außerhalb der EEZ-Exportdateien in `firmware/components/eez_gui/ui_navigation.c` und wird nach `ui_init()` unter dem LVGL-Lock initialisiert. Links von `Main` zu `Page_2`, rechts zurück; kein Umlauf. Gesten über Kindobjekten werden zur Bildschirmwurzel weitergereicht, die festen Seiten scrollen nicht.
|
||||||
|
- Native Tests mit echten LVGL-Quellen, beiden Displayseiten und simuliertem Zeiger bestanden: Tippen, kurze/vertikale Gesten, äußere Grenzen, Kindobjekte und wiederholtes Hin-/Herwechseln. Aufruf und EEZ-Exporthinweise stehen in `firmware/HARDWARE.md`; Test: `python3 firmware/test/ui/run_tests.py`.
|
||||||
|
- Ziel erneut eindeutig bestätigt: `CC:BA:97:F2:5F:7C`, ESP32-C6FH8, Revision v0.2, 8 MB. Environment `esp32-c6-devkitc-1`, ESP-IDF 5.5.0, SEN66 mit Display, Sensor GPIO7/8 und separater Touch-Bus GPIO18/19.
|
||||||
|
- Neues vollständiges 8-MB-Backup und unabhängige Anfangs-/Endproben erfolgreich geprüft. Vor Upload Partitionstabelle einschließlich MD5, gültige OTA-Auswahl (`ota_0`, Sequenz 1, Zustand 2, CRC gültig), vorhandener Bootloader, Image-Prüfsumme/Validierungshash und Sektorgrenzen geprüft.
|
||||||
|
- Genau ein Anwendungsschreibvorgang bei `0x20000`, 1.736.384 Bytes, SHA256 `86021d81ed8b2e2f284f2f1bda0c32efd231a878f3792a705a307fa816c36a46`. Vollständige bytegenaue Rücklese-/SHA256-Verifikation erfolgreich; kein vollständiges Löschen. Anschließender vollständiger Flash-Vergleich bestätigt unveränderten Bootloader, Partitionstabellensektor, OTA-Auswahl, PHY, übrige Flash-Bereiche und 320-Byte-Sektorrand. NVS änderte sich zur Laufzeit um 85 Rohbytes; kein NVS-Schreibbefehl oder Reset ausgeführt, logische Inhaltsgleichheit diesmal nicht separat geprüft.
|
||||||
|
- 60 Sekunden Monitor: Navigation bereit, laufende SEN66-Messung und 55 erfolgreiche Influx-Antworten mit HTTP 204; keine erkannten Fehler-, Panic-, Reset- oder Sensorfehlerzeilen. Keine physischen Wischgesten im Monitor beobachtet; sichtbares Display und Fingerbedienung müssen vor Ort geprüft werden. `Page_2` bleibt entsprechend dem EEZ-Projekt leer.
|
||||||
|
- Geschützte Backups und Logs außerhalb des Repositorys enthalten `flash-plan.json`, `backup-report.json`, `write-results.json`, `deployment-report.json`, Build-/UI-Testlogs, Monitor und vollständige Vor-/Nach-Flashdateien. Diese abgeschlossene Ausführung ist keine Freigabe für weitere Schreibvorgänge.
|
||||||
|
|
||||||
|
## Vier Displayseiten, Verlauf und Einstellungen (11.11.2026)
|
||||||
|
|
||||||
|
- Neuer Benutzerauftrag: vollständige Umsetzung der vorgeschlagenen Display-Erweiterungen einschließlich EEZ-Projekt, Bedienung, Build und Flash. Die bisherige Hauptansicht bleibt erhalten; `Page_2` zeigt CO₂/VOC-/NOx-Index mit CO₂-Verlauf, `History` den wählbaren Verlauf und `Device` WLAN/IP, Alter des letzten HTTP-204-Erfolgs, Sensoralter und Display-Einstellungen. Wischen durch vier Seiten ohne Umlauf; Statussymbole öffnen die Geräteseite.
|
||||||
|
- `eez/nanopsx.eez-project` und generierte Bildschirmdateien synchronisiert. PlatformIO führt `firmware/tools/export_display.py` vor jedem Build automatisch aus. Native Anwendungslogik und threadgeschütztes Zahlen-/Verlaufsmodell bleiben außerhalb der Exportdateien. Details, unterstützte Exporter-Widgets und Testbefehle: `firmware/HARDWARE.md`.
|
||||||
|
- Lokaler RAM-Verlauf: 180 Zehn-Sekunden-Mittelwerte, sechs auswählbare Messgrößen, fehlende Werte als Lücken, Neustart leert den Puffer. Veraltete Messungen nach mehr als fünf Sekunden und nicht verfügbare Kanäle werden gekennzeichnet. SEN54 liefert weiterhin keine künstlichen CO₂-Werte.
|
||||||
|
- Display: Helligkeit 20–100 %, Standard 100 %; Abdunkeln aus/30/60/120 s, Standard 60 s auf 15 %. Erste Berührung weckt ausschließlich. Eigene NVS-Einstellungen in `ui_display`, gespeichert bei Reglerfreigabe bzw. Auswahl, keine Änderung der WLAN-/Influx-Konfiguration.
|
||||||
|
- Erfolgreicher vollständiger Build für `esp32-c6-devkitc-1`, ESP-IDF 5.5.0, SEN66 mit Display. UI-Integrationstest mit echten LVGL-Quellen und 48 KiB LVGL-Heap bestanden: vierseitige Navigation, kurze/vertikale Gesten und Grenzen, Dropdown-Isolation, Regler, Aufwecken, Abschalten der Abdunklung, fehlende/veraltete Werte, alle sechs Diagrammkanäle sowie Ringpuffer-Mittelwerte, Lücken und Verdrängung. Native Hersteller-/Software-I²C- und Profilauswahltests bestanden. Gerenderte Vorschauen mit simulierten Werten visuell geprüft.
|
||||||
|
- Ziel erneut per `list`/`info`/`flash-id` bestätigt: `CC:BA:97:F2:5F:7C`, ESP32-C6FH8, Revision v0.2, 8 MB. Frisches vollständiges Backup mit unabhängigen Anfangs-/Endproben; Partitionstabelle, MD5, OTA-Auswahl, Bootloader, Firmware-Prüfsumme/Hash und Sektorrand vor Upload geprüft.
|
||||||
|
- Genau ein App-Schreibvorgang bei `0x20000`: 1.844.048 Bytes, SHA256 `10826853d6574c272dc91ca9cde0aabadc231172cbc8bdd1e32b628ba3701443`. Vollständige bytegenaue Rücklese-/SHA256-Verifikation erfolgreich. Kein vollständiges Löschen. Abschließender 8-MB-Vergleich bestätigt unveränderten Bootloader, Partitionstabellensektor, OTA-Auswahl, PHY, sonstige Flash-Bereiche und 3248-Byte-Sektorrand. NVS änderte sich zur Laufzeit um 74 Rohbytes; logische Inhalte diesmal nicht separat verglichen.
|
||||||
|
- 60 Sekunden Monitor: Vier-Seiten-Navigation bereit, SEN66-Messungen und 55 erfolgreiche Influx-Antworten mit HTTP 204. Keine erkannten Panics oder Sensor-/Touch-Fehler. Zwei bekannte SD-Timeout-Fehlerzeilen, keine sonstigen Fehlerzeilen. Physische Wischgesten, sichtbares Displaybild und Speichern/Neuladen der Einstellungen sind am Gerät durch den Benutzer zu prüfen; keine entsprechende Hardwarebetätigung im Monitor beobachtet.
|
||||||
|
- Geschützte Backups und Logs außerhalb des Repositorys: `flash-plan.json`, `backup-report.json`, `write-results.json`, `deployment-report.json`, Vor-/Nach-Flashdateien, Monitor, Build-/UI-Testlogs und Quellen-Hashes. Ausführung abgeschlossen; keine weitere Schreib-/Löschfreigabe ableiten.
|
||||||
|
|
||||||
|
## InfluxDB-Bündelung und Verbindungswiederverwendung (11.11.2026)
|
||||||
|
|
||||||
|
- Benutzerauftrag: effizientere Übertragung durch größere Sammelanfragen. Messung und Display bleiben bei nominal 1 Hz; keine Mittelung der Influx-Messpunkte oder Änderung ihrer Felder. Bis zu zehn Punkte / 4096 Bytes pro Anfrage, Restpakete nach maximal zehn Sekunden. Im Normalbetrieb etwa sechs Schreibanfragen pro Minute statt 60; serverseitige Sichtbarkeit entsprechend verzögert.
|
||||||
|
- Asynchrone API serialisiert beim Einreihen in eine feste Warteschlange mit 32 Einträgen. Keine einzelnen Heap-Allokationen pro Feld. Worker-Stack 8192 Bytes. HTTP-Client/Verbindung werden wiederverwendet; Fehler oder geänderte Konfiguration bauen den Handle neu auf. Token und Payloads werden nicht protokolliert.
|
||||||
|
- Einzelne UTC-Zeitstempel mit `precision=ms` verhindern Zusammenfallen gebündelter Punkte derselben Serie. Messzeit wird monoton beim Einreihen erfasst. Ein GET `/health` richtet die private Messuhr am HTTP-Date desselben Servers aus (ungefähr sekundengenaue absolute UTC-Zuordnung, kein externer Zeitdienst/kein Stellen der Systemuhr). Ohne gültige Zeitbasis sichere Einzelpunkt-Anfragen statt ungestempelter Mehrpunktpakete. Explizite API-Zeitstempel bleiben erhalten.
|
||||||
|
- Transport-/Serverfehler behalten Paketinhalt und Zeitstempel für Wiederholungen bei; exponentielle Pause 2 s bis 300 s, Konfiguration nach fünf Fehlern erneut lesen. HTTP 400/413/422 verwirft das abgelehnte Paket mit Meldung. Ohne Zeitbasis werden fehlgeschlagene Einzelpunkte nicht automatisch mit neuer Serverzeit wiederholt. Volle Queue ersetzt die ältesten wartenden Punkte und zählt die Verluste. RAM-Inhalte gehen bei Reset verloren. Details/API-/Testhinweise stehen in `firmware/HARDWARE.md`.
|
||||||
|
- Zehn native Szenarien mit echtem Worker und FreeRTOS-/HTTP-Simulation unter Address-/UndefinedBehavior-Sanitizer bestanden: Formatierung/escaping/Sentinels, UTC/Kalender, 10er-Pakete, identische Wiederholungen, volle Queue, fehlende Zeitbasis, Einzelpunktfehler, Restpakete, Bytegrenze und abgelehnte Pakete. Client-Lebensdauer und eindeutige Messzeitstempel geprüft. Vollständiger ESP-IDF-5.5-Build im Environment `esp32-c6-devkitc-1` erfolgreich.
|
||||||
|
- Ziel `CC:BA:97:F2:5F:7C`, ESP32-C6FH8/v0.2/8MB erneut per `list`/`info`/`flash-id` bestätigt. Frisches vollständiges Backup mit unabhängigen Anfangs-/Endproben, Tabelle/MD5, OTA-Auswahl, Bootloader und Sektorrand geprüft. Genau ein App-Schreibvorgang bei `0x20000`, 1.846.464 Bytes, SHA256 `734654f29e16a20aa43086131115cc06d16b09909f55c2bbb14b4e4704a063a7`. Vollständiges bytegenaues/SHA256-Rücklesen erfolgreich, kein vollständiges Löschen.
|
||||||
|
- Vollständiger anschließender 8-MB-Vergleich: Bootloader, Partitionstabellensektor, OTA-Auswahl, PHY, übrige Flashbereiche und 832-Byte-Sektorrand unverändert. NVS änderte sich zur Laufzeit um 2067 Rohbytes; logische Inhalte diesmal nicht separat verglichen. Neue Influx-Logik liest die vorhandene Konfiguration und schreibt selbst keine NVS-Einstellungen.
|
||||||
|
- 60 Sekunden Monitor: fünf bestätigte Schreibanfragen mit 10/10/8/10/10 Punkten (48 Punkte gesamt), ein Verbindungsaufbau inklusive initialem Health-Request. Private Messuhr erfolgreich ausgerichtet; protokollierte Paketzeitstempel unterscheiden die Messzeitpunkte. Keine Schreibfehler, keine erkannten Panics, Sensor-/Touch-Fehler oder gezählten Queue-Verluste. Zwei bekannte SD-Timeout-Zeilen, keine anderen Fehlerzeilen. Kleinere Pakete bei Zeitlimit sind vorgesehen; keine Messwerte für fehlende Sensorpakete erfinden.
|
||||||
|
- Berichte/geschützte Logs außerhalb des Repositorys: `flash-plan.json`, `backup-report.json`, `write-results.json`, `deployment-report.json`, vollständige Flashdateien, Monitor, Build-/Testlogs und Quellen-Hashes. Diese Ausführung ist abgeschlossen; keine weitere automatische Schreib-/Löschfreigabe ableiten.
|
||||||
|
|
||||||
|
## Bekannte Anwendungsprobleme (historischer Stand)
|
||||||
|
|
||||||
|
Beim letzten Hardwaretest wurden festgestellt:
|
||||||
|
|
||||||
|
- InfluxDB-Verbindung zu `10.8.0.4:8086` läuft in HTTP-Timeouts. Genauer: TCP-Verbindungsaufbau mit Timeout, keine HTTP-Antwort; `tls=0`, daher kein nachgewiesener TLS-Zertifikatsfehler.
|
||||||
|
- SD-Karteninitialisierung meldet Timeout.
|
||||||
|
- Display-Initialisierung meldet eine Warnung.
|
||||||
|
- WLAN funktioniert, nutzt jedoch 802.11n statt eines höheren WLAN-Modus.
|
||||||
|
- mDNS findet weder `_influxdb2._tcp` noch `_http._tcp`.
|
||||||
|
|
||||||
|
Diese Anwendungsprobleme sind unabhängig vom erfolgreich getesteten Flash-Workflow zu untersuchen.
|
||||||
|
|
||||||
|
Aktualisierung vom 07.11.2026: Für den NUC-WLAN-Access-Point ist die InfluxDB-Adresse `http://192.168.50.1:8086`. Die Einrichtung unter `linux-app/` kündigt `_influxdb2._tcp` über Avahi an. Den vorhandenen Avahi-Hostnamen verwenden; ein zusätzlicher statischer Alias auf dieselbe lokale IP verursachte in dieser Einrichtung `Local name collision`. Der Benutzer bestätigte die Auflösung auf dem WLAN und nach erneuter Konfiguration die funktionierende SEN54-Übertragung zu InfluxDB (Organisation `Home`, Bucket `nanoPSX`). Serielle Tests bestätigten zuvor die HTTP-Erreichbarkeit, aber Authentifizierungsfehler; die abschließende erfolgreiche Datenübertragung wurde vom Benutzer bestätigt. SD-Karten-Timeout und WLAN-Rückfall auf 11N wurden durch die Netzwerkeinrichtung nicht behoben. Tokens weiterhin ausschließlich lokal verwalten und nicht committen.
|
||||||
|
|
||||||
|
Der Upload selbst schreibt nicht in NVS. Die Anwendung kann NVS aber zur Laufzeit verändern und löscht NVS bei `ESP_ERR_NVS_NO_FREE_PAGES` oder `ESP_ERR_NVS_NEW_VERSION_FOUND` während der Initialisierung (`firmware/src/main.c`, `firmware/components/storage/src/storage.c`). Keine absolute Unveränderlichkeit von NVS nach Anwendungsstart zusichern. Beim Referenztest änderten sich WLAN-Journal-Einträge für `opmode`; die gültigen Einstellungswerte blieben im Vor-/Nachvergleich gleich.
|
||||||
|
|
||||||
|
## Dokumentation
|
||||||
|
|
||||||
|
Nach jedem erfolgreichen Hardwaretest dokumentieren:
|
||||||
|
|
||||||
|
- Zielboard und USB-Seriennummer
|
||||||
|
- Build-Environment
|
||||||
|
- Firmware-Hash
|
||||||
|
- Flash-Adressen
|
||||||
|
- Prüfergebnisse
|
||||||
|
- Boot- und Laufzeitlogs
|
||||||
|
- Erforderliche nächste Schritte
|
||||||
|
|
||||||
|
Temporäre Backups, Firmware-Binärdateien, SSH-Schlüssel und Logdateien dürfen nicht versehentlich in Git eingecheckt werden. Backups und Logs können Zugangsdaten enthalten und sind entsprechend geschützt außerhalb des Repositorys aufzubewahren.
|
||||||
|
|
||||||
|
Maschinenspezifische SSH-Schlüsselpfade, Host-Fingerprints, Docker-Mounts und absolute Backup-/Logpfade werden in lokalen Ergänzungen außerhalb des Repositorys gepflegt. Keine privaten Zugangsdaten oder lokalen Binärartefakte in diese Datei übernehmen.
|
||||||
+58
@@ -0,0 +1,58 @@
|
|||||||
|
# nanoPSX Roadmap
|
||||||
|
|
||||||
|
Die nächsten Entwicklungsschritte sind eine übersichtlichere Projektstruktur,
|
||||||
|
die gezielte Optimierung der eigenen Module und die dauerhafte Speicherung
|
||||||
|
der Messwerte auf einer SD-Karte. Alle drei Punkte sind offen; die Reihenfolge
|
||||||
|
entspricht der geplanten Priorität.
|
||||||
|
|
||||||
|
## 1 Eigenen Projektcode strukturieren
|
||||||
|
|
||||||
|
Ziel ist Code, den Menschen und KI leichter verstehen, ändern und prüfen können.
|
||||||
|
Der Umfang umfasst den selbst entwickelten Code im gesamten Projekt, einschließlich
|
||||||
|
Firmware, Serveranwendung, Werkzeugen und Tests. Herstellerbibliotheken, SDK und
|
||||||
|
unverändert übernommene Fremdkomponenten bleiben von der Umstrukturierung ausgenommen.
|
||||||
|
|
||||||
|
- [ ] Eigene Module, übernommene Bibliotheken und generierte Dateien erfassen und eindeutig unterscheiden.
|
||||||
|
- [ ] Große Module nach klaren Verantwortlichkeiten in kleinere Dateien aufteilen; zusammengehörige Logik zusammenhalten.
|
||||||
|
- [ ] Benennung, Verzeichnisstruktur und öffentliche Schnittstellen vereinheitlichen.
|
||||||
|
- [ ] Initialisierung, Hardwarezugriff, Datenverarbeitung, Anzeige und Netzwerklogik klar zuordnen.
|
||||||
|
- [ ] Eine kompakte Architekturübersicht mit Einstiegspunkten, Zuständigkeiten, Abhängigkeiten und Datenflüssen ergänzen.
|
||||||
|
- [ ] Generierte EEZ-Dateien weiterhin aus ihrer Quelle erzeugen; Anpassungen an der Struktur im Exporter berücksichtigen.
|
||||||
|
- [ ] Nach jeder abgegrenzten Umstrukturierung Build und passende Tests ausführen; das bisherige Verhalten erhalten.
|
||||||
|
|
||||||
|
**Ergebnis:** Kleine, verständliche Module mit klaren Aufgaben und dokumentierten
|
||||||
|
Schnittstellen. Zusätzliche Dateien entstehen dort, wo sie das Verständnis verbessern;
|
||||||
|
eine möglichst hohe Dateizahl ist kein eigenes Ziel.
|
||||||
|
|
||||||
|
## 2 Logik und Effizienz der eigenen Module prüfen
|
||||||
|
|
||||||
|
Jedes selbst entwickelte Modul einzeln durchgehen und untersuchen, ob seine Logik
|
||||||
|
einfacher, zuverlässiger oder sparsamer umgesetzt werden kann.
|
||||||
|
|
||||||
|
- [ ] Aufgaben, Zustände, Datenflüsse und Fehlerfälle jedes eigenen Moduls nachvollziehen.
|
||||||
|
- [ ] CPU-Zeit, RAM- und Stackbedarf sowie unnötige Speicherallokationen untersuchen.
|
||||||
|
- [ ] Blockierende Aufrufe, Warteschlangen, Task-Zusammenspiel und gemeinsame Datenzugriffe prüfen.
|
||||||
|
- [ ] Wiederholte Berechnungen, doppelte Logik und unnötige Hardware-, Netzwerk- oder Flashzugriffe erkennen.
|
||||||
|
- [ ] Verbesserungen nach messbarem Nutzen priorisieren und in kleinen Schritten umsetzen.
|
||||||
|
- [ ] Vorher und nachher vergleichen und die relevanten Normal- und Fehlerfälle testen.
|
||||||
|
|
||||||
|
**Ergebnis:** Nachvollziehbar effizientere Module. Messfrequenz, Messwertbedeutung,
|
||||||
|
Bedienung und bestehende Funktionen bleiben erhalten, sofern keine bewusste
|
||||||
|
Funktionsänderung vereinbart wird.
|
||||||
|
|
||||||
|
## 3 Messwerte auf SD-Karte speichern
|
||||||
|
|
||||||
|
Die Messwerte sollen zusätzlich zur InfluxDB-Übertragung dauerhaft lokal gespeichert
|
||||||
|
werden. Aktuell meldet die SD-Karteninitialisierung einen Timeout; dessen Ursache
|
||||||
|
muss vor der Integration des Datenloggers geklärt werden.
|
||||||
|
|
||||||
|
- [ ] SD-Anbindung, Verdrahtung, Pull-ups und Initialisierung prüfen und den bestehenden Timeout beheben.
|
||||||
|
- [ ] Ein geeignetes Dateiformat für Zeitstempel, Sensortyp, Messwerte und Einheiten festlegen.
|
||||||
|
- [ ] Einen separaten Schreibpfad mit begrenztem Puffer und gebündelten Schreibvorgängen integrieren.
|
||||||
|
- [ ] Sensorerfassung, Display und InfluxDB-Übertragung unabhängig von langsamen SD-Zugriffen weiterlaufen lassen.
|
||||||
|
- [ ] Dateirotation, Speichergrenzen und Verhalten bei voller, fehlender oder entfernter Karte festlegen.
|
||||||
|
- [ ] Nicht verfügbare Messwerte und eine noch fehlende UTC-Zeit eindeutig kennzeichnen.
|
||||||
|
- [ ] Lesen und Auswerten der Dateien sowie Neustart, Schreibfehler und Unterbrechungen testen.
|
||||||
|
|
||||||
|
**Ergebnis:** Dauerhaft gespeicherte und auswertbare Messdateien auf der SD-Karte.
|
||||||
|
Probleme mit der Karte werden angezeigt und verhindern den übrigen Gerätebetrieb nicht.
|
||||||
+2012
-13
File diff suppressed because it is too large
Load Diff
Vendored
+2
-1
@@ -5,6 +5,7 @@
|
|||||||
"platformio.platformio-ide"
|
"platformio.platformio-ide"
|
||||||
],
|
],
|
||||||
"unwantedRecommendations": [
|
"unwantedRecommendations": [
|
||||||
"ms-vscode.cpptools-extension-pack"
|
"ms-vscode.cpptools-extension-pack",
|
||||||
|
"pioarduino.pioarduino-ide"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
cmake_minimum_required(VERSION 3.16.0)
|
cmake_minimum_required(VERSION 3.16.0)
|
||||||
|
|
||||||
|
# Avoid LVGL Kconfig failures from the optional component update scan.
|
||||||
|
set(ENV{IDF_COMPONENT_CHECK_NEW_VERSION} "0")
|
||||||
|
|
||||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||||
project(lcd_demo)
|
project(lcd_demo)
|
||||||
|
|||||||
@@ -0,0 +1,299 @@
|
|||||||
|
# Sensor und Board auswählen
|
||||||
|
|
||||||
|
Die zentrale Konfiguration steht in
|
||||||
|
[`components/hardware_config/hardware_config.h`](components/hardware_config/hardware_config.h).
|
||||||
|
Es handelt sich um eine **Build-Konfiguration**: Nach Änderungen neu kompilieren
|
||||||
|
und die passende Firmware übertragen. Das Webportal verwaltet weiterhin WLAN
|
||||||
|
und InfluxDB; es ändert den Sensortreiber nicht zur Laufzeit.
|
||||||
|
|
||||||
|
## Die zwei Auswahleinstellungen
|
||||||
|
|
||||||
|
Aktueller Standard: SEN66 mit Display, Sensor weiterhin an GPIO7/8:
|
||||||
|
|
||||||
|
```c
|
||||||
|
#define NANOPSX_SENSOR NANOPSX_SENSOR_SEN66
|
||||||
|
#define NANOPSX_BOARD NANOPSX_BOARD_C6_DISPLAY_8MB
|
||||||
|
```
|
||||||
|
|
||||||
|
Für einen SEN66 an GPIO7/8 ohne Display:
|
||||||
|
|
||||||
|
```c
|
||||||
|
#define NANOPSX_SENSOR NANOPSX_SENSOR_SEN66
|
||||||
|
#define NANOPSX_BOARD NANOPSX_BOARD_C6_DEVKIT_8MB
|
||||||
|
```
|
||||||
|
|
||||||
|
Für den bisher getesteten SEN54 am nanoPSX-Display-Board:
|
||||||
|
|
||||||
|
```c
|
||||||
|
#define NANOPSX_SENSOR NANOPSX_SENSOR_SEN54
|
||||||
|
#define NANOPSX_BOARD NANOPSX_BOARD_C6_DISPLAY_8MB
|
||||||
|
```
|
||||||
|
|
||||||
|
Diese beiden Zeilen im jeweiligen `#ifndef`-Block der Konfigurationsdatei ändern.
|
||||||
|
Sensor und Board sind unabhängig wählbar: Auch ein SEN54 am Devkit oder ein
|
||||||
|
SEN66 am gemeinsamen Display-Bus sind möglich, wenn die Verdrahtung dem
|
||||||
|
ausgewählten Profil entspricht.
|
||||||
|
|
||||||
|
| Boardprofil | Hardware-I²C SDA | Hardware-I²C SCL | I²C-Port | Peripherie |
|
||||||
|
| --- | --- | --- | --- | --- |
|
||||||
|
| `NANOPSX_BOARD_C6_DISPLAY_8MB` | GPIO18 | GPIO19 | 0 | Bestehendes LCD, Touch, SD, Batterie und Taste |
|
||||||
|
| `NANOPSX_BOARD_C6_DEVKIT_8MB` | GPIO7 | GPIO8 | 0 | Sensor, WLAN, Konfigurationsportal, InfluxDB; keine Display-/SD-/Tasteninitialisierung |
|
||||||
|
|
||||||
|
| Sensor | I²C-Adresse | Takt | Messgrößen |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| SEN54 | `0x69` | 400 kHz | PM1/2.5/4/10, Temperatur, Feuchte, VOC |
|
||||||
|
| SEN66 | `0x6b` | 100 kHz | PM1/2.5/4/10, Temperatur, Feuchte, VOC, NOx, CO₂ |
|
||||||
|
|
||||||
|
SEN54 verwendet die Hardware-I²C-Pins aus dem Boardprofil. SEN66 bleibt
|
||||||
|
unabhängig vom Profil an **SDA GPIO7 / SCL GPIO8**. Beim Display-Profil benutzt
|
||||||
|
der Touchscreen den Hardware-I²C-Controller auf GPIO18/19; der SEN66 erhält einen
|
||||||
|
separaten Software-I²C-Bus auf GPIO7/8. Damit muss der Sensor beim Wechsel zum
|
||||||
|
Display-Profil nicht umgesteckt werden. Ohne Display wird für GPIO7/8 der
|
||||||
|
Hardware-Controller verwendet.
|
||||||
|
|
||||||
|
Der Software-Bus nutzt ausschließlich Open-Drain-Ausgänge mit internen Pull-ups,
|
||||||
|
ACK/NACK-Prüfung, Clock-Stretching mit begrenztem Timeout und einen Mutex.
|
||||||
|
Der Solltakt beträgt 100 kHz; GPIO-Aufrufe und Interrupts können den tatsächlichen
|
||||||
|
Takt verringern. Die elektrische Verdrahtung und externe Pull-ups entsprechend
|
||||||
|
dem Sensordatenblatt prüfen. GPIO-Nummern sind keine Steckkontakt-Nummern.
|
||||||
|
|
||||||
|
Ein fehlender Touchcontroller wird nach Reset per ACK-Probe erkannt. Die
|
||||||
|
Firmware protokolliert dies und aktiviert den LVGL-Toucheingang nur bei
|
||||||
|
vorhandenem Controller. LCD, Sensor und Netzwerk können ohne Touch weiterlaufen.
|
||||||
|
|
||||||
|
## Kompilieren
|
||||||
|
|
||||||
|
Aus dem Repository-Hauptverzeichnis:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pio run -d firmware -e esp32-c6-devkitc-1 -j 2
|
||||||
|
```
|
||||||
|
|
||||||
|
Die bekannten Profile setzen ESP32-C6 und **8 MB Flash** voraus. PlatformIO bleibt
|
||||||
|
auf `espressif32@6.12.0` und ESP-IDF 5.5.0 festgelegt. Der Build bricht ab, wenn
|
||||||
|
ein unbekanntes Profil, ein anderer Chip oder eine SDK-Konfiguration für eine
|
||||||
|
andere Flash-Größe ausgewählt wurde. Ein Profil ersetzt keine Boarderkennung.
|
||||||
|
|
||||||
|
Für weitere Boards einen neuen expliziten Profilzweig mit eigener Pinbelegung
|
||||||
|
und Peripherieauswahl hinzufügen. Bei anderen ESP32-Chips oder Flash-Größen
|
||||||
|
zusätzlich ein passendes PlatformIO-Environment, SDK-Defaults und eine passende
|
||||||
|
Partitionstabelle einrichten und prüfen. Die aktuelle 8-MB-Partitionstabelle
|
||||||
|
nicht auf das bekannte 4-MB-Board übertragen. Die zwei vorhandenen Profile
|
||||||
|
sind keine pauschale Freigabe für andere ESP32-Modelle.
|
||||||
|
|
||||||
|
## Treiber und Daten
|
||||||
|
|
||||||
|
Der SEN66 verwendet den offiziellen Sensirion-C-Treiber. Der genaue Quellstand,
|
||||||
|
die Lizenz und die unverändert übernommenen Dateien stehen in
|
||||||
|
[`SENSIRION-UPSTREAM.md`](components/sen5x/SENSIRION-UPSTREAM.md).
|
||||||
|
Der Verzeichnisname `sen5x` bleibt aus Kompatibilität bestehen; darin liegen
|
||||||
|
beide Treiber und die gemeinsame Anwendung `air_sensor_app.c`.
|
||||||
|
|
||||||
|
Die Sensoren teilen sich den ESP-IDF-HAL und die Verarbeitung für Anzeige und
|
||||||
|
InfluxDB. Die Messreihe bleibt `air`, bestehende Felder bleiben
|
||||||
|
`pm1`, `pm2_5`, `pm4`, `pm10`, `temp`, `rh`, `voc`, `nox`.
|
||||||
|
SEN66 ergänzt `co2` in ppm. Nicht verfügbare Messgrößen und die vom Sensor
|
||||||
|
definierten ungültigen Rohwerte werden ausgelassen, nicht als Null übertragen.
|
||||||
|
Insbesondere erzeugt SEN54 keine künstlichen CO₂-Werte. Die Displayoberfläche entspricht der bisherigen SEN54-Ansicht einschließlich
|
||||||
|
Schriftzug und Statussymbolen. **NOx und CO₂ werden vorerst nicht auf dem Display
|
||||||
|
angezeigt.** Diese Werte bleiben für InfluxDB verfügbar; CO₂ erscheint außerdem
|
||||||
|
in den seriellen SEN66-Messwertmeldungen. Eine erweiterte Displayansicht ist
|
||||||
|
für einen späteren Auftrag vorgesehen.
|
||||||
|
|
||||||
|
Die Anwendung prüft die Datenbereitschaft etwa einmal pro Sekunde und
|
||||||
|
protokolliert alle zehn erfolgreichen Messungen einen Datensatz ohne
|
||||||
|
Zugangsdaten. Beim Start meldet sie Boardprofil, Sensor, Pins und Takt; beim
|
||||||
|
SEN66 wird zusätzlich der Produktname gelesen und geprüft. Sensorkalibrierung,
|
||||||
|
CO₂-Zwangskalibrierung und Sensoreinstellungen werden nicht automatisch geändert.
|
||||||
|
|
||||||
|
## Tests
|
||||||
|
|
||||||
|
Mit einem nativen C-Compiler auf Linux, aus dem Repository-Hauptverzeichnis:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bash firmware/test/sensors/run.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
Diese Tests verwenden die echten SEN54-/SEN66-Treiber mit einer simulierten
|
||||||
|
I²C-HAL. Sie prüfen Geräteadressen, verschiedene Messbefehle, Datenrahmen,
|
||||||
|
vorzeichenbehaftete Werte, ungültige Rohwerte, CRC-Fehler und Übertragungsfehler.
|
||||||
|
Der separate Software-Bus wird zusätzlich auf START/STOP, Adress-/Datenbits,
|
||||||
|
ACK/NACK, Clock-Stretching, begrenzten Timeout und Freigabe der Leitungen geprüft.
|
||||||
|
Alle vier Kombinationen der Board-/Sensorauswahl und die Zurückweisung
|
||||||
|
unbekannter Profile werden ebenfalls geprüft. Das ersetzt keine elektrische
|
||||||
|
oder vollständige Hardwareprüfung.
|
||||||
|
|
||||||
|
Für vollständige ESP-IDF-Builds der Referenzkombinationen kann die Auswahl
|
||||||
|
vorübergehend pro Prozess überschrieben werden, ohne die Konfigurationsdatei
|
||||||
|
zu ändern:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
PLATFORMIO_BUILD_FLAGS='-DNANOPSX_SENSOR=54 -DNANOPSX_BOARD=1' pio run -d firmware -e esp32-c6-devkitc-1 -j 2
|
||||||
|
PLATFORMIO_BUILD_FLAGS='-DNANOPSX_SENSOR=66 -DNANOPSX_BOARD=2' pio run -d firmware -e esp32-c6-devkitc-1 -j 2
|
||||||
|
```
|
||||||
|
|
||||||
|
Die letzte Kompilierung bestimmt den Inhalt von `.pio/build/.../firmware.bin`.
|
||||||
|
Vor einem Upload immer Auswahl, Build-Erfolg und Image-Hash neu prüfen.
|
||||||
|
|
||||||
|
## Vor einem Upload
|
||||||
|
|
||||||
|
Den Workflow aus `../AGENTS.md` einhalten: Board über USB-Seriennummer auswählen,
|
||||||
|
vollständiges Backup bereitstellen und das tatsächlich aktive Partitionslayout
|
||||||
|
lesen. Eine andere Sensorauswahl benötigt normalerweise nur ein App-Update;
|
||||||
|
NVS mit WLAN-/Influx-Einstellungen muss dafür nicht gelöscht werden.
|
||||||
|
|
||||||
|
Das bekannte Board `CC:BA:97:F2:5F:7C` hatte zunächst eine einzelne
|
||||||
|
Factory-Partition von 1 MiB bei `0x10000`. Nach ausdrücklicher Freigabe wurde es
|
||||||
|
am 09.11.2026 ohne vollständiges Löschen auf das nanoPSX-8-MB-Layout mit
|
||||||
|
`ota_0` bei `0x20000` umgestellt. Die neue Partitionstabelle wurde zuletzt
|
||||||
|
aktiviert; NVS und Bootloader wurden erhalten und der alte PHY-Partitionsinhalt
|
||||||
|
an die neue Adresse kopiert. Der gültige OTA-Datensatz wählt `ota_0`.
|
||||||
|
|
||||||
|
Für einen weiteren Upload das aktuelle Layout trotzdem erneut auslesen.
|
||||||
|
Adressen, Images und frühere Einzelfreigaben niemals ungeprüft übernehmen.
|
||||||
|
Ein vollständiges Löschen ist für einen Sensorwechsel nicht nötig und nicht
|
||||||
|
automatisch freigegeben.
|
||||||
|
|
||||||
|
## Prüfstand vom 09.11.2026
|
||||||
|
|
||||||
|
- Vollständige ESP-IDF-Builds für alle vier Kombinationen (SEN54/SEN66,
|
||||||
|
jeweils Devkit ohne Display/Display-Board): erfolgreich. Dabei wurde die
|
||||||
|
Auswahl direkt in der zentralen Konfigurationsdatei gewechselt. Die fertigen
|
||||||
|
ELF-Dateien enthalten jeweils nur den gewählten Sensortreiber. Abschließend
|
||||||
|
wurden die Standardauswahl und das zugehörige Build-Artefakt
|
||||||
|
wiederhergestellt.
|
||||||
|
- Native Treiber-/CRC-/Fehlertests und Auswahltests: erfolgreich.
|
||||||
|
- Hardwaretest auf `CC:BA:97:F2:5F:7C`, ESP32-C6FH8, 8 MB: neue SEN66-Firmware
|
||||||
|
mit Display migriert und alle vier geschriebenen Bereiche vollständig
|
||||||
|
bytegenau sowie per SHA256 bestätigt. Eine vollständige Rückleseprüfung der
|
||||||
|
8 MB bestätigt zusätzlich den Schutz der übrigen Flash-Bereiche.
|
||||||
|
- 60 Sekunden Laufzeit ohne erkannte Panic oder Sensor-I²C-Fehler. SEN66
|
||||||
|
identifiziert, laufende Messungen über Software-I²C GPIO7/8, Displayinitialisierung
|
||||||
|
erfolgreich, kein Touch-Ausfall gemeldet. Die Anzeige entspricht nach Benutzerkorrektur wieder der bisherigen
|
||||||
|
SEN54-Ansicht, ohne zusätzliche NOx-/CO₂-Felder. Die sichtbare Anzeige muss am
|
||||||
|
Gerät beurteilt werden, da das Gateway kein Displaybild liefert.
|
||||||
|
- Standardauswahl ist jetzt **SEN66 mit Display**. Der bisherige separate
|
||||||
|
Standalone-SEN66-Build ist auf diesem Board ersetzt. Ein vollständiges Backup
|
||||||
|
liegt geschützt außerhalb des Repositorys vor.
|
||||||
|
- Der SD-Karten-Timeout besteht weiter. Im Test war der Setup-AP `nanoPSX`
|
||||||
|
mit Portal `http://192.168.4.1` aktiv; keine STA-IP oder erfolgreichen
|
||||||
|
Influx-Schreibvorgänge beobachtet. WLAN und bei Bedarf Organisation `Home` /
|
||||||
|
Bucket `nanoPSX` im Portal einstellen; Tokens lokal eingeben.
|
||||||
|
|
||||||
|
## Displayseiten und Bedienung
|
||||||
|
|
||||||
|
Die vier EEZ-Seiten sind `Main` (bisherige Messwertansicht), `Page_2` (Raumluft),
|
||||||
|
`History` (Verlauf) und `Device` (Gerät). Nach links zur nächsten, nach rechts zur
|
||||||
|
vorherigen Seite wischen; an den äußeren Seiten gibt es keinen Umlauf. Vier kleine
|
||||||
|
Markierungen am oberen Rand zeigen die aktuelle Seite. Tippen auf ein Statussymbol
|
||||||
|
der Hauptseite öffnet die Geräteseite. Dropdowns und Helligkeitsregler verarbeiten
|
||||||
|
ihre Berührungen selbst, ohne dabei versehentlich die Seite zu wechseln.
|
||||||
|
|
||||||
|
- Raumluft: CO₂ in ppm, VOC-/NOx-Index und ein kleiner CO₂-Verlauf. Nicht verfügbare
|
||||||
|
Kanäle erscheinen als `--`; SEN54 erzeugt keine künstlichen CO₂-Werte.
|
||||||
|
- Verlauf: Auswahl zwischen CO₂, PM2.5, Temperatur, Feuchte, VOC und NOx. Gezeigt
|
||||||
|
werden 180 Zehn-Sekunden-Mittelwerte über die letzten 30 Minuten. Die angezeigte
|
||||||
|
Wertespanne entspricht der automatisch angepassten Diagrammachse. Fehlende
|
||||||
|
Zeitabschnitte bleiben Lücken. Der feste RAM-Ringpuffer wird bei Neustart geleert;
|
||||||
|
SD-Karte, WLAN und InfluxDB sind für den lokalen Verlauf nicht erforderlich.
|
||||||
|
- Gerätestatus: WLAN/IP, Alter der letzten bestätigten Influx-Übertragung (HTTP 204)
|
||||||
|
und Sensoraktualität. Ein WLAN-Erfolg gilt nicht als erfolgreiche Datenübertragung.
|
||||||
|
- Helligkeit: 20–100 %, Standard 100 %. Automatisches Abdunkeln: aus oder nach
|
||||||
|
30/60/120 Sekunden, Standard 60 Sekunden. Abgedunkelt wird auf 15 %. Die erste
|
||||||
|
Berührung weckt nur das Display und wird bis zum Loslassen verbraucht.
|
||||||
|
- Display-Einstellungen werden erst nach Änderung gespeichert: Helligkeit beim
|
||||||
|
Loslassen, Zeitwahl beim Auswählen. Eigener NVS-Namespace `ui_display`, keine
|
||||||
|
WLAN-/Influx-Einstellungen. Beim ersten Start werden nur die Defaults gelesen.
|
||||||
|
- Vor dem ersten Sensorpaket erscheint ein Starthinweis. Nach mehr als fünf
|
||||||
|
Sekunden ohne erfolgreiches Paket werden die aktuellen Anzeigen als veraltet
|
||||||
|
markiert und die Zahlen durch `--` ersetzt; der vorhandene Verlauf bleibt sichtbar.
|
||||||
|
|
||||||
|
## EEZ-Projekt und Firmware zusammen bearbeiten
|
||||||
|
|
||||||
|
`eez/nanopsx.eez-project` enthält Layout, Beschriftungen, Namen und Grundkonfiguration
|
||||||
|
der Widgets. PlatformIO ruft vor jedem Build `tools/export_display.py` auf und hält
|
||||||
|
`screens.c`/`screens.h` automatisch synchron. Kein manueller EEZ-Studio-Export nötig.
|
||||||
|
Der projektspezifische Exporter unterstützt die hier verwendeten statischen Screen-,
|
||||||
|
Panel-, Label-, Image-, Chart-, Slider- und Dropdown-Widgets und deren verwendete
|
||||||
|
Stile. Nicht unterstützte Widgettypen/Stile brechen den Build ab, statt unbemerkt
|
||||||
|
wegzufallen; bei Erweiterungen zuerst den Exporter ergänzen. EEZ Flow bleibt aus.
|
||||||
|
|
||||||
|
Navigation, dynamische Texte, Chart-Daten, Touch-Aufwecken und Einstellungen liegen
|
||||||
|
außerhalb der generierten Dateien in `ui_navigation.c`, `ui_dashboard.c` und
|
||||||
|
`ui_model.c`. Diese werden nach `ui_init()` unter dem LVGL-Lock initialisiert.
|
||||||
|
Der Sensorproducer übergibt skalierte Zahlen an `ui_model_publish()` und ruft
|
||||||
|
keine LVGL-Funktionen auf. Snapshot und begrenzter Ringpuffer sind auf dem ESP
|
||||||
|
mit einem Spinlock geschützt. Die Diagramme werden im GUI-Task aktualisiert.
|
||||||
|
|
||||||
|
Prüfungen aus dem Repository-Hauptverzeichnis:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 firmware/tools/export_display.py --check
|
||||||
|
python3 firmware/test/ui/run_tests.py
|
||||||
|
bash firmware/test/sensors/run.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
Die UI-Tests verwenden echte LVGL-Quellen und exportierte Displayobjekte bei
|
||||||
|
48 KiB LVGL-Speicher. Sie prüfen vierseitige Navigation, Tippen, kurze/vertikale
|
||||||
|
Gesten, äußere Grenzen, Kindobjekte, Dropdown-Isolation, Helligkeitsregler,
|
||||||
|
Aufweckberührung, Abdunkeln, fehlende/veraltete Werte und Verlaufsmittelwerte,
|
||||||
|
Lücken und Verdrängung alter Daten. Voraussetzung sind ein C-Compiler und die
|
||||||
|
bereits aufgelöste LVGL-Komponente unter `firmware/managed_components`.
|
||||||
|
Ein optionaler Verzeichnispfad hinter dem UI-Testbefehl speichert vier gerenderte
|
||||||
|
PPM-Vorschauen mit simulierten Messwerten. Physische Darstellung und Fingerbedienung
|
||||||
|
müssen zusätzlich am Gerät geprüft werden.
|
||||||
|
|
||||||
|
## Effiziente InfluxDB-Übertragung
|
||||||
|
|
||||||
|
Der Sensor misst weiter mit 1 Hz. Der Influx-Worker bündelt bis zu zehn einzelne
|
||||||
|
Messpunkte in einer HTTP-Anfrage; spätestens zehn Sekunden nach Beginn eines
|
||||||
|
Pakets wird auch ein kleineres Restpaket versendet. Ein Paket ist zusätzlich auf
|
||||||
|
4096 Bytes begrenzt. Keine Mittelung oder Änderung der Influx-Feldnamen/Einheiten;
|
||||||
|
Display und lokaler Verlauf aktualisieren sich unabhängig vom Netzwerk weiter.
|
||||||
|
Im normalen 1-Hz-Betrieb entstehen etwa sechs Schreibanfragen pro Minute statt 60,
|
||||||
|
mit bis zu etwa zehn Sekunden zusätzlicher Sichtbarkeitsverzögerung auf dem Server.
|
||||||
|
|
||||||
|
Jeder Punkt erhält einen eigenen Zeitstempel mit `precision=ms`. Der Messzeitpunkt
|
||||||
|
wird beim Einreihen über den monotonen ESP-Timer erfasst. Ein einmaliger GET auf
|
||||||
|
`/health` liest den HTTP-`Date`-Header desselben Influx-Servers und richtet damit
|
||||||
|
nur die interne Messuhr aus; weder ein Internet-Zeitdienst noch eine Änderung der
|
||||||
|
Systemuhr ist nötig. HTTP Date besitzt Sekundenauflösung: Die absolute Zuordnung
|
||||||
|
ist entsprechend ungefähr sekundengenau; die Abstände der Sekundenmessungen
|
||||||
|
bleiben erhalten. Spätere Date-Header gleichen größere Uhrdrift vorsichtig aus.
|
||||||
|
Explizite Zeitstempel der API bleiben erhalten. Fehlt ein gültiges Date vollständig,
|
||||||
|
werden sichere Einzelpunkt-Anfragen mit Serverzeit verwendet, bis eine Zeitbasis
|
||||||
|
verfügbar ist. Mehrere ungestempelte Punkte derselben Serie werden nicht gebündelt.
|
||||||
|
|
||||||
|
HTTP-Client und Verbindung werden über mehrere Anfragen wiederverwendet. Ein
|
||||||
|
Konfigurationswechsel oder Verbindungsfehler verwirft den Handle; der nächste
|
||||||
|
Versuch baut ihn neu auf. Es werden keine Token oder Messwert-Payloads protokolliert.
|
||||||
|
Der Worker meldet HTTP-Status, Punkt-/Bytezahl, erste/letzte UTC-Zeit im Paket und
|
||||||
|
gezählte Verbindungsaufbauten. Die Gerätestatusanzeige zählt nur bestätigte HTTP 204
|
||||||
|
als erfolgreiche Übertragung; ihr Alter kann jetzt regulär etwa zehn Sekunden betragen.
|
||||||
|
|
||||||
|
Der RAM-Puffer enthält 32 vorserialisierte Punkte ohne einzelne Heap-Allokationen
|
||||||
|
für jeden Feldnamen/Wert. Ein Paket bleibt bei Transportfehlern, Rate-Limits oder
|
||||||
|
Serverproblemen mit unverändertem Inhalt und Zeitstempeln für einen erneuten
|
||||||
|
Versuch erhalten (exponentielle Pause von 2 s bis maximal 300 s). Fünf Fehler lösen
|
||||||
|
ein Neuladen der vorhandenen Konfiguration aus. HTTP 400/413/422 wird als abgelehntes
|
||||||
|
Paket protokolliert und verworfen; bereits teilweise geschriebene Daten werden dabei
|
||||||
|
nicht gelöscht. Ohne Zeitbasis werden fehlgeschlagene Einzelpunkte nicht automatisch
|
||||||
|
wiederholt, da deren Serverzeit sonst neue Punkte erzeugen könnte.
|
||||||
|
|
||||||
|
Bei längerem Ausfall ersetzt die volle Warteschlange die ältesten noch nicht
|
||||||
|
versendeten Punkte; die Verluste werden gezählt und protokolliert. Puffer und
|
||||||
|
laufendes Paket sind RAM-basiert und gehen bei Neustart verloren. Der Producer
|
||||||
|
wartet nicht auf HTTP. Beim Stoppen räumt der Worker seine Ressourcen selbst auf;
|
||||||
|
er wird nicht mitten in einer Anfrage gewaltsam beendet.
|
||||||
|
|
||||||
|
Nativer Test mit dem echten Worker und simuliertem FreeRTOS/HTTP unter Address- und
|
||||||
|
UndefinedBehavior-Sanitizer, vom Repository-Hauptverzeichnis:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 firmware/test/net_influx/run_tests.py
|
||||||
|
```
|
||||||
|
|
||||||
|
Prüft Serialisierung/escaping, fehlende Kanäle, UTC-/Kalenderkonvertierung,
|
||||||
|
Messzeitabstände, 10er-Pakete, Wiederholungen mit identischem Body, Warteschlangen-
|
||||||
|
Überlauf, fehlende Zeitbasis, Einzelpunktfehler, Zeitlimit bei Restpaketen,
|
||||||
|
Bytegrenzen, dauerhaft abgelehnte Pakete und Wiederverwendung/Freigabe des Clients.
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
idf_component_register(
|
idf_component_register(
|
||||||
SRCS
|
SRCS
|
||||||
"ui.c"
|
"ui.c"
|
||||||
|
"ui_navigation.c"
|
||||||
|
"ui_dashboard.c"
|
||||||
|
"ui_model.c"
|
||||||
"images.c"
|
"images.c"
|
||||||
"screens.c"
|
"screens.c"
|
||||||
"styles.c"
|
"styles.c"
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,15 +1,22 @@
|
|||||||
#ifndef EEZ_LVGL_UI_SCREENS_H
|
/* Generated by firmware/tools/export_display.py from the EEZ project. */
|
||||||
#define EEZ_LVGL_UI_SCREENS_H
|
#pragma once
|
||||||
|
|
||||||
#include <lvgl.h>
|
#include <lvgl.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
typedef struct {
|
||||||
typedef struct _objects_t {
|
|
||||||
lv_obj_t *main;
|
lv_obj_t *main;
|
||||||
|
lv_obj_t *page_2;
|
||||||
|
lv_obj_t *history;
|
||||||
|
lv_obj_t *device;
|
||||||
lv_obj_t *obj0;
|
lv_obj_t *obj0;
|
||||||
|
lv_obj_t *obj5;
|
||||||
|
lv_obj_t *obj6;
|
||||||
|
lv_obj_t *obj7;
|
||||||
|
lv_obj_t *obj8;
|
||||||
|
lv_obj_t *obj9;
|
||||||
|
lv_obj_t *obj10;
|
||||||
|
lv_obj_t *obj11;
|
||||||
lv_obj_t *obj1;
|
lv_obj_t *obj1;
|
||||||
lv_obj_t *obj2;
|
lv_obj_t *obj2;
|
||||||
lv_obj_t *obj3;
|
lv_obj_t *obj3;
|
||||||
@@ -20,32 +27,63 @@ typedef struct _objects_t {
|
|||||||
lv_obj_t *influx_off;
|
lv_obj_t *influx_off;
|
||||||
lv_obj_t *mdns_ok;
|
lv_obj_t *mdns_ok;
|
||||||
lv_obj_t *mdns_off;
|
lv_obj_t *mdns_off;
|
||||||
lv_obj_t *obj5;
|
lv_obj_t *main_notice;
|
||||||
lv_obj_t *obj6;
|
lv_obj_t *page_dot_0_0;
|
||||||
lv_obj_t *obj7;
|
lv_obj_t *page_dot_0_1;
|
||||||
lv_obj_t *obj8;
|
lv_obj_t *page_dot_0_2;
|
||||||
lv_obj_t *obj9;
|
lv_obj_t *page_dot_0_3;
|
||||||
lv_obj_t *obj10;
|
lv_obj_t *page_2_title;
|
||||||
lv_obj_t *obj11;
|
lv_obj_t *room_state;
|
||||||
|
lv_obj_t *room_co2;
|
||||||
|
lv_obj_t *room_unit;
|
||||||
|
lv_obj_t *room_voc;
|
||||||
|
lv_obj_t *room_nox;
|
||||||
|
lv_obj_t *room_chart;
|
||||||
|
lv_obj_t *room_chart_caption;
|
||||||
|
lv_obj_t *page_dot_1_0;
|
||||||
|
lv_obj_t *page_dot_1_1;
|
||||||
|
lv_obj_t *page_dot_1_2;
|
||||||
|
lv_obj_t *page_dot_1_3;
|
||||||
|
lv_obj_t *history_title;
|
||||||
|
lv_obj_t *history_metric;
|
||||||
|
lv_obj_t *history_range;
|
||||||
|
lv_obj_t *history_chart;
|
||||||
|
lv_obj_t *history_caption;
|
||||||
|
lv_obj_t *page_dot_2_0;
|
||||||
|
lv_obj_t *page_dot_2_1;
|
||||||
|
lv_obj_t *page_dot_2_2;
|
||||||
|
lv_obj_t *page_dot_2_3;
|
||||||
|
lv_obj_t *device_title;
|
||||||
|
lv_obj_t *device_wifi;
|
||||||
|
lv_obj_t *device_influx;
|
||||||
|
lv_obj_t *device_sensor;
|
||||||
|
lv_obj_t *brightness_label;
|
||||||
|
lv_obj_t *brightness;
|
||||||
|
lv_obj_t *dim_label;
|
||||||
|
lv_obj_t *dim_timeout;
|
||||||
|
lv_obj_t *page_dot_3_0;
|
||||||
|
lv_obj_t *page_dot_3_1;
|
||||||
|
lv_obj_t *page_dot_3_2;
|
||||||
|
lv_obj_t *page_dot_3_3;
|
||||||
} objects_t;
|
} objects_t;
|
||||||
|
|
||||||
extern objects_t objects;
|
extern objects_t objects;
|
||||||
|
|
||||||
enum ScreensEnum {
|
enum ScreensEnum {
|
||||||
SCREEN_ID_MAIN = 1,
|
SCREEN_ID_MAIN = 1,
|
||||||
|
SCREEN_ID_PAGE_2 = 2,
|
||||||
|
SCREEN_ID_HISTORY = 3,
|
||||||
|
SCREEN_ID_DEVICE = 4,
|
||||||
};
|
};
|
||||||
|
void create_screen_main(void);
|
||||||
void create_screen_main();
|
void tick_screen_main(void);
|
||||||
void tick_screen_main();
|
void create_screen_page_2(void);
|
||||||
|
void tick_screen_page_2(void);
|
||||||
void tick_screen_by_id(enum ScreensEnum screenId);
|
void create_screen_history(void);
|
||||||
|
void tick_screen_history(void);
|
||||||
|
void create_screen_device(void);
|
||||||
|
void tick_screen_device(void);
|
||||||
|
void create_screens(void);
|
||||||
void tick_screen(int screen_index);
|
void tick_screen(int screen_index);
|
||||||
|
void tick_screen_by_id(enum ScreensEnum screen_id);
|
||||||
void create_screens();
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*EEZ_LVGL_UI_SCREENS_H*/
|
|
||||||
@@ -0,0 +1,204 @@
|
|||||||
|
#include "ui_dashboard.h"
|
||||||
|
#include "ui_model.h"
|
||||||
|
#include "ui.h"
|
||||||
|
#include "fonts.h"
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
static ui_display_config_t config;
|
||||||
|
static ui_brightness_cb_t set_brightness;
|
||||||
|
static ui_save_config_cb_t save_config;
|
||||||
|
static lv_chart_series_t *room_series, *history_series;
|
||||||
|
static uint32_t last_activity;
|
||||||
|
static bool initialized, dimmed, suppress_touch;
|
||||||
|
static const uint16_t dim_seconds[] = {0, 30, 60, 120};
|
||||||
|
static const char *units[] = {"ppm", "µg/m³", "°C", "%", "Index", "Index"};
|
||||||
|
|
||||||
|
static void update_brightness_label(void)
|
||||||
|
{
|
||||||
|
lv_label_set_text_fmt(objects.brightness_label, "Licht %u%%", config.brightness);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void settings_event(lv_event_t *event)
|
||||||
|
{
|
||||||
|
lv_obj_t *target = lv_event_get_target(event);
|
||||||
|
if (target == objects.brightness) {
|
||||||
|
config.brightness = (uint8_t)lv_slider_get_value(target);
|
||||||
|
set_brightness(config.brightness);
|
||||||
|
update_brightness_label();
|
||||||
|
/* Dragging previews immediately, persistence happens only on release. */
|
||||||
|
if (lv_event_get_code(event) == LV_EVENT_RELEASED && save_config) save_config(&config);
|
||||||
|
} else if (target == objects.dim_timeout) {
|
||||||
|
unsigned selected = lv_dropdown_get_selected(target);
|
||||||
|
if (selected < sizeof(dim_seconds) / sizeof(dim_seconds[0])) {
|
||||||
|
config.dim_after_s = dim_seconds[selected];
|
||||||
|
if (save_config) save_config(&config);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
last_activity = lv_tick_get();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void status_clicked(lv_event_t *event)
|
||||||
|
{
|
||||||
|
(void)event;
|
||||||
|
loadScreen(SCREEN_ID_DEVICE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ui_dashboard_init(ui_display_config_t selected, ui_brightness_cb_t brightness,
|
||||||
|
ui_save_config_cb_t save)
|
||||||
|
{
|
||||||
|
config = selected;
|
||||||
|
if (config.brightness < 20 || config.brightness > 100) config.brightness = 100;
|
||||||
|
unsigned dim_index = 2;
|
||||||
|
for (unsigned i = 0; i < 4; ++i) if (config.dim_after_s == dim_seconds[i]) dim_index = i;
|
||||||
|
config.dim_after_s = dim_seconds[dim_index];
|
||||||
|
set_brightness = brightness;
|
||||||
|
save_config = save;
|
||||||
|
dimmed = suppress_touch = false;
|
||||||
|
last_activity = lv_tick_get();
|
||||||
|
initialized = true;
|
||||||
|
lv_slider_set_value(objects.brightness, config.brightness, LV_ANIM_OFF);
|
||||||
|
lv_obj_set_ext_click_area(objects.brightness, 12);
|
||||||
|
lv_dropdown_set_selected(objects.dim_timeout, dim_index);
|
||||||
|
update_brightness_label();
|
||||||
|
/* Custom Ubuntu fonts do not contain LVGL's private-use arrow glyphs. */
|
||||||
|
lv_obj_set_style_text_font(objects.history_metric, LV_FONT_DEFAULT, LV_PART_INDICATOR);
|
||||||
|
lv_obj_set_style_text_font(objects.dim_timeout, LV_FONT_DEFAULT, LV_PART_INDICATOR);
|
||||||
|
lv_obj_add_event_cb(objects.brightness, settings_event, LV_EVENT_VALUE_CHANGED, NULL);
|
||||||
|
lv_obj_add_event_cb(objects.brightness, settings_event, LV_EVENT_RELEASED, NULL);
|
||||||
|
lv_obj_add_event_cb(objects.dim_timeout, settings_event, LV_EVENT_VALUE_CHANGED, NULL);
|
||||||
|
lv_obj_t *icons[] = {objects.wifi_ok, objects.wifi_off, objects.influx_ok,
|
||||||
|
objects.influx_off, objects.mdns_ok, objects.mdns_off};
|
||||||
|
for (unsigned i = 0; i < sizeof(icons) / sizeof(icons[0]); ++i) {
|
||||||
|
lv_obj_add_flag(icons[i], LV_OBJ_FLAG_CLICKABLE);
|
||||||
|
lv_obj_add_event_cb(icons[i], status_clicked, LV_EVENT_CLICKED, NULL);
|
||||||
|
}
|
||||||
|
lv_chart_set_point_count(objects.room_chart, UI_HISTORY_POINTS);
|
||||||
|
lv_chart_set_point_count(objects.history_chart, UI_HISTORY_POINTS);
|
||||||
|
room_series = lv_chart_add_series(objects.room_chart, lv_color_hex(0x62D6C5), LV_CHART_AXIS_PRIMARY_Y);
|
||||||
|
history_series = lv_chart_add_series(objects.history_chart, lv_color_hex(0x62D6C5), LV_CHART_AXIS_PRIMARY_Y);
|
||||||
|
lv_chart_set_all_value(objects.room_chart, room_series, LV_CHART_POINT_NONE);
|
||||||
|
lv_chart_set_all_value(objects.history_chart, history_series, LV_CHART_POINT_NONE);
|
||||||
|
lv_obj_set_style_size(objects.room_chart, 0, LV_PART_INDICATOR);
|
||||||
|
lv_obj_set_style_size(objects.history_chart, 0, LV_PART_INDICATOR);
|
||||||
|
lv_obj_set_style_line_width(objects.room_chart, 2, LV_PART_ITEMS);
|
||||||
|
lv_obj_set_style_line_width(objects.history_chart, 2, LV_PART_ITEMS);
|
||||||
|
set_brightness(config.brightness);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ui_dashboard_filter_touch(lv_indev_data_t *data)
|
||||||
|
{
|
||||||
|
if (!initialized) return;
|
||||||
|
const bool pressed = data->state == LV_INDEV_STATE_PRESSED;
|
||||||
|
if (pressed) {
|
||||||
|
last_activity = lv_tick_get();
|
||||||
|
if (dimmed) {
|
||||||
|
dimmed = false;
|
||||||
|
suppress_touch = true;
|
||||||
|
set_brightness(config.brightness);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (suppress_touch) {
|
||||||
|
data->state = LV_INDEV_STATE_RELEASED;
|
||||||
|
if (!pressed) suppress_touch = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void format_value(lv_obj_t *label, const char *prefix, float value, unsigned decimals)
|
||||||
|
{
|
||||||
|
if (!isfinite(value)) lv_label_set_text_fmt(label, "%s--", prefix);
|
||||||
|
else {
|
||||||
|
/* LVGL's compact printf is built without floating-point support. */
|
||||||
|
char text[64];
|
||||||
|
snprintf(text, sizeof(text), "%s%.*f", prefix, (int)decimals, (double)value);
|
||||||
|
lv_label_set_text(label, text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void fill_chart(lv_obj_t *chart, lv_chart_series_t *series,
|
||||||
|
ui_metric_t metric, uint64_t now_ms, lv_obj_t *range_label)
|
||||||
|
{
|
||||||
|
float values[UI_HISTORY_POINTS];
|
||||||
|
ui_model_history(metric, now_ms, values);
|
||||||
|
float low = INFINITY, high = -INFINITY;
|
||||||
|
for (unsigned i = 0; i < UI_HISTORY_POINTS; ++i) {
|
||||||
|
if (isfinite(values[i])) {
|
||||||
|
if (values[i] < low) low = values[i];
|
||||||
|
if (values[i] > high) high = values[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* Values use tenths in the plot. Never overflow LVGL's 16-bit coordinates. */
|
||||||
|
const float scale = metric == UI_METRIC_CO2 ? 1.0f : 10.0f;
|
||||||
|
int minimum = isfinite(low) ? (int)floorf(low * scale) : 0;
|
||||||
|
int maximum = isfinite(high) ? (int)ceilf(high * scale) : 10;
|
||||||
|
int margin = (maximum - minimum) / 10;
|
||||||
|
if (margin < 5) margin = 5;
|
||||||
|
minimum -= margin; maximum += margin;
|
||||||
|
if (metric != UI_METRIC_TEMP && minimum < 0) minimum = 0;
|
||||||
|
if (minimum < -32000) minimum = -32000;
|
||||||
|
if (maximum > 32000) maximum = 32000;
|
||||||
|
if (maximum <= minimum) maximum = minimum + 1;
|
||||||
|
lv_chart_set_range(chart, LV_CHART_AXIS_PRIMARY_Y, minimum, maximum);
|
||||||
|
for (unsigned i = 0; i < UI_HISTORY_POINTS; ++i) {
|
||||||
|
float value = values[i] * scale;
|
||||||
|
series->y_points[i] = !isfinite(value) ? LV_CHART_POINT_NONE :
|
||||||
|
(lv_coord_t)lroundf(fminf(32000, fmaxf(-32000, value)));
|
||||||
|
}
|
||||||
|
lv_chart_refresh(chart);
|
||||||
|
if (range_label) {
|
||||||
|
if (isfinite(low)) {
|
||||||
|
char text[64];
|
||||||
|
snprintf(text, sizeof(text), "%.0f..%.0f %s", minimum / scale, maximum / scale, units[metric]);
|
||||||
|
lv_label_set_text(range_label, text);
|
||||||
|
}
|
||||||
|
else lv_label_set_text(range_label, "Noch keine Daten");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ui_dashboard_tick(uint64_t now_ms, const ui_device_status_t *status)
|
||||||
|
{
|
||||||
|
if (!initialized) return;
|
||||||
|
lv_obj_t *on[] = {objects.wifi_ok, objects.influx_ok, objects.mdns_ok};
|
||||||
|
lv_obj_t *off[] = {objects.wifi_off, objects.influx_off, objects.mdns_off};
|
||||||
|
bool ok[] = {status->wifi_connected, status->influx_ok, status->mdns_ok};
|
||||||
|
for (unsigned i = 0; i < 3; ++i) {
|
||||||
|
lv_obj_add_flag(ok[i] ? off[i] : on[i], LV_OBJ_FLAG_HIDDEN);
|
||||||
|
lv_obj_clear_flag(ok[i] ? on[i] : off[i], LV_OBJ_FLAG_HIDDEN);
|
||||||
|
}
|
||||||
|
if (!dimmed && config.dim_after_s &&
|
||||||
|
lv_tick_elaps(last_activity) >= (uint32_t)config.dim_after_s * 1000) {
|
||||||
|
dimmed = true;
|
||||||
|
set_brightness(15);
|
||||||
|
}
|
||||||
|
ui_sample_t sample;
|
||||||
|
ui_model_snapshot(&sample);
|
||||||
|
const uint64_t age = sample.available && now_ms >= sample.timestamp_ms ? now_ms - sample.timestamp_ms : 0;
|
||||||
|
const bool fresh = sample.available && now_ms >= sample.timestamp_ms && age <= UI_SENSOR_STALE_MS;
|
||||||
|
const char *state = !sample.available ? "Sensor startet ..." : fresh ? "Live / 1 Messung pro Sekunde" : "Messwerte veraltet";
|
||||||
|
lv_label_set_text(objects.room_state, state);
|
||||||
|
if (fresh) lv_obj_add_flag(objects.main_notice, LV_OBJ_FLAG_HIDDEN);
|
||||||
|
else {
|
||||||
|
lv_obj_clear_flag(objects.main_notice, LV_OBJ_FLAG_HIDDEN);
|
||||||
|
lv_label_set_text(objects.main_notice, state);
|
||||||
|
lv_obj_t *values[] = {objects.obj5, objects.obj6, objects.obj7, objects.obj8,
|
||||||
|
objects.obj9, objects.obj10, objects.obj11};
|
||||||
|
for (unsigned i = 0; i < sizeof(values) / sizeof(values[0]); ++i) lv_label_set_text(values[i], "--");
|
||||||
|
}
|
||||||
|
format_value(objects.room_co2, "", fresh ? sample.values[UI_METRIC_CO2] : NAN, 0);
|
||||||
|
format_value(objects.room_voc, "VOC-Index ", fresh ? sample.values[UI_METRIC_VOC] : NAN, 0);
|
||||||
|
format_value(objects.room_nox, "NOx-Index ", fresh ? sample.values[UI_METRIC_NOX] : NAN, 0);
|
||||||
|
if (fresh && !isfinite(sample.values[UI_METRIC_CO2]))
|
||||||
|
lv_label_set_text(objects.room_state, "CO2-Kanal nicht verfügbar");
|
||||||
|
fill_chart(objects.room_chart, room_series, UI_METRIC_CO2, now_ms, NULL);
|
||||||
|
unsigned metric = lv_dropdown_get_selected(objects.history_metric);
|
||||||
|
if (metric >= UI_METRIC_COUNT) metric = UI_METRIC_CO2;
|
||||||
|
fill_chart(objects.history_chart, history_series, (ui_metric_t)metric, now_ms, objects.history_range);
|
||||||
|
lv_label_set_text_fmt(objects.device_wifi, "WLAN: %s", status->wifi_connected ? status->ip : "nicht verbunden");
|
||||||
|
if (status->last_influx_success_ms && now_ms >= status->last_influx_success_ms) {
|
||||||
|
unsigned seconds = (unsigned)((now_ms - status->last_influx_success_ms) / 1000);
|
||||||
|
if (seconds < 60) lv_label_set_text_fmt(objects.device_influx, "Influx: vor %u s / %s", seconds, status->influx_ok ? "OK" : "Fehler");
|
||||||
|
else lv_label_set_text_fmt(objects.device_influx, "Influx: vor %u min / %s", seconds / 60, status->influx_ok ? "OK" : "Fehler");
|
||||||
|
} else lv_label_set_text(objects.device_influx, "Influx: noch keine Übertragung");
|
||||||
|
if (!sample.available) lv_label_set_text(objects.device_sensor, "Sensor: startet / wartet auf Daten");
|
||||||
|
else lv_label_set_text_fmt(objects.device_sensor, "Sensor: %s / vor %u s", fresh ? "OK" : "veraltet", (unsigned)(age / 1000));
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <lvgl.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint8_t brightness; /* 20..100 percent */
|
||||||
|
uint16_t dim_after_s; /* 0, 30, 60, 120 */
|
||||||
|
} ui_display_config_t;
|
||||||
|
typedef struct {
|
||||||
|
bool wifi_connected, influx_ok, mdns_ok;
|
||||||
|
char ip[16];
|
||||||
|
uint64_t last_influx_success_ms; /* zero until first successful HTTP 204 */
|
||||||
|
} ui_device_status_t;
|
||||||
|
typedef void (*ui_brightness_cb_t)(uint8_t percent);
|
||||||
|
typedef void (*ui_save_config_cb_t)(const ui_display_config_t *config);
|
||||||
|
|
||||||
|
/* All calls run on the LVGL task or while its lock is held. */
|
||||||
|
void ui_dashboard_init(ui_display_config_t config, ui_brightness_cb_t brightness,
|
||||||
|
ui_save_config_cb_t save);
|
||||||
|
void ui_dashboard_tick(uint64_t now_ms, const ui_device_status_t *status);
|
||||||
|
/* Wrap the touch read callback, so the wake-up touch cannot activate controls. */
|
||||||
|
void ui_dashboard_filter_touch(lv_indev_data_t *data);
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
#include "ui_model.h"
|
||||||
|
#include <math.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#ifdef ESP_PLATFORM
|
||||||
|
#include "freertos/FreeRTOS.h"
|
||||||
|
#include "freertos/portmacro.h"
|
||||||
|
static portMUX_TYPE model_mux = portMUX_INITIALIZER_UNLOCKED;
|
||||||
|
#define LOCK() portENTER_CRITICAL(&model_mux)
|
||||||
|
#define UNLOCK() portEXIT_CRITICAL(&model_mux)
|
||||||
|
#else
|
||||||
|
#define LOCK() ((void)0)
|
||||||
|
#define UNLOCK() ((void)0)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint64_t bucket;
|
||||||
|
float sum[UI_METRIC_COUNT];
|
||||||
|
uint16_t count[UI_METRIC_COUNT];
|
||||||
|
bool used;
|
||||||
|
} history_bin_t;
|
||||||
|
static ui_sample_t latest;
|
||||||
|
static history_bin_t bins[UI_HISTORY_POINTS];
|
||||||
|
|
||||||
|
void ui_model_publish(const ui_sample_t *sample)
|
||||||
|
{
|
||||||
|
if (!sample || !sample->available) return;
|
||||||
|
const uint64_t bucket = sample->timestamp_ms / UI_HISTORY_BUCKET_MS;
|
||||||
|
LOCK();
|
||||||
|
latest = *sample;
|
||||||
|
history_bin_t *bin = &bins[bucket % UI_HISTORY_POINTS];
|
||||||
|
if (!bin->used || bin->bucket != bucket) {
|
||||||
|
*bin = (history_bin_t){.bucket = bucket, .used = true};
|
||||||
|
}
|
||||||
|
for (unsigned i = 0; i < UI_METRIC_COUNT; ++i) {
|
||||||
|
if (isfinite(sample->values[i]) && bin->count[i] < UINT16_MAX) {
|
||||||
|
bin->sum[i] += sample->values[i];
|
||||||
|
++bin->count[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
UNLOCK();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ui_model_snapshot(ui_sample_t *sample)
|
||||||
|
{
|
||||||
|
LOCK();
|
||||||
|
*sample = latest;
|
||||||
|
UNLOCK();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ui_model_history(ui_metric_t metric, uint64_t now_ms, float *values)
|
||||||
|
{
|
||||||
|
const uint64_t last_bucket = now_ms / UI_HISTORY_BUCKET_MS;
|
||||||
|
LOCK();
|
||||||
|
for (unsigned i = 0; i < UI_HISTORY_POINTS; ++i) {
|
||||||
|
const unsigned age = UI_HISTORY_POINTS - 1 - i;
|
||||||
|
values[i] = NAN;
|
||||||
|
if ((unsigned)metric >= UI_METRIC_COUNT || last_bucket < age) continue;
|
||||||
|
const uint64_t bucket = last_bucket - age;
|
||||||
|
const history_bin_t *bin = &bins[bucket % UI_HISTORY_POINTS];
|
||||||
|
if (bin->used && bin->bucket == bucket && bin->count[metric]) {
|
||||||
|
values[i] = bin->sum[metric] / bin->count[metric];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
UNLOCK();
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#define UI_HISTORY_POINTS 180
|
||||||
|
#define UI_HISTORY_BUCKET_MS 10000
|
||||||
|
#define UI_SENSOR_STALE_MS 5000
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
UI_METRIC_CO2, UI_METRIC_PM25, UI_METRIC_TEMP, UI_METRIC_RH,
|
||||||
|
UI_METRIC_VOC, UI_METRIC_NOX, UI_METRIC_COUNT
|
||||||
|
} ui_metric_t;
|
||||||
|
typedef struct {
|
||||||
|
uint64_t timestamp_ms;
|
||||||
|
float values[UI_METRIC_COUNT]; /* ppm, ug/m3, degC, %, VOC index, NOx index */
|
||||||
|
bool available;
|
||||||
|
} ui_sample_t;
|
||||||
|
|
||||||
|
/* Producer submits scaled numbers, with NAN for unavailable channels. No LVGL calls. */
|
||||||
|
void ui_model_publish(const ui_sample_t *sample);
|
||||||
|
void ui_model_snapshot(ui_sample_t *sample);
|
||||||
|
/* 180 fixed ten-second bins, oldest first; empty bins are NAN. RAM only. */
|
||||||
|
void ui_model_history(ui_metric_t metric, uint64_t now_ms, float *values);
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
#include "ui_navigation.h"
|
||||||
|
#include "esp_log.h"
|
||||||
|
#include "screens.h"
|
||||||
|
#include "ui.h"
|
||||||
|
|
||||||
|
static void screen_gesture_cb(lv_event_t *event)
|
||||||
|
{
|
||||||
|
lv_indev_t *input = lv_indev_get_act();
|
||||||
|
if (!input || lv_dropdown_is_open(objects.history_metric) ||
|
||||||
|
lv_dropdown_is_open(objects.dim_timeout)) return;
|
||||||
|
lv_obj_t *screen = lv_event_get_current_target(event);
|
||||||
|
lv_obj_t *screens[] = {objects.main, objects.page_2, objects.history, objects.device};
|
||||||
|
unsigned index = 0;
|
||||||
|
while (index < 4 && screens[index] != screen) ++index;
|
||||||
|
if (index >= 4) return;
|
||||||
|
lv_dir_t direction = lv_indev_get_gesture_dir(input);
|
||||||
|
unsigned next = index;
|
||||||
|
if (direction == LV_DIR_LEFT && index < 3) ++next;
|
||||||
|
else if (direction == LV_DIR_RIGHT && index > 0) --next;
|
||||||
|
if (next == index) return;
|
||||||
|
lv_indev_wait_release(input);
|
||||||
|
loadScreen((enum ScreensEnum)(next + 1));
|
||||||
|
ESP_LOGI("ui_navigation", "Swipe: page %u -> %u", index + 1, next + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void prepare_gestures(lv_obj_t *object)
|
||||||
|
{
|
||||||
|
lv_obj_clear_flag(object, LV_OBJ_FLAG_SCROLLABLE);
|
||||||
|
lv_obj_add_flag(object, LV_OBJ_FLAG_GESTURE_BUBBLE);
|
||||||
|
for (uint32_t i = 0; i < lv_obj_get_child_cnt(object); ++i)
|
||||||
|
prepare_gestures(lv_obj_get_child(object, i));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ui_navigation_init(void)
|
||||||
|
{
|
||||||
|
lv_obj_t *screens[] = {objects.main, objects.page_2, objects.history, objects.device};
|
||||||
|
for (unsigned i = 0; i < 4; ++i) {
|
||||||
|
prepare_gestures(screens[i]);
|
||||||
|
lv_obj_clear_flag(screens[i], LV_OBJ_FLAG_GESTURE_BUBBLE);
|
||||||
|
lv_obj_add_event_cb(screens[i], screen_gesture_cb, LV_EVENT_GESTURE, NULL);
|
||||||
|
}
|
||||||
|
/* Sliders/dropdowns own their gestures; changing brightness must not navigate. */
|
||||||
|
lv_obj_clear_flag(objects.brightness, LV_OBJ_FLAG_GESTURE_BUBBLE);
|
||||||
|
lv_obj_clear_flag(objects.history_metric, LV_OBJ_FLAG_GESTURE_BUBBLE);
|
||||||
|
lv_obj_clear_flag(objects.dim_timeout, LV_OBJ_FLAG_GESTURE_BUBBLE);
|
||||||
|
ESP_LOGI("ui_navigation", "Ready: 4 pages / measurements, air, history, device");
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
/* Call once after ui_init(), with the LVGL lock held. Kept outside EEZ exports. */
|
||||||
|
void ui_navigation_init(void);
|
||||||
@@ -2,4 +2,4 @@ file(GLOB_RECURSE SRC_FILES "*.c")
|
|||||||
|
|
||||||
idf_component_register(SRCS ${SRC_FILES}
|
idf_component_register(SRCS ${SRC_FILES}
|
||||||
INCLUDE_DIRS "."
|
INCLUDE_DIRS "."
|
||||||
REQUIRES "esp_lcd" "driver" "esp_adc" "esp_lcd_jd9853" "esp_lcd_touch_axs5106" "fatfs" "nvs_flash" "lwip" "esp_wifi")
|
REQUIRES "hardware_config" "esp_lcd" "driver" "esp_adc" "esp_lcd_jd9853" "esp_lcd_touch_axs5106" "fatfs" "nvs_flash" "lwip" "esp_wifi")
|
||||||
|
|||||||
@@ -4,9 +4,11 @@
|
|||||||
#include "driver/i2c_master.h"
|
#include "driver/i2c_master.h"
|
||||||
#include "driver/gpio.h"
|
#include "driver/gpio.h"
|
||||||
|
|
||||||
#define EXAMPLE_PIN_I2C_SDA GPIO_NUM_18
|
#include "hardware_config.h"
|
||||||
#define EXAMPLE_PIN_I2C_SCL GPIO_NUM_19
|
|
||||||
#define I2C_PORT_NUM 0
|
#define EXAMPLE_PIN_I2C_SDA NANOPSX_I2C_SDA
|
||||||
|
#define EXAMPLE_PIN_I2C_SCL NANOPSX_I2C_SCL
|
||||||
|
#define I2C_PORT_NUM NANOPSX_I2C_PORT
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "bsp_touch.h"
|
#include "bsp_touch.h"
|
||||||
|
|
||||||
void bsp_touch_init(esp_lcd_touch_handle_t *touch_handle, i2c_master_bus_handle_t bus_handle, uint16_t xmax, uint16_t ymax, uint16_t rotation)
|
esp_err_t bsp_touch_init(esp_lcd_touch_handle_t *touch_handle, i2c_master_bus_handle_t bus_handle, uint16_t xmax, uint16_t ymax, uint16_t rotation)
|
||||||
{
|
{
|
||||||
static i2c_master_dev_handle_t dev_handle;
|
static i2c_master_dev_handle_t dev_handle;
|
||||||
i2c_device_config_t dev_cfg = {
|
i2c_device_config_t dev_cfg = {
|
||||||
@@ -15,7 +15,9 @@ void bsp_touch_init(esp_lcd_touch_handle_t *touch_handle, i2c_master_bus_handle_
|
|||||||
.device_address = ESP_LCD_TOUCH_IO_I2C_AXS5106_ADDRESS,
|
.device_address = ESP_LCD_TOUCH_IO_I2C_AXS5106_ADDRESS,
|
||||||
.scl_speed_hz = 400000,
|
.scl_speed_hz = 400000,
|
||||||
};
|
};
|
||||||
ESP_ERROR_CHECK(i2c_master_bus_add_device(bus_handle, &dev_cfg, &dev_handle));
|
*touch_handle = NULL;
|
||||||
|
esp_err_t err = i2c_master_bus_add_device(bus_handle, &dev_cfg, &dev_handle);
|
||||||
|
if (err != ESP_OK) return err;
|
||||||
|
|
||||||
esp_lcd_touch_config_t tp_cfg = {};
|
esp_lcd_touch_config_t tp_cfg = {};
|
||||||
tp_cfg.x_max = xmax < ymax ? xmax : ymax;
|
tp_cfg.x_max = xmax < ymax ? xmax : ymax;
|
||||||
@@ -48,5 +50,14 @@ void bsp_touch_init(esp_lcd_touch_handle_t *touch_handle, i2c_master_bus_handle_
|
|||||||
tp_cfg.flags.mirror_y = 0;
|
tp_cfg.flags.mirror_y = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ESP_ERROR_CHECK(esp_lcd_touch_new_i2c_axs5106(dev_handle, &tp_cfg, touch_handle));
|
err = esp_lcd_touch_new_i2c_axs5106(dev_handle, &tp_cfg, touch_handle);
|
||||||
|
if (err == ESP_OK) {
|
||||||
|
err = i2c_master_probe(bus_handle, dev_cfg.device_address, 100);
|
||||||
|
if (err != ESP_OK) esp_lcd_touch_del(*touch_handle);
|
||||||
|
}
|
||||||
|
if (err != ESP_OK) {
|
||||||
|
i2c_master_bus_rm_device(dev_handle);
|
||||||
|
*touch_handle = NULL;
|
||||||
|
}
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void bsp_touch_init(esp_lcd_touch_handle_t *touch_handle, i2c_master_bus_handle_t bus_handle, uint16_t xmax, uint16_t ymax, uint16_t rotation);
|
esp_err_t bsp_touch_init(esp_lcd_touch_handle_t *touch_handle, i2c_master_bus_handle_t bus_handle, uint16_t xmax, uint16_t ymax, uint16_t rotation);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
idf_component_register(INCLUDE_DIRS ".")
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
/* Central build-time hardware selection. See firmware/HARDWARE.md.
|
||||||
|
* Select sensor and board independently; no credentials belong in this file.
|
||||||
|
*/
|
||||||
|
#define NANOPSX_SENSOR_SEN54 54
|
||||||
|
#define NANOPSX_SENSOR_SEN66 66
|
||||||
|
#define NANOPSX_BOARD_C6_DISPLAY_8MB 1
|
||||||
|
#define NANOPSX_BOARD_C6_DEVKIT_8MB 2
|
||||||
|
|
||||||
|
#ifndef NANOPSX_SENSOR
|
||||||
|
#define NANOPSX_SENSOR NANOPSX_SENSOR_SEN66
|
||||||
|
#endif
|
||||||
|
#ifndef NANOPSX_BOARD
|
||||||
|
#define NANOPSX_BOARD NANOPSX_BOARD_C6_DISPLAY_8MB
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* SEN66 retains its known GPIO7/8 wiring. With a display the sole HP I2C
|
||||||
|
* controller serves touch on GPIO18/19, so the sensor uses a GPIO bus.
|
||||||
|
* SEN54 retains the existing shared hardware-bus wiring.
|
||||||
|
*/
|
||||||
|
#if NANOPSX_SENSOR == NANOPSX_SENSOR_SEN66
|
||||||
|
#define NANOPSX_SENSOR_SDA 7
|
||||||
|
#define NANOPSX_SENSOR_SCL 8
|
||||||
|
#else
|
||||||
|
#define NANOPSX_SENSOR_SDA NANOPSX_I2C_SDA
|
||||||
|
#define NANOPSX_SENSOR_SCL NANOPSX_I2C_SCL
|
||||||
|
#endif
|
||||||
|
#define NANOPSX_SENSOR_SOFT_I2C \
|
||||||
|
(NANOPSX_SENSOR_SDA != NANOPSX_I2C_SDA || NANOPSX_SENSOR_SCL != NANOPSX_I2C_SCL)
|
||||||
|
|
||||||
|
#if NANOPSX_BOARD == NANOPSX_BOARD_C6_DISPLAY_8MB
|
||||||
|
#define NANOPSX_BOARD_NAME "ESP32-C6 display / 8 MB"
|
||||||
|
#define NANOPSX_HAS_DISPLAY 1
|
||||||
|
#define NANOPSX_I2C_SDA 18
|
||||||
|
#define NANOPSX_I2C_SCL 19
|
||||||
|
#elif NANOPSX_BOARD == NANOPSX_BOARD_C6_DEVKIT_8MB
|
||||||
|
#define NANOPSX_BOARD_NAME "ESP32-C6 devkit / 8 MB"
|
||||||
|
#define NANOPSX_HAS_DISPLAY 0
|
||||||
|
#define NANOPSX_I2C_SDA 7
|
||||||
|
#define NANOPSX_I2C_SCL 8
|
||||||
|
#else
|
||||||
|
#error "Unsupported NANOPSX_BOARD: add a reviewed board profile first"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define NANOPSX_I2C_PORT 0
|
||||||
|
#define NANOPSX_FLASH_BYTES 8388608
|
||||||
|
|
||||||
|
#if NANOPSX_SENSOR == NANOPSX_SENSOR_SEN54
|
||||||
|
#define NANOPSX_SENSOR_NAME "SEN54"
|
||||||
|
#define NANOPSX_SENSOR_ADDRESS 0x69
|
||||||
|
#define NANOPSX_SENSOR_I2C_HZ 400000
|
||||||
|
#elif NANOPSX_SENSOR == NANOPSX_SENSOR_SEN66
|
||||||
|
#define NANOPSX_SENSOR_NAME "SEN66"
|
||||||
|
#define NANOPSX_SENSOR_ADDRESS 0x6b
|
||||||
|
#define NANOPSX_SENSOR_I2C_HZ 100000
|
||||||
|
#else
|
||||||
|
#error "Unsupported NANOPSX_SENSOR: use SEN54 or SEN66"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Board profiles describe wiring/peripherals, not a replacement for the
|
||||||
|
* PlatformIO chip, SDK configuration and partition-table selection.
|
||||||
|
*/
|
||||||
|
#ifdef ESP_PLATFORM
|
||||||
|
#include "sdkconfig.h"
|
||||||
|
#if !CONFIG_IDF_TARGET_ESP32C6
|
||||||
|
#error "These board profiles require ESP32-C6"
|
||||||
|
#endif
|
||||||
|
#if !CONFIG_ESPTOOLPY_FLASHSIZE_8MB
|
||||||
|
#error "These board profiles require the 8 MB SDK/partition configuration"
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
idf_component_register(
|
idf_component_register(
|
||||||
SRCS
|
SRCS
|
||||||
"src/net_influx.c"
|
"src/net_influx.c"
|
||||||
|
"src/influx_batch.c"
|
||||||
INCLUDE_DIRS
|
INCLUDE_DIRS
|
||||||
"include"
|
"include"
|
||||||
REQUIRES
|
REQUIRES
|
||||||
@@ -10,5 +11,6 @@ idf_component_register(
|
|||||||
storage
|
storage
|
||||||
esp_http_client
|
esp_http_client
|
||||||
sys_status
|
sys_status
|
||||||
|
esp_timer
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "esp_err.h"
|
#include "esp_err.h"
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
@@ -28,15 +30,15 @@ typedef struct {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
const char* measurement; // z.B. "air"
|
const char* measurement; // z.B. "air"
|
||||||
const char* tags; // z.B. "device=xyz,location=lab" (optional, kann NULL sein)
|
const char* tags; // z.B. "device=xyz,location=lab" (optional, kann NULL sein)
|
||||||
uint64_t ts_ms; // 0 => server time
|
uint64_t ts_ms; // 0 => acquisition time aligned to the server HTTP Date (async API)
|
||||||
const net_influx_field_t* fields;
|
const net_influx_field_t* fields;
|
||||||
size_t num_fields;
|
size_t num_fields;
|
||||||
} net_influx_point_t;
|
} net_influx_point_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
// Task/Queue
|
// Task/Queue
|
||||||
uint16_t queue_len; // z.B. 16
|
uint16_t queue_len; // Standard 32
|
||||||
uint32_t task_stack; // z.B. 6144
|
uint32_t task_stack; // Standard 8192
|
||||||
UBaseType_t task_prio; // z.B. 5
|
UBaseType_t task_prio; // z.B. 5
|
||||||
|
|
||||||
// Init/Retry/Backoff
|
// Init/Retry/Backoff
|
||||||
@@ -68,7 +70,9 @@ esp_err_t net_influx_init_from_nvs(const char* ca_cert_pem_opt, int timeout_ms);
|
|||||||
esp_err_t net_influx_start(const net_influx_runtime_cfg_t* rt);
|
esp_err_t net_influx_start(const net_influx_runtime_cfg_t* rt);
|
||||||
void net_influx_stop(void);
|
void net_influx_stop(void);
|
||||||
|
|
||||||
// Asynchron: kopiert point+felder intern und queued sie.
|
// Asynchron: serialisiert den Punkt sofort in eine feste RAM-Warteschlange.
|
||||||
|
// 1-Hz-Werte werden bis zu 10 Punkte / 10 s gesammelt, mit eigenen Zeitstempeln.
|
||||||
|
// Ohne gültige Serverzeit werden sichere Einzelpunkt-Schreibvorgänge verwendet.
|
||||||
// Rückgabe:
|
// Rückgabe:
|
||||||
// - ESP_OK: queued
|
// - ESP_OK: queued
|
||||||
// - ESP_ERR_NO_MEM / ESP_ERR_INVALID_ARG / ESP_FAIL: sonst
|
// - ESP_ERR_NO_MEM / ESP_ERR_INVALID_ARG / ESP_FAIL: sonst
|
||||||
|
|||||||
@@ -0,0 +1,87 @@
|
|||||||
|
#include "influx_batch.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
static bool leap(unsigned year) { return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0); }
|
||||||
|
|
||||||
|
bool influx_parse_http_date(const char *date, uint64_t *epoch_ms)
|
||||||
|
{
|
||||||
|
if (!date || !epoch_ms || strlen(date) != 29) return false;
|
||||||
|
char weekday[4], month[4], zone[4], extra;
|
||||||
|
unsigned day, year, hour, minute, second;
|
||||||
|
if (sscanf(date, "%3s, %u %3s %u %u:%u:%u %3s%c", weekday, &day, month,
|
||||||
|
&year, &hour, &minute, &second, zone, &extra) != 8) return false;
|
||||||
|
if (strcmp(zone, "GMT") || year < 2020 || year > 2261 || hour > 23 || minute > 59 || second > 59) return false;
|
||||||
|
const char *months[] = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
|
||||||
|
const unsigned days[] = {31,28,31,30,31,30,31,31,30,31,30,31};
|
||||||
|
unsigned m = 0;
|
||||||
|
while (m < 12 && strcmp(month, months[m])) ++m;
|
||||||
|
if (m == 12 || day == 0 || day > days[m] + (m == 1 && leap(year))) return false;
|
||||||
|
uint64_t total = 0;
|
||||||
|
for (unsigned y = 1970; y < year; ++y) total += leap(y) ? 366 : 365;
|
||||||
|
for (unsigned i = 0; i < m; ++i) total += days[i] + (i == 1 && leap(year));
|
||||||
|
total += day - 1;
|
||||||
|
*epoch_ms = ((total * 24 + hour) * 60 * 60 + minute * 60 + second) * 1000;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint64_t clock_at(const influx_clock_t *clock, uint64_t mono_ms)
|
||||||
|
{
|
||||||
|
return mono_ms >= clock->monotonic_ms ? clock->epoch_ms + mono_ms - clock->monotonic_ms :
|
||||||
|
clock->epoch_ms - (clock->monotonic_ms - mono_ms);
|
||||||
|
}
|
||||||
|
|
||||||
|
void influx_clock_observe(influx_clock_t *clock, const char *date, uint64_t mono_ms)
|
||||||
|
{
|
||||||
|
uint64_t server_ms;
|
||||||
|
if (!influx_parse_http_date(date, &server_ms)) return;
|
||||||
|
/* HTTP Date has one-second resolution. Use its midpoint; no external NTP needed. */
|
||||||
|
if (!clock->ready) {
|
||||||
|
clock->epoch_ms = server_ms + 500;
|
||||||
|
clock->monotonic_ms = mono_ms;
|
||||||
|
clock->ready = true;
|
||||||
|
} else {
|
||||||
|
/* Correct oscillator drift gently; header rounding must not jitter every batch. */
|
||||||
|
int64_t delta = (int64_t)(server_ms + 500) - (int64_t)clock_at(clock, mono_ms);
|
||||||
|
if (delta > 1500) clock->epoch_ms += 50;
|
||||||
|
else if (delta < -1500) clock->epoch_ms -= 50;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool influx_clock_timestamp(influx_clock_t *clock, uint64_t acquired_ms, uint64_t *timestamp)
|
||||||
|
{
|
||||||
|
if (!clock->ready) return false;
|
||||||
|
uint64_t value = clock_at(clock, acquired_ms);
|
||||||
|
if (value <= clock->last_timestamp_ms) value = clock->last_timestamp_ms + 1;
|
||||||
|
clock->last_timestamp_ms = value;
|
||||||
|
*timestamp = value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool influx_batch_add(influx_batch_t *batch, const char *line, uint64_t now_ms)
|
||||||
|
{
|
||||||
|
size_t length = strlen(line), separator = batch->points ? 1 : 0;
|
||||||
|
if (!length || batch->points >= INFLUX_BATCH_POINTS ||
|
||||||
|
length + separator >= sizeof(batch->body) - batch->bytes) return false;
|
||||||
|
if (!batch->points) batch->started_ms = now_ms;
|
||||||
|
if (separator) batch->body[batch->bytes++] = '\n';
|
||||||
|
memcpy(batch->body + batch->bytes, line, length + 1);
|
||||||
|
batch->bytes += length;
|
||||||
|
const char *last_space = strrchr(line, ' ');
|
||||||
|
if (last_space) {
|
||||||
|
char *end;
|
||||||
|
uint64_t timestamp = strtoull(last_space + 1, &end, 10);
|
||||||
|
if (end != last_space + 1 && *end == 0) {
|
||||||
|
if (!batch->points) batch->first_timestamp_ms = timestamp;
|
||||||
|
batch->last_timestamp_ms = timestamp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
++batch->points;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool influx_batch_due(const influx_batch_t *batch, uint64_t now_ms)
|
||||||
|
{
|
||||||
|
return batch->points && (batch->points >= INFLUX_BATCH_POINTS || now_ms - batch->started_ms >= INFLUX_FLUSH_MS);
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#define INFLUX_LINE_CAP 512
|
||||||
|
#define INFLUX_BATCH_CAP 4096
|
||||||
|
#define INFLUX_BATCH_POINTS 10
|
||||||
|
#define INFLUX_FLUSH_MS 10000
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char body[INFLUX_BATCH_CAP];
|
||||||
|
size_t bytes;
|
||||||
|
unsigned points;
|
||||||
|
uint64_t started_ms;
|
||||||
|
uint64_t first_timestamp_ms, last_timestamp_ms;
|
||||||
|
} influx_batch_t;
|
||||||
|
typedef struct {
|
||||||
|
bool ready;
|
||||||
|
uint64_t epoch_ms, monotonic_ms, last_timestamp_ms;
|
||||||
|
} influx_clock_t;
|
||||||
|
|
||||||
|
bool influx_parse_http_date(const char *date, uint64_t *epoch_ms);
|
||||||
|
void influx_clock_observe(influx_clock_t *clock, const char *date, uint64_t mono_ms);
|
||||||
|
bool influx_clock_timestamp(influx_clock_t *clock, uint64_t acquired_ms, uint64_t *timestamp);
|
||||||
|
bool influx_batch_add(influx_batch_t *batch, const char *line, uint64_t now_ms);
|
||||||
|
bool influx_batch_due(const influx_batch_t *batch, uint64_t now_ms);
|
||||||
@@ -6,8 +6,13 @@
|
|||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
#include "freertos/queue.h"
|
#include "freertos/queue.h"
|
||||||
|
#include "freertos/semphr.h"
|
||||||
|
#include "esp_timer.h"
|
||||||
|
#include "influx_batch.h"
|
||||||
|
#include <stdatomic.h>
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <strings.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
@@ -50,11 +55,11 @@ typedef struct {
|
|||||||
|
|
||||||
static QueueHandle_t s_q = NULL;
|
static QueueHandle_t s_q = NULL;
|
||||||
static TaskHandle_t s_task = NULL;
|
static TaskHandle_t s_task = NULL;
|
||||||
static bool s_run = false;
|
static atomic_bool s_run = false;
|
||||||
|
|
||||||
static net_influx_runtime_cfg_i_t s_rt = {
|
static net_influx_runtime_cfg_i_t s_rt = {
|
||||||
.queue_len = 16,
|
.queue_len = 32,
|
||||||
.task_stack = 6144,
|
.task_stack = 8192,
|
||||||
.task_prio = 5,
|
.task_prio = 5,
|
||||||
.init_retry_ms = 1000,
|
.init_retry_ms = 1000,
|
||||||
.backoff_start_ms = 2000,
|
.backoff_start_ms = 2000,
|
||||||
@@ -131,28 +136,6 @@ static bool parse_base_url(const char* in, base_parts_t* out) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mask_token(const char* token, char* out, size_t out_len) {
|
|
||||||
if (!token || !out || out_len < 8) return;
|
|
||||||
size_t n = strlen(token);
|
|
||||||
if (n <= 8) {
|
|
||||||
snprintf(out, out_len, "****");
|
|
||||||
} else {
|
|
||||||
size_t keep = 4;
|
|
||||||
snprintf(out, out_len, "%.*s****%.*s",
|
|
||||||
(int)keep, token,
|
|
||||||
(int)keep, token + n - keep);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static char* dup0(const char* str) {
|
|
||||||
if (!str) return NULL;
|
|
||||||
size_t n = strlen(str) + 1;
|
|
||||||
char* p = (char*)malloc(n);
|
|
||||||
if (!p) return NULL;
|
|
||||||
memcpy(p, str, n);
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Minimal escaping für measurement/key: spaces/commas */
|
/* Minimal escaping für measurement/key: spaces/commas */
|
||||||
static size_t esc_copy(char* dst, size_t cap, const char* src, bool escape_equals) {
|
static size_t esc_copy(char* dst, size_t cap, const char* src, bool escape_equals) {
|
||||||
size_t pos = 0;
|
size_t pos = 0;
|
||||||
@@ -164,11 +147,11 @@ static size_t esc_copy(char* dst, size_t cap, const char* src, bool escape_equal
|
|||||||
char c = *p;
|
char c = *p;
|
||||||
bool esc = (c == ' ' || c == ',' || (escape_equals && c == '='));
|
bool esc = (c == ' ' || c == ',' || (escape_equals && c == '='));
|
||||||
if (esc) {
|
if (esc) {
|
||||||
if (pos + 2 >= cap) break;
|
if (pos + 2 >= cap) { dst[0] = 0; return SIZE_MAX; }
|
||||||
dst[pos++] = '\\';
|
dst[pos++] = '\\';
|
||||||
dst[pos++] = c;
|
dst[pos++] = c;
|
||||||
} else {
|
} else {
|
||||||
if (pos + 1 >= cap) break;
|
if (pos + 1 >= cap) { dst[0] = 0; return SIZE_MAX; }
|
||||||
dst[pos++] = c;
|
dst[pos++] = c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -176,122 +159,139 @@ static size_t esc_copy(char* dst, size_t cap, const char* src, bool escape_equal
|
|||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------- HTTP Event Handler (IDF-kompatibel) ---------------- */
|
/* Persistent HTTP client; shared with the optional synchronous API. */
|
||||||
static esp_err_t http_evt(esp_http_client_event_t* evt) {
|
static esp_http_client_handle_t s_http;
|
||||||
switch (evt->event_id) {
|
static SemaphoreHandle_t s_http_lock;
|
||||||
case HTTP_EVENT_ERROR: ESP_LOGE(TAG, "HTTP_EVENT_ERROR"); break;
|
static influx_clock_t s_clock;
|
||||||
case HTTP_EVENT_ON_CONNECTED: ESP_LOGI(TAG, "HTTP_EVENT_ON_CONNECTED"); break;
|
static char s_write_url[640];
|
||||||
case HTTP_EVENT_HEADER_SENT: ESP_LOGD(TAG, "HTTP_EVENT_HEADER_SENT"); break;
|
static atomic_uint s_dropped;
|
||||||
case HTTP_EVENT_ON_HEADER:
|
static uint64_t monotonic_ms(void) { return (uint64_t)(esp_timer_get_time() / 1000); }
|
||||||
ESP_LOGD(TAG, "HDR: %s: %s",
|
|
||||||
evt->header_key ? evt->header_key : "(null)",
|
static void http_close(void)
|
||||||
evt->header_value ? evt->header_value : "(null)");
|
{
|
||||||
break;
|
if (s_http) esp_http_client_cleanup(s_http);
|
||||||
case HTTP_EVENT_ON_DATA: ESP_LOGV(TAG, "DATA chunk len=%d", evt->data_len); break;
|
s_http = NULL;
|
||||||
case HTTP_EVENT_ON_FINISH: ESP_LOGD(TAG, "HTTP_EVENT_ON_FINISH"); break;
|
}
|
||||||
case HTTP_EVENT_DISCONNECTED: ESP_LOGW(TAG, "HTTP_EVENT_DISCONNECTED"); break;
|
|
||||||
default: break;
|
static esp_err_t http_evt(esp_http_client_event_t *event)
|
||||||
|
{
|
||||||
|
if (event->event_id == HTTP_EVENT_ON_CONNECTED) ESP_LOGI(TAG, "HTTP connection established.");
|
||||||
|
if (event->event_id == HTTP_EVENT_ON_HEADER && event->header_key && event->header_value &&
|
||||||
|
strcasecmp(event->header_key, "Date") == 0) {
|
||||||
|
bool ready = s_clock.ready;
|
||||||
|
influx_clock_observe(&s_clock, event->header_value, monotonic_ms());
|
||||||
|
if (!ready && s_clock.ready) ESP_LOGI(TAG, "Measurement clock aligned to server HTTP Date.");
|
||||||
}
|
}
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------- Internal: HTTP send "line protocol" ---------------- */
|
static bool encode_query(char *out, size_t cap, const char *text)
|
||||||
static esp_err_t net_influx_write_line(const char* line) {
|
{
|
||||||
bool ok = false;
|
static const char hex[] = "0123456789ABCDEF";
|
||||||
|
size_t n = 0;
|
||||||
if (!line || !*line) {
|
for (const unsigned char *p = (const unsigned char *)text; *p; ++p) {
|
||||||
sys_status_set_influx_ok(false);
|
bool plain = isalnum(*p) || *p == '-' || *p == '_' || *p == '.' || *p == '~';
|
||||||
return ESP_ERR_INVALID_ARG;
|
size_t need = plain ? 1 : 3;
|
||||||
}
|
if (n + need >= cap) return false;
|
||||||
if (s.url_base[0] == 0 || s.org[0] == 0 || s.bucket[0] == 0 || s.token[0] == 0) {
|
if (plain) out[n++] = *p;
|
||||||
sys_status_set_influx_ok(false);
|
else { out[n++] = '%'; out[n++] = hex[*p >> 4]; out[n++] = hex[*p & 15]; }
|
||||||
return ESP_ERR_INVALID_STATE;
|
|
||||||
}
|
}
|
||||||
|
out[n] = 0;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Base parse → host/port/tls
|
/* Caller holds s_http_lock. URLs/headers are configured once per connection. */
|
||||||
base_parts_t bp;
|
static esp_err_t http_prepare(void)
|
||||||
if (!parse_base_url(s.url_base, &bp)) {
|
{
|
||||||
ESP_LOGE(TAG, "Base-URL ungueltig: \"%s\"", s.url_base);
|
if (s_http) return ESP_OK;
|
||||||
sys_status_set_influx_ok(false);
|
if (!s.url_base[0] || !s.org[0] || !s.bucket[0] || !s.token[0]) return ESP_ERR_INVALID_STATE;
|
||||||
return ESP_ERR_INVALID_ARG;
|
base_parts_t base;
|
||||||
}
|
if (!parse_base_url(s.url_base, &base)) return ESP_ERR_INVALID_ARG;
|
||||||
if (s.use_tls) bp.tls = true;
|
if (s.use_tls) base.tls = true;
|
||||||
int port = (bp.port > 0) ? bp.port : (bp.tls ? 443 : 8086);
|
int port = base.port > 0 ? base.port : base.tls ? 443 : 8086;
|
||||||
|
char org[192], bucket[192];
|
||||||
// Pfad
|
if (!encode_query(org, sizeof(org), s.org) || !encode_query(bucket, sizeof(bucket), s.bucket)) return ESP_ERR_INVALID_SIZE;
|
||||||
char path[192];
|
int length = snprintf(s_write_url, sizeof(s_write_url), "%s://%s:%d/api/v2/write?org=%s&bucket=%s&precision=ms",
|
||||||
snprintf(path, sizeof(path), "/api/v2/write?org=%s&bucket=%s&precision=ms", s.org, s.bucket);
|
base.tls ? "https" : "http", base.host, port, org, bucket);
|
||||||
|
if (length < 0 || length >= sizeof(s_write_url)) return ESP_ERR_INVALID_SIZE;
|
||||||
ESP_LOGI(TAG, "HTTP cfg: host=%s, port=%d, path=%s, tls=%d", bp.host, port, path, (int)bp.tls);
|
|
||||||
ESP_LOGD(TAG, "Line: %s", line);
|
|
||||||
|
|
||||||
esp_http_client_config_t cfg = {
|
esp_http_client_config_t cfg = {
|
||||||
.host = bp.host,
|
.url = s_write_url,
|
||||||
.port = port,
|
|
||||||
.path = path,
|
|
||||||
.timeout_ms = s.http_timeout_ms,
|
.timeout_ms = s.http_timeout_ms,
|
||||||
.cert_pem = bp.tls ? s.ca_cert_pem : NULL,
|
.cert_pem = base.tls ? s.ca_cert_pem : NULL,
|
||||||
.method = HTTP_METHOD_POST,
|
.method = HTTP_METHOD_POST,
|
||||||
.event_handler = http_evt,
|
.event_handler = http_evt,
|
||||||
.transport_type = bp.tls ? HTTP_TRANSPORT_OVER_SSL : HTTP_TRANSPORT_OVER_TCP,
|
.transport_type = base.tls ? HTTP_TRANSPORT_OVER_SSL : HTTP_TRANSPORT_OVER_TCP,
|
||||||
.disable_auto_redirect = false,
|
.disable_auto_redirect = true,
|
||||||
|
.keep_alive_enable = true,
|
||||||
|
.keep_alive_idle = 30,
|
||||||
|
.keep_alive_interval = 10,
|
||||||
|
.keep_alive_count = 3,
|
||||||
};
|
};
|
||||||
|
s_http = esp_http_client_init(&cfg);
|
||||||
esp_http_client_handle_t h = esp_http_client_init(&cfg);
|
if (!s_http) return ESP_ERR_NO_MEM;
|
||||||
if (!h) {
|
char auth[sizeof(s.token) + 7];
|
||||||
ESP_LOGE(TAG, "http_client_init: no mem");
|
snprintf(auth, sizeof(auth), "Token %s", s.token);
|
||||||
sys_status_set_influx_ok(false);
|
esp_err_t err = esp_http_client_set_header(s_http, "Authorization", auth);
|
||||||
return ESP_ERR_NO_MEM;
|
if (err == ESP_OK) err = esp_http_client_set_header(s_http, "Content-Type", "text/plain; charset=utf-8");
|
||||||
}
|
if (err != ESP_OK) { http_close(); return err; }
|
||||||
|
ESP_LOGI(TAG, "HTTP client ready / persistent connections enabled.");
|
||||||
// Header
|
return ESP_OK;
|
||||||
size_t auth_len = strlen(s.token) + 7; // "Token " + '\0'
|
|
||||||
char* auth = (char*)malloc(auth_len);
|
|
||||||
if (!auth) {
|
|
||||||
ESP_LOGE(TAG, "malloc auth header: no mem");
|
|
||||||
esp_http_client_cleanup(h);
|
|
||||||
sys_status_set_influx_ok(false);
|
|
||||||
return ESP_ERR_NO_MEM;
|
|
||||||
}
|
|
||||||
snprintf(auth, auth_len, "Token %s", s.token);
|
|
||||||
esp_http_client_set_header(h, "Authorization", auth);
|
|
||||||
free(auth);
|
|
||||||
|
|
||||||
esp_http_client_set_header(h, "Content-Type", "text/plain; charset=utf-8");
|
|
||||||
|
|
||||||
esp_err_t err = esp_http_client_set_post_field(h, line, (int)strlen(line));
|
|
||||||
if (err != ESP_OK) {
|
|
||||||
ESP_LOGE(TAG, "set_post_field: %s", esp_err_to_name(err));
|
|
||||||
esp_http_client_cleanup(h);
|
|
||||||
sys_status_set_influx_ok(false);
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
err = esp_http_client_perform(h);
|
|
||||||
|
|
||||||
int status = -1;
|
|
||||||
if (err == ESP_OK) {
|
|
||||||
status = esp_http_client_get_status_code(h);
|
|
||||||
int64_t cl = esp_http_client_get_content_length(h);
|
|
||||||
ESP_LOGI(TAG, "HTTP status=%d, content_length=%lld", status, (long long)cl);
|
|
||||||
|
|
||||||
if (status != 204) {
|
|
||||||
char resp[256] = {0};
|
|
||||||
int n = esp_http_client_read_response(h, resp, sizeof(resp)-1);
|
|
||||||
if (n > 0) ESP_LOGW(TAG, "Resp(%d): %.*s", status, n, resp);
|
|
||||||
else ESP_LOGW(TAG, "Resp(%d): <kein Body>", status);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ESP_LOGE(TAG, "perform: %s", esp_err_to_name(err));
|
|
||||||
}
|
|
||||||
|
|
||||||
esp_http_client_cleanup(h);
|
|
||||||
|
|
||||||
ok = (err == ESP_OK && status == 204);
|
|
||||||
sys_status_set_influx_ok(ok);
|
|
||||||
return ok ? ESP_OK : ESP_FAIL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* One read-only request bootstraps the private measurement clock, even without Internet/NTP. */
|
||||||
|
static void clock_bootstrap(void)
|
||||||
|
{
|
||||||
|
xSemaphoreTake(s_http_lock, portMAX_DELAY);
|
||||||
|
if (!s_clock.ready && http_prepare() == ESP_OK) {
|
||||||
|
char health_url[160];
|
||||||
|
base_parts_t base;
|
||||||
|
if (parse_base_url(s.url_base, &base)) {
|
||||||
|
if (s.use_tls) base.tls = true;
|
||||||
|
snprintf(health_url, sizeof(health_url), "%s://%s:%d/health", base.tls ? "https" : "http",
|
||||||
|
base.host, base.port > 0 ? base.port : base.tls ? 443 : 8086);
|
||||||
|
esp_http_client_set_url(s_http, health_url);
|
||||||
|
esp_http_client_set_method(s_http, HTTP_METHOD_GET);
|
||||||
|
esp_http_client_set_post_field(s_http, NULL, 0);
|
||||||
|
esp_err_t err = esp_http_client_perform(s_http);
|
||||||
|
if (err != ESP_OK) http_close();
|
||||||
|
else {
|
||||||
|
esp_http_client_set_url(s_http, s_write_url);
|
||||||
|
esp_http_client_set_method(s_http, HTTP_METHOD_POST);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!s_clock.ready) ESP_LOGW(TAG, "No server Date available; safe single-point fallback.");
|
||||||
|
}
|
||||||
|
xSemaphoreGive(s_http_lock);
|
||||||
|
}
|
||||||
|
|
||||||
|
static esp_err_t net_influx_write_payload(const char *body, unsigned points, int *status_out)
|
||||||
|
{
|
||||||
|
if (status_out) *status_out = 0;
|
||||||
|
if (!body || !*body || !s_http_lock) return ESP_ERR_INVALID_ARG;
|
||||||
|
xSemaphoreTake(s_http_lock, portMAX_DELAY);
|
||||||
|
int status = 0;
|
||||||
|
esp_err_t err = http_prepare();
|
||||||
|
if (err == ESP_OK) err = esp_http_client_set_post_field(s_http, body, (int)strlen(body));
|
||||||
|
if (err == ESP_OK) err = esp_http_client_perform(s_http);
|
||||||
|
if (err == ESP_OK) status = esp_http_client_get_status_code(s_http);
|
||||||
|
bool ok = err == ESP_OK && status == 204;
|
||||||
|
if (ok) {
|
||||||
|
ESP_LOGI(TAG, "HTTP status=204, points=%u, bytes=%u", points, (unsigned)strlen(body));
|
||||||
|
sys_status_record_influx_success();
|
||||||
|
} else {
|
||||||
|
ESP_LOGW(TAG, "Write failed: HTTP=%d error=%s points=%u", status, esp_err_to_name(err), points);
|
||||||
|
http_close();
|
||||||
|
}
|
||||||
|
/* Do not retain a pointer to the caller's temporary line/batch buffer. */
|
||||||
|
if (s_http) esp_http_client_set_post_field(s_http, NULL, 0);
|
||||||
|
sys_status_set_influx_ok(ok);
|
||||||
|
if (status_out) *status_out = status;
|
||||||
|
xSemaphoreGive(s_http_lock);
|
||||||
|
return ok ? ESP_OK : err != ESP_OK ? err : ESP_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static esp_err_t net_influx_write_line(const char *line) { return net_influx_write_payload(line, 1, NULL); }
|
||||||
|
|
||||||
/* ---------------- Generic Point/Fields → Line Protocol ---------------- */
|
/* ---------------- Generic Point/Fields → Line Protocol ---------------- */
|
||||||
static bool field_is_valid(const net_influx_field_t* f) {
|
static bool field_is_valid(const net_influx_field_t* f) {
|
||||||
if (!f || !f->key || !*f->key) return false;
|
if (!f || !f->key || !*f->key) return false;
|
||||||
@@ -305,11 +305,18 @@ static esp_err_t build_line_protocol(const net_influx_point_t* p, char* out, siz
|
|||||||
return ESP_ERR_INVALID_ARG;
|
return ESP_ERR_INVALID_ARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (strpbrk(p->measurement, "\r\n") || (p->tags && strpbrk(p->tags, "\r\n"))) return ESP_ERR_INVALID_ARG;
|
||||||
|
for (size_t i = 0; i < p->num_fields; ++i) {
|
||||||
|
const net_influx_field_t *field = &p->fields[i];
|
||||||
|
if ((field->key && strpbrk(field->key, "\r\n")) ||
|
||||||
|
(field->type == NET_INFLUX_F_STRING && field->v.s && strpbrk(field->v.s, "\r\n")))
|
||||||
|
return ESP_ERR_INVALID_ARG;
|
||||||
|
}
|
||||||
size_t off = 0;
|
size_t off = 0;
|
||||||
|
|
||||||
// measurement escaped (space/comma)
|
// measurement escaped (space/comma)
|
||||||
char meas[96];
|
char meas[96];
|
||||||
esc_copy(meas, sizeof(meas), p->measurement, false);
|
if (esc_copy(meas, sizeof(meas), p->measurement, false) == SIZE_MAX) return ESP_ERR_INVALID_SIZE;
|
||||||
off += snprintf(out + off, out_cap - off, "%s", meas);
|
off += snprintf(out + off, out_cap - off, "%s", meas);
|
||||||
if (off >= out_cap) return ESP_FAIL;
|
if (off >= out_cap) return ESP_FAIL;
|
||||||
|
|
||||||
@@ -329,7 +336,7 @@ static esp_err_t build_line_protocol(const net_influx_point_t* p, char* out, siz
|
|||||||
if (!field_is_valid(f)) continue;
|
if (!field_is_valid(f)) continue;
|
||||||
|
|
||||||
char key[64];
|
char key[64];
|
||||||
esc_copy(key, sizeof(key), f->key, false);
|
if (esc_copy(key, sizeof(key), f->key, true) == SIZE_MAX) return ESP_ERR_INVALID_SIZE;
|
||||||
|
|
||||||
if (!first) {
|
if (!first) {
|
||||||
off += snprintf(out + off, out_cap - off, ",");
|
off += snprintf(out + off, out_cap - off, ",");
|
||||||
@@ -349,7 +356,7 @@ static esp_err_t build_line_protocol(const net_influx_point_t* p, char* out, siz
|
|||||||
off += snprintf(out + off, out_cap - off, "%s=%lldi", key, (long long)f->v.i);
|
off += snprintf(out + off, out_cap - off, "%s=%lldi", key, (long long)f->v.i);
|
||||||
break;
|
break;
|
||||||
case NET_INFLUX_F_UINT:
|
case NET_INFLUX_F_UINT:
|
||||||
off += snprintf(out + off, out_cap - off, "%s=%llui", key, (unsigned long long)f->v.u);
|
off += snprintf(out + off, out_cap - off, "%s=%lluu", key, (unsigned long long)f->v.u);
|
||||||
break;
|
break;
|
||||||
case NET_INFLUX_F_BOOL:
|
case NET_INFLUX_F_BOOL:
|
||||||
off += snprintf(out + off, out_cap - off, "%s=%s", key, f->v.b ? "true" : "false");
|
off += snprintf(out + off, out_cap - off, "%s=%s", key, f->v.b ? "true" : "false");
|
||||||
@@ -386,124 +393,116 @@ static esp_err_t build_line_protocol(const net_influx_point_t* p, char* out, siz
|
|||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------- Async Queue Message (deep copy) ---------------- */
|
/* Fixed-size, pre-serialized queue entries: no per-field heap allocation. */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char* measurement;
|
char line[INFLUX_LINE_CAP];
|
||||||
char* tags; // optional
|
uint64_t acquired_ms;
|
||||||
uint64_t ts_ms;
|
bool timestamped;
|
||||||
|
|
||||||
size_t num_fields;
|
|
||||||
net_influx_field_t* fields; // deep-copied array; keys and string-values are duplicated
|
|
||||||
} influx_msg_t;
|
} influx_msg_t;
|
||||||
|
|
||||||
static void free_msg(influx_msg_t* m) {
|
static bool wait_running(uint32_t ms)
|
||||||
if (!m) return;
|
{
|
||||||
if (m->measurement) free(m->measurement);
|
while (s_run && ms) {
|
||||||
if (m->tags) free(m->tags);
|
uint32_t step = ms > 100 ? 100 : ms;
|
||||||
if (m->fields) {
|
vTaskDelay(pdMS_TO_TICKS(step));
|
||||||
for (size_t i = 0; i < m->num_fields; ++i) {
|
ms -= step;
|
||||||
if (m->fields[i].type == NET_INFLUX_F_STRING && m->fields[i].v.s) {
|
|
||||||
free((void*)m->fields[i].v.s);
|
|
||||||
}
|
}
|
||||||
if (m->fields[i].key) free((void*)m->fields[i].key);
|
return s_run;
|
||||||
}
|
|
||||||
free(m->fields);
|
|
||||||
}
|
|
||||||
memset(m, 0, sizeof(*m));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------- Init/Backoff (im Worker) ---------------- */
|
static bool influx_init_blocking(void)
|
||||||
static bool influx_init_blocking(void) {
|
{
|
||||||
while (s_run) {
|
while (s_run) {
|
||||||
if (net_influx_init_from_nvs(s_rt.ca_cert_pem_opt, s_rt.http_timeout_ms) == ESP_OK) {
|
if (net_influx_init_from_nvs(s_rt.ca_cert_pem_opt, s_rt.http_timeout_ms) == ESP_OK) return true;
|
||||||
ESP_LOGI(TAG, "Influx ready (from NVS).");
|
ESP_LOGW(TAG, "Influx configuration unavailable; retrying.");
|
||||||
return true;
|
wait_running(s_rt.init_retry_ms);
|
||||||
}
|
|
||||||
ESP_LOGW(TAG, "Influx nicht bereit – retry in %u ms", (unsigned)s_rt.init_retry_ms);
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(s_rt.init_retry_ms));
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool influx_reinit_with_backoff(uint32_t* backoff_ms) {
|
static void net_influx_worker(void *arg)
|
||||||
if (!backoff_ms) return false;
|
{
|
||||||
|
|
||||||
uint32_t wait_ms = (*backoff_ms == 0) ? s_rt.backoff_start_ms : *backoff_ms;
|
|
||||||
ESP_LOGW(TAG, "Re-Init Influx in %u ms", (unsigned)wait_ms);
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(wait_ms));
|
|
||||||
|
|
||||||
bool ok = (net_influx_init_from_nvs(s_rt.ca_cert_pem_opt, s_rt.http_timeout_ms) == ESP_OK);
|
|
||||||
if (ok) {
|
|
||||||
ESP_LOGI(TAG, "Influx Re-Init OK");
|
|
||||||
*backoff_ms = s_rt.backoff_start_ms;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (wait_ms < s_rt.backoff_max_ms) {
|
|
||||||
uint32_t next = wait_ms * 2;
|
|
||||||
*backoff_ms = (next > s_rt.backoff_max_ms) ? s_rt.backoff_max_ms : next;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ---------------- Worker Task ---------------- */
|
|
||||||
static void net_influx_worker(void* arg) {
|
|
||||||
(void)arg;
|
(void)arg;
|
||||||
ESP_LOGI(TAG, "Influx worker started.");
|
influx_batch_t *batch = calloc(1, sizeof(*batch));
|
||||||
|
influx_msg_t carry = {0};
|
||||||
if (!influx_init_blocking()) {
|
bool have_carry = false, batch_timestamped = true;
|
||||||
ESP_LOGE(TAG, "Worker beendet (Influx init fatal).");
|
unsigned failures = 0;
|
||||||
vTaskDelete(NULL);
|
uint32_t backoff = s_rt.backoff_start_ms;
|
||||||
return;
|
if (!batch) { ESP_LOGE(TAG, "Cannot allocate Influx batch buffer."); goto done; }
|
||||||
}
|
if (!influx_init_blocking()) goto done;
|
||||||
|
clock_bootstrap();
|
||||||
int fail_count = 0;
|
ESP_LOGI(TAG, "Influx batching ready: up to %u points / %u ms, queue=%u", INFLUX_BATCH_POINTS, INFLUX_FLUSH_MS, s_rt.queue_len);
|
||||||
uint32_t backoff_ms = s_rt.backoff_start_ms;
|
|
||||||
|
|
||||||
while (s_run) {
|
while (s_run) {
|
||||||
influx_msg_t msg = {0};
|
bool flush = influx_batch_due(batch, monotonic_ms());
|
||||||
if (xQueueReceive(s_q, &msg, portMAX_DELAY) != pdTRUE) continue;
|
if (!flush) {
|
||||||
|
influx_msg_t msg;
|
||||||
net_influx_point_t p = {
|
bool received = have_carry;
|
||||||
.measurement = msg.measurement,
|
if (received) { msg = carry; have_carry = false; }
|
||||||
.tags = msg.tags,
|
else received = xQueueReceive(s_q, &msg, pdMS_TO_TICKS(100)) == pdTRUE;
|
||||||
.ts_ms = msg.ts_ms,
|
if (!received) continue;
|
||||||
.fields = msg.fields,
|
if (!msg.timestamped) {
|
||||||
.num_fields = msg.num_fields,
|
uint64_t timestamp;
|
||||||
};
|
xSemaphoreTake(s_http_lock, portMAX_DELAY);
|
||||||
|
bool known = influx_clock_timestamp(&s_clock, msg.acquired_ms, ×tamp);
|
||||||
char line[512];
|
xSemaphoreGive(s_http_lock);
|
||||||
esp_err_t b = build_line_protocol(&p, line, sizeof(line));
|
if (known) {
|
||||||
|
size_t used = strlen(msg.line);
|
||||||
if (b == ESP_ERR_INVALID_STATE) {
|
int n = snprintf(msg.line + used, sizeof(msg.line) - used, " %llu", (unsigned long long)timestamp);
|
||||||
ESP_LOGW(TAG, "Skipping write: no valid fields.");
|
if (n < 0 || (size_t)n >= sizeof(msg.line) - used) { ESP_LOGW(TAG, "Dropping oversized timestamped point."); continue; }
|
||||||
free_msg(&msg);
|
msg.timestamped = true;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
if (b != ESP_OK) {
|
|
||||||
ESP_LOGW(TAG, "Line build failed: %s", esp_err_to_name(b));
|
|
||||||
free_msg(&msg);
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
if ((!msg.timestamped && batch->points) || !influx_batch_add(batch, msg.line, monotonic_ms())) {
|
||||||
esp_err_t e = net_influx_write_line(line);
|
carry = msg; have_carry = true; flush = true;
|
||||||
|
|
||||||
if (e == ESP_OK) {
|
|
||||||
if (fail_count) ESP_LOGI(TAG, "Influx write recovered.");
|
|
||||||
fail_count = 0;
|
|
||||||
backoff_ms = s_rt.backoff_start_ms;
|
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGW(TAG, "Influx write failed: %s", esp_err_to_name(e));
|
batch_timestamped = msg.timestamped;
|
||||||
if (++fail_count >= (int)s_rt.fails_before_reinit) {
|
flush = !msg.timestamped || influx_batch_due(batch, monotonic_ms());
|
||||||
(void)influx_reinit_with_backoff(&backoff_ms);
|
|
||||||
fail_count = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!flush || !batch->points) continue;
|
||||||
free_msg(&msg);
|
/* Retries keep the exact body AND timestamps; acknowledged points are never resubmitted. */
|
||||||
|
while (s_run && batch->points) {
|
||||||
|
int status;
|
||||||
|
esp_err_t err = net_influx_write_payload(batch->body, batch->points, &status);
|
||||||
|
if (err == ESP_OK) {
|
||||||
|
ESP_LOGI(TAG, "Batch UTC: first_ms=%llu last_ms=%llu dropped=%u",
|
||||||
|
(unsigned long long)batch->first_timestamp_ms,
|
||||||
|
(unsigned long long)batch->last_timestamp_ms,
|
||||||
|
(unsigned)atomic_load(&s_dropped));
|
||||||
|
memset(batch, 0, sizeof(*batch));
|
||||||
|
failures = 0; backoff = s_rt.backoff_start_ms;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
if (!batch_timestamped || status == 400 || status == 413 || status == 422) {
|
||||||
ESP_LOGI(TAG, "Influx worker stopping.");
|
if (!batch_timestamped)
|
||||||
|
ESP_LOGW(TAG, "Single-point request failed without a clock; no automatic replay with a new server timestamp.");
|
||||||
|
else
|
||||||
|
ESP_LOGW(TAG, "Dropping %u rejected points (HTTP %d); inspect schema/payload limits.", batch->points, status);
|
||||||
|
memset(batch, 0, sizeof(*batch));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
++failures;
|
||||||
|
ESP_LOGW(TAG, "Retaining %u points; retry in %u ms.", batch->points, (unsigned)backoff);
|
||||||
|
if (!wait_running(backoff)) break;
|
||||||
|
if (failures >= s_rt.fails_before_reinit) {
|
||||||
|
net_influx_init_from_nvs(s_rt.ca_cert_pem_opt, s_rt.http_timeout_ms);
|
||||||
|
failures = 0;
|
||||||
|
}
|
||||||
|
if (backoff < s_rt.backoff_max_ms) {
|
||||||
|
uint64_t next = (uint64_t)backoff * 2;
|
||||||
|
backoff = next > s_rt.backoff_max_ms ? s_rt.backoff_max_ms : (uint32_t)next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
done:
|
||||||
|
if (batch && batch->points) ESP_LOGW(TAG, "Stopping: %u pending points discarded from RAM.", batch->points);
|
||||||
|
free(batch);
|
||||||
|
if (s_http_lock) {
|
||||||
|
xSemaphoreTake(s_http_lock, portMAX_DELAY); http_close(); xSemaphoreGive(s_http_lock);
|
||||||
|
}
|
||||||
|
if (s_q) { vQueueDelete(s_q); s_q = NULL; }
|
||||||
|
s_run = false;
|
||||||
|
s_task = NULL;
|
||||||
vTaskDelete(NULL);
|
vTaskDelete(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -512,20 +511,26 @@ esp_err_t net_influx_init(const net_influx_cfg_t* cfg) {
|
|||||||
if (!cfg || !cfg->url_base || !cfg->org || !cfg->bucket || !cfg->token) {
|
if (!cfg || !cfg->url_base || !cfg->org || !cfg->bucket || !cfg->token) {
|
||||||
return ESP_ERR_INVALID_ARG;
|
return ESP_ERR_INVALID_ARG;
|
||||||
}
|
}
|
||||||
safe_copy(s.url_base, sizeof(s.url_base), cfg->url_base);
|
if (!s_http_lock) {
|
||||||
safe_copy(s.org, sizeof(s.org), cfg->org);
|
s_http_lock = xSemaphoreCreateMutex();
|
||||||
safe_copy(s.bucket, sizeof(s.bucket), cfg->bucket);
|
if (!s_http_lock) return ESP_ERR_NO_MEM;
|
||||||
safe_copy(s.token, sizeof(s.token), cfg->token);
|
}
|
||||||
trim_inplace(s.url_base);
|
net_influx_state_t next = {0};
|
||||||
|
safe_copy(next.url_base, sizeof(next.url_base), cfg->url_base);
|
||||||
s.use_tls = cfg->use_tls;
|
safe_copy(next.org, sizeof(next.org), cfg->org);
|
||||||
s.ca_cert_pem = cfg->ca_cert_pem;
|
safe_copy(next.bucket, sizeof(next.bucket), cfg->bucket);
|
||||||
s.http_timeout_ms = (cfg->http_timeout_ms > 0) ? cfg->http_timeout_ms : 3000;
|
safe_copy(next.token, sizeof(next.token), cfg->token);
|
||||||
|
trim_inplace(next.url_base);
|
||||||
char tok[32] = {0};
|
next.use_tls = cfg->use_tls;
|
||||||
mask_token(s.token, tok, sizeof(tok));
|
next.ca_cert_pem = cfg->ca_cert_pem;
|
||||||
ESP_LOGI(TAG, "init: base=\"%s\", org=\"%s\", bucket=\"%s\", tls=%d, timeout=%dms, token=%s",
|
next.http_timeout_ms = cfg->http_timeout_ms > 0 ? cfg->http_timeout_ms : 3000;
|
||||||
s.url_base, s.org, s.bucket, (int)s.use_tls, s.http_timeout_ms, tok);
|
xSemaphoreTake(s_http_lock, portMAX_DELAY);
|
||||||
|
bool host_changed = strcmp(s.url_base, next.url_base) || s.use_tls != next.use_tls;
|
||||||
|
if (memcmp(&s, &next, sizeof(s))) http_close();
|
||||||
|
if (host_changed) memset(&s_clock, 0, sizeof(s_clock));
|
||||||
|
s = next;
|
||||||
|
xSemaphoreGive(s_http_lock);
|
||||||
|
ESP_LOGI(TAG, "Influx configuration loaded; batching uses existing organization/bucket.");
|
||||||
sys_status_set_influx_ok(false);
|
sys_status_set_influx_ok(false);
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
@@ -552,8 +557,9 @@ esp_err_t net_influx_write_fields(const char* measurement,
|
|||||||
char fields[256];
|
char fields[256];
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, fields_fmt);
|
va_start(ap, fields_fmt);
|
||||||
vsnprintf(fields, sizeof(fields), fields_fmt, ap);
|
int fields_length = vsnprintf(fields, sizeof(fields), fields_fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
if (fields_length < 0 || (size_t)fields_length >= sizeof(fields)) return ESP_ERR_INVALID_SIZE;
|
||||||
|
|
||||||
// 2) Line Protocol
|
// 2) Line Protocol
|
||||||
char line[512];
|
char line[512];
|
||||||
@@ -561,7 +567,7 @@ esp_err_t net_influx_write_fields(const char* measurement,
|
|||||||
|
|
||||||
// measurement escaping (space/comma)
|
// measurement escaping (space/comma)
|
||||||
char meas[96];
|
char meas[96];
|
||||||
esc_copy(meas, sizeof(meas), measurement, false);
|
if (esc_copy(meas, sizeof(meas), measurement, false) == SIZE_MAX) return ESP_ERR_INVALID_SIZE;
|
||||||
|
|
||||||
off += snprintf(line + off, sizeof(line) - off, "%s", meas);
|
off += snprintf(line + off, sizeof(line) - off, "%s", meas);
|
||||||
if (off < 0 || off >= (int)sizeof(line)) { sys_status_set_influx_ok(false); return ESP_FAIL; }
|
if (off < 0 || off >= (int)sizeof(line)) { sys_status_set_influx_ok(false); return ESP_FAIL; }
|
||||||
@@ -619,7 +625,7 @@ esp_err_t net_influx_init_from_nvs(const char* ca_cert_pem_opt, int timeout_ms)
|
|||||||
|
|
||||||
/* ---------------- NEW: Start/Stop/Submit (generic, multi-sensor) ---------------- */
|
/* ---------------- NEW: Start/Stop/Submit (generic, multi-sensor) ---------------- */
|
||||||
esp_err_t net_influx_start(const net_influx_runtime_cfg_t* rt) {
|
esp_err_t net_influx_start(const net_influx_runtime_cfg_t* rt) {
|
||||||
if (s_task) return ESP_OK;
|
if (s_task) return s_run ? ESP_OK : ESP_ERR_INVALID_STATE;
|
||||||
|
|
||||||
// runtime cfg übernehmen (mit Defaults)
|
// runtime cfg übernehmen (mit Defaults)
|
||||||
if (rt) {
|
if (rt) {
|
||||||
@@ -639,6 +645,7 @@ esp_err_t net_influx_start(const net_influx_runtime_cfg_t* rt) {
|
|||||||
s_q = xQueueCreate(s_rt.queue_len, sizeof(influx_msg_t));
|
s_q = xQueueCreate(s_rt.queue_len, sizeof(influx_msg_t));
|
||||||
if (!s_q) return ESP_ERR_NO_MEM;
|
if (!s_q) return ESP_ERR_NO_MEM;
|
||||||
|
|
||||||
|
s_dropped = 0;
|
||||||
s_run = true;
|
s_run = true;
|
||||||
if (xTaskCreate(net_influx_worker, "influx_worker", s_rt.task_stack, NULL, s_rt.task_prio, &s_task) != pdPASS) {
|
if (xTaskCreate(net_influx_worker, "influx_worker", s_rt.task_stack, NULL, s_rt.task_prio, &s_task) != pdPASS) {
|
||||||
vQueueDelete(s_q);
|
vQueueDelete(s_q);
|
||||||
@@ -649,71 +656,32 @@ esp_err_t net_influx_start(const net_influx_runtime_cfg_t* rt) {
|
|||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void net_influx_stop(void) {
|
void net_influx_stop(void)
|
||||||
|
{
|
||||||
s_run = false;
|
s_run = false;
|
||||||
|
/* Worker owns its HTTP handle, batch and queue. Never delete it mid-request. */
|
||||||
if (s_task) {
|
for (unsigned i = 0; s_task && i < 50; ++i) vTaskDelay(pdMS_TO_TICKS(100));
|
||||||
vTaskDelete(s_task);
|
if (s_task) ESP_LOGW(TAG, "Worker still finishing an HTTP request; cleanup deferred.");
|
||||||
s_task = NULL;
|
|
||||||
}
|
|
||||||
if (s_q) {
|
|
||||||
influx_msg_t msg;
|
|
||||||
while (xQueueReceive(s_q, &msg, 0) == pdTRUE) {
|
|
||||||
free_msg(&msg);
|
|
||||||
}
|
|
||||||
vQueueDelete(s_q);
|
|
||||||
s_q = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t net_influx_submit_point(const net_influx_point_t* p) {
|
esp_err_t net_influx_submit_point(const net_influx_point_t *point)
|
||||||
if (!p || !p->measurement || !*p->measurement || !p->fields || p->num_fields == 0) {
|
{
|
||||||
|
if (!point || !point->measurement || !*point->measurement || !point->fields || !point->num_fields || point->ts_ms > 9223372036854ULL)
|
||||||
return ESP_ERR_INVALID_ARG;
|
return ESP_ERR_INVALID_ARG;
|
||||||
}
|
if (!s_run || !s_q) return ESP_ERR_INVALID_STATE;
|
||||||
if (!s_q) return ESP_ERR_INVALID_STATE;
|
influx_msg_t msg = {.acquired_ms = monotonic_ms(), .timestamped = point->ts_ms != 0};
|
||||||
|
/* Reserve room for an automatically assigned millisecond timestamp. */
|
||||||
influx_msg_t msg = {0};
|
size_t cap = msg.timestamped ? sizeof(msg.line) : sizeof(msg.line) - 24;
|
||||||
msg.measurement = dup0(p->measurement);
|
esp_err_t err = build_line_protocol(point, msg.line, cap);
|
||||||
msg.tags = (p->tags && *p->tags) ? dup0(p->tags) : NULL;
|
if (err != ESP_OK) return err;
|
||||||
msg.ts_ms = p->ts_ms;
|
|
||||||
msg.num_fields = p->num_fields;
|
|
||||||
|
|
||||||
msg.fields = (net_influx_field_t*)calloc(p->num_fields, sizeof(net_influx_field_t));
|
|
||||||
if (!msg.measurement || !msg.fields) {
|
|
||||||
free_msg(&msg);
|
|
||||||
return ESP_ERR_NO_MEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t i = 0; i < p->num_fields; ++i) {
|
|
||||||
msg.fields[i] = p->fields[i];
|
|
||||||
|
|
||||||
// deep copy key
|
|
||||||
msg.fields[i].key = dup0(p->fields[i].key);
|
|
||||||
if (!msg.fields[i].key) {
|
|
||||||
free_msg(&msg);
|
|
||||||
return ESP_ERR_NO_MEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
// deep copy string value if needed
|
|
||||||
if (p->fields[i].type == NET_INFLUX_F_STRING && p->fields[i].v.s) {
|
|
||||||
msg.fields[i].v.s = dup0(p->fields[i].v.s);
|
|
||||||
if (!msg.fields[i].v.s) {
|
|
||||||
free_msg(&msg);
|
|
||||||
return ESP_ERR_NO_MEM;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Non-blocking enqueue; wenn voll: drop oldest
|
|
||||||
if (xQueueSend(s_q, &msg, 0) != pdPASS) {
|
if (xQueueSend(s_q, &msg, 0) != pdPASS) {
|
||||||
influx_msg_t dump;
|
influx_msg_t old;
|
||||||
if (xQueueReceive(s_q, &dump, 0) == pdTRUE) free_msg(&dump);
|
if (xQueueReceive(s_q, &old, 0) == pdTRUE) {
|
||||||
|
unsigned dropped = atomic_fetch_add(&s_dropped, 1) + 1;
|
||||||
if (xQueueSend(s_q, &msg, 0) != pdPASS) {
|
if (dropped == 1 || dropped % 10 == 0)
|
||||||
free_msg(&msg);
|
ESP_LOGW(TAG, "Influx queue full: %u old pending points dropped since start.", dropped);
|
||||||
return ESP_FAIL;
|
|
||||||
}
|
}
|
||||||
|
if (xQueueSend(s_q, &msg, 0) != pdPASS) return ESP_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
idf_component_register(
|
idf_component_register(
|
||||||
SRCS
|
SRCS
|
||||||
"sen5x_i2c.c"
|
"sen5x_i2c.c"
|
||||||
|
"sen66_i2c.c"
|
||||||
"sensirion_common.c"
|
"sensirion_common.c"
|
||||||
"sensirion_i2c.c"
|
"sensirion_i2c.c"
|
||||||
"sensirion_i2c_hal.c"
|
"sensirion_i2c_hal.c"
|
||||||
|
"sensor_soft_i2c.c"
|
||||||
"i2cdev.c"
|
"i2cdev.c"
|
||||||
"sen5x_app.c"
|
"air_sensor_app.c"
|
||||||
INCLUDE_DIRS
|
INCLUDE_DIRS
|
||||||
"."
|
"."
|
||||||
REQUIRES
|
REQUIRES
|
||||||
@@ -14,4 +16,7 @@ idf_component_register(
|
|||||||
log
|
log
|
||||||
net_influx
|
net_influx
|
||||||
eez_gui
|
eez_gui
|
||||||
|
storage
|
||||||
|
hardware_config
|
||||||
|
esp_timer
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
BSD 3-Clause License
|
||||||
|
|
||||||
|
Copyright (c) 2026, Sensirion AG
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer in the documentation
|
||||||
|
and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
3. Neither the name of the copyright holder nor the names of its
|
||||||
|
contributors may be used to endorse or promote products derived from
|
||||||
|
this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
# Sensirion driver provenance
|
||||||
|
|
||||||
|
Source: https://github.com/Sensirion/embedded-i2c-sen66
|
||||||
|
|
||||||
|
Pinned commit: `31cae0dd5253d256e8e647408ea1c544eff5d1c2` (retrieved 2026-11-09).
|
||||||
|
|
||||||
|
Unmodified upstream files: `sen66_i2c.c`, `sen66_i2c.h`, `sensirion_common.c`,
|
||||||
|
`sensirion_common.h`, `sensirion_i2c.c`, `sensirion_i2c.h`, `sensirion_config.h`.
|
||||||
|
License: `LICENSE.sensirion` (BSD-3-Clause). The common helpers also provide the
|
||||||
|
API used by the existing SEN5x driver. `sensirion_i2c_hal.c` remains our ESP-IDF
|
||||||
|
port using the shared, mutex-protected i2cdev hardware bus when sensor and
|
||||||
|
board pins match. SEN66 with the display uses a separate local open-drain GPIO
|
||||||
|
I2C engine (`sensor_soft_i2c.c/.h`) on GPIO7/8; touch retains hardware I2C on
|
||||||
|
GPIO18/19. The GPIO engine has its own wire-level ACK/NACK/stretch/timeout tests.
|
||||||
|
No upstream example HAL is
|
||||||
|
compiled. The manufacturer driver files retain their original copyright text.
|
||||||
|
|
||||||
|
`sen5x_i2c.c/.h` are the existing SEN5x driver; `air_sensor_app.c` selects the
|
||||||
|
SEN54 or SEN66 command API at compile time using `hardware_config.h`.
|
||||||
+109
-82
@@ -1,6 +1,6 @@
|
|||||||
// File: src/sen5x_app.c
|
// File: src/air_sensor_app.c
|
||||||
|
|
||||||
#include "sen5x_app.h"
|
#include "air_sensor_app.h"
|
||||||
|
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
@@ -9,7 +9,12 @@
|
|||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "sensirion_i2c_hal.h"
|
#include "sensirion_i2c_hal.h"
|
||||||
#include "sensirion_i2c_esp32_config.h"
|
#include "sensirion_i2c_esp32_config.h"
|
||||||
|
#include "hardware_config.h"
|
||||||
|
#if NANOPSX_SENSOR == NANOPSX_SENSOR_SEN66
|
||||||
|
#include "sen66_i2c.h"
|
||||||
|
#else
|
||||||
#include "sen5x_i2c.h"
|
#include "sen5x_i2c.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "net_influx.h"
|
#include "net_influx.h"
|
||||||
#include "storage.h"
|
#include "storage.h"
|
||||||
@@ -19,16 +24,18 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <math.h> // NAN, isfinite, lround
|
#include <math.h> // NAN, isfinite, lround
|
||||||
#include "vars.h"
|
#include "vars.h"
|
||||||
|
#include "ui_model.h"
|
||||||
|
#include "esp_timer.h"
|
||||||
|
|
||||||
static const char* TAG = "sen5x_app";
|
static const char* TAG = "air_sensor_app";
|
||||||
|
|
||||||
/* ====================== Konfiguration ====================== */
|
/* ====================== Konfiguration ====================== */
|
||||||
#define SEN5X_PROD_STACK 4096
|
#define AIR_SENSOR_PROD_STACK 4096
|
||||||
#define SEN5X_PROD_PRIO 6 // Producer leicht höher priorisiert
|
#define AIR_SENSOR_PROD_PRIO 6 // Producer leicht höher priorisiert
|
||||||
|
|
||||||
// Influx worker runtime (läuft in net_influx.c)
|
// Influx worker runtime (läuft in net_influx.c)
|
||||||
#define INFLUX_QUEUE_LEN 16
|
#define INFLUX_QUEUE_LEN 32
|
||||||
#define INFLUX_TASK_STACK 6144
|
#define INFLUX_TASK_STACK 8192
|
||||||
#define INFLUX_TASK_PRIO 5
|
#define INFLUX_TASK_PRIO 5
|
||||||
|
|
||||||
#define INFLUX_INIT_RETRY_MS 1000
|
#define INFLUX_INIT_RETRY_MS 1000
|
||||||
@@ -42,7 +49,7 @@ typedef struct {
|
|||||||
uint16_t pm1p0, pm2p5, pm4p0, pm10p0; // Rohwerte (x10)
|
uint16_t pm1p0, pm2p5, pm4p0, pm10p0; // Rohwerte (x10)
|
||||||
float temp_c, rh_pct; // skaliert
|
float temp_c, rh_pct; // skaliert
|
||||||
int16_t voc_idx, nox_idx; // Rohwerte (x10)
|
int16_t voc_idx, nox_idx; // Rohwerte (x10)
|
||||||
} sen5x_sample_t;
|
} air_sensor_sample_t;
|
||||||
|
|
||||||
static bool g_inited = false;
|
static bool g_inited = false;
|
||||||
static bool g_run = false;
|
static bool g_run = false;
|
||||||
@@ -68,52 +75,54 @@ static char* g_device_tag = NULL; // z.B. "device=xyz"
|
|||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
/* ====================== Lokale Float-Wrapper (optional) ====================== */
|
/* One selected command set; shared HAL and presentation/Influx pipeline. */
|
||||||
static int16_t sen5x_read_measured_values_float(float* pm1p0, float* pm2p5,
|
static int16_t sensor_ready(bool *ready) {
|
||||||
float* pm4p0, float* pm10p0,
|
#if NANOPSX_SENSOR == NANOPSX_SENSOR_SEN66
|
||||||
float* rh, float* t,
|
uint8_t padding;
|
||||||
float* voc, float* nox) {
|
return sen66_get_data_ready(&padding, ready);
|
||||||
uint16_t pm1_i=0, pm2_i=0, pm4_i=0, pm10_i=0;
|
#else
|
||||||
int16_t rh_i=0, t_i=0, voc_i=0, nox_i=0;
|
return sen5x_read_data_ready(ready);
|
||||||
int16_t err = sen5x_read_measured_values(&pm1_i, &pm2_i, &pm4_i, &pm10_i,
|
#endif
|
||||||
&rh_i, &t_i, &voc_i, &nox_i);
|
|
||||||
if (err) return err;
|
|
||||||
|
|
||||||
if (pm1p0) *pm1p0 = (pm1_i == 0xFFFF) ? NAN : pm1_i / 10.0f;
|
|
||||||
if (pm2p5) *pm2p5 = (pm2_i == 0xFFFF) ? NAN : pm2_i / 10.0f;
|
|
||||||
if (pm4p0) *pm4p0 = (pm4_i == 0xFFFF) ? NAN : pm4_i / 10.0f;
|
|
||||||
if (pm10p0) *pm10p0 = (pm10_i == 0xFFFF) ? NAN : pm10_i / 10.0f;
|
|
||||||
|
|
||||||
if (rh) *rh = (rh_i == 0x7FFF) ? NAN : rh_i / 100.0f;
|
|
||||||
if (t) *t = (t_i == 0x7FFF) ? NAN : t_i / 200.0f;
|
|
||||||
if (voc) *voc = (voc_i == 0x7FFF) ? NAN : voc_i / 10.0f;
|
|
||||||
if (nox) *nox = (nox_i == 0x7FFF) ? NAN : nox_i / 10.0f;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int16_t sen5x_read_measured_pm_values_float(float* pm1, float* pm2,
|
static int16_t sensor_read(uint16_t *pm1, uint16_t *pm2, uint16_t *pm4,
|
||||||
float* pm4, float* pm10,
|
uint16_t *pm10, int16_t *rh, int16_t *temp,
|
||||||
float* n05, float* n10,
|
int16_t *voc, int16_t *nox, uint16_t *co2) {
|
||||||
float* n25, float* n40,
|
#if NANOPSX_SENSOR == NANOPSX_SENSOR_SEN66
|
||||||
float* n100, float* dtyp) {
|
return sen66_read_measured_values_as_integers(pm1, pm2, pm4, pm10,
|
||||||
uint16_t pm1_i=0, pm2_i=0, pm4_i=0, pm10_i=0, n05_i=0, n10_i=0, n25_i=0, n40_i=0, n100_i=0, dtyp_i=0;
|
rh, temp, voc, nox, co2);
|
||||||
int16_t err = sen5x_read_measured_pm_values(&pm1_i, &pm2_i, &pm4_i, &pm10_i,
|
#else
|
||||||
&n05_i, &n10_i, &n25_i, &n40_i, &n100_i, &dtyp_i);
|
*co2 = UINT16_MAX; // SEN54 has no CO2 channel: never submit a fake zero.
|
||||||
if (err) return err;
|
return sen5x_read_measured_values(pm1, pm2, pm4, pm10, rh, temp, voc, nox);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
if (pm1) *pm1 = (pm1_i == 0xFFFF) ? NAN : pm1_i / 10.0f;
|
static int16_t sensor_start(void) {
|
||||||
if (pm2) *pm2 = (pm2_i == 0xFFFF) ? NAN : pm2_i / 10.0f;
|
#if NANOPSX_SENSOR == NANOPSX_SENSOR_SEN66
|
||||||
if (pm4) *pm4 = (pm4_i == 0xFFFF) ? NAN : pm4_i / 10.0f;
|
sen66_init(NANOPSX_SENSOR_ADDRESS);
|
||||||
if (pm10) *pm10 = (pm10_i == 0xFFFF) ? NAN : pm10_i / 10.0f;
|
// A sensor can keep measuring across an ESP-only reset.
|
||||||
|
int16_t rc = sen66_stop_measurement();
|
||||||
|
if (rc) return rc;
|
||||||
|
int8_t product[32] = {0};
|
||||||
|
rc = sen66_get_product_name(product, sizeof(product) - 1);
|
||||||
|
if (rc) return rc;
|
||||||
|
if (strncmp((const char *)product, "SEN66", 5) != 0) {
|
||||||
|
ESP_LOGE(TAG, "Expected SEN66, product=%s", (char *)product);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
ESP_LOGI(TAG, "Sensor identified: %s", (char *)product);
|
||||||
|
return sen66_start_continuous_measurement();
|
||||||
|
#else
|
||||||
|
return sen5x_start_measurement();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
if (n05) *n05 = (n05_i == 0xFFFF) ? NAN : n05_i / 10.0f;
|
static int16_t sensor_stop(void) {
|
||||||
if (n10) *n10 = (n10_i == 0xFFFF) ? NAN : n10_i / 10.0f;
|
#if NANOPSX_SENSOR == NANOPSX_SENSOR_SEN66
|
||||||
if (n25) *n25 = (n25_i == 0xFFFF) ? NAN : n25_i / 10.0f;
|
return sen66_stop_measurement();
|
||||||
if (n40) *n40 = (n40_i == 0xFFFF) ? NAN : n40_i / 10.0f;
|
#else
|
||||||
if (n100) *n100 = (n100_i == 0xFFFF) ? NAN : n100_i / 10.0f;
|
return sen5x_stop_measurement();
|
||||||
|
#endif
|
||||||
if (dtyp) *dtyp = (dtyp_i == 0xFFFF) ? NAN : dtyp_i / 1000.0f; // µm
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ====================== App-Context: Device Tag ====================== */
|
/* ====================== App-Context: Device Tag ====================== */
|
||||||
@@ -137,7 +146,7 @@ static esp_err_t make_device_tag_once(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ====================== Producer-Task ====================== */
|
/* ====================== Producer-Task ====================== */
|
||||||
static void sen5x_task_producer(void* arg) {
|
static void air_sensor_task_producer(void* arg) {
|
||||||
(void)arg;
|
(void)arg;
|
||||||
|
|
||||||
const TickType_t period = pdMS_TO_TICKS(1000); // exakt 1 Hz
|
const TickType_t period = pdMS_TO_TICKS(1000); // exakt 1 Hz
|
||||||
@@ -147,26 +156,26 @@ static void sen5x_task_producer(void* arg) {
|
|||||||
|
|
||||||
for (; g_run; ) {
|
for (; g_run; ) {
|
||||||
bool ready = false;
|
bool ready = false;
|
||||||
int16_t rc = sen5x_read_data_ready(&ready);
|
int16_t rc = sensor_ready(&ready);
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
ESP_LOGW(TAG, "sen5x_read_data_ready error: %d", (int)rc);
|
ESP_LOGW(TAG, "sensor_ready error: %d", (int)rc);
|
||||||
} else if (ready) {
|
} else if (ready) {
|
||||||
uint16_t pm1p0=0, pm2p5=0, pm4p0=0, pm10p0=0;
|
uint16_t pm1p0=0, pm2p5=0, pm4p0=0, pm10p0=0, co2_raw=UINT16_MAX;
|
||||||
int16_t rh_raw=0, t_raw=0, voc_idx=0, nox_idx=0;
|
int16_t rh_raw=0, t_raw=0, voc_idx=0, nox_idx=0;
|
||||||
|
|
||||||
rc = sen5x_read_measured_values(&pm1p0, &pm2p5, &pm4p0, &pm10p0,
|
rc = sensor_read(&pm1p0, &pm2p5, &pm4p0, &pm10p0,
|
||||||
&rh_raw, &t_raw, &voc_idx, &nox_idx);
|
&rh_raw, &t_raw, &voc_idx, &nox_idx, &co2_raw);
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
ESP_LOGW(TAG, "sen5x_read_measured_values error: %d", (int)rc);
|
ESP_LOGW(TAG, "sensor_read error: %d", (int)rc);
|
||||||
} else {
|
} else {
|
||||||
// Roh → Struct (wie bisher)
|
// Roh → Struct (wie bisher)
|
||||||
sen5x_sample_t s = {
|
air_sensor_sample_t s = {
|
||||||
.pm1p0 = pm1p0,
|
.pm1p0 = pm1p0,
|
||||||
.pm2p5 = pm2p5,
|
.pm2p5 = pm2p5,
|
||||||
.pm4p0 = pm4p0,
|
.pm4p0 = pm4p0,
|
||||||
.pm10p0 = pm10p0,
|
.pm10p0 = pm10p0,
|
||||||
.temp_c = ((float)t_raw) / 200.0f,
|
.temp_c = (t_raw == INT16_MAX) ? NAN : ((float)t_raw) / 200.0f,
|
||||||
.rh_pct = ((float)rh_raw) / 100.0f,
|
.rh_pct = (rh_raw == INT16_MAX) ? NAN : ((float)rh_raw) / 100.0f,
|
||||||
.voc_idx = voc_idx,
|
.voc_idx = voc_idx,
|
||||||
.nox_idx = nox_idx
|
.nox_idx = nox_idx
|
||||||
};
|
};
|
||||||
@@ -181,26 +190,28 @@ static void sen5x_task_producer(void* arg) {
|
|||||||
// float noxf = (s.nox_idx == 0x7FFF) ? NAN : s.nox_idx / 10.0f; // bei Bedarf anzeigen
|
// float noxf = (s.nox_idx == 0x7FFF) ? NAN : s.nox_idx / 10.0f; // bei Bedarf anzeigen
|
||||||
|
|
||||||
// Temperatur
|
// Temperatur
|
||||||
snprintf(buf, sizeof(buf), "%.1f", (double)s.temp_c);
|
if (isfinite(s.temp_c)) snprintf(buf, sizeof(buf), "%.1f", (double)s.temp_c);
|
||||||
|
else snprintf(buf, sizeof(buf), "--");
|
||||||
set_var_temp(buf);
|
set_var_temp(buf);
|
||||||
|
|
||||||
// Feuchte
|
// Feuchte
|
||||||
snprintf(buf, sizeof(buf), "%.1f", (double)s.rh_pct);
|
if (isfinite(s.rh_pct)) snprintf(buf, sizeof(buf), "%.1f", (double)s.rh_pct);
|
||||||
|
else snprintf(buf, sizeof(buf), "--");
|
||||||
set_var_humidity(buf);
|
set_var_humidity(buf);
|
||||||
|
|
||||||
// VOC-Index (gerundet), falls NAN → "nan"
|
// VOC-Index (gerundet), nicht verfügbare Werte als "--"
|
||||||
if (!isfinite(vocf)) snprintf(buf, sizeof(buf), "nan");
|
if (!isfinite(vocf)) snprintf(buf, sizeof(buf), "--");
|
||||||
else snprintf(buf, sizeof(buf), "%d", (int)lround(vocf));
|
else snprintf(buf, sizeof(buf), "%d", (int)lround(vocf));
|
||||||
set_var_voc_ind(buf);
|
set_var_voc_ind(buf);
|
||||||
|
|
||||||
// PM (µg/m³) mit einer Nachkommastelle
|
// PM (µg/m³) mit einer Nachkommastelle
|
||||||
if (!isfinite(pm10f)) snprintf(buf, sizeof(buf), "nan"); else snprintf(buf, sizeof(buf), "%.1f", (double)pm10f);
|
if (!isfinite(pm10f)) snprintf(buf, sizeof(buf), "--"); else snprintf(buf, sizeof(buf), "%.1f", (double)pm10f);
|
||||||
set_var_pm10p0(buf);
|
set_var_pm10p0(buf);
|
||||||
if (!isfinite(pm4f)) snprintf(buf, sizeof(buf), "nan"); else snprintf(buf, sizeof(buf), "%.1f", (double)pm4f);
|
if (!isfinite(pm4f)) snprintf(buf, sizeof(buf), "--"); else snprintf(buf, sizeof(buf), "%.1f", (double)pm4f);
|
||||||
set_var_pm4p0(buf);
|
set_var_pm4p0(buf);
|
||||||
if (!isfinite(pm2f)) snprintf(buf, sizeof(buf), "nan"); else snprintf(buf, sizeof(buf), "%.1f", (double)pm2f);
|
if (!isfinite(pm2f)) snprintf(buf, sizeof(buf), "--"); else snprintf(buf, sizeof(buf), "%.1f", (double)pm2f);
|
||||||
set_var_pm2p5(buf);
|
set_var_pm2p5(buf);
|
||||||
if (!isfinite(pm1f)) snprintf(buf, sizeof(buf), "nan"); else snprintf(buf, sizeof(buf), "%.1f", (double)pm1f);
|
if (!isfinite(pm1f)) snprintf(buf, sizeof(buf), "--"); else snprintf(buf, sizeof(buf), "%.1f", (double)pm1f);
|
||||||
set_var_pm1p0(buf);
|
set_var_pm1p0(buf);
|
||||||
|
|
||||||
/* === Influx submit (generisch, variabel viele Felder) === */
|
/* === Influx submit (generisch, variabel viele Felder) === */
|
||||||
@@ -212,6 +223,21 @@ static void sen5x_task_producer(void* arg) {
|
|||||||
const double nox = (s.nox_idx == 0x7FFF) ? NAN : ((double)s.nox_idx / 10.0);
|
const double nox = (s.nox_idx == 0x7FFF) ? NAN : ((double)s.nox_idx / 10.0);
|
||||||
const double temp = (double)s.temp_c;
|
const double temp = (double)s.temp_c;
|
||||||
const double rh = (double)s.rh_pct;
|
const double rh = (double)s.rh_pct;
|
||||||
|
const double co2 = (co2_raw == UINT16_MAX) ? NAN : (double)co2_raw;
|
||||||
|
#if NANOPSX_HAS_DISPLAY
|
||||||
|
ui_sample_t display_sample = {
|
||||||
|
.timestamp_ms = (uint64_t)(esp_timer_get_time() / 1000),
|
||||||
|
.available = true,
|
||||||
|
.values = {(float)co2, (float)pm2_5, (float)temp,
|
||||||
|
(float)rh, (float)voc, (float)nox}
|
||||||
|
};
|
||||||
|
ui_model_publish(&display_sample);
|
||||||
|
#endif
|
||||||
|
static unsigned samples;
|
||||||
|
if (++samples % 10 == 0) {
|
||||||
|
ESP_LOGI(TAG, "%s sample: PM2.5=%.1f temp=%.2f rh=%.2f CO2=%.0f",
|
||||||
|
NANOPSX_SENSOR_NAME, pm2_5, temp, rh, co2);
|
||||||
|
}
|
||||||
|
|
||||||
net_influx_field_t f[] = {
|
net_influx_field_t f[] = {
|
||||||
{ .key="pm1", .type=NET_INFLUX_F_FLOAT, .precision=1, .v.f=pm1 },
|
{ .key="pm1", .type=NET_INFLUX_F_FLOAT, .precision=1, .v.f=pm1 },
|
||||||
@@ -222,12 +248,13 @@ static void sen5x_task_producer(void* arg) {
|
|||||||
{ .key="rh", .type=NET_INFLUX_F_FLOAT, .precision=3, .v.f=rh },
|
{ .key="rh", .type=NET_INFLUX_F_FLOAT, .precision=3, .v.f=rh },
|
||||||
{ .key="voc", .type=NET_INFLUX_F_FLOAT, .precision=1, .v.f=voc },
|
{ .key="voc", .type=NET_INFLUX_F_FLOAT, .precision=1, .v.f=voc },
|
||||||
{ .key="nox", .type=NET_INFLUX_F_FLOAT, .precision=1, .v.f=nox },
|
{ .key="nox", .type=NET_INFLUX_F_FLOAT, .precision=1, .v.f=nox },
|
||||||
|
{ .key="co2", .type=NET_INFLUX_F_FLOAT, .precision=0, .v.f=co2 },
|
||||||
};
|
};
|
||||||
|
|
||||||
net_influx_point_t p = {
|
net_influx_point_t p = {
|
||||||
.measurement = "air",
|
.measurement = "air",
|
||||||
.tags = g_device_tag ? g_device_tag : "device=unknown",
|
.tags = g_device_tag ? g_device_tag : "device=unknown",
|
||||||
.ts_ms = 0, // Serverzeit
|
.ts_ms = 0, // Messzeitpunkt; Worker richtet UTC an Server-HTTP-Date aus
|
||||||
.fields = f,
|
.fields = f,
|
||||||
.num_fields = sizeof(f) / sizeof(f[0]),
|
.num_fields = sizeof(f) / sizeof(f[0]),
|
||||||
};
|
};
|
||||||
@@ -245,14 +272,14 @@ static void sen5x_task_producer(void* arg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ====================== Öffentliche API ====================== */
|
/* ====================== Öffentliche API ====================== */
|
||||||
esp_err_t sen5x_app_init(const sen5x_i2c_cfg_t* cfg) {
|
esp_err_t air_sensor_app_init(const air_sensor_i2c_cfg_t* cfg) {
|
||||||
if (g_inited) {
|
if (g_inited) {
|
||||||
ESP_LOGW(TAG, "already initialized");
|
ESP_LOGW(TAG, "already initialized");
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
if (!cfg) return ESP_ERR_INVALID_ARG;
|
if (!cfg) return ESP_ERR_INVALID_ARG;
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Initializing SEN5x app...");
|
ESP_LOGI(TAG, "Initializing selected air sensor...");
|
||||||
|
|
||||||
// 1) I2C-Subsystem
|
// 1) I2C-Subsystem
|
||||||
|
|
||||||
@@ -274,7 +301,7 @@ esp_err_t sen5x_app_init(const sen5x_i2c_cfg_t* cfg) {
|
|||||||
CHECK_ESP_OR_RET(sensirion_i2c_esp32_ok());
|
CHECK_ESP_OR_RET(sensirion_i2c_esp32_ok());
|
||||||
|
|
||||||
// 4) Messung starten
|
// 4) Messung starten
|
||||||
CHECK_SEN_OR_RET(sen5x_start_measurement());
|
CHECK_SEN_OR_RET(sensor_start());
|
||||||
ESP_LOGI(TAG, "Measurement started.");
|
ESP_LOGI(TAG, "Measurement started.");
|
||||||
|
|
||||||
// 5) Device Tag (App-Kontext)
|
// 5) Device Tag (App-Kontext)
|
||||||
@@ -299,7 +326,7 @@ esp_err_t sen5x_app_init(const sen5x_i2c_cfg_t* cfg) {
|
|||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sen5x_app_deinit(void) {
|
void air_sensor_app_deinit(void) {
|
||||||
if (!g_inited) return;
|
if (!g_inited) return;
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Deinitializing SEN5x app...");
|
ESP_LOGI(TAG, "Deinitializing SEN5x app...");
|
||||||
@@ -311,8 +338,8 @@ void sen5x_app_deinit(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (g_task_prod) {
|
if (g_task_prod) {
|
||||||
ESP_LOGW(TAG, "Producer did not stop in time; skip sen5x_stop_measurement/HAL free");
|
ESP_LOGW(TAG, "Producer did not stop in time; skip sensor_stop/HAL free");
|
||||||
// Hier NICHT sen5x_stop_measurement() / HAL free, weil Task evtl. noch I2C nutzt
|
// Hier NICHT sensor_stop() / HAL free, weil Task evtl. noch I2C nutzt
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -323,33 +350,33 @@ void sen5x_app_deinit(void) {
|
|||||||
g_device_tag = NULL;
|
g_device_tag = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
sen5x_stop_measurement();
|
sensor_stop();
|
||||||
sensirion_i2c_hal_free();
|
sensirion_i2c_hal_free();
|
||||||
|
|
||||||
// i2cdev_done(); // NICHT hier, da Bus global genutzt wird
|
// i2cdev_done(); // NICHT hier, da Bus global genutzt wird
|
||||||
|
|
||||||
g_inited = false;
|
g_inited = false;
|
||||||
ESP_LOGI(TAG, "SEN5x app deinitialized.");
|
ESP_LOGI(TAG, "Air sensor app deinitialized.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Kompatibilität zur bisherigen main.c:
|
* Kompatibilität zur bisherigen main.c:
|
||||||
* Diese Task fungiert nun als "Launcher": startet Producer und beendet sich dann.
|
* Diese Task fungiert nun als "Launcher": startet Producer und beendet sich dann.
|
||||||
* In main.c bleibt der Aufruf von xTaskCreate(sen5x_app_task, ...) unverändert.
|
* In main.c bleibt der Aufruf von xTaskCreate(air_sensor_app_task, ...) unverändert.
|
||||||
*/
|
*/
|
||||||
void sen5x_app_task(void* arg) {
|
void air_sensor_app_task(void* arg) {
|
||||||
(void)arg;
|
(void)arg;
|
||||||
|
|
||||||
if (!g_inited) {
|
if (!g_inited) {
|
||||||
ESP_LOGE(TAG, "sen5x_app_task called before sen5x_app_init()");
|
ESP_LOGE(TAG, "air_sensor_app_task called before air_sensor_app_init()");
|
||||||
vTaskDelete(NULL);
|
vTaskDelete(NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Producer starten
|
// Producer starten
|
||||||
if (xTaskCreate(sen5x_task_producer, "sen5x_prod",
|
if (xTaskCreate(air_sensor_task_producer, "air_sensor_prod",
|
||||||
SEN5X_PROD_STACK, NULL, SEN5X_PROD_PRIO, &g_task_prod) != pdPASS) {
|
AIR_SENSOR_PROD_STACK, NULL, AIR_SENSOR_PROD_PRIO, &g_task_prod) != pdPASS) {
|
||||||
ESP_LOGE(TAG, "Failed to create producer task");
|
ESP_LOGE(TAG, "Failed to create producer task");
|
||||||
vTaskDelete(NULL);
|
vTaskDelete(NULL);
|
||||||
return;
|
return;
|
||||||
@@ -5,20 +5,20 @@
|
|||||||
|
|
||||||
// Schlanke I2C/HAL-Konfiguration (wie zuvor genutzt)
|
// Schlanke I2C/HAL-Konfiguration (wie zuvor genutzt)
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t addr; // 7-bit I2C-Adresse (0x69)
|
uint8_t addr; // selected sensor, 7-bit I2C address
|
||||||
int port; // I2C Port (0)
|
int port; // I2C Port (0)
|
||||||
int sda; // GPIO SDA
|
int sda; // GPIO SDA
|
||||||
int scl; // GPIO SCL
|
int scl; // GPIO SCL
|
||||||
bool sda_pullup; // interne Pullups
|
bool sda_pullup; // interne Pullups
|
||||||
bool scl_pullup; // interne Pullups
|
bool scl_pullup; // interne Pullups
|
||||||
uint32_t freq; // I2C Takt (Hz, z.B. 400000)
|
uint32_t freq; // I2C Takt (Hz, z.B. 400000)
|
||||||
} sen5x_i2c_cfg_t;
|
} air_sensor_i2c_cfg_t;
|
||||||
|
|
||||||
// Initialisiert I2C/Treiber/HAL und startet die Messung
|
// Initialisiert I2C/Treiber/HAL und startet die Messung
|
||||||
esp_err_t sen5x_app_init(const sen5x_i2c_cfg_t* cfg);
|
esp_err_t air_sensor_app_init(const air_sensor_i2c_cfg_t* cfg);
|
||||||
|
|
||||||
// Endlosschleife (Pollt "data ready" und loggt Messwerte); als FreeRTOS-Task nutzbar
|
// Endlosschleife (Pollt "data ready" und loggt Messwerte); als FreeRTOS-Task nutzbar
|
||||||
void sen5x_app_task(void* arg);
|
void air_sensor_app_task(void* arg);
|
||||||
|
|
||||||
// Stoppt Messung & gibt Ressourcen frei (optional aufzurufen z.B. bei Shutdown)
|
// Stoppt Messung & gibt Ressourcen frei (optional aufzurufen z.B. bei Shutdown)
|
||||||
void sen5x_app_deinit(void);
|
void air_sensor_app_deinit(void);
|
||||||
@@ -0,0 +1,798 @@
|
|||||||
|
/*
|
||||||
|
* THIS FILE IS AUTOMATICALLY GENERATED
|
||||||
|
*
|
||||||
|
* Generator: sensirion-driver-generator 1.7.0
|
||||||
|
* Product: sen66
|
||||||
|
* Model-Version: 1.7.3
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2026, Sensirion AG
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* * Neither the name of Sensirion AG nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||||
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "sen66_i2c.h"
|
||||||
|
#include "sensirion_common.h"
|
||||||
|
#include "sensirion_i2c.h"
|
||||||
|
#include "sensirion_i2c_hal.h"
|
||||||
|
|
||||||
|
#define sensirion_hal_sleep_us sensirion_i2c_hal_sleep_usec
|
||||||
|
|
||||||
|
static uint8_t communication_buffer[48] = {0};
|
||||||
|
|
||||||
|
static uint8_t _i2c_address;
|
||||||
|
|
||||||
|
void sen66_init(uint8_t i2c_address) {
|
||||||
|
_i2c_address = i2c_address;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t sen66_get_voc_algorithm_tuning_parameters(
|
||||||
|
int16_t* index_offset, int16_t* learning_time_offset_hours,
|
||||||
|
int16_t* learning_time_gain_hours, int16_t* gating_max_duration_minutes,
|
||||||
|
int16_t* std_initial, int16_t* gain_factor) {
|
||||||
|
int16_t local_error = NO_ERROR;
|
||||||
|
uint8_t* buffer_ptr = communication_buffer;
|
||||||
|
uint16_t local_offset = 0;
|
||||||
|
|
||||||
|
local_offset = sensirion_i2c_add_command16_to_buffer(
|
||||||
|
buffer_ptr, local_offset,
|
||||||
|
SEN66_GET_VOC_ALGORITHM_TUNING_PARAMETERS_CMD_ID);
|
||||||
|
local_error =
|
||||||
|
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
sensirion_i2c_hal_sleep_usec(20 * 1000);
|
||||||
|
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 12);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
*index_offset = sensirion_common_bytes_to_int16_t(&buffer_ptr[0]);
|
||||||
|
*learning_time_offset_hours =
|
||||||
|
sensirion_common_bytes_to_int16_t(&buffer_ptr[2]);
|
||||||
|
*learning_time_gain_hours =
|
||||||
|
sensirion_common_bytes_to_int16_t(&buffer_ptr[4]);
|
||||||
|
*gating_max_duration_minutes =
|
||||||
|
sensirion_common_bytes_to_int16_t(&buffer_ptr[6]);
|
||||||
|
*std_initial = sensirion_common_bytes_to_int16_t(&buffer_ptr[8]);
|
||||||
|
*gain_factor = sensirion_common_bytes_to_int16_t(&buffer_ptr[10]);
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t sen66_set_voc_algorithm_tuning_parameters(
|
||||||
|
int16_t index_offset, int16_t learning_time_offset_hours,
|
||||||
|
int16_t learning_time_gain_hours, int16_t gating_max_duration_minutes,
|
||||||
|
int16_t std_initial, int16_t gain_factor) {
|
||||||
|
int16_t local_error = NO_ERROR;
|
||||||
|
uint8_t* buffer_ptr = communication_buffer;
|
||||||
|
uint16_t local_offset = 0;
|
||||||
|
|
||||||
|
local_offset = sensirion_i2c_add_command16_to_buffer(
|
||||||
|
buffer_ptr, local_offset,
|
||||||
|
SEN66_SET_VOC_ALGORITHM_TUNING_PARAMETERS_CMD_ID);
|
||||||
|
local_offset = sensirion_i2c_add_int16_t_to_buffer(buffer_ptr, local_offset,
|
||||||
|
index_offset);
|
||||||
|
local_offset = sensirion_i2c_add_int16_t_to_buffer(
|
||||||
|
buffer_ptr, local_offset, learning_time_offset_hours);
|
||||||
|
local_offset = sensirion_i2c_add_int16_t_to_buffer(
|
||||||
|
buffer_ptr, local_offset, learning_time_gain_hours);
|
||||||
|
local_offset = sensirion_i2c_add_int16_t_to_buffer(
|
||||||
|
buffer_ptr, local_offset, gating_max_duration_minutes);
|
||||||
|
local_offset = sensirion_i2c_add_int16_t_to_buffer(buffer_ptr, local_offset,
|
||||||
|
std_initial);
|
||||||
|
local_offset = sensirion_i2c_add_int16_t_to_buffer(buffer_ptr, local_offset,
|
||||||
|
gain_factor);
|
||||||
|
local_error =
|
||||||
|
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
sensirion_i2c_hal_sleep_usec(20 * 1000);
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t sen66_get_voc_algorithm_state(uint8_t* state, uint16_t state_size) {
|
||||||
|
int16_t local_error = NO_ERROR;
|
||||||
|
uint8_t* buffer_ptr = communication_buffer;
|
||||||
|
uint16_t local_offset = 0;
|
||||||
|
|
||||||
|
local_offset = sensirion_i2c_add_command16_to_buffer(
|
||||||
|
buffer_ptr, local_offset, SEN66_GET_VOC_ALGORITHM_STATE_CMD_ID);
|
||||||
|
local_error =
|
||||||
|
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
sensirion_i2c_hal_sleep_usec(20 * 1000);
|
||||||
|
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 8);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
sensirion_common_copy_bytes(&buffer_ptr[0], (uint8_t*)state, state_size);
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t sen66_set_voc_algorithm_state(const uint8_t* state,
|
||||||
|
uint16_t state_size) {
|
||||||
|
int16_t local_error = NO_ERROR;
|
||||||
|
uint8_t* buffer_ptr = communication_buffer;
|
||||||
|
uint16_t local_offset = 0;
|
||||||
|
|
||||||
|
local_offset = sensirion_i2c_add_command16_to_buffer(
|
||||||
|
buffer_ptr, local_offset, SEN66_SET_VOC_ALGORITHM_STATE_CMD_ID);
|
||||||
|
local_offset = sensirion_i2c_add_bytes_to_buffer(buffer_ptr, local_offset,
|
||||||
|
state, state_size);
|
||||||
|
|
||||||
|
local_error =
|
||||||
|
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t sen66_get_nox_algorithm_tuning_parameters(
|
||||||
|
int16_t* index_offset, int16_t* learning_time_offset_hours,
|
||||||
|
int16_t* learning_time_gain_hours, int16_t* gating_max_duration_minutes,
|
||||||
|
int16_t* std_initial, int16_t* gain_factor) {
|
||||||
|
int16_t local_error = NO_ERROR;
|
||||||
|
uint8_t* buffer_ptr = communication_buffer;
|
||||||
|
uint16_t local_offset = 0;
|
||||||
|
|
||||||
|
local_offset = sensirion_i2c_add_command16_to_buffer(
|
||||||
|
buffer_ptr, local_offset,
|
||||||
|
SEN66_GET_NOX_ALGORITHM_TUNING_PARAMETERS_CMD_ID);
|
||||||
|
local_error =
|
||||||
|
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
sensirion_i2c_hal_sleep_usec(20 * 1000);
|
||||||
|
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 12);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
*index_offset = sensirion_common_bytes_to_int16_t(&buffer_ptr[0]);
|
||||||
|
*learning_time_offset_hours =
|
||||||
|
sensirion_common_bytes_to_int16_t(&buffer_ptr[2]);
|
||||||
|
*learning_time_gain_hours =
|
||||||
|
sensirion_common_bytes_to_int16_t(&buffer_ptr[4]);
|
||||||
|
*gating_max_duration_minutes =
|
||||||
|
sensirion_common_bytes_to_int16_t(&buffer_ptr[6]);
|
||||||
|
*std_initial = sensirion_common_bytes_to_int16_t(&buffer_ptr[8]);
|
||||||
|
*gain_factor = sensirion_common_bytes_to_int16_t(&buffer_ptr[10]);
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t sen66_set_nox_algorithm_tuning_parameters(
|
||||||
|
int16_t index_offset, int16_t learning_time_offset_hours,
|
||||||
|
int16_t learning_time_gain_hours, int16_t gating_max_duration_minutes,
|
||||||
|
int16_t std_initial, int16_t gain_factor) {
|
||||||
|
int16_t local_error = NO_ERROR;
|
||||||
|
uint8_t* buffer_ptr = communication_buffer;
|
||||||
|
uint16_t local_offset = 0;
|
||||||
|
|
||||||
|
local_offset = sensirion_i2c_add_command16_to_buffer(
|
||||||
|
buffer_ptr, local_offset,
|
||||||
|
SEN66_SET_NOX_ALGORITHM_TUNING_PARAMETERS_CMD_ID);
|
||||||
|
local_offset = sensirion_i2c_add_int16_t_to_buffer(buffer_ptr, local_offset,
|
||||||
|
index_offset);
|
||||||
|
local_offset = sensirion_i2c_add_int16_t_to_buffer(
|
||||||
|
buffer_ptr, local_offset, learning_time_offset_hours);
|
||||||
|
local_offset = sensirion_i2c_add_int16_t_to_buffer(
|
||||||
|
buffer_ptr, local_offset, learning_time_gain_hours);
|
||||||
|
local_offset = sensirion_i2c_add_int16_t_to_buffer(
|
||||||
|
buffer_ptr, local_offset, gating_max_duration_minutes);
|
||||||
|
local_offset = sensirion_i2c_add_int16_t_to_buffer(buffer_ptr, local_offset,
|
||||||
|
std_initial);
|
||||||
|
local_offset = sensirion_i2c_add_int16_t_to_buffer(buffer_ptr, local_offset,
|
||||||
|
gain_factor);
|
||||||
|
local_error =
|
||||||
|
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
sensirion_i2c_hal_sleep_usec(20 * 1000);
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t
|
||||||
|
sen66_perform_forced_co2_recalibration(uint16_t target_co2_concentration,
|
||||||
|
uint16_t* correction) {
|
||||||
|
int16_t local_error = NO_ERROR;
|
||||||
|
uint8_t* buffer_ptr = communication_buffer;
|
||||||
|
uint16_t local_offset = 0;
|
||||||
|
|
||||||
|
local_offset = sensirion_i2c_add_command16_to_buffer(
|
||||||
|
buffer_ptr, local_offset,
|
||||||
|
SEN66_PERFORM_FORCED_CO2_RECALIBRATION_CMD_ID);
|
||||||
|
local_offset = sensirion_i2c_add_uint16_t_to_buffer(
|
||||||
|
buffer_ptr, local_offset, target_co2_concentration);
|
||||||
|
local_error =
|
||||||
|
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
sensirion_i2c_hal_sleep_usec(500 * 1000);
|
||||||
|
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 2);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
*correction = sensirion_common_bytes_to_uint16_t(&buffer_ptr[0]);
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t sen66_perform_co2_sensor_factory_reset(void) {
|
||||||
|
int16_t local_error = NO_ERROR;
|
||||||
|
uint8_t* buffer_ptr = communication_buffer;
|
||||||
|
uint16_t local_offset = 0;
|
||||||
|
|
||||||
|
local_offset = sensirion_i2c_add_command16_to_buffer(
|
||||||
|
buffer_ptr, local_offset,
|
||||||
|
SEN66_PERFORM_CO2_SENSOR_FACTORY_RESET_CMD_ID);
|
||||||
|
local_error =
|
||||||
|
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
sensirion_i2c_hal_sleep_usec(1400 * 1000);
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t sen66_get_co2_sensor_automatic_self_calibration(uint8_t* padding,
|
||||||
|
bool* status) {
|
||||||
|
int16_t local_error = NO_ERROR;
|
||||||
|
uint8_t* buffer_ptr = communication_buffer;
|
||||||
|
uint16_t local_offset = 0;
|
||||||
|
|
||||||
|
local_offset = sensirion_i2c_add_command16_to_buffer(
|
||||||
|
buffer_ptr, local_offset,
|
||||||
|
SEN66_GET_CO2_SENSOR_AUTOMATIC_SELF_CALIBRATION_CMD_ID);
|
||||||
|
local_error =
|
||||||
|
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
sensirion_i2c_hal_sleep_usec(20 * 1000);
|
||||||
|
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 2);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
*padding = (uint8_t)buffer_ptr[0];
|
||||||
|
*status = (bool)buffer_ptr[1];
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t sen66_set_co2_sensor_automatic_self_calibration(uint16_t status) {
|
||||||
|
int16_t local_error = NO_ERROR;
|
||||||
|
uint8_t* buffer_ptr = communication_buffer;
|
||||||
|
uint16_t local_offset = 0;
|
||||||
|
|
||||||
|
local_offset = sensirion_i2c_add_command16_to_buffer(
|
||||||
|
buffer_ptr, local_offset,
|
||||||
|
SEN66_SET_CO2_SENSOR_AUTOMATIC_SELF_CALIBRATION_CMD_ID);
|
||||||
|
local_offset =
|
||||||
|
sensirion_i2c_add_uint16_t_to_buffer(buffer_ptr, local_offset, status);
|
||||||
|
local_error =
|
||||||
|
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
sensirion_i2c_hal_sleep_usec(20 * 1000);
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t sen66_get_ambient_pressure(uint16_t* ambient_pressure) {
|
||||||
|
int16_t local_error = NO_ERROR;
|
||||||
|
uint8_t* buffer_ptr = communication_buffer;
|
||||||
|
uint16_t local_offset = 0;
|
||||||
|
|
||||||
|
local_offset = sensirion_i2c_add_command16_to_buffer(
|
||||||
|
buffer_ptr, local_offset, SEN66_GET_AMBIENT_PRESSURE_CMD_ID);
|
||||||
|
local_error =
|
||||||
|
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
sensirion_i2c_hal_sleep_usec(20 * 1000);
|
||||||
|
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 2);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
*ambient_pressure = sensirion_common_bytes_to_uint16_t(&buffer_ptr[0]);
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t sen66_set_ambient_pressure(uint16_t ambient_pressure) {
|
||||||
|
int16_t local_error = NO_ERROR;
|
||||||
|
uint8_t* buffer_ptr = communication_buffer;
|
||||||
|
uint16_t local_offset = 0;
|
||||||
|
|
||||||
|
local_offset = sensirion_i2c_add_command16_to_buffer(
|
||||||
|
buffer_ptr, local_offset, SEN66_SET_AMBIENT_PRESSURE_CMD_ID);
|
||||||
|
local_offset = sensirion_i2c_add_uint16_t_to_buffer(
|
||||||
|
buffer_ptr, local_offset, ambient_pressure);
|
||||||
|
local_error =
|
||||||
|
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
sensirion_i2c_hal_sleep_usec(20 * 1000);
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t sen66_get_sensor_altitude(uint16_t* altitude) {
|
||||||
|
int16_t local_error = NO_ERROR;
|
||||||
|
uint8_t* buffer_ptr = communication_buffer;
|
||||||
|
uint16_t local_offset = 0;
|
||||||
|
|
||||||
|
local_offset = sensirion_i2c_add_command16_to_buffer(
|
||||||
|
buffer_ptr, local_offset, SEN66_GET_SENSOR_ALTITUDE_CMD_ID);
|
||||||
|
local_error =
|
||||||
|
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
sensirion_i2c_hal_sleep_usec(20 * 1000);
|
||||||
|
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 2);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
*altitude = sensirion_common_bytes_to_uint16_t(&buffer_ptr[0]);
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t sen66_set_sensor_altitude(uint16_t altitude) {
|
||||||
|
int16_t local_error = NO_ERROR;
|
||||||
|
uint8_t* buffer_ptr = communication_buffer;
|
||||||
|
uint16_t local_offset = 0;
|
||||||
|
|
||||||
|
local_offset = sensirion_i2c_add_command16_to_buffer(
|
||||||
|
buffer_ptr, local_offset, SEN66_SET_SENSOR_ALTITUDE_CMD_ID);
|
||||||
|
local_offset = sensirion_i2c_add_uint16_t_to_buffer(buffer_ptr,
|
||||||
|
local_offset, altitude);
|
||||||
|
local_error =
|
||||||
|
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
sensirion_i2c_hal_sleep_usec(20 * 1000);
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t sen66_start_continuous_measurement(void) {
|
||||||
|
int16_t local_error = NO_ERROR;
|
||||||
|
uint8_t* buffer_ptr = communication_buffer;
|
||||||
|
uint16_t local_offset = 0;
|
||||||
|
|
||||||
|
local_offset = sensirion_i2c_add_command16_to_buffer(
|
||||||
|
buffer_ptr, local_offset, SEN66_START_CONTINUOUS_MEASUREMENT_CMD_ID);
|
||||||
|
local_error =
|
||||||
|
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
sensirion_i2c_hal_sleep_usec(50 * 1000);
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t sen66_stop_measurement(void) {
|
||||||
|
int16_t local_error = NO_ERROR;
|
||||||
|
uint8_t* buffer_ptr = communication_buffer;
|
||||||
|
uint16_t local_offset = 0;
|
||||||
|
|
||||||
|
local_offset = sensirion_i2c_add_command16_to_buffer(
|
||||||
|
buffer_ptr, local_offset, SEN66_STOP_MEASUREMENT_CMD_ID);
|
||||||
|
local_error =
|
||||||
|
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
sensirion_i2c_hal_sleep_usec(1400 * 1000);
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t sen66_get_data_ready(uint8_t* padding, bool* data_ready) {
|
||||||
|
int16_t local_error = NO_ERROR;
|
||||||
|
uint8_t* buffer_ptr = communication_buffer;
|
||||||
|
uint16_t local_offset = 0;
|
||||||
|
|
||||||
|
local_offset = sensirion_i2c_add_command16_to_buffer(
|
||||||
|
buffer_ptr, local_offset, SEN66_GET_DATA_READY_CMD_ID);
|
||||||
|
local_error =
|
||||||
|
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
sensirion_i2c_hal_sleep_usec(20 * 1000);
|
||||||
|
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 2);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
*padding = (uint8_t)buffer_ptr[0];
|
||||||
|
*data_ready = (bool)buffer_ptr[1];
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t sen66_read_number_concentration_values_as_integers(
|
||||||
|
uint16_t* number_concentration_pm0p5, uint16_t* number_concentration_pm1p0,
|
||||||
|
uint16_t* number_concentration_pm2p5, uint16_t* number_concentration_pm4p0,
|
||||||
|
uint16_t* number_concentration_pm10p0) {
|
||||||
|
int16_t local_error = NO_ERROR;
|
||||||
|
uint8_t* buffer_ptr = communication_buffer;
|
||||||
|
uint16_t local_offset = 0;
|
||||||
|
|
||||||
|
local_offset = sensirion_i2c_add_command16_to_buffer(
|
||||||
|
buffer_ptr, local_offset,
|
||||||
|
SEN66_READ_NUMBER_CONCENTRATION_VALUES_AS_INTEGERS_CMD_ID);
|
||||||
|
local_error =
|
||||||
|
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
sensirion_i2c_hal_sleep_usec(20 * 1000);
|
||||||
|
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 10);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
*number_concentration_pm0p5 =
|
||||||
|
sensirion_common_bytes_to_uint16_t(&buffer_ptr[0]);
|
||||||
|
*number_concentration_pm1p0 =
|
||||||
|
sensirion_common_bytes_to_uint16_t(&buffer_ptr[2]);
|
||||||
|
*number_concentration_pm2p5 =
|
||||||
|
sensirion_common_bytes_to_uint16_t(&buffer_ptr[4]);
|
||||||
|
*number_concentration_pm4p0 =
|
||||||
|
sensirion_common_bytes_to_uint16_t(&buffer_ptr[6]);
|
||||||
|
*number_concentration_pm10p0 =
|
||||||
|
sensirion_common_bytes_to_uint16_t(&buffer_ptr[8]);
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t sen66_set_temperature_offset_parameters(int16_t offset, int16_t slope,
|
||||||
|
uint16_t time_constant,
|
||||||
|
uint16_t slot) {
|
||||||
|
int16_t local_error = NO_ERROR;
|
||||||
|
uint8_t* buffer_ptr = communication_buffer;
|
||||||
|
uint16_t local_offset = 0;
|
||||||
|
|
||||||
|
local_offset = sensirion_i2c_add_command16_to_buffer(
|
||||||
|
buffer_ptr, local_offset,
|
||||||
|
SEN66_SET_TEMPERATURE_OFFSET_PARAMETERS_CMD_ID);
|
||||||
|
local_offset =
|
||||||
|
sensirion_i2c_add_int16_t_to_buffer(buffer_ptr, local_offset, offset);
|
||||||
|
local_offset =
|
||||||
|
sensirion_i2c_add_int16_t_to_buffer(buffer_ptr, local_offset, slope);
|
||||||
|
local_offset = sensirion_i2c_add_uint16_t_to_buffer(
|
||||||
|
buffer_ptr, local_offset, time_constant);
|
||||||
|
local_offset =
|
||||||
|
sensirion_i2c_add_uint16_t_to_buffer(buffer_ptr, local_offset, slot);
|
||||||
|
local_error =
|
||||||
|
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
sensirion_i2c_hal_sleep_usec(20 * 1000);
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t sen66_set_temperature_acceleration_parameters(uint16_t k, uint16_t p,
|
||||||
|
uint16_t t1,
|
||||||
|
uint16_t t2) {
|
||||||
|
int16_t local_error = NO_ERROR;
|
||||||
|
uint8_t* buffer_ptr = communication_buffer;
|
||||||
|
uint16_t local_offset = 0;
|
||||||
|
|
||||||
|
local_offset = sensirion_i2c_add_command16_to_buffer(
|
||||||
|
buffer_ptr, local_offset,
|
||||||
|
SEN66_SET_TEMPERATURE_ACCELERATION_PARAMETERS_CMD_ID);
|
||||||
|
local_offset =
|
||||||
|
sensirion_i2c_add_uint16_t_to_buffer(buffer_ptr, local_offset, k);
|
||||||
|
local_offset =
|
||||||
|
sensirion_i2c_add_uint16_t_to_buffer(buffer_ptr, local_offset, p);
|
||||||
|
local_offset =
|
||||||
|
sensirion_i2c_add_uint16_t_to_buffer(buffer_ptr, local_offset, t1);
|
||||||
|
local_offset =
|
||||||
|
sensirion_i2c_add_uint16_t_to_buffer(buffer_ptr, local_offset, t2);
|
||||||
|
local_error =
|
||||||
|
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
sensirion_i2c_hal_sleep_usec(20 * 1000);
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t sen66_get_product_type(int8_t* product_type,
|
||||||
|
uint16_t product_type_size) {
|
||||||
|
int16_t local_error = NO_ERROR;
|
||||||
|
uint8_t* buffer_ptr = communication_buffer;
|
||||||
|
uint16_t local_offset = 0;
|
||||||
|
|
||||||
|
local_offset = sensirion_i2c_add_command16_to_buffer(
|
||||||
|
buffer_ptr, local_offset, SEN66_GET_PRODUCT_TYPE_CMD_ID);
|
||||||
|
local_error =
|
||||||
|
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
sensirion_i2c_hal_sleep_usec(20 * 1000);
|
||||||
|
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 32);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
sensirion_common_copy_bytes(&buffer_ptr[0], (uint8_t*)product_type,
|
||||||
|
product_type_size);
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t sen66_get_product_name(int8_t* product_name,
|
||||||
|
uint16_t product_name_size) {
|
||||||
|
int16_t local_error = NO_ERROR;
|
||||||
|
uint8_t* buffer_ptr = communication_buffer;
|
||||||
|
uint16_t local_offset = 0;
|
||||||
|
|
||||||
|
local_offset = sensirion_i2c_add_command16_to_buffer(
|
||||||
|
buffer_ptr, local_offset, SEN66_GET_PRODUCT_NAME_CMD_ID);
|
||||||
|
local_error =
|
||||||
|
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
sensirion_i2c_hal_sleep_usec(20 * 1000);
|
||||||
|
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 32);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
sensirion_common_copy_bytes(&buffer_ptr[0], (uint8_t*)product_name,
|
||||||
|
product_name_size);
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t sen66_get_serial_number(int8_t* serial_number,
|
||||||
|
uint16_t serial_number_size) {
|
||||||
|
int16_t local_error = NO_ERROR;
|
||||||
|
uint8_t* buffer_ptr = communication_buffer;
|
||||||
|
uint16_t local_offset = 0;
|
||||||
|
|
||||||
|
local_offset = sensirion_i2c_add_command16_to_buffer(
|
||||||
|
buffer_ptr, local_offset, SEN66_GET_SERIAL_NUMBER_CMD_ID);
|
||||||
|
local_error =
|
||||||
|
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
sensirion_i2c_hal_sleep_usec(20 * 1000);
|
||||||
|
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 32);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
sensirion_common_copy_bytes(&buffer_ptr[0], (uint8_t*)serial_number,
|
||||||
|
serial_number_size);
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t sen66_read_device_status(sen66_device_status* device_status) {
|
||||||
|
int16_t local_error = NO_ERROR;
|
||||||
|
uint8_t* buffer_ptr = communication_buffer;
|
||||||
|
uint16_t local_offset = 0;
|
||||||
|
|
||||||
|
local_offset = sensirion_i2c_add_command16_to_buffer(
|
||||||
|
buffer_ptr, local_offset, SEN66_READ_DEVICE_STATUS_CMD_ID);
|
||||||
|
local_error =
|
||||||
|
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
sensirion_i2c_hal_sleep_usec(20 * 1000);
|
||||||
|
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 4);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
(*device_status).value = sensirion_common_bytes_to_uint32_t(&buffer_ptr[0]);
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t sen66_read_and_clear_device_status(sen66_device_status* device_status) {
|
||||||
|
int16_t local_error = NO_ERROR;
|
||||||
|
uint8_t* buffer_ptr = communication_buffer;
|
||||||
|
uint16_t local_offset = 0;
|
||||||
|
|
||||||
|
local_offset = sensirion_i2c_add_command16_to_buffer(
|
||||||
|
buffer_ptr, local_offset, SEN66_READ_AND_CLEAR_DEVICE_STATUS_CMD_ID);
|
||||||
|
local_error =
|
||||||
|
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
sensirion_i2c_hal_sleep_usec(20 * 1000);
|
||||||
|
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 4);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
(*device_status).value = sensirion_common_bytes_to_uint32_t(&buffer_ptr[0]);
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t sen66_get_version(uint8_t* firmware_major, uint8_t* firmware_minor) {
|
||||||
|
int16_t local_error = NO_ERROR;
|
||||||
|
uint8_t* buffer_ptr = communication_buffer;
|
||||||
|
uint16_t local_offset = 0;
|
||||||
|
|
||||||
|
local_offset = sensirion_i2c_add_command16_to_buffer(
|
||||||
|
buffer_ptr, local_offset, SEN66_GET_VERSION_CMD_ID);
|
||||||
|
local_error =
|
||||||
|
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
sensirion_i2c_hal_sleep_usec(20 * 1000);
|
||||||
|
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 2);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
*firmware_major = (uint8_t)buffer_ptr[0];
|
||||||
|
*firmware_minor = (uint8_t)buffer_ptr[1];
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t sen66_device_reset(void) {
|
||||||
|
int16_t local_error = NO_ERROR;
|
||||||
|
uint8_t* buffer_ptr = communication_buffer;
|
||||||
|
uint16_t local_offset = 0;
|
||||||
|
|
||||||
|
local_offset = sensirion_i2c_add_command16_to_buffer(
|
||||||
|
buffer_ptr, local_offset, SEN66_DEVICE_RESET_CMD_ID);
|
||||||
|
local_error =
|
||||||
|
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
sensirion_i2c_hal_sleep_usec(1200 * 1000);
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t sen66_start_fan_cleaning(void) {
|
||||||
|
int16_t local_error = NO_ERROR;
|
||||||
|
uint8_t* buffer_ptr = communication_buffer;
|
||||||
|
uint16_t local_offset = 0;
|
||||||
|
|
||||||
|
local_offset = sensirion_i2c_add_command16_to_buffer(
|
||||||
|
buffer_ptr, local_offset, SEN66_START_FAN_CLEANING_CMD_ID);
|
||||||
|
local_error =
|
||||||
|
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
sensirion_i2c_hal_sleep_usec(20 * 1000);
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t sen66_activate_sht_heater(void) {
|
||||||
|
int16_t local_error = NO_ERROR;
|
||||||
|
uint8_t* buffer_ptr = communication_buffer;
|
||||||
|
uint16_t local_offset = 0;
|
||||||
|
|
||||||
|
local_offset = sensirion_i2c_add_command16_to_buffer(
|
||||||
|
buffer_ptr, local_offset, SEN66_ACTIVATE_SHT_HEATER_CMD_ID);
|
||||||
|
local_error =
|
||||||
|
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
sensirion_i2c_hal_sleep_usec(20 * 1000);
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t sen66_get_sht_heater_measurements(int16_t* sht_relative_humidity,
|
||||||
|
int16_t* sht_temperature) {
|
||||||
|
int16_t local_error = NO_ERROR;
|
||||||
|
uint8_t* buffer_ptr = communication_buffer;
|
||||||
|
uint16_t local_offset = 0;
|
||||||
|
|
||||||
|
local_offset = sensirion_i2c_add_command16_to_buffer(
|
||||||
|
buffer_ptr, local_offset, SEN66_GET_SHT_HEATER_MEASUREMENTS_CMD_ID);
|
||||||
|
local_error =
|
||||||
|
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
sensirion_i2c_hal_sleep_usec(20 * 1000);
|
||||||
|
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 4);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
*sht_relative_humidity = sensirion_common_bytes_to_int16_t(&buffer_ptr[0]);
|
||||||
|
*sht_temperature = sensirion_common_bytes_to_int16_t(&buffer_ptr[2]);
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t sen66_read_measured_values_as_integers(
|
||||||
|
uint16_t* mass_concentration_pm1p0, uint16_t* mass_concentration_pm2p5,
|
||||||
|
uint16_t* mass_concentration_pm4p0, uint16_t* mass_concentration_pm10p0,
|
||||||
|
int16_t* ambient_humidity, int16_t* ambient_temperature, int16_t* voc_index,
|
||||||
|
int16_t* nox_index, uint16_t* co2) {
|
||||||
|
int16_t local_error = NO_ERROR;
|
||||||
|
uint8_t* buffer_ptr = communication_buffer;
|
||||||
|
uint16_t local_offset = 0;
|
||||||
|
|
||||||
|
local_offset = sensirion_i2c_add_command16_to_buffer(
|
||||||
|
buffer_ptr, local_offset,
|
||||||
|
SEN66_READ_MEASURED_VALUES_AS_INTEGERS_CMD_ID);
|
||||||
|
local_error =
|
||||||
|
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
sensirion_i2c_hal_sleep_usec(20 * 1000);
|
||||||
|
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 18);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
*mass_concentration_pm1p0 =
|
||||||
|
sensirion_common_bytes_to_uint16_t(&buffer_ptr[0]);
|
||||||
|
*mass_concentration_pm2p5 =
|
||||||
|
sensirion_common_bytes_to_uint16_t(&buffer_ptr[2]);
|
||||||
|
*mass_concentration_pm4p0 =
|
||||||
|
sensirion_common_bytes_to_uint16_t(&buffer_ptr[4]);
|
||||||
|
*mass_concentration_pm10p0 =
|
||||||
|
sensirion_common_bytes_to_uint16_t(&buffer_ptr[6]);
|
||||||
|
*ambient_humidity = sensirion_common_bytes_to_int16_t(&buffer_ptr[8]);
|
||||||
|
*ambient_temperature = sensirion_common_bytes_to_int16_t(&buffer_ptr[10]);
|
||||||
|
*voc_index = sensirion_common_bytes_to_int16_t(&buffer_ptr[12]);
|
||||||
|
*nox_index = sensirion_common_bytes_to_int16_t(&buffer_ptr[14]);
|
||||||
|
*co2 = sensirion_common_bytes_to_uint16_t(&buffer_ptr[16]);
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t sen66_read_measured_raw_values(int16_t* raw_humidity,
|
||||||
|
int16_t* raw_temperature,
|
||||||
|
uint16_t* raw_voc, uint16_t* raw_nox,
|
||||||
|
uint16_t* raw_co2) {
|
||||||
|
int16_t local_error = NO_ERROR;
|
||||||
|
uint8_t* buffer_ptr = communication_buffer;
|
||||||
|
uint16_t local_offset = 0;
|
||||||
|
|
||||||
|
local_offset = sensirion_i2c_add_command16_to_buffer(
|
||||||
|
buffer_ptr, local_offset, SEN66_READ_MEASURED_RAW_VALUES_CMD_ID);
|
||||||
|
local_error =
|
||||||
|
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
sensirion_i2c_hal_sleep_usec(20 * 1000);
|
||||||
|
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 10);
|
||||||
|
if (local_error != NO_ERROR) {
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
|
*raw_humidity = sensirion_common_bytes_to_int16_t(&buffer_ptr[0]);
|
||||||
|
*raw_temperature = sensirion_common_bytes_to_int16_t(&buffer_ptr[2]);
|
||||||
|
*raw_voc = sensirion_common_bytes_to_uint16_t(&buffer_ptr[4]);
|
||||||
|
*raw_nox = sensirion_common_bytes_to_uint16_t(&buffer_ptr[6]);
|
||||||
|
*raw_co2 = sensirion_common_bytes_to_uint16_t(&buffer_ptr[8]);
|
||||||
|
return local_error;
|
||||||
|
}
|
||||||
@@ -0,0 +1,899 @@
|
|||||||
|
/*
|
||||||
|
* THIS FILE IS AUTOMATICALLY GENERATED
|
||||||
|
*
|
||||||
|
* Generator: sensirion-driver-generator 1.7.0
|
||||||
|
* Product: sen66
|
||||||
|
* Model-Version: 1.7.3
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2026, Sensirion AG
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* * Neither the name of Sensirion AG nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||||
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SEN66_I2C_H
|
||||||
|
#define SEN66_I2C_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "sensirion_config.h"
|
||||||
|
#define SEN66_I2C_ADDR_6B 0x6b
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
SEN66_GET_VOC_ALGORITHM_TUNING_PARAMETERS_CMD_ID = 0x60d0,
|
||||||
|
SEN66_SET_VOC_ALGORITHM_TUNING_PARAMETERS_CMD_ID = 0x60d0,
|
||||||
|
SEN66_GET_VOC_ALGORITHM_STATE_CMD_ID = 0x6181,
|
||||||
|
SEN66_SET_VOC_ALGORITHM_STATE_CMD_ID = 0x6181,
|
||||||
|
SEN66_GET_NOX_ALGORITHM_TUNING_PARAMETERS_CMD_ID = 0x60e1,
|
||||||
|
SEN66_SET_NOX_ALGORITHM_TUNING_PARAMETERS_CMD_ID = 0x60e1,
|
||||||
|
SEN66_PERFORM_FORCED_CO2_RECALIBRATION_CMD_ID = 0x6707,
|
||||||
|
SEN66_PERFORM_CO2_SENSOR_FACTORY_RESET_CMD_ID = 0x6754,
|
||||||
|
SEN66_GET_CO2_SENSOR_AUTOMATIC_SELF_CALIBRATION_CMD_ID = 0x6711,
|
||||||
|
SEN66_SET_CO2_SENSOR_AUTOMATIC_SELF_CALIBRATION_CMD_ID = 0x6711,
|
||||||
|
SEN66_GET_AMBIENT_PRESSURE_CMD_ID = 0x6720,
|
||||||
|
SEN66_SET_AMBIENT_PRESSURE_CMD_ID = 0x6720,
|
||||||
|
SEN66_GET_SENSOR_ALTITUDE_CMD_ID = 0x6736,
|
||||||
|
SEN66_SET_SENSOR_ALTITUDE_CMD_ID = 0x6736,
|
||||||
|
SEN66_START_CONTINUOUS_MEASUREMENT_CMD_ID = 0x21,
|
||||||
|
SEN66_STOP_MEASUREMENT_CMD_ID = 0x104,
|
||||||
|
SEN66_GET_DATA_READY_CMD_ID = 0x202,
|
||||||
|
SEN66_READ_NUMBER_CONCENTRATION_VALUES_AS_INTEGERS_CMD_ID = 0x316,
|
||||||
|
SEN66_SET_TEMPERATURE_OFFSET_PARAMETERS_CMD_ID = 0x60b2,
|
||||||
|
SEN66_SET_TEMPERATURE_ACCELERATION_PARAMETERS_CMD_ID = 0x6100,
|
||||||
|
SEN66_GET_PRODUCT_TYPE_CMD_ID = 0xd002,
|
||||||
|
SEN66_GET_PRODUCT_NAME_CMD_ID = 0xd014,
|
||||||
|
SEN66_GET_SERIAL_NUMBER_CMD_ID = 0xd033,
|
||||||
|
SEN66_READ_DEVICE_STATUS_CMD_ID = 0xd206,
|
||||||
|
SEN66_READ_AND_CLEAR_DEVICE_STATUS_CMD_ID = 0xd210,
|
||||||
|
SEN66_GET_VERSION_CMD_ID = 0xd100,
|
||||||
|
SEN66_DEVICE_RESET_CMD_ID = 0xd304,
|
||||||
|
SEN66_START_FAN_CLEANING_CMD_ID = 0x5607,
|
||||||
|
SEN66_ACTIVATE_SHT_HEATER_CMD_ID = 0x6765,
|
||||||
|
SEN66_GET_SHT_HEATER_MEASUREMENTS_CMD_ID = 0x6790,
|
||||||
|
SEN66_READ_MEASURED_VALUES_AS_INTEGERS_CMD_ID = 0x300,
|
||||||
|
SEN66_READ_MEASURED_RAW_VALUES_CMD_ID = 0x405,
|
||||||
|
} SEN66_CMD_ID;
|
||||||
|
|
||||||
|
typedef union {
|
||||||
|
struct {
|
||||||
|
uint32_t reserved1 : 4;
|
||||||
|
uint32_t fan_error : 1;
|
||||||
|
uint32_t reserved2 : 1;
|
||||||
|
uint32_t rht_error : 1;
|
||||||
|
uint32_t gas_error : 1;
|
||||||
|
uint32_t reserved3 : 1;
|
||||||
|
uint32_t co2_2_error : 1;
|
||||||
|
uint32_t hcho_error : 1;
|
||||||
|
uint32_t pm_error : 1;
|
||||||
|
uint32_t co2_1_error : 1;
|
||||||
|
uint32_t reserved4 : 8;
|
||||||
|
uint32_t fan_speed_warning : 1;
|
||||||
|
uint32_t reserved5 : 10;
|
||||||
|
};
|
||||||
|
uint32_t value;
|
||||||
|
} sen66_device_status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Initialize i2c address of driver
|
||||||
|
*
|
||||||
|
* @param[in] i2c_address Used i2c address
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void sen66_init(uint8_t i2c_address);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief sen66_get_voc_algorithm_tuning_parameters
|
||||||
|
*
|
||||||
|
* Gets the parameters to customize the VOC algorithm.
|
||||||
|
*
|
||||||
|
* @param[out] index_offset VOC index representing typical (average) conditions.
|
||||||
|
* @param[out] learning_time_offset_hours Time constant to estimate the VOC
|
||||||
|
* algorithm offset from the history in hours. Past events will be forgotten
|
||||||
|
* after about twice the learning time.
|
||||||
|
* @param[out] learning_time_gain_hours Time constant to estimate the VOC
|
||||||
|
* algorithm gain from the history in hours. Past events will be forgotten after
|
||||||
|
* about twice the learning time.
|
||||||
|
* @param[out] gating_max_duration_minutes Maximum duration of gating in minutes
|
||||||
|
* (freeze of estimator during high VOC index signal). Zero disables the gating.
|
||||||
|
* @param[out] std_initial Initial estimate for standard deviation. Lower value
|
||||||
|
* boosts events during initial learning period, but may result in larger
|
||||||
|
* device-to-device variations.
|
||||||
|
* @param[out] gain_factor Gain factor to amplify or to attenuate the VOC index
|
||||||
|
* output.
|
||||||
|
*
|
||||||
|
* @note This command is only available in idle mode.
|
||||||
|
*
|
||||||
|
* @return error_code 0 on success, an error code otherwise.
|
||||||
|
*/
|
||||||
|
int16_t sen66_get_voc_algorithm_tuning_parameters(
|
||||||
|
int16_t* index_offset, int16_t* learning_time_offset_hours,
|
||||||
|
int16_t* learning_time_gain_hours, int16_t* gating_max_duration_minutes,
|
||||||
|
int16_t* std_initial, int16_t* gain_factor);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief sen66_set_voc_algorithm_tuning_parameters
|
||||||
|
*
|
||||||
|
* Sets the parameters to customize the VOC algorithm. This configuration is
|
||||||
|
* volatile, i.e. the parameters will be reverted to their default values after
|
||||||
|
* a device reset.
|
||||||
|
*
|
||||||
|
* @param[in] index_offset VOC index representing typical (average) conditions.
|
||||||
|
* Allowed values are in range 1..250. The default value is 100.
|
||||||
|
* @param[in] learning_time_offset_hours Time constant to estimate the VOC
|
||||||
|
* algorithm offset from the history in hours. Past events will be forgotten
|
||||||
|
* after about twice the learning time. Allowed values are in range 1..1000. The
|
||||||
|
* default value is 12 hours.
|
||||||
|
* @param[in] learning_time_gain_hours Time constant to estimate the VOC
|
||||||
|
* algorithm gain from the history in hours. Past events will be forgotten after
|
||||||
|
* about twice the learning time. Allowed values are in range 1..1000. The
|
||||||
|
* default value is 12 hours.
|
||||||
|
* @param[in] gating_max_duration_minutes Maximum duration of gating in minutes
|
||||||
|
* (freeze of estimator during high VOC index signal). Set to zero to disable
|
||||||
|
* the gating. Allowed values are in range 0..3000. The default value is 180
|
||||||
|
* minutes
|
||||||
|
* @param[in] std_initial Initial estimate for standard deviation. Lower value
|
||||||
|
* boosts events during initial learning period, but may result in larger
|
||||||
|
* device-to-device variations. Allowed values are in range 10..5000. The
|
||||||
|
* default value is 50.
|
||||||
|
* @param[in] gain_factor Gain factor to amplify or to attenuate the VOC index
|
||||||
|
* output. Allowed values are in range 1..1000. The default value is 230.
|
||||||
|
*
|
||||||
|
* @note This command is available only in idle mode. In measure mode, this
|
||||||
|
* command has no effect. In addition, it has no effect if at least one
|
||||||
|
* parameter is outside the specified range.
|
||||||
|
*
|
||||||
|
* @return error_code 0 on success, an error code otherwise.
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
* --------
|
||||||
|
*
|
||||||
|
* @code{.c}
|
||||||
|
*
|
||||||
|
* int16_t local_error = 0;
|
||||||
|
*
|
||||||
|
* local_error = sen66_set_voc_algorithm_tuning_parameters(100, 12, 12, 180,
|
||||||
|
* 50, 230); if (local_error != NO_ERROR) { return local_error;
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
int16_t sen66_set_voc_algorithm_tuning_parameters(
|
||||||
|
int16_t index_offset, int16_t learning_time_offset_hours,
|
||||||
|
int16_t learning_time_gain_hours, int16_t gating_max_duration_minutes,
|
||||||
|
int16_t std_initial, int16_t gain_factor);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief sen66_get_voc_algorithm_state
|
||||||
|
*
|
||||||
|
* Gets the current VOC algorithm state. Allows to backup and restore the VOC
|
||||||
|
* algorithm state to resume operation after a power cycle or device reset,
|
||||||
|
* skipping initial learning phase. By default, the VOC Engine is reset and the
|
||||||
|
* algorithm state is retained if a measurement is stopped and started again.
|
||||||
|
* If the VOC algorithm state shall be reset, a device reset or a power cycle
|
||||||
|
* can be executed.
|
||||||
|
*
|
||||||
|
* @param[out] state Current VOC algorithm state.
|
||||||
|
*
|
||||||
|
* @note This command can be used either in measure mode or in idle mode (which
|
||||||
|
* will then return the state at the time when the measurement was stopped). In
|
||||||
|
* measure mode, the state can be read each measure interval to always have the
|
||||||
|
* latest state available, even in case of a sudden power loss.
|
||||||
|
*
|
||||||
|
* @return error_code 0 on success, an error code otherwise.
|
||||||
|
*/
|
||||||
|
int16_t sen66_get_voc_algorithm_state(uint8_t* state, uint16_t state_size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief sen66_set_voc_algorithm_state
|
||||||
|
*
|
||||||
|
* Sets the VOC algorithm state previously received with "Get VOC Algorithm
|
||||||
|
* State" command. Allows restoration of the VOC algorithm state to resume
|
||||||
|
* operation after a power cycle or device reset, skipping initial learning
|
||||||
|
* phase. By default, the VOC Engine is reset, and the algorithm state is
|
||||||
|
* retained if a measurement is stopped and started again. If the VOC algorithm
|
||||||
|
* state shall be reset, a device reset, or a power cycle can be executed.
|
||||||
|
*
|
||||||
|
* @param[in] state VOC algorithm state to restore.
|
||||||
|
*
|
||||||
|
* @note This command is only available in idle mode and the state will be
|
||||||
|
* applied only once when starting the next measurement. In measure mode, this
|
||||||
|
* command has no effect.
|
||||||
|
*
|
||||||
|
* @return error_code 0 on success, an error code otherwise.
|
||||||
|
*/
|
||||||
|
int16_t sen66_set_voc_algorithm_state(const uint8_t* state,
|
||||||
|
uint16_t state_size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief sen66_get_nox_algorithm_tuning_parameters
|
||||||
|
*
|
||||||
|
* Gets the parameters to customize the NOx algorithm.
|
||||||
|
*
|
||||||
|
* @param[out] index_offset NOx index representing typical (average) conditions.
|
||||||
|
* @param[out] learning_time_offset_hours Time constant to estimate the NOx
|
||||||
|
* algorithm offset from the history in hours. Past events will be forgotten
|
||||||
|
* after about twice the learning time.
|
||||||
|
* @param[out] learning_time_gain_hours The time constant to estimate the NOx
|
||||||
|
* algorithm gain from the history has no impact for NOx. This parameter is
|
||||||
|
* still in place for consistency reasons with the VOC tuning parameters
|
||||||
|
* command.
|
||||||
|
* @param[out] gating_max_duration_minutes Maximum duration of gating in minutes
|
||||||
|
* (freeze of estimator during high NOx index signal). Zero disables the gating.
|
||||||
|
* @param[out] std_initial The initial estimate for standard deviation has no
|
||||||
|
* impact for NOx. This parameter is still in place for consistency reasons with
|
||||||
|
* the VOC tuning parameters command.
|
||||||
|
* @param[out] gain_factor Gain factor to amplify or to attenuate the NOx index
|
||||||
|
* output.
|
||||||
|
*
|
||||||
|
* @note This command is available only in idle mode.
|
||||||
|
*
|
||||||
|
* @return error_code 0 on success, an error code otherwise.
|
||||||
|
*/
|
||||||
|
int16_t sen66_get_nox_algorithm_tuning_parameters(
|
||||||
|
int16_t* index_offset, int16_t* learning_time_offset_hours,
|
||||||
|
int16_t* learning_time_gain_hours, int16_t* gating_max_duration_minutes,
|
||||||
|
int16_t* std_initial, int16_t* gain_factor);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief sen66_set_nox_algorithm_tuning_parameters
|
||||||
|
*
|
||||||
|
* Sets the parameters to customize the NOx algorithm. This configuration is
|
||||||
|
* volatile, i.e. the parameters will be reverted to their default values after
|
||||||
|
* a device reset.
|
||||||
|
*
|
||||||
|
* @param[in] index_offset NOx index representing typical (average) conditions.
|
||||||
|
* Allowed values are in range 1..250. The default value is 1.
|
||||||
|
* @param[in] learning_time_offset_hours Time constant to estimate the NOx
|
||||||
|
* algorithm offset from the history in hours. Past events will be forgotten
|
||||||
|
* after about twice the learning time. Allowed values are in range 1..1000. The
|
||||||
|
* default value is 12 hours.
|
||||||
|
* @param[in] learning_time_gain_hours The time constant to estimate the NOx
|
||||||
|
* algorithm gain from the history has no impact for NOx. This parameter is
|
||||||
|
* still in place for consistency reasons with the VOC tuning parameters
|
||||||
|
* command. This parameter must always be set to 12 hours.
|
||||||
|
* @param[in] gating_max_duration_minutes Maximum duration of gating in minutes
|
||||||
|
* (freeze of estimator during high NOx index signal). Set to zero to disable
|
||||||
|
* the gating. Allowed values are in range 0..3000. The default value is 720
|
||||||
|
* minutes.
|
||||||
|
* @param[in] std_initial The initial estimate for standard deviation parameter
|
||||||
|
* has no impact for NOx. This parameter is still in place for consistency
|
||||||
|
* reasons with the VOC tuning parameters command. This parameter must always be
|
||||||
|
* set to 50.
|
||||||
|
* @param[in] gain_factor Gain factor to amplify or to attenuate the NOx index
|
||||||
|
* output. Allowed values are in range 1..1000. The default value is 230.
|
||||||
|
*
|
||||||
|
* @note This command is available only in idle mode. In measure mode, this
|
||||||
|
* command has no effect. In addition, it has no effect if at least one
|
||||||
|
* parameter is outside the specified range.
|
||||||
|
*
|
||||||
|
* @return error_code 0 on success, an error code otherwise.
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
* --------
|
||||||
|
*
|
||||||
|
* @code{.c}
|
||||||
|
*
|
||||||
|
* int16_t local_error = 0;
|
||||||
|
*
|
||||||
|
* local_error = sen66_set_nox_algorithm_tuning_parameters(1, 12, 12, 720,
|
||||||
|
* 50, 230); if (local_error != NO_ERROR) { return local_error;
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
int16_t sen66_set_nox_algorithm_tuning_parameters(
|
||||||
|
int16_t index_offset, int16_t learning_time_offset_hours,
|
||||||
|
int16_t learning_time_gain_hours, int16_t gating_max_duration_minutes,
|
||||||
|
int16_t std_initial, int16_t gain_factor);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Perform Forced CO₂ Recalibration
|
||||||
|
*
|
||||||
|
* Execute the forced recalibration (FRC) of the CO₂. See the datasheet of the
|
||||||
|
* SCD4x sensor for details how the forced recalibration shall be used.
|
||||||
|
*
|
||||||
|
* @param[in] target_co2_concentration Target CO₂ concentration [ppm] of the
|
||||||
|
* test setup.
|
||||||
|
* @param[out] correction Correction value as received from the SCD [ppm CO₂].
|
||||||
|
* FRC correction [ppm CO₂] is calculated as follows: FRC = return_value -
|
||||||
|
* 0x8000 If the recalibration has failed this returned value is 0xFFFF.
|
||||||
|
*
|
||||||
|
* @note After power-on wait at least 1000 ms and after stopping a measurement
|
||||||
|
* 600 ms before sending this command. This command is not available in measure
|
||||||
|
* mode. The recalibration procedure will take about 500 ms to complete, during
|
||||||
|
* which time no other functions can be executed. This configuration is
|
||||||
|
* persistent, i.e. the parameters will be retained during a device reset or
|
||||||
|
* power cycle.
|
||||||
|
*
|
||||||
|
* @return error_code 0 on success, an error code otherwise.
|
||||||
|
*/
|
||||||
|
int16_t
|
||||||
|
sen66_perform_forced_co2_recalibration(uint16_t target_co2_concentration,
|
||||||
|
uint16_t* correction);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Perform CO₂ Sensor Factory Reset
|
||||||
|
*
|
||||||
|
* This command resets all CO₂ sensor configuration settings stored in the
|
||||||
|
* EEPROM and erases the FRC and ASC algorithm history of the CO₂ sensor. The
|
||||||
|
* configuration settings are CO₂ sensor temperature offset (cannot be modified
|
||||||
|
* over I2C interface), sensor altitude and the ASC enabled/disabled parameters
|
||||||
|
* which are by default stored in the volatile memory (RAM). This command is
|
||||||
|
* only available in idle mode.
|
||||||
|
*
|
||||||
|
* @return error_code 0 on success, an error code otherwise.
|
||||||
|
*/
|
||||||
|
int16_t sen66_perform_co2_sensor_factory_reset(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief sen66_get_co2_sensor_automatic_self_calibration
|
||||||
|
*
|
||||||
|
* The CO₂ sensor supports automatic self calibration (ASC) for long-term
|
||||||
|
* stability of the CO₂ output. This feature can be enabled or disabled. By
|
||||||
|
* default it is enabled.
|
||||||
|
*
|
||||||
|
* @param[out] padding Padding byte, always 0x00.
|
||||||
|
* @param[out] status Is set true (0x01) if the automatic self calibration is
|
||||||
|
* enabled or false (0x00) if the automatic self calibration is disabled.
|
||||||
|
*
|
||||||
|
* @note This command is only available in idle mode. This configuration is
|
||||||
|
* persistent, i.e. the status will be retained during a device reset or power
|
||||||
|
* cycle.
|
||||||
|
*
|
||||||
|
* @return error_code 0 on success, an error code otherwise.
|
||||||
|
*/
|
||||||
|
int16_t sen66_get_co2_sensor_automatic_self_calibration(uint8_t* padding,
|
||||||
|
bool* status);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief sen66_set_co2_sensor_automatic_self_calibration
|
||||||
|
*
|
||||||
|
* Sets the status of the CO₂ sensor automatic self-calibration (ASC). The CO₂
|
||||||
|
* sensor supports automatic self calibration (ASC) for long-term stability of
|
||||||
|
* the CO₂ output. This feature can be enabled or disabled. By default it is
|
||||||
|
* enabled.
|
||||||
|
*
|
||||||
|
* @param[in] status Set to true (0x0001) to enable or false (0x0000) to disable
|
||||||
|
* the automatic CO₂ measurement self calibration feature. High byte of uint16
|
||||||
|
* is padding and always 0x00.
|
||||||
|
*
|
||||||
|
* @note This command is only available in idle mode. This configuration is
|
||||||
|
* persistent, i.e. the status will be retained during a device reset or power
|
||||||
|
* cycle.
|
||||||
|
*
|
||||||
|
* @return error_code 0 on success, an error code otherwise.
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
* --------
|
||||||
|
*
|
||||||
|
* @code{.c}
|
||||||
|
*
|
||||||
|
* int16_t local_error = 0;
|
||||||
|
*
|
||||||
|
* local_error = sen66_set_co2_sensor_automatic_self_calibration(0);
|
||||||
|
* if (local_error != NO_ERROR) {
|
||||||
|
* return local_error;
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
int16_t sen66_set_co2_sensor_automatic_self_calibration(uint16_t status);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief sen66_get_ambient_pressure
|
||||||
|
*
|
||||||
|
* Gets the ambient pressure value. The ambient pressure can be used for
|
||||||
|
* pressure compensation in the CO₂ sensor.
|
||||||
|
*
|
||||||
|
* @param[out] ambient_pressure Currently used ambient pressure [hPa] for
|
||||||
|
* pressure compensation.
|
||||||
|
*
|
||||||
|
* @note This command can be used in any state of the device, i.e. both in idle
|
||||||
|
* mode and in measure mode.
|
||||||
|
*
|
||||||
|
* @return error_code 0 on success, an error code otherwise.
|
||||||
|
*/
|
||||||
|
int16_t sen66_get_ambient_pressure(uint16_t* ambient_pressure);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief sen66_set_ambient_pressure
|
||||||
|
*
|
||||||
|
* The ambient pressure can be used for pressure compensation in the CO₂ sensor.
|
||||||
|
* Setting an ambient pressure overrides any pressure compensation based on a
|
||||||
|
* previously set sensor altitude. Use of this command is recommended for
|
||||||
|
* applications experiencing significant ambient pressure changes to ensure CO₂
|
||||||
|
* sensor accuracy. Valid input values are between 700 to 1'200 hPa. The default
|
||||||
|
* value is 1013 hPa. This configuration is volatile, i.e. the parameter will be
|
||||||
|
* reverted to its default value after a device restart.
|
||||||
|
*
|
||||||
|
* @param[in] ambient_pressure Ambient pressure [hPa] to be used for pressure
|
||||||
|
* compensation.
|
||||||
|
*
|
||||||
|
* @note This command can be used in any state of the device, i.e. both in idle
|
||||||
|
* mode and in measure mode.
|
||||||
|
*
|
||||||
|
* @return error_code 0 on success, an error code otherwise.
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
* --------
|
||||||
|
*
|
||||||
|
* @code{.c}
|
||||||
|
*
|
||||||
|
* int16_t local_error = 0;
|
||||||
|
*
|
||||||
|
* local_error = sen66_set_ambient_pressure(1013);
|
||||||
|
* if (local_error != NO_ERROR) {
|
||||||
|
* return local_error;
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
int16_t sen66_set_ambient_pressure(uint16_t ambient_pressure);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief sen66_get_sensor_altitude
|
||||||
|
*
|
||||||
|
* Gets the current sensor altitude. The sensor altitude can be used for
|
||||||
|
* pressure compensation in the CO₂ sensor.
|
||||||
|
*
|
||||||
|
* @param[out] altitude Current sensor altitude [m].
|
||||||
|
*
|
||||||
|
* @note This command is only available in idle mode.
|
||||||
|
*
|
||||||
|
* @return error_code 0 on success, an error code otherwise.
|
||||||
|
*/
|
||||||
|
int16_t sen66_get_sensor_altitude(uint16_t* altitude);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief sen66_set_sensor_altitude
|
||||||
|
*
|
||||||
|
* The sensor altitude can be used for pressure compensation in the CO₂ sensor.
|
||||||
|
* The default sensor altitude value is set to 0 meters above sea level. Valid
|
||||||
|
* input values are between 0 and 3000m. This configuration is volatile, i.e.
|
||||||
|
* the parameter will be reverted to its default value after a device reset.
|
||||||
|
*
|
||||||
|
* @param[in] altitude Sensor altitude [m], valid input between 0 and 3000m.
|
||||||
|
*
|
||||||
|
* @return error_code 0 on success, an error code otherwise.
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
* --------
|
||||||
|
*
|
||||||
|
* @code{.c}
|
||||||
|
*
|
||||||
|
* int16_t local_error = 0;
|
||||||
|
*
|
||||||
|
* local_error = sen66_set_sensor_altitude(0);
|
||||||
|
* if (local_error != NO_ERROR) {
|
||||||
|
* return local_error;
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
int16_t sen66_set_sensor_altitude(uint16_t altitude);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Start a continuous measurement (interval 1s)
|
||||||
|
*
|
||||||
|
* Starts a continuous measurement. After starting the measurement, it takes
|
||||||
|
* some time (~1.1s) until the first measurement results are available. You
|
||||||
|
* could poll with the command "Get Data Ready" to check when the results are
|
||||||
|
* ready to read. This command is only available in idle mode. If the device is
|
||||||
|
* already in any measure mode, this command has no effect.
|
||||||
|
*
|
||||||
|
* @return error_code 0 on success, an error code otherwise.
|
||||||
|
*/
|
||||||
|
int16_t sen66_start_continuous_measurement(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Stop the continuous measurement
|
||||||
|
*
|
||||||
|
* Stops the measurement and returns to idle mode. After sending this command,
|
||||||
|
* wait at least 1000 ms before starting a new measurement. If the device is
|
||||||
|
* already in idle mode, this command has no effect.
|
||||||
|
*
|
||||||
|
* @return error_code 0 on success, an error code otherwise.
|
||||||
|
*/
|
||||||
|
int16_t sen66_stop_measurement(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Check if data is ready to be read out from the sensor
|
||||||
|
*
|
||||||
|
* This command can be used to check if new measurement results are ready to
|
||||||
|
* read. The data ready flag is automatically reset after reading the
|
||||||
|
* measurement values.
|
||||||
|
*
|
||||||
|
* @param[out] padding Padding byte, always 0x00.
|
||||||
|
* @param[out] data_ready True (0x01) if data is ready, False (0x00) if not.
|
||||||
|
* When no measurement is running, False will be returned.
|
||||||
|
*
|
||||||
|
* @return error_code 0 on success, an error code otherwise.
|
||||||
|
*/
|
||||||
|
int16_t sen66_get_data_ready(uint8_t* padding, bool* data_ready);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief sen66_read_number_concentration_values_as_integers
|
||||||
|
*
|
||||||
|
* Returns the measured number concentration values. The command 0x0202 "Get
|
||||||
|
* Data Ready" can be used to check if new data is available since the last read
|
||||||
|
* operation. If no new data is available, the previous values will be returned
|
||||||
|
* again. If no data is available at all (e.g. measurement not running for at
|
||||||
|
* least one second), all values will be at their upper limit (0xFFFF for
|
||||||
|
* uint16).
|
||||||
|
*
|
||||||
|
* @param[out] number_concentration_pm0p5 Value is scaled with factor 10: PM0.5
|
||||||
|
* [particles/cm³] = value / 10. *Note: If this value is unknown, 0xFFFF is
|
||||||
|
* returned.*
|
||||||
|
* @param[out] number_concentration_pm1p0 Value is scaled with factor 10: PM1.0
|
||||||
|
* [particles/cm³] = value / 10. *Note: If this value is unknown, 0xFFFF is
|
||||||
|
* returned.*
|
||||||
|
* @param[out] number_concentration_pm2p5 Value is scaled with factor 10: PM2.5
|
||||||
|
* [particles/cm³] = value / 10. *Note: If this value is unknown, 0xFFFF is
|
||||||
|
* returned.*
|
||||||
|
* @param[out] number_concentration_pm4p0 Value is scaled with factor 10: PM4.0
|
||||||
|
* [particles/cm³] = value / 10. *Note: If this value is unknown, 0xFFFF is
|
||||||
|
* returned.*
|
||||||
|
* @param[out] number_concentration_pm10p0 Value is scaled with factor 10:
|
||||||
|
* PM10.0 [particles/cm³] = value / 10. *Note: If this value is unknown, 0xFFFF
|
||||||
|
* is returned.*
|
||||||
|
*
|
||||||
|
* @return error_code 0 on success, an error code otherwise.
|
||||||
|
*/
|
||||||
|
int16_t sen66_read_number_concentration_values_as_integers(
|
||||||
|
uint16_t* number_concentration_pm0p5, uint16_t* number_concentration_pm1p0,
|
||||||
|
uint16_t* number_concentration_pm2p5, uint16_t* number_concentration_pm4p0,
|
||||||
|
uint16_t* number_concentration_pm10p0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief sen66_set_temperature_offset_parameters
|
||||||
|
*
|
||||||
|
* This command allows to compensate temperature effects of the design-in at
|
||||||
|
* customer side by applying custom temperature offsets to the ambient
|
||||||
|
* temperature.
|
||||||
|
*
|
||||||
|
* The compensated ambient temperature is calculated as follows:
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* * T_Ambient_Compensated = T_Ambient + (slope * T_Ambient) + offset
|
||||||
|
* Where | ||||||