32 Commits
Author SHA1 Message Date
root f639f14427 docs: add roadmap for code structure, optimization and SD logging 2026-11-11 23:13:32 +00:00
root e88623cf6e perf(influx): batch measurements and reuse HTTP connections 2026-11-11 22:57:12 +00:00
root dde4736cc2 feat(display): add air quality pages, history and display settings 2026-11-11 22:24:29 +00:00
admin 62e9d249cb ein Page mit hand in EEZ hinzugefügt 2026-11-11 22:42:10 +01:00
root 69bb47dda1 feat(firmware): support configurable SEN54 and SEN66 boards
Add the pinned Sensirion SEN66 driver, central sensor and board profiles, and a separate GPIO I2C bus for SEN66 with display. Preserve the original display layout and keep NOx and CO2 in InfluxDB. Include protocol tests, hardware workflow documentation and verified deployment results without credentials.
2026-11-09 21:44:04 +00:00
root 45b05d045a feat(linux): add persistent Avahi discovery for InfluxDB
Add a Debian NUC installer, IPv4 service definition and usage guide with backup and legacy alias migration. Document the user-confirmed SEN54-to-InfluxDB connection without including credentials.
2026-11-07 20:00:02 +00:00
root 3dcfdedc18 fix(build): disable optional component update checks
Set IDF_COMPONENT_CHECK_NEW_VERSION before loading ESP-IDF so PlatformIO and VS Code builds do not require a shell export. Document the LVGL Kconfig workaround while preserving the dependency lockfile.
2026-11-07 13:57:12 +00:00
root b10b96f1ae build: pin ESP-IDF 5.5.0 for 8 MB ESP32-C6
Configure the active SDK and defaults for the existing OTA layout. Add repository hardware development instructions and the verified application upload reference.
2026-11-04 22:36:05 +00:00
admin 71a01cc63e sen5x: remove unused i2cdev forward declarations 2026-02-08 23:07:01 +01:00
admin 4d2e84f027 sen5x: Producer-Task sauber beenden und externes vTaskDelete vermeiden
- Producer setzt g_task_prod = NULL und löscht sich beim Beenden selbst
- sen5x_app_deinit signalisiert Stopp via g_run = false und wartet auf den Producer
- verhindert das „Abschießen“ von Tasks, die ggf. I2C/Mutexe oder andere Ressourcen halten
2026-02-08 22:58:55 +01:00
admin 81b5677b5f main: I2C Port/Pins vereinheitlicht (BSP-Defines) für i2cdev_adopt_bus + SEN5x 2026-02-08 22:15:29 +01:00
admin daa6909f5d fix(sen5x): Sensirion I2C HAL an int8_t-Fehlercodes angepasst
Ersetzt unsichere Casts von esp_err_t nach int8_t durch ein stabiles Mapping gemäß Sensirion-HAL, nutzt die i2cdev-Mutex-API direkt statt Makros mit esp_err_t-Rückgaben, korrigiert sleep_usec() auf aufrundende µs→ms-Umrechnung zur Einhaltung der Mindestwartezeit und setzt addr_bit_len explizit auf 7 Bit mit zusätzlicher Grundvalidierung der I2C-Frequenz.
2026-02-08 21:50:22 +01:00
eugen 7a163ec85f Refactor: wifi_mgr, net_influx und sen5x_app als eigene Komponenten platziert 2026-01-29 15:20:33 +01:00
eugen ac7d26eb9c Refactor: Influx-Handling aus sen5x_app ausgelagert und generisch gemacht
- sen5x_app.c auf reine Sensor-App reduziert (SEN5x Readout, Skalierung, GUI vars, device-tag)
- Influx-Init/Retry/Backoff/HTTP komplett nach net_influx.c verlagert
- SEN5x schreibt nicht mehr direkt Line-Protocol, sondern submit via net_influx_submit_point()
- net_influx als generisches Interface für unterschiedliche Sensor-Samples (variable Anzahl Felder) vorbereitet
- Consumer/Queue für Influx aus sen5x_app entfernt; nur noch Producer-Task im Sensor-Modul
2026-01-29 13:11:21 +01:00
eugen 531256529f Die Flag-Funktion fürs mDNS-Icon korregiert 2026-01-22 17:33:19 +01:00
admin 2352075c58 refactor: entkopple mDNS-Discovery, Status-Flags und WiFi-Manager
- net_mdns: Autostart + Discovery-Retry stabilisiert (Forward-Declarations, Task-Start bei GOT_IP)
- sys_status: EventGroup zentralisiert; Statusbits nicht mehr aus net_mdns gesetzt
- main: Integration von net_mdns Autostart/Discovery und UI-Status-Update vorbereitet
- wifi_mgr: mDNS-Discovery-Logik entfernt/vereinheitlicht, damit keine doppelte Discovery läuft
- net_influx: Anpassungen an neue Discovery/Storage-Semantik
2026-01-22 13:45:15 +01:00
admin ca8ec3c993 Refactor: net_mdns in separate component ausgelagert 2025-12-11 01:36:01 +01:00
admin 5f60ea3841 Refactor: sys_status in separate component ausgelagert 2025-12-11 01:16:06 +01:00
admin 882f7d6784 Refactor: http_portal in separate component ausgelagert 2025-12-11 01:09:34 +01:00
admin 5fccab5aff Refactor: storage in separate component ausgelagert 2025-12-11 00:56:54 +01:00
admin 707df025b8 Refactor: dns_captive als eigenständige ESP-IDF-Komponente ausgelagert
- dns_captive.c/.h nach components/dns_captive verschoben
- Neues CMakeLists.txt für Komponente ergänzt
- src/CMakeLists.txt angepasst (komponentenbasiert, REQUIRES dns_captive)
- Projektstruktur bereinigt und klar modularisiert
2025-12-11 00:42:59 +01:00
admin b7f6325dea Refactoring: Module entkoppelt und Aufrufe über main zentralisiert
wifi_mgr vollständig von http_portal und dns_captive entkoppelt
- Neues Callback-Interface in http_portal implementiert
- Callback-Initialisierung in main.c hinzugefügt (WiFi-Creds, Device-Info)
- dns_captive in eigenes Modul ausgelagert (dns_captive.h ergänzt)
- Alte Vorwärtsdeklarationen entfernt und öffentliche API in wifi_mgr.h ergänzt
- Startreihenfolge der Module neu strukturiert (Orchestrierung in main.c)
- Projektabhängigkeiten vereinfacht und Zyklus zwischen Modulen aufgelöst
2025-12-10 22:14:55 +01:00
eugen 6225906851 sen5x Module in eigenes Component verschoben 2025-12-04 15:57:57 +01:00
admin 63dbc4a5cd images hinzugefügt 2025-11-25 18:53:16 +01:00
eugen 6dc0968f88 Datasheets hinzugefügt 2025-11-24 18:35:34 +01:00
eugen 6b1ca06c91 Treiberarchiv hinzugefügt 2025-11-24 18:31:30 +01:00
eugen f04e18a366 Schriftarten verlagert 2025-11-24 18:14:47 +01:00
eugen b5502d0249 Schriftarten hinzugefügt 2025-11-24 18:14:01 +01:00
eugen f79ac90eb5 Pythonskripte für mDNS und uninstall hinzugefügt 2025-11-24 18:11:26 +01:00
eugen 40a62bf023 Schrifft für nanoPSX in cad hinzugefügt; Windowsinstallation hinzugefügt 2025-11-24 18:04:33 +01:00
admin 0ff204fd63 eez hinzugefügt 2025-11-24 01:48:47 +01:00
admin f46c75d405 cad hinzugefügt 2025-11-24 01:37:34 +01:00
152 changed files with 226650 additions and 4513 deletions
+1
View File
@@ -3,4 +3,5 @@
.vscode/c_cpp_properties.json .vscode/c_cpp_properties.json
.vscode/launch.json .vscode/launch.json
.vscode/ipch .vscode/ipch
.venv
todo.txt todo.txt
+225
View File
@@ -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.
View File
+58
View File
@@ -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.
BIN
View File
Binary file not shown.
+53
View File
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="210mm"
height="297mm"
viewBox="0 0 210 297"
version="1.1"
id="svg1"
inkscape:version="1.4 (86a8ad7, 2024-10-11)"
sodipodi:docname="nanoPSX.svg"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<sodipodi:namedview
id="namedview1"
pagecolor="#505050"
bordercolor="#eeeeee"
borderopacity="1"
inkscape:showpageshadow="0"
inkscape:pageopacity="0"
inkscape:pagecheckerboard="0"
inkscape:deskcolor="#505050"
inkscape:document-units="mm"
inkscape:zoom="2.2501035"
inkscape:cx="395.75958"
inkscape:cy="449.97931"
inkscape:window-width="1920"
inkscape:window-height="1137"
inkscape:window-x="-8"
inkscape:window-y="-8"
inkscape:window-maximized="1"
inkscape:current-layer="layer1" />
<defs
id="defs1" />
<g
inkscape:label="Ebene 1"
inkscape:groupmode="layer"
id="layer1">
<text
xml:space="preserve"
style="font-style:italic;font-size:27.2145px;font-family:Pigiarniq;-inkscape-font-specification:'Pigiarniq, Italic';text-align:start;writing-mode:lr-tb;direction:ltr;text-anchor:start;opacity:0.371681;fill:none;fill-opacity:0;stroke:#000000;stroke-width:0.1;stroke-linecap:round"
x="46.894733"
y="125.05263"
id="text1"><tspan
sodipodi:role="line"
id="tspan1"
style="font-style:italic;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:27.2145px;font-family:Pigiarniq;-inkscape-font-specification:'Pigiarniq, Italic';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;stroke-width:0.1;fill:none"
x="46.894733"
y="125.05263">nanoPSX</tspan></text>
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.0 KiB

BIN
View File
Binary file not shown.
+34510
View File
File diff suppressed because it is too large Load Diff
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
+167729
View File
File diff suppressed because it is too large Load Diff
+4678
View File
File diff suppressed because it is too large Load Diff
+4202
View File
File diff suppressed because it is too large Load Diff
Executable
+996
View File
@@ -0,0 +1,996 @@
solid ascii
facet normal 1.953640e-01 -9.807308e-01 0.000000e+00
outer loop
vertex 1.157977e+01 -2.255061e+01 -7.800003e+00
vertex 1.173283e+01 -2.252012e+01 -8.300002e+00
vertex 1.173283e+01 -2.252012e+01 -7.300004e+00
endloop
endfacet
facet normal 0.000000e+00 0.000000e+00 -1.000000e+00
outer loop
vertex 1.222648e+01 -2.178088e+01 -8.300002e+00
vertex 1.216567e+01 -2.208704e+01 -8.300002e+00
vertex -1.227195e+01 -2.178774e+01 -8.300002e+00
endloop
endfacet
facet normal 2.802079e-04 -1.000000e+00 -6.507516e-10
outer loop
vertex -2.251063e-02 -2.258431e+01 -7.800003e+00
vertex -1.147173e+01 -2.258752e+01 -8.300002e+00
vertex 1.142670e+01 -2.258110e+01 -8.300002e+00
endloop
endfacet
facet normal 0.000000e+00 0.000000e+00 -1.000000e+00
outer loop
vertex 1.173283e+01 -2.252012e+01 -8.300002e+00
vertex 1.142670e+01 -2.258110e+01 -8.300002e+00
vertex -1.227195e+01 -2.178774e+01 -8.300002e+00
endloop
endfacet
facet normal -9.807296e-01 -1.953699e-01 0.000000e+00
outer loop
vertex -1.224146e+01 -2.194081e+01 -7.800003e+00
vertex -1.221097e+01 -2.209387e+01 -8.300002e+00
vertex -1.221097e+01 -2.209387e+01 -7.300004e+00
endloop
endfacet
facet normal -9.999999e-01 -2.802309e-04 9.546130e-07
outer loop
vertex -1.227848e+01 1.501878e+00 -7.800001e+00
vertex -1.228500e+01 2.479150e+01 -8.299997e+00
vertex -1.227195e+01 -2.178774e+01 -8.300002e+00
endloop
endfacet
facet normal -9.999999e-01 -2.802103e-04 0.000000e+00
outer loop
vertex -1.227848e+01 1.501878e+00 -7.800001e+00
vertex -1.227195e+01 -2.178774e+01 -8.300002e+00
vertex -1.227195e+01 -2.178774e+01 -7.300004e+00
endloop
endfacet
facet normal 9.808400e-01 -1.948151e-01 -3.699727e-07
outer loop
vertex 1.219607e+01 -2.193396e+01 -7.800003e+00
vertex 1.216567e+01 -2.208704e+01 -8.300002e+00
vertex 1.222648e+01 -2.178088e+01 -8.300002e+00
endloop
endfacet
facet normal -9.807306e-01 -1.953652e-01 -1.497794e-06
outer loop
vertex -1.224146e+01 -2.194081e+01 -7.800003e+00
vertex -1.227195e+01 -2.178774e+01 -8.300002e+00
vertex -1.221097e+01 -2.209387e+01 -8.300002e+00
endloop
endfacet
facet normal 0.000000e+00 0.000000e+00 -1.000000e+00
outer loop
vertex -1.221097e+01 -2.209387e+01 -8.300002e+00
vertex -1.177789e+01 -2.252670e+01 -8.300002e+00
vertex -1.203748e+01 -2.235336e+01 -8.300002e+00
endloop
endfacet
facet normal -9.807315e-01 -1.953605e-01 -0.000000e+00
outer loop
vertex -1.224146e+01 -2.194081e+01 -7.800003e+00
vertex -1.227195e+01 -2.178774e+01 -7.300004e+00
vertex -1.227195e+01 -2.178774e+01 -8.300002e+00
endloop
endfacet
facet normal -8.313134e-01 -5.558038e-01 0.000000e+00
outer loop
vertex -1.212422e+01 -2.222361e+01 -7.800003e+00
vertex -1.203748e+01 -2.235336e+01 -8.300002e+00
vertex -1.203748e+01 -2.235336e+01 -7.300004e+00
endloop
endfacet
facet normal 0.000000e+00 0.000000e+00 -1.000000e+00
outer loop
vertex -1.227195e+01 -2.178774e+01 -8.300002e+00
vertex -1.147173e+01 -2.258752e+01 -8.300002e+00
vertex -1.221097e+01 -2.209387e+01 -8.300002e+00
endloop
endfacet
facet normal -8.313140e-01 -5.558031e-01 -2.625587e-07
outer loop
vertex -1.212422e+01 -2.222361e+01 -7.800003e+00
vertex -1.221097e+01 -2.209387e+01 -8.300002e+00
vertex -1.203748e+01 -2.235336e+01 -8.300002e+00
endloop
endfacet
facet normal -1.948128e-01 -9.808405e-01 0.000000e+00
outer loop
vertex -1.162481e+01 -2.255711e+01 -7.800003e+00
vertex -1.147173e+01 -2.258752e+01 -8.300002e+00
vertex -1.147173e+01 -2.258752e+01 -7.300004e+00
endloop
endfacet
facet normal 0.000000e+00 0.000000e+00 -1.000000e+00
outer loop
vertex 1.142670e+01 -2.258110e+01 -8.300002e+00
vertex -1.147173e+01 -2.258752e+01 -8.300002e+00
vertex -1.227195e+01 -2.178774e+01 -8.300002e+00
endloop
endfacet
facet normal -8.313144e-01 -5.558025e-01 -0.000000e+00
outer loop
vertex -1.212422e+01 -2.222361e+01 -7.800003e+00
vertex -1.221097e+01 -2.209387e+01 -7.300004e+00
vertex -1.221097e+01 -2.209387e+01 -8.300002e+00
endloop
endfacet
facet normal 1.943541e-07 1.199650e-07 -1.000000e+00
outer loop
vertex 1.221979e+01 2.078772e+00 -8.299999e+00
vertex 1.222648e+01 -2.178088e+01 -8.300002e+00
vertex 7.611846e+00 1.594458e+00 -8.300000e+00
endloop
endfacet
facet normal 2.802079e-04 -1.000000e+00 0.000000e+00
outer loop
vertex -2.251063e-02 -2.258431e+01 -7.800003e+00
vertex 1.142670e+01 -2.258110e+01 -8.300002e+00
vertex 1.142670e+01 -2.258110e+01 -7.300004e+00
endloop
endfacet
facet normal -5.553374e-01 -8.316251e-01 0.000000e+00
outer loop
vertex -1.190768e+01 -2.244003e+01 -7.800003e+00
vertex -1.177789e+01 -2.252670e+01 -8.300002e+00
vertex -1.177789e+01 -2.252670e+01 -7.300004e+00
endloop
endfacet
facet normal -1.948269e-01 -9.808376e-01 -0.000000e+00
outer loop
vertex -1.162481e+01 -2.255711e+01 -7.800003e+00
vertex -1.177789e+01 -2.252670e+01 -7.300004e+00
vertex -1.177789e+01 -2.252670e+01 -8.300002e+00
endloop
endfacet
facet normal -1.948198e-01 -9.808390e-01 -2.243689e-06
outer loop
vertex -1.162481e+01 -2.255711e+01 -7.800003e+00
vertex -1.177789e+01 -2.252670e+01 -8.300002e+00
vertex -1.147173e+01 -2.258752e+01 -8.300002e+00
endloop
endfacet
facet normal 2.802079e-04 -9.999999e-01 0.000000e+00
outer loop
vertex -2.251063e-02 -2.258431e+01 -7.800003e+00
vertex -1.147173e+01 -2.258752e+01 -7.300004e+00
vertex -1.147173e+01 -2.258752e+01 -8.300002e+00
endloop
endfacet
facet normal 0.000000e+00 0.000000e+00 -1.000000e+00
outer loop
vertex -1.147173e+01 -2.258752e+01 -8.300002e+00
vertex -1.177789e+01 -2.252670e+01 -8.300002e+00
vertex -1.221097e+01 -2.209387e+01 -8.300002e+00
endloop
endfacet
facet normal -5.553346e-01 -8.316270e-01 1.062179e-06
outer loop
vertex -1.190768e+01 -2.244003e+01 -7.800003e+00
vertex -1.203748e+01 -2.235336e+01 -8.300002e+00
vertex -1.177789e+01 -2.252670e+01 -8.300002e+00
endloop
endfacet
facet normal 9.808398e-01 -1.948163e-01 0.000000e+00
outer loop
vertex 1.219607e+01 -2.193396e+01 -7.800003e+00
vertex 1.216567e+01 -2.208704e+01 -7.300004e+00
vertex 1.216567e+01 -2.208704e+01 -8.300002e+00
endloop
endfacet
facet normal 5.557968e-01 -8.313181e-01 0.000000e+00
outer loop
vertex 1.186258e+01 -2.243337e+01 -7.800003e+00
vertex 1.199232e+01 -2.234663e+01 -8.300002e+00
vertex 1.199232e+01 -2.234663e+01 -7.300004e+00
endloop
endfacet
facet normal 9.808402e-01 -1.948140e-01 0.000000e+00
outer loop
vertex 1.219607e+01 -2.193396e+01 -7.800003e+00
vertex 1.222648e+01 -2.178088e+01 -8.300002e+00
vertex 1.222648e+01 -2.178088e+01 -7.300004e+00
endloop
endfacet
facet normal -8.922910e-08 6.398150e-08 -1.000000e+00
outer loop
vertex 7.611846e+00 1.594458e+00 -8.300000e+00
vertex 1.222648e+01 -2.178088e+01 -8.300002e+00
vertex -5.513295e+00 1.310097e+01 -8.299998e+00
endloop
endfacet
facet normal 8.316317e-01 -5.553275e-01 0.000000e+00
outer loop
vertex 1.207900e+01 -2.221683e+01 -7.800003e+00
vertex 1.199232e+01 -2.234663e+01 -7.300004e+00
vertex 1.199232e+01 -2.234663e+01 -8.300002e+00
endloop
endfacet
facet normal 0.000000e+00 0.000000e+00 -1.000000e+00
outer loop
vertex 1.199232e+01 -2.234663e+01 -8.300002e+00
vertex 1.173283e+01 -2.252012e+01 -8.300002e+00
vertex -1.227195e+01 -2.178774e+01 -8.300002e+00
endloop
endfacet
facet normal 3.591652e-08 1.023813e-07 -1.000000e+00
outer loop
vertex -1.228500e+01 2.479150e+01 -8.299997e+00
vertex -5.513295e+00 1.310097e+01 -8.299998e+00
vertex -1.227195e+01 -2.178774e+01 -8.300002e+00
endloop
endfacet
facet normal 0.000000e+00 0.000000e+00 -1.000000e+00
outer loop
vertex 1.216567e+01 -2.208704e+01 -8.300002e+00
vertex 1.199232e+01 -2.234663e+01 -8.300002e+00
vertex -1.227195e+01 -2.178774e+01 -8.300002e+00
endloop
endfacet
facet normal 5.557982e-01 -8.313172e-01 5.370561e-07
outer loop
vertex 1.186258e+01 -2.243337e+01 -7.800003e+00
vertex 1.173283e+01 -2.252012e+01 -8.300002e+00
vertex 1.199232e+01 -2.234663e+01 -8.300002e+00
endloop
endfacet
facet normal -5.553318e-01 -8.316289e-01 -0.000000e+00
outer loop
vertex -1.190768e+01 -2.244003e+01 -7.800003e+00
vertex -1.203748e+01 -2.235336e+01 -7.300004e+00
vertex -1.203748e+01 -2.235336e+01 -8.300002e+00
endloop
endfacet
facet normal -3.064736e-11 1.093449e-07 -1.000000e+00
outer loop
vertex -5.513295e+00 1.310097e+01 -8.299998e+00
vertex 1.222648e+01 -2.178088e+01 -8.300002e+00
vertex -1.227195e+01 -2.178774e+01 -8.300002e+00
endloop
endfacet
facet normal 8.316280e-01 -5.553332e-01 2.112395e-06
outer loop
vertex 1.207900e+01 -2.221683e+01 -7.800003e+00
vertex 1.199232e+01 -2.234663e+01 -8.300002e+00
vertex 1.216567e+01 -2.208704e+01 -8.300002e+00
endloop
endfacet
facet normal 1.000000e+00 2.801910e-04 0.000000e+00
outer loop
vertex 1.222314e+01 -9.851052e+00 -7.800002e+00
vertex 1.222648e+01 -2.178088e+01 -7.300004e+00
vertex 1.222648e+01 -2.178088e+01 -8.300002e+00
endloop
endfacet
facet normal 9.999999e-01 2.802309e-04 -9.536661e-07
outer loop
vertex 1.222314e+01 -9.851052e+00 -7.800002e+00
vertex 1.222648e+01 -2.178088e+01 -8.300002e+00
vertex 1.221979e+01 2.078772e+00 -8.299999e+00
endloop
endfacet
facet normal 1.953699e-01 -9.807296e-01 1.873721e-06
outer loop
vertex 1.157977e+01 -2.255061e+01 -7.800003e+00
vertex 1.142670e+01 -2.258110e+01 -8.300002e+00
vertex 1.173283e+01 -2.252012e+01 -8.300002e+00
endloop
endfacet
facet normal 5.557997e-01 -8.313163e-01 0.000000e+00
outer loop
vertex 1.186258e+01 -2.243337e+01 -7.800003e+00
vertex 1.173283e+01 -2.252012e+01 -7.300004e+00
vertex 1.173283e+01 -2.252012e+01 -8.300002e+00
endloop
endfacet
facet normal 8.316242e-01 -5.553388e-01 0.000000e+00
outer loop
vertex 1.207900e+01 -2.221683e+01 -7.800003e+00
vertex 1.216567e+01 -2.208704e+01 -8.300002e+00
vertex 1.216567e+01 -2.208704e+01 -7.300004e+00
endloop
endfacet
facet normal 1.953758e-01 -9.807284e-01 0.000000e+00
outer loop
vertex 1.157977e+01 -2.255061e+01 -7.800003e+00
vertex 1.142670e+01 -2.258110e+01 -7.300004e+00
vertex 1.142670e+01 -2.258110e+01 -8.300002e+00
endloop
endfacet
facet normal 7.071067e-01 1.225341e-07 -7.071068e-01
outer loop
vertex 7.861846e+00 7.195271e+00 -8.049999e+00
vertex 7.611846e+00 1.594458e+00 -8.300000e+00
vertex 7.611846e+00 1.260118e+01 -8.299998e+00
endloop
endfacet
facet normal -4.644116e-11 1.657095e-07 -1.000000e+00
outer loop
vertex 5.416704e+00 1.310403e+01 -8.299998e+00
vertex 7.611846e+00 1.594458e+00 -8.300000e+00
vertex -5.513295e+00 1.310097e+01 -8.299998e+00
endloop
endfacet
facet normal 7.071071e-01 9.072717e-08 -7.071065e-01
outer loop
vertex 7.861846e+00 7.195271e+00 -8.049999e+00
vertex 8.111846e+00 1.647010e+00 -7.800000e+00
vertex 7.611846e+00 1.594458e+00 -8.300000e+00
endloop
endfacet
facet normal -1.045283e-01 9.945220e-01 -1.479396e-07
outer loop
vertex 1.221979e+01 2.078772e+00 -8.299999e+00
vertex 7.611846e+00 1.594458e+00 -8.300000e+00
vertex 8.111846e+00 1.647010e+00 -7.800000e+00
endloop
endfacet
facet normal 3.969645e-08 1.732894e-07 -1.000000e+00
outer loop
vertex 7.611846e+00 1.260118e+01 -8.299998e+00
vertex 7.611846e+00 1.594458e+00 -8.300000e+00
vertex 5.416704e+00 1.310403e+01 -8.299998e+00
endloop
endfacet
facet normal -1.045283e-01 9.945219e-01 0.000000e+00
outer loop
vertex 1.221979e+01 2.078772e+00 -8.299999e+00
vertex 8.111846e+00 1.647010e+00 -7.800000e+00
vertex 8.111846e+00 1.647010e+00 -7.300002e+00
endloop
endfacet
facet normal 9.999999e-01 2.802708e-04 -0.000000e+00
outer loop
vertex 1.222314e+01 -9.851052e+00 -7.800002e+00
vertex 1.221979e+01 2.078772e+00 -8.299999e+00
vertex 1.221979e+01 2.078772e+00 -7.300002e+00
endloop
endfacet
facet normal -1.045283e-01 9.945220e-01 0.000000e+00
outer loop
vertex 1.221979e+01 2.078772e+00 -7.300002e+00
vertex 1.221979e+01 2.078772e+00 -8.299999e+00
vertex 8.111846e+00 1.647010e+00 -7.300002e+00
endloop
endfacet
facet normal 1.000000e+00 2.802101e-04 9.534234e-07
outer loop
vertex 1.221460e+01 2.060253e+01 -7.799999e+00
vertex 1.221597e+01 1.570670e+01 -8.299998e+00
vertex 1.221323e+01 2.549836e+01 -8.299997e+00
endloop
endfacet
facet normal 1.000000e+00 2.803075e-04 0.000000e+00
outer loop
vertex 1.221460e+01 2.060253e+01 -7.799999e+00
vertex 1.221597e+01 1.570670e+01 -7.300000e+00
vertex 1.221597e+01 1.570670e+01 -8.299998e+00
endloop
endfacet
facet normal -1.048722e-07 2.082973e-08 -1.000000e+00
outer loop
vertex -1.223179e+01 2.505939e+01 -8.299997e+00
vertex -5.513295e+00 1.310097e+01 -8.299998e+00
vertex -1.228500e+01 2.479150e+01 -8.299997e+00
endloop
endfacet
facet normal -6.485803e-08 4.331049e-08 -1.000000e+00
outer loop
vertex -1.208012e+01 2.528653e+01 -8.299997e+00
vertex -5.513295e+00 1.310097e+01 -8.299998e+00
vertex -1.223179e+01 2.505939e+01 -8.299997e+00
endloop
endfacet
facet normal -3.846582e-08 5.753344e-08 -1.000000e+00
outer loop
vertex -1.185306e+01 2.543833e+01 -8.299997e+00
vertex -5.513295e+00 1.310097e+01 -8.299998e+00
vertex -1.208012e+01 2.528653e+01 -8.299997e+00
endloop
endfacet
facet normal 5.591929e-01 -8.290375e-01 4.293063e-07
outer loop
vertex 1.221597e+01 1.570670e+01 -8.299998e+00
vertex 8.111846e+00 1.293843e+01 -7.799999e+00
vertex 7.611846e+00 1.260118e+01 -8.299998e+00
endloop
endfacet
facet normal -1.396867e-08 7.012171e-08 -1.000000e+00
outer loop
vertex -1.158520e+01 2.549169e+01 -8.299997e+00
vertex -5.513295e+00 1.310097e+01 -8.299998e+00
vertex -1.185306e+01 2.543833e+01 -8.299997e+00
endloop
endfacet
facet normal -9.999999e-01 -2.802315e-04 0.000000e+00
outer loop
vertex 5.414967e+00 1.930120e+01 -7.799999e+00
vertex 5.416704e+00 1.310403e+01 -8.299998e+00
vertex 5.416704e+00 1.310403e+01 -7.300001e+00
endloop
endfacet
facet normal 0.000000e+00 9.739661e-08 -1.000000e+00
outer loop
vertex 1.221323e+01 2.549836e+01 -8.299997e+00
vertex 1.221597e+01 1.570670e+01 -8.299998e+00
vertex 5.413230e+00 2.549836e+01 -8.299997e+00
endloop
endfacet
facet normal -2.802564e-04 1.000000e+00 0.000000e+00
outer loop
vertex -4.829637e-02 1.310250e+01 -7.800000e+00
vertex 5.416704e+00 1.310403e+01 -7.300001e+00
vertex 5.416704e+00 1.310403e+01 -8.299998e+00
endloop
endfacet
facet normal -2.802564e-04 1.000000e+00 0.000000e+00
outer loop
vertex -4.829637e-02 1.310250e+01 -7.800000e+00
vertex -5.513295e+00 1.310097e+01 -8.299998e+00
vertex -5.513295e+00 1.310097e+01 -7.300001e+00
endloop
endfacet
facet normal -2.802564e-04 9.999999e-01 -3.408327e-10
outer loop
vertex -4.829637e-02 1.310250e+01 -7.800000e+00
vertex 5.416704e+00 1.310403e+01 -8.299998e+00
vertex -5.513295e+00 1.310097e+01 -8.299998e+00
endloop
endfacet
facet normal 9.999999e-01 2.802746e-04 0.000000e+00
outer loop
vertex -5.515032e+00 1.929718e+01 -7.799999e+00
vertex -5.513295e+00 1.310097e+01 -7.300001e+00
vertex -5.513295e+00 1.310097e+01 -8.299998e+00
endloop
endfacet
facet normal -9.999999e-01 -2.802316e-04 6.011294e-10
outer loop
vertex 5.414967e+00 1.930120e+01 -7.799999e+00
vertex 5.413230e+00 2.549836e+01 -8.299997e+00
vertex 5.416704e+00 1.310403e+01 -8.299998e+00
endloop
endfacet
facet normal -2.157557e-11 7.695623e-08 -1.000000e+00
outer loop
vertex -5.516768e+00 2.549339e+01 -8.299997e+00
vertex -5.513295e+00 1.310097e+01 -8.299998e+00
vertex -1.158520e+01 2.549169e+01 -8.299997e+00
endloop
endfacet
facet normal 9.999999e-01 2.802361e-04 4.773700e-07
outer loop
vertex -5.515032e+00 1.929718e+01 -7.799999e+00
vertex -5.513295e+00 1.310097e+01 -8.299998e+00
vertex -5.516768e+00 2.549339e+01 -8.299997e+00
endloop
endfacet
facet normal 0.000000e+00 0.000000e+00 -1.000000e+00
outer loop
vertex 1.221597e+01 1.570670e+01 -8.299998e+00
vertex 7.611846e+00 1.260118e+01 -8.299998e+00
vertex 5.416704e+00 1.310403e+01 -8.299998e+00
endloop
endfacet
facet normal -2.945013e-08 7.693617e-08 -1.000000e+00
outer loop
vertex 5.413230e+00 2.549836e+01 -8.299997e+00
vertex 1.221597e+01 1.570670e+01 -8.299998e+00
vertex 5.416704e+00 1.310403e+01 -8.299998e+00
endloop
endfacet
facet normal 7.071064e-01 9.072726e-08 -7.071071e-01
outer loop
vertex 7.861846e+00 7.195271e+00 -8.049999e+00
vertex 7.611846e+00 1.260118e+01 -8.299998e+00
vertex 8.111846e+00 1.293843e+01 -7.799999e+00
endloop
endfacet
facet normal 5.591929e-01 -8.290375e-01 0.000000e+00
outer loop
vertex 1.221597e+01 1.570670e+01 -7.300000e+00
vertex 8.111846e+00 1.293843e+01 -7.300001e+00
vertex 1.221597e+01 1.570670e+01 -8.299998e+00
endloop
endfacet
facet normal 5.591929e-01 -8.290376e-01 0.000000e+00
outer loop
vertex 1.221597e+01 1.570670e+01 -8.299998e+00
vertex 8.111846e+00 1.293843e+01 -7.300001e+00
vertex 8.111846e+00 1.293843e+01 -7.799999e+00
endloop
endfacet
facet normal -9.808400e-01 1.948146e-01 0.000000e+00
outer loop
vertex -1.225840e+01 2.492544e+01 -7.799998e+00
vertex -1.228500e+01 2.479150e+01 -8.299997e+00
vertex -1.228500e+01 2.479150e+01 -7.299999e+00
endloop
endfacet
facet normal -9.808400e-01 1.948146e-01 0.000000e+00
outer loop
vertex -1.225840e+01 2.492544e+01 -7.799998e+00
vertex -1.223179e+01 2.505939e+01 -8.299997e+00
vertex -1.228500e+01 2.479150e+01 -8.299997e+00
endloop
endfacet
facet normal -8.316252e-01 5.553374e-01 -7.910898e-07
outer loop
vertex -1.215596e+01 2.517296e+01 -7.799998e+00
vertex -1.208012e+01 2.528653e+01 -8.299997e+00
vertex -1.223179e+01 2.505939e+01 -8.299997e+00
endloop
endfacet
facet normal -5.557988e-01 8.313168e-01 0.000000e+00
outer loop
vertex -1.196659e+01 2.536243e+01 -7.799998e+00
vertex -1.185306e+01 2.543833e+01 -7.299999e+00
vertex -1.185306e+01 2.543833e+01 -8.299997e+00
endloop
endfacet
facet normal -5.558053e-01 8.313125e-01 0.000000e+00
outer loop
vertex -1.196659e+01 2.536243e+01 -7.799998e+00
vertex -1.208012e+01 2.528653e+01 -8.299997e+00
vertex -1.208012e+01 2.528653e+01 -7.299999e+00
endloop
endfacet
facet normal -5.558020e-01 8.313147e-01 -1.050240e-06
outer loop
vertex -1.196659e+01 2.536243e+01 -7.799998e+00
vertex -1.185306e+01 2.543833e+01 -8.299997e+00
vertex -1.208012e+01 2.528653e+01 -8.299997e+00
endloop
endfacet
facet normal -1.953667e-01 9.807302e-01 0.000000e+00
outer loop
vertex -1.171913e+01 2.546501e+01 -7.799998e+00
vertex -1.185306e+01 2.543833e+01 -8.299997e+00
vertex -1.185306e+01 2.543833e+01 -7.299999e+00
endloop
endfacet
facet normal -9.808400e-01 1.948146e-01 0.000000e+00
outer loop
vertex -1.225840e+01 2.492544e+01 -7.799998e+00
vertex -1.223179e+01 2.505939e+01 -7.299999e+00
vertex -1.223179e+01 2.505939e+01 -8.299997e+00
endloop
endfacet
facet normal -1.953681e-01 9.807300e-01 0.000000e+00
outer loop
vertex -1.171913e+01 2.546501e+01 -7.799998e+00
vertex -1.158520e+01 2.549169e+01 -7.299999e+00
vertex -1.158520e+01 2.549169e+01 -8.299997e+00
endloop
endfacet
facet normal -1.953674e-01 9.807302e-01 1.875426e-07
outer loop
vertex -1.171913e+01 2.546501e+01 -7.799998e+00
vertex -1.158520e+01 2.549169e+01 -8.299997e+00
vertex -1.185306e+01 2.543833e+01 -8.299997e+00
endloop
endfacet
facet normal -9.999999e-01 -2.802316e-04 -0.000000e+00
outer loop
vertex 5.414967e+00 1.930120e+01 -7.799999e+00
vertex 5.413230e+00 2.549836e+01 -7.299999e+00
vertex 5.413230e+00 2.549836e+01 -8.299997e+00
endloop
endfacet
facet normal 0.000000e+00 1.000000e+00 0.000000e+00
outer loop
vertex 8.813231e+00 2.549836e+01 -7.799998e+00
vertex 1.221323e+01 2.549836e+01 -7.299999e+00
vertex 1.221323e+01 2.549836e+01 -8.299997e+00
endloop
endfacet
facet normal 0.000000e+00 1.000000e+00 0.000000e+00
outer loop
vertex 8.813231e+00 2.549836e+01 -7.799998e+00
vertex 5.413230e+00 2.549836e+01 -8.299997e+00
vertex 5.413230e+00 2.549836e+01 -7.299999e+00
endloop
endfacet
facet normal 0.000000e+00 1.000000e+00 0.000000e+00
outer loop
vertex 8.813231e+00 2.549836e+01 -7.799998e+00
vertex 1.221323e+01 2.549836e+01 -8.299997e+00
vertex 5.413230e+00 2.549836e+01 -8.299997e+00
endloop
endfacet
facet normal 9.999999e-01 2.801977e-04 5.344356e-10
outer loop
vertex -5.515032e+00 1.929718e+01 -7.799999e+00
vertex -5.516768e+00 2.549339e+01 -8.299997e+00
vertex -5.516768e+00 2.549339e+01 -7.299999e+00
endloop
endfacet
facet normal -2.803615e-04 9.999999e-01 1.534703e-10
outer loop
vertex -8.550983e+00 2.549254e+01 -7.799998e+00
vertex -5.516768e+00 2.549339e+01 -8.299997e+00
vertex -1.158520e+01 2.549169e+01 -8.299997e+00
endloop
endfacet
facet normal -8.316268e-01 5.553350e-01 0.000000e+00
outer loop
vertex -1.215596e+01 2.517296e+01 -7.799998e+00
vertex -1.223179e+01 2.505939e+01 -8.299997e+00
vertex -1.223179e+01 2.505939e+01 -7.299999e+00
endloop
endfacet
facet normal -2.800473e-04 9.999999e-01 1.907352e-06
outer loop
vertex -8.550983e+00 2.549254e+01 -7.799998e+00
vertex -5.516768e+00 2.549339e+01 -7.299999e+00
vertex -5.516768e+00 2.549339e+01 -8.299997e+00
endloop
endfacet
facet normal -2.803615e-04 9.999999e-01 0.000000e+00
outer loop
vertex -8.550983e+00 2.549254e+01 -7.799998e+00
vertex -1.158520e+01 2.549169e+01 -8.299997e+00
vertex -1.158520e+01 2.549169e+01 -7.299999e+00
endloop
endfacet
facet normal -9.999999e-01 -2.802513e-04 -0.000000e+00
outer loop
vertex -1.227848e+01 1.501878e+00 -7.800001e+00
vertex -1.228500e+01 2.479150e+01 -7.299999e+00
vertex -1.228500e+01 2.479150e+01 -8.299997e+00
endloop
endfacet
facet normal 1.000000e+00 2.801127e-04 -0.000000e+00
outer loop
vertex 1.221460e+01 2.060253e+01 -7.799999e+00
vertex 1.221323e+01 2.549836e+01 -8.299997e+00
vertex 1.221323e+01 2.549836e+01 -7.299999e+00
endloop
endfacet
facet normal -8.316236e-01 5.553398e-01 0.000000e+00
outer loop
vertex -1.215596e+01 2.517296e+01 -7.799998e+00
vertex -1.208012e+01 2.528653e+01 -7.299999e+00
vertex -1.208012e+01 2.528653e+01 -8.299997e+00
endloop
endfacet
facet normal 7.071068e-01 5.972228e-08 -7.071068e-01
outer loop
vertex 7.861846e+00 7.195271e+00 -8.049999e+00
vertex 8.111846e+00 1.293843e+01 -7.799999e+00
vertex 8.111846e+00 1.647010e+00 -7.800000e+00
endloop
endfacet
facet normal -5.553346e-01 -8.316270e-01 -1.050244e-06
outer loop
vertex -1.190768e+01 -2.244003e+01 -7.800003e+00
vertex -1.177789e+01 -2.252670e+01 -7.300004e+00
vertex -1.203748e+01 -2.235336e+01 -7.300004e+00
endloop
endfacet
facet normal -1.948198e-01 -9.808390e-01 2.237722e-06
outer loop
vertex -1.162481e+01 -2.255711e+01 -7.800003e+00
vertex -1.147173e+01 -2.258752e+01 -7.300004e+00
vertex -1.177789e+01 -2.252670e+01 -7.300004e+00
endloop
endfacet
facet normal 9.808400e-01 -1.948151e-01 3.759400e-07
outer loop
vertex 1.219607e+01 -2.193396e+01 -7.800003e+00
vertex 1.222648e+01 -2.178088e+01 -7.300004e+00
vertex 1.216567e+01 -2.208704e+01 -7.300004e+00
endloop
endfacet
facet normal -9.807306e-01 -1.953652e-01 1.497794e-06
outer loop
vertex -1.224146e+01 -2.194081e+01 -7.800003e+00
vertex -1.221097e+01 -2.209387e+01 -7.300004e+00
vertex -1.227195e+01 -2.178774e+01 -7.300004e+00
endloop
endfacet
facet normal 1.953699e-01 -9.807296e-01 -1.867753e-06
outer loop
vertex 1.157977e+01 -2.255061e+01 -7.800003e+00
vertex 1.173283e+01 -2.252012e+01 -7.300004e+00
vertex 1.142670e+01 -2.258110e+01 -7.300004e+00
endloop
endfacet
facet normal 5.557982e-01 -8.313172e-01 -5.251215e-07
outer loop
vertex 1.186258e+01 -2.243337e+01 -7.800003e+00
vertex 1.199232e+01 -2.234663e+01 -7.300004e+00
vertex 1.173283e+01 -2.252012e+01 -7.300004e+00
endloop
endfacet
facet normal 8.316280e-01 -5.553332e-01 -2.124329e-06
outer loop
vertex 1.207900e+01 -2.221683e+01 -7.800003e+00
vertex 1.216567e+01 -2.208704e+01 -7.300004e+00
vertex 1.199232e+01 -2.234663e+01 -7.300004e+00
endloop
endfacet
facet normal 2.802079e-04 -1.000000e+00 0.000000e+00
outer loop
vertex -2.251063e-02 -2.258431e+01 -7.800003e+00
vertex 1.142670e+01 -2.258110e+01 -7.300004e+00
vertex -1.147173e+01 -2.258752e+01 -7.300004e+00
endloop
endfacet
facet normal -8.313140e-01 -5.558031e-01 2.625587e-07
outer loop
vertex -1.212422e+01 -2.222361e+01 -7.800003e+00
vertex -1.203748e+01 -2.235336e+01 -7.300004e+00
vertex -1.221097e+01 -2.209387e+01 -7.300004e+00
endloop
endfacet
facet normal 1.000000e+00 2.802309e-04 9.536648e-07
outer loop
vertex 1.222314e+01 -9.851052e+00 -7.800002e+00
vertex 1.221979e+01 2.078772e+00 -7.300002e+00
vertex 1.222648e+01 -2.178088e+01 -7.300004e+00
endloop
endfacet
facet normal -9.999999e-01 -2.802309e-04 -9.558927e-07
outer loop
vertex -1.227848e+01 1.501878e+00 -7.800001e+00
vertex -1.227195e+01 -2.178774e+01 -7.300004e+00
vertex -1.228500e+01 2.479150e+01 -7.299999e+00
endloop
endfacet
facet normal 1.000000e+00 0.000000e+00 0.000000e+00
outer loop
vertex 8.111846e+00 7.292722e+00 -7.550000e+00
vertex 8.111846e+00 1.647010e+00 -7.800000e+00
vertex 8.111846e+00 1.293843e+01 -7.799999e+00
endloop
endfacet
facet normal 1.000000e+00 0.000000e+00 0.000000e+00
outer loop
vertex 8.111846e+00 7.292722e+00 -7.550000e+00
vertex 8.111846e+00 1.647010e+00 -7.300002e+00
vertex 8.111846e+00 1.647010e+00 -7.800000e+00
endloop
endfacet
facet normal -2.802564e-04 1.000000e+00 3.408324e-10
outer loop
vertex -4.829637e-02 1.310250e+01 -7.800000e+00
vertex -5.513295e+00 1.310097e+01 -7.300001e+00
vertex 5.416704e+00 1.310403e+01 -7.300001e+00
endloop
endfacet
facet normal 1.000000e+00 2.802101e-04 -9.534234e-07
outer loop
vertex 1.221460e+01 2.060253e+01 -7.799999e+00
vertex 1.221323e+01 2.549836e+01 -7.299999e+00
vertex 1.221597e+01 1.570670e+01 -7.300000e+00
endloop
endfacet
facet normal 9.999999e-01 2.802362e-04 -4.767691e-07
outer loop
vertex -5.515032e+00 1.929718e+01 -7.799999e+00
vertex -5.516768e+00 2.549339e+01 -7.299999e+00
vertex -5.513295e+00 1.310097e+01 -7.300001e+00
endloop
endfacet
facet normal -1.000000e+00 -2.802316e-04 -3.005649e-10
outer loop
vertex 5.414967e+00 1.930120e+01 -7.799999e+00
vertex 5.416704e+00 1.310403e+01 -7.300001e+00
vertex 5.413230e+00 2.549836e+01 -7.299999e+00
endloop
endfacet
facet normal 1.000000e+00 0.000000e+00 -0.000000e+00
outer loop
vertex 8.111846e+00 7.292722e+00 -7.550000e+00
vertex 8.111846e+00 1.293843e+01 -7.799999e+00
vertex 8.111846e+00 1.293843e+01 -7.300001e+00
endloop
endfacet
facet normal -9.808400e-01 1.948146e-01 0.000000e+00
outer loop
vertex -1.225840e+01 2.492544e+01 -7.799998e+00
vertex -1.228500e+01 2.479150e+01 -7.299999e+00
vertex -1.223179e+01 2.505939e+01 -7.299999e+00
endloop
endfacet
facet normal -2.800472e-04 9.999999e-01 1.907329e-06
outer loop
vertex -8.550983e+00 2.549254e+01 -7.799998e+00
vertex -1.158520e+01 2.549169e+01 -7.299999e+00
vertex -5.516768e+00 2.549339e+01 -7.299999e+00
endloop
endfacet
facet normal -0.000000e+00 1.000000e+00 0.000000e+00
outer loop
vertex 8.813231e+00 2.549836e+01 -7.799998e+00
vertex 5.413230e+00 2.549836e+01 -7.299999e+00
vertex 1.221323e+01 2.549836e+01 -7.299999e+00
endloop
endfacet
facet normal -5.558020e-01 8.313147e-01 1.050240e-06
outer loop
vertex -1.196659e+01 2.536243e+01 -7.799998e+00
vertex -1.208012e+01 2.528653e+01 -7.299999e+00
vertex -1.185306e+01 2.543833e+01 -7.299999e+00
endloop
endfacet
facet normal -1.953674e-01 9.807302e-01 -1.841328e-07
outer loop
vertex -1.171913e+01 2.546501e+01 -7.799998e+00
vertex -1.185306e+01 2.543833e+01 -7.299999e+00
vertex -1.158520e+01 2.549169e+01 -7.299999e+00
endloop
endfacet
facet normal -8.316252e-01 5.553374e-01 7.910898e-07
outer loop
vertex -1.215596e+01 2.517296e+01 -7.799998e+00
vertex -1.223179e+01 2.505939e+01 -7.299999e+00
vertex -1.208012e+01 2.528653e+01 -7.299999e+00
endloop
endfacet
facet normal 1.000000e+00 0.000000e+00 0.000000e+00
outer loop
vertex 8.111846e+00 7.292722e+00 -7.550000e+00
vertex 8.111846e+00 1.293843e+01 -7.300001e+00
vertex 8.111846e+00 1.647010e+00 -7.300002e+00
endloop
endfacet
facet normal -0.000000e+00 0.000000e+00 1.000000e+00
outer loop
vertex 1.222648e+01 -2.178088e+01 -7.300004e+00
vertex -1.227195e+01 -2.178774e+01 -7.300004e+00
vertex 1.216567e+01 -2.208704e+01 -7.300004e+00
endloop
endfacet
facet normal 1.050226e-08 -9.992250e-08 1.000000e+00
outer loop
vertex 1.221979e+01 2.078772e+00 -7.300002e+00
vertex 8.111846e+00 1.647010e+00 -7.300002e+00
vertex 1.222648e+01 -2.178088e+01 -7.300004e+00
endloop
endfacet
facet normal 3.453364e-08 -1.023615e-07 1.000000e+00
outer loop
vertex -1.228500e+01 2.479150e+01 -7.299999e+00
vertex -1.227195e+01 -2.178774e+01 -7.300004e+00
vertex -5.513295e+00 1.310097e+01 -7.300001e+00
endloop
endfacet
facet normal -1.825128e-08 -1.049725e-07 1.000000e+00
outer loop
vertex 8.111846e+00 1.647010e+00 -7.300002e+00
vertex -5.513295e+00 1.310097e+01 -7.300001e+00
vertex 1.222648e+01 -2.178088e+01 -7.300004e+00
endloop
endfacet
facet normal 2.681644e-11 -9.567682e-08 1.000000e+00
outer loop
vertex -5.513295e+00 1.310097e+01 -7.300001e+00
vertex -1.227195e+01 -2.178774e+01 -7.300004e+00
vertex 1.222648e+01 -2.178088e+01 -7.300004e+00
endloop
endfacet
facet normal 0.000000e+00 0.000000e+00 1.000000e+00
outer loop
vertex -1.147173e+01 -2.258752e+01 -7.300004e+00
vertex -1.227195e+01 -2.178774e+01 -7.300004e+00
vertex -1.177789e+01 -2.252670e+01 -7.300004e+00
endloop
endfacet
facet normal 0.000000e+00 0.000000e+00 1.000000e+00
outer loop
vertex 1.216567e+01 -2.208704e+01 -7.300004e+00
vertex -1.227195e+01 -2.178774e+01 -7.300004e+00
vertex 1.199232e+01 -2.234663e+01 -7.300004e+00
endloop
endfacet
facet normal 0.000000e+00 0.000000e+00 1.000000e+00
outer loop
vertex 1.199232e+01 -2.234663e+01 -7.300004e+00
vertex -1.227195e+01 -2.178774e+01 -7.300004e+00
vertex 1.173283e+01 -2.252012e+01 -7.300004e+00
endloop
endfacet
facet normal 0.000000e+00 0.000000e+00 1.000000e+00
outer loop
vertex 1.173283e+01 -2.252012e+01 -7.300004e+00
vertex -1.227195e+01 -2.178774e+01 -7.300004e+00
vertex 1.142670e+01 -2.258110e+01 -7.300004e+00
endloop
endfacet
facet normal 0.000000e+00 0.000000e+00 1.000000e+00
outer loop
vertex 1.142670e+01 -2.258110e+01 -7.300004e+00
vertex -1.227195e+01 -2.178774e+01 -7.300004e+00
vertex -1.147173e+01 -2.258752e+01 -7.300004e+00
endloop
endfacet
facet normal -0.000000e+00 -0.000000e+00 1.000000e+00
outer loop
vertex -1.227195e+01 -2.178774e+01 -7.300004e+00
vertex -1.221097e+01 -2.209387e+01 -7.300004e+00
vertex -1.177789e+01 -2.252670e+01 -7.300004e+00
endloop
endfacet
facet normal 0.000000e+00 0.000000e+00 1.000000e+00
outer loop
vertex -1.177789e+01 -2.252670e+01 -7.300004e+00
vertex -1.221097e+01 -2.209387e+01 -7.300004e+00
vertex -1.203748e+01 -2.235336e+01 -7.300004e+00
endloop
endfacet
facet normal 2.332680e-11 -8.323378e-08 1.000000e+00
outer loop
vertex 5.416704e+00 1.310403e+01 -7.300001e+00
vertex -5.513295e+00 1.310097e+01 -7.300001e+00
vertex 8.111846e+00 1.647010e+00 -7.300002e+00
endloop
endfacet
facet normal -5.189548e-09 -8.446005e-08 1.000000e+00
outer loop
vertex 8.111846e+00 1.293843e+01 -7.300001e+00
vertex 5.416704e+00 1.310403e+01 -7.300001e+00
vertex 8.111846e+00 1.647010e+00 -7.300002e+00
endloop
endfacet
facet normal 2.095299e-08 -1.051825e-07 1.000000e+00
outer loop
vertex -1.158520e+01 2.549169e+01 -7.299999e+00
vertex -1.185306e+01 2.543833e+01 -7.299999e+00
vertex -5.513295e+00 1.310097e+01 -7.300001e+00
endloop
endfacet
facet normal 3.232708e-11 -1.154344e-07 1.000000e+00
outer loop
vertex -5.516768e+00 2.549339e+01 -7.299999e+00
vertex -1.158520e+01 2.549169e+01 -7.299999e+00
vertex -5.513295e+00 1.310097e+01 -7.300001e+00
endloop
endfacet
facet normal -9.700132e-09 -1.578699e-07 1.000000e+00
outer loop
vertex 1.221597e+01 1.570670e+01 -7.300000e+00
vertex 5.416704e+00 1.310403e+01 -7.300001e+00
vertex 8.111846e+00 1.293843e+01 -7.300001e+00
endloop
endfacet
facet normal 5.769867e-08 -8.630008e-08 1.000000e+00
outer loop
vertex -1.185306e+01 2.543833e+01 -7.299999e+00
vertex -1.208012e+01 2.528653e+01 -7.299999e+00
vertex -5.513295e+00 1.310097e+01 -7.300001e+00
endloop
endfacet
facet normal 9.728713e-08 -6.496578e-08 1.000000e+00
outer loop
vertex -1.208012e+01 2.528653e+01 -7.299999e+00
vertex -1.223179e+01 2.505939e+01 -7.299999e+00
vertex -5.513295e+00 1.310097e+01 -7.300001e+00
endloop
endfacet
facet normal 1.573083e-07 -3.124460e-08 1.000000e+00
outer loop
vertex -1.223179e+01 2.505939e+01 -7.299999e+00
vertex -1.228500e+01 2.479150e+01 -7.299999e+00
vertex -5.513295e+00 1.310097e+01 -7.300001e+00
endloop
endfacet
facet normal -2.594791e-08 -1.154239e-07 1.000000e+00
outer loop
vertex 5.413230e+00 2.549836e+01 -7.299999e+00
vertex 5.416704e+00 1.310403e+01 -7.300001e+00
vertex 1.221597e+01 1.570670e+01 -7.300000e+00
endloop
endfacet
facet normal 0.000000e+00 -9.739662e-08 1.000000e+00
outer loop
vertex 1.221323e+01 2.549836e+01 -7.299999e+00
vertex 5.413230e+00 2.549836e+01 -7.299999e+00
vertex 1.221597e+01 1.570670e+01 -7.300000e+00
endloop
endfacet
endsolid
BIN
View File
Binary file not shown.
Binary file not shown.
+188
View File
@@ -0,0 +1,188 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="viewport" content="width=device-width" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="refresh" content="5;url=http://fontsgeek.com/fonts/pigiarniq-italic?ref=readme">
<title>Pigiarniq ItalicFontsgeek</title>
<style>
/* -------------------------------------
GLOBAL
------------------------------------- */
* {
margin:0;
padding:0;
font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;
font-size: 100%;
line-height: 1.6;
}
img {
max-width: 100%;
}
body {
-webkit-font-smoothing:antialiased;
-webkit-text-size-adjust:none;
width: 100%!important;
height: 100%;
background:#DDD;
}
/* -------------------------------------
ELEMENTS
------------------------------------- */
a {
color: #348eda;
}
.btn-primary, .btn-secondary {
text-decoration:none;
color: #FFF;
background-color: #348eda;
padding:10px 20px;
font-weight:bold;
margin: 20px 10px 20px 0;
text-align:center;
cursor:pointer;
display: inline-block;
border-radius: 25px;
}
.btn-secondary{
background: #aaa;
}
.last {
margin-bottom: 0;
}
.first{
margin-top: 0;
}
/* -------------------------------------
BODY
------------------------------------- */
table.body-wrap {
width: 100%;
padding: 20px;
}
table.body-wrap .container{
border: 1px solid #f0f0f0;
}
/* -------------------------------------
FOOTER
------------------------------------- */
table.footer-wrap {
width: 100%;
clear:both!important;
}
.footer-wrap .container p {
font-size:12px;
color:#666;
}
table.footer-wrap a{
color: #999;
}
/* -------------------------------------
TYPOGRAPHY
------------------------------------- */
h1,h2,h3{
font-family: "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif; line-height: 1.1; margin-bottom:15px; color:#000;
margin: 40px 0 10px;
line-height: 1.2;
font-weight:200;
}
h1 {
font-size: 36px;
}
h2 {
font-size: 28px;
}
h3 {
font-size: 22px;
}
p, ul {
margin-bottom: 10px;
font-weight: normal;
font-size:14px;
}
ul li {
margin-left:5px;
list-style-position: inside;
}
/* ---------------------------------------------------
RESPONSIVENESS
Nuke it from orbit. It's the only way to be sure.
------------------------------------------------------ */
/* Set a max-width, and make it display as block so it will automatically stretch to that width, but will also shrink down on a phone or something */
.container {
display:block!important;
max-width:600px!important;
margin:0 auto!important; /* makes it centered */
clear:both!important;
}
/* This should also be a block element, so that it will fill 100% of the .container */
.content {
padding:20px;
max-width:600px;
margin:0 auto;
display:block;
}
/* Let's make sure tables in the content area are 100% wide */
.content table {
width: 100%;
}
</style>
</head>
<body bgcolor="#f6f6f6">
<!-- body -->
<table class="body-wrap">
<tr>
<td></td>
<td class="container" bgcolor="#FFFFFF">
<!-- content -->
<div class="content">
<table>
<tr>
<td>
<h1>Pigiarniq Italic</h1>
<p>This font was downloaded from <a href="http://fontsgeek.com?ref=readme">fontsgeek.com</a> . You can visit <a href="http://fontsgeek.com?ref=readme">fontsgeek.com</a> for thousands of free fonts.</p>
<p><a href="http://fontsgeek.com/fonts/pigiarniq-italic?ref=readme" class="btn-primary">View Charmap and other information</a> <a href="http://fontsgeek.com?ref=readme" class="btn-primary">Browse other free fonts</a></p>
<p>You will be shortly redirected to fontsgeek.</p>
</td>
</tr>
</table>
</div>
<!-- /content -->
</td>
<td></td>
</tr>
</table>
<!-- /body -->
</body>
</html>
BIN
View File
Binary file not shown.
+96
View File
@@ -0,0 +1,96 @@
-------------------------------
UBUNTU FONT LICENCE Version 1.0
-------------------------------
PREAMBLE
This licence allows the licensed fonts to be used, studied, modified and
redistributed freely. The fonts, including any derivative works, can be
bundled, embedded, and redistributed provided the terms of this licence
are met. The fonts and derivatives, however, cannot be released under
any other licence. The requirement for fonts to remain under this
licence does not require any document created using the fonts or their
derivatives to be published under this licence, as long as the primary
purpose of the document is not to be a vehicle for the distribution of
the fonts.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this licence and clearly marked as such. This may
include source files, build scripts and documentation.
"Original Version" refers to the collection of Font Software components
as received under this licence.
"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to
a new environment.
"Copyright Holder(s)" refers to all individuals and companies who have a
copyright ownership of the Font Software.
"Substantially Changed" refers to Modified Versions which can be easily
identified as dissimilar to the Font Software by users of the Font
Software comparing the Original Version with the Modified Version.
To "Propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification and with or without charging
a redistribution fee), making available to the public, and in some
countries other activities as well.
PERMISSION & CONDITIONS
This licence does not grant any rights under trademark law and all such
rights are reserved.
Permission is hereby granted, free of charge, to any person obtaining a
copy of the Font Software, to propagate the Font Software, subject to
the below conditions:
1) Each copy of the Font Software must contain the above copyright
notice and this licence. These can be included either as stand-alone
text files, human-readable headers or in the appropriate machine-
readable metadata fields within text or binary files as long as those
fields can be easily viewed by the user.
2) The font name complies with the following:
(a) The Original Version must retain its name, unmodified.
(b) Modified Versions which are Substantially Changed must be renamed to
avoid use of the name of the Original Version or similar names entirely.
(c) Modified Versions which are not Substantially Changed must be
renamed to both (i) retain the name of the Original Version and (ii) add
additional naming elements to distinguish the Modified Version from the
Original Version. The name of such Modified Versions must be the name of
the Original Version, with "derivative X" where X represents the name of
the new work, appended to that name.
3) The name(s) of the Copyright Holder(s) and any contributor to the
Font Software shall not be used to promote, endorse or advertise any
Modified Version, except (i) as required by this licence, (ii) to
acknowledge the contribution(s) of the Copyright Holder(s) or (iii) with
their explicit written permission.
4) The Font Software, modified or unmodified, in part or in whole, must
be distributed entirely under this licence, and must not be distributed
under any other licence. The requirement for fonts to remain under this
licence does not affect any document created using the Font Software,
except any version of the Font Software extracted from a document
created using the Font Software may only be distributed under this
licence.
TERMINATION
This licence becomes null and void if any of the above conditions are
not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER
DEALINGS IN THE FONT SOFTWARE.
BIN
View File
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 7.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

File diff suppressed because one or more lines are too long
File diff suppressed because it is too large Load Diff
+2 -1
View File
@@ -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"
] ]
} }
+4
View File
@@ -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)
+299
View File
@@ -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.
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,9 @@
idf_component_register(
SRCS
"src/dns_captive.c"
INCLUDE_DIRS
"include"
REQUIRES
lwip
esp_netif
)
@@ -1,3 +1,4 @@
// File: dns_captive.c
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <inttypes.h> #include <inttypes.h>
@@ -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
+64 -26
View File
@@ -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*/
+204
View File
@@ -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);
+65
View File
@@ -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();
}
+23
View File
@@ -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);
+1 -1
View File
@@ -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")
+5 -3
View File
@@ -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" {
+14 -3
View File
@@ -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;
} }
+1 -1
View File
@@ -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
@@ -0,0 +1,12 @@
idf_component_register(
SRCS
"src/http_portal.c"
INCLUDE_DIRS
"include"
REQUIRES
esp_wifi
esp_http_server
esp_netif
storage
)
@@ -0,0 +1,27 @@
// http_portal.h
#pragma once
#include "freertos/FreeRTOS.h"
#include "freertos/event_groups.h"
#include "esp_err.h"
// Callbacks, die das Portal nach außen benutzt
typedef struct {
bool (*load_sta_creds)(char **ssid, char **pass); // optional, wenn du es später brauchst
void (*save_sta_creds_and_reconnect)(const char *ssid, const char *pass);
void (*save_device_info)(
const char *devicename,
const char *token,
const char *bucket,
const char *org
);
} portal_http_callbacks_t;
// HTTP-Portal starten / stoppen
esp_err_t portal_http_start(EventGroupHandle_t wifi_events,
EventBits_t bit_gotip,
EventBits_t bit_fail,
const char* ap_ssid,
const portal_http_callbacks_t *cb);
void portal_http_stop(void);
@@ -14,9 +14,7 @@
#include "http_portal.h" #include "http_portal.h"
#include "storage.h" #include "storage.h"
// Diese beiden werden vom WiFi-Manager bereitgestellt (in wifi_mgr.c definiert) static portal_http_callbacks_t s_cb;
bool wifi_mgr_load_sta_creds(char **out_ssid, char **out_pass);
void wifi_mgr_save_sta_creds_and_reconnect(const char* ssid, const char* pass);
static void __attribute__((unused)) log_one_hdr(httpd_req_t *req, const char* key) { static void __attribute__((unused)) log_one_hdr(httpd_req_t *req, const char* key) {
size_t len = httpd_req_get_hdr_value_len(req, key); size_t len = httpd_req_get_hdr_value_len(req, key);
@@ -34,9 +32,6 @@ static void __attribute__((unused)) log_one_hdr(httpd_req_t *req, const char* ke
} }
} }
// Geräteeigenschaften speichern (in wifi_mgr.c implementieren)
void wifi_mgr_save_device_info(const char* devicename, const char* token, const char* bucket, const char* org);
static const char *TAG = "portal_http"; static const char *TAG = "portal_http";
static httpd_handle_t s_http = NULL; static httpd_handle_t s_http = NULL;
@@ -460,16 +455,21 @@ static esp_err_t save_post(httpd_req_t *req) {
log_resp_basic("save_post", "200 OK", "text/html; charset=utf-8", (int)strlen(saved_html)); log_resp_basic("save_post", "200 OK", "text/html; charset=utf-8", (int)strlen(saved_html));
httpd_resp_send(req, saved_html, HTTPD_RESP_USE_STRLEN); httpd_resp_send(req, saved_html, HTTPD_RESP_USE_STRLEN);
// Geräteeigenschaften speichern // Geräteeigenschaften speichern (über Callback)
wifi_mgr_save_device_info( if (s_cb.save_device_info) {
dev, s_cb.save_device_info(
(token && token[0]) ? token : NULL, // NULL = nicht geändert dev,
(bucket && bucket[0]) ? bucket : NULL, (token && token[0]) ? token : NULL, // NULL = nicht geändert
(org && org[0]) ? org : NULL (bucket && bucket[0]) ? bucket : NULL,
); (org && org[0]) ? org : NULL
);
}
// STA-Creds speichern & reconnect (über Callback)
if (s_cb.save_sta_creds_and_reconnect) {
s_cb.save_sta_creds_and_reconnect(ssid, pass);
}
// STA-Creds speichern & reconnect
wifi_mgr_save_sta_creds_and_reconnect(ssid, pass);
s_force_captive = false; // Captive beenden; OS darf 204 sehen s_force_captive = false; // Captive beenden; OS darf 204 sehen
// Cleanup (Erfolgsweg) // Cleanup (Erfolgsweg)
@@ -653,8 +653,12 @@ static httpd_handle_t start_http(void) {
esp_err_t portal_http_start(EventGroupHandle_t wifi_events, esp_err_t portal_http_start(EventGroupHandle_t wifi_events,
EventBits_t bit_gotip, EventBits_t bit_gotip,
EventBits_t bit_fail, EventBits_t bit_fail,
const char* ap_ssid) const char* ap_ssid,
const portal_http_callbacks_t *cb)
{ {
if (s_http) return ESP_OK;
if (!cb) return ESP_ERR_INVALID_ARG;
s_cb = *cb;
if (s_http) return ESP_OK; if (s_http) return ESP_OK;
s_wifi_events = wifi_events; s_wifi_events = wifi_events;
s_BIT_GOTIP = bit_gotip; s_BIT_GOTIP = bit_gotip;
@@ -0,0 +1,16 @@
idf_component_register(
SRCS
"src/net_influx.c"
"src/influx_batch.c"
INCLUDE_DIRS
"include"
REQUIRES
mdns
esp_netif
esp_wifi
storage
esp_http_client
sys_status
esp_timer
)
@@ -0,0 +1,86 @@
// File: include/net_influx.h (oder wo dein Header liegt)
#pragma once
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include "freertos/FreeRTOS.h"
#include "esp_err.h"
typedef enum {
NET_INFLUX_F_FLOAT,
NET_INFLUX_F_INT,
NET_INFLUX_F_UINT,
NET_INFLUX_F_BOOL,
NET_INFLUX_F_STRING,
} net_influx_field_type_t;
typedef struct {
const char* key; // field key
net_influx_field_type_t type;
int precision; // nur für FLOAT (z.B. 1,3). sonst ignoriert
union {
double f;
int64_t i;
uint64_t u;
bool b;
const char* s;
} v;
} net_influx_field_t;
typedef struct {
const char* measurement; // z.B. "air"
const char* tags; // z.B. "device=xyz,location=lab" (optional, kann NULL sein)
uint64_t ts_ms; // 0 => acquisition time aligned to the server HTTP Date (async API)
const net_influx_field_t* fields;
size_t num_fields;
} net_influx_point_t;
typedef struct {
// Task/Queue
uint16_t queue_len; // Standard 32
uint32_t task_stack; // Standard 8192
UBaseType_t task_prio; // z.B. 5
// Init/Retry/Backoff
uint32_t init_retry_ms; // z.B. 1000
uint32_t backoff_start_ms; // z.B. 2000
uint32_t backoff_max_ms; // z.B. 300000
uint8_t fails_before_reinit; // z.B. 5
// Influx init
const char* ca_cert_pem_opt; // optional
int http_timeout_ms; // z.B. 3000
} net_influx_runtime_cfg_t;
// Bestehende Funktionen bleiben:
typedef struct {
const char* url_base;
const char* org;
const char* bucket;
const char* token;
bool use_tls;
const char* ca_cert_pem;
int http_timeout_ms;
} net_influx_cfg_t;
esp_err_t net_influx_init(const net_influx_cfg_t* cfg);
esp_err_t net_influx_init_from_nvs(const char* ca_cert_pem_opt, int timeout_ms);
// NEU:
esp_err_t net_influx_start(const net_influx_runtime_cfg_t* rt);
void net_influx_stop(void);
// 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:
// - ESP_OK: queued
// - ESP_ERR_NO_MEM / ESP_ERR_INVALID_ARG / ESP_FAIL: sonst
esp_err_t net_influx_submit_point(const net_influx_point_t* p);
// Optional (falls du synchron brauchst, bleibt deine alte API nutzbar):
esp_err_t net_influx_write_fields(const char* measurement,
const char* tags,
uint64_t ts_ms,
const char* fields_fmt,
...);
@@ -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);
@@ -0,0 +1,687 @@
// File: src/net_influx.c
#include "esp_http_client.h"
#include "esp_err.h"
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "freertos/semphr.h"
#include "esp_timer.h"
#include "influx_batch.h"
#include <stdatomic.h>
#include <string.h>
#include <strings.h>
#include <stdio.h>
#include <stdarg.h>
#include <ctype.h>
#include <stdlib.h>
#include <math.h>
#include "sys_status.h"
#include "storage.h"
#include "net_influx.h"
static const char* TAG = "net_influx";
/* ---------------- State (mit internen Kopien!) ---------------- */
typedef struct {
char url_base[128];
char org[64];
char bucket[64];
char token[512]; // lang genug für Influx Token
bool use_tls;
const char* ca_cert_pem;
int http_timeout_ms;
} net_influx_state_t;
static net_influx_state_t s = {0};
/* ---------------- Worker Runtime State (asynchrones Submit) ---------------- */
typedef struct {
uint16_t queue_len;
uint32_t task_stack;
UBaseType_t task_prio;
uint32_t init_retry_ms;
uint32_t backoff_start_ms;
uint32_t backoff_max_ms;
uint8_t fails_before_reinit;
const char* ca_cert_pem_opt;
int http_timeout_ms;
} net_influx_runtime_cfg_i_t;
static QueueHandle_t s_q = NULL;
static TaskHandle_t s_task = NULL;
static atomic_bool s_run = false;
static net_influx_runtime_cfg_i_t s_rt = {
.queue_len = 32,
.task_stack = 8192,
.task_prio = 5,
.init_retry_ms = 1000,
.backoff_start_ms = 2000,
.backoff_max_ms = 300000,
.fails_before_reinit = 5,
.ca_cert_pem_opt = NULL,
.http_timeout_ms = 3000,
};
/* ---------------- Utils ---------------- */
static void trim_inplace(char* p) {
if (!p) return;
size_t len = strlen(p);
size_t a = 0, b = len;
while (a < b && (isspace((unsigned char)p[a]) || p[a] == '\"')) a++;
while (b > a && (isspace((unsigned char)p[b-1]) || p[b-1] == '\"' || p[b-1] == '/')) b--;
if (a || b != len) {
memmove(p, p + a, b - a);
p[b - a] = 0;
}
}
static void safe_copy(char* dst, size_t dst_sz, const char* src) {
if (!dst || dst_sz == 0) return;
if (!src) { dst[0] = 0; return; }
strncpy(dst, src, dst_sz - 1);
dst[dst_sz - 1] = 0;
}
typedef struct {
bool tls; // http=false, https=true
char host[64];
int port; // -1 = nicht angegeben
} base_parts_t;
// erwartet: "http://host:port" oder "host:port" oder "host"
static bool parse_base_url(const char* in, base_parts_t* out) {
if (!in || !*in || !out) return false;
char buf[128];
safe_copy(buf, sizeof(buf), in);
trim_inplace(buf);
const char* p = buf;
out->tls = false;
out->port = -1;
memset(out->host, 0, sizeof(out->host));
if (strncasecmp(p, "http://", 7) == 0) { p += 7; out->tls = false; }
else if (strncasecmp(p, "https://", 8) == 0) { p += 8; out->tls = true; }
const char* colon = strchr(p, ':');
if (colon) {
size_t host_len = (size_t)(colon - p);
if (host_len == 0 || host_len >= sizeof(out->host)) return false;
memcpy(out->host, p, host_len);
out->host[host_len] = 0;
const char* port_str = colon + 1;
if (!*port_str) return false;
int port = 0;
while (*port_str && isdigit((unsigned char)*port_str)) {
port = port * 10 + (*port_str - '0');
port_str++;
}
if (*port_str != 0) return false; // kein weiterer Kram erlaubt
out->port = port;
} else {
size_t host_len = strlen(p);
if (host_len == 0 || host_len >= sizeof(out->host)) return false;
memcpy(out->host, p, host_len);
out->host[host_len] = 0;
}
return true;
}
/* Minimal escaping für measurement/key: spaces/commas */
static size_t esc_copy(char* dst, size_t cap, const char* src, bool escape_equals) {
size_t pos = 0;
if (!dst || cap == 0) return 0;
dst[0] = 0;
if (!src) return 0;
for (const char* p = src; *p; ++p) {
char c = *p;
bool esc = (c == ' ' || c == ',' || (escape_equals && c == '='));
if (esc) {
if (pos + 2 >= cap) { dst[0] = 0; return SIZE_MAX; }
dst[pos++] = '\\';
dst[pos++] = c;
} else {
if (pos + 1 >= cap) { dst[0] = 0; return SIZE_MAX; }
dst[pos++] = c;
}
}
dst[(pos < cap) ? pos : (cap - 1)] = 0;
return pos;
}
/* Persistent HTTP client; shared with the optional synchronous API. */
static esp_http_client_handle_t s_http;
static SemaphoreHandle_t s_http_lock;
static influx_clock_t s_clock;
static char s_write_url[640];
static atomic_uint s_dropped;
static uint64_t monotonic_ms(void) { return (uint64_t)(esp_timer_get_time() / 1000); }
static void http_close(void)
{
if (s_http) esp_http_client_cleanup(s_http);
s_http = NULL;
}
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;
}
static bool encode_query(char *out, size_t cap, const char *text)
{
static const char hex[] = "0123456789ABCDEF";
size_t n = 0;
for (const unsigned char *p = (const unsigned char *)text; *p; ++p) {
bool plain = isalnum(*p) || *p == '-' || *p == '_' || *p == '.' || *p == '~';
size_t need = plain ? 1 : 3;
if (n + need >= cap) return false;
if (plain) out[n++] = *p;
else { out[n++] = '%'; out[n++] = hex[*p >> 4]; out[n++] = hex[*p & 15]; }
}
out[n] = 0;
return true;
}
/* Caller holds s_http_lock. URLs/headers are configured once per connection. */
static esp_err_t http_prepare(void)
{
if (s_http) return ESP_OK;
if (!s.url_base[0] || !s.org[0] || !s.bucket[0] || !s.token[0]) return ESP_ERR_INVALID_STATE;
base_parts_t base;
if (!parse_base_url(s.url_base, &base)) return ESP_ERR_INVALID_ARG;
if (s.use_tls) base.tls = true;
int port = base.port > 0 ? base.port : base.tls ? 443 : 8086;
char org[192], bucket[192];
if (!encode_query(org, sizeof(org), s.org) || !encode_query(bucket, sizeof(bucket), s.bucket)) return ESP_ERR_INVALID_SIZE;
int length = snprintf(s_write_url, sizeof(s_write_url), "%s://%s:%d/api/v2/write?org=%s&bucket=%s&precision=ms",
base.tls ? "https" : "http", base.host, port, org, bucket);
if (length < 0 || length >= sizeof(s_write_url)) return ESP_ERR_INVALID_SIZE;
esp_http_client_config_t cfg = {
.url = s_write_url,
.timeout_ms = s.http_timeout_ms,
.cert_pem = base.tls ? s.ca_cert_pem : NULL,
.method = HTTP_METHOD_POST,
.event_handler = http_evt,
.transport_type = base.tls ? HTTP_TRANSPORT_OVER_SSL : HTTP_TRANSPORT_OVER_TCP,
.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);
if (!s_http) return ESP_ERR_NO_MEM;
char auth[sizeof(s.token) + 7];
snprintf(auth, sizeof(auth), "Token %s", s.token);
esp_err_t err = esp_http_client_set_header(s_http, "Authorization", auth);
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.");
return ESP_OK;
}
/* 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 ---------------- */
static bool field_is_valid(const net_influx_field_t* f) {
if (!f || !f->key || !*f->key) return false;
if (f->type == NET_INFLUX_F_FLOAT) return isfinite(f->v.f);
if (f->type == NET_INFLUX_F_STRING) return (f->v.s != NULL);
return true;
}
static esp_err_t build_line_protocol(const net_influx_point_t* p, char* out, size_t out_cap) {
if (!p || !p->measurement || !p->fields || p->num_fields == 0 || !out || out_cap < 64) {
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;
// measurement escaped (space/comma)
char meas[96];
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);
if (off >= out_cap) return ESP_FAIL;
// tags: passthrough (caller liefert "k=v,k2=v2")
if (p->tags && *p->tags) {
off += snprintf(out + off, out_cap - off, ",%s", p->tags);
if (off >= out_cap) return ESP_FAIL;
}
off += snprintf(out + off, out_cap - off, " ");
if (off >= out_cap) return ESP_FAIL;
bool first = true;
for (size_t i = 0; i < p->num_fields; ++i) {
const net_influx_field_t* f = &p->fields[i];
if (!field_is_valid(f)) continue;
char key[64];
if (esc_copy(key, sizeof(key), f->key, true) == SIZE_MAX) return ESP_ERR_INVALID_SIZE;
if (!first) {
off += snprintf(out + off, out_cap - off, ",");
if (off >= out_cap) return ESP_FAIL;
}
first = false;
switch (f->type) {
case NET_INFLUX_F_FLOAT: {
int prec = (f->precision >= 0 && f->precision <= 9) ? f->precision : 3;
char fmt[24];
snprintf(fmt, sizeof(fmt), "%%s=%%.%df", prec);
off += snprintf(out + off, out_cap - off, fmt, key, f->v.f);
break;
}
case NET_INFLUX_F_INT:
off += snprintf(out + off, out_cap - off, "%s=%lldi", key, (long long)f->v.i);
break;
case NET_INFLUX_F_UINT:
off += snprintf(out + off, out_cap - off, "%s=%lluu", key, (unsigned long long)f->v.u);
break;
case NET_INFLUX_F_BOOL:
off += snprintf(out + off, out_cap - off, "%s=%s", key, f->v.b ? "true" : "false");
break;
case NET_INFLUX_F_STRING: {
off += snprintf(out + off, out_cap - off, "%s=\"", key);
if (off >= out_cap) return ESP_FAIL;
const char* s0 = f->v.s ? f->v.s : "";
for (const char* sp = s0; *sp; ++sp) {
if (off + 2 >= out_cap) return ESP_FAIL;
if (*sp == '\"' || *sp == '\\') out[off++] = '\\';
out[off++] = *sp;
}
if (off + 2 >= out_cap) return ESP_FAIL;
out[off++] = '\"';
out[off] = 0;
break;
}
default:
return ESP_ERR_INVALID_ARG;
}
if (off >= out_cap) return ESP_FAIL;
}
if (first) return ESP_ERR_INVALID_STATE; // keine validen Felder
if (p->ts_ms != 0) {
off += snprintf(out + off, out_cap - off, " %llu", (unsigned long long)p->ts_ms);
if (off >= out_cap) return ESP_FAIL;
}
return ESP_OK;
}
/* Fixed-size, pre-serialized queue entries: no per-field heap allocation. */
typedef struct {
char line[INFLUX_LINE_CAP];
uint64_t acquired_ms;
bool timestamped;
} influx_msg_t;
static bool wait_running(uint32_t ms)
{
while (s_run && ms) {
uint32_t step = ms > 100 ? 100 : ms;
vTaskDelay(pdMS_TO_TICKS(step));
ms -= step;
}
return s_run;
}
static bool influx_init_blocking(void)
{
while (s_run) {
if (net_influx_init_from_nvs(s_rt.ca_cert_pem_opt, s_rt.http_timeout_ms) == ESP_OK) return true;
ESP_LOGW(TAG, "Influx configuration unavailable; retrying.");
wait_running(s_rt.init_retry_ms);
}
return false;
}
static void net_influx_worker(void *arg)
{
(void)arg;
influx_batch_t *batch = calloc(1, sizeof(*batch));
influx_msg_t carry = {0};
bool have_carry = false, batch_timestamped = true;
unsigned failures = 0;
uint32_t backoff = s_rt.backoff_start_ms;
if (!batch) { ESP_LOGE(TAG, "Cannot allocate Influx batch buffer."); goto done; }
if (!influx_init_blocking()) goto done;
clock_bootstrap();
ESP_LOGI(TAG, "Influx batching ready: up to %u points / %u ms, queue=%u", INFLUX_BATCH_POINTS, INFLUX_FLUSH_MS, s_rt.queue_len);
while (s_run) {
bool flush = influx_batch_due(batch, monotonic_ms());
if (!flush) {
influx_msg_t msg;
bool received = have_carry;
if (received) { msg = carry; have_carry = false; }
else received = xQueueReceive(s_q, &msg, pdMS_TO_TICKS(100)) == pdTRUE;
if (!received) continue;
if (!msg.timestamped) {
uint64_t timestamp;
xSemaphoreTake(s_http_lock, portMAX_DELAY);
bool known = influx_clock_timestamp(&s_clock, msg.acquired_ms, &timestamp);
xSemaphoreGive(s_http_lock);
if (known) {
size_t used = strlen(msg.line);
int n = snprintf(msg.line + used, sizeof(msg.line) - used, " %llu", (unsigned long long)timestamp);
if (n < 0 || (size_t)n >= sizeof(msg.line) - used) { ESP_LOGW(TAG, "Dropping oversized timestamped point."); continue; }
msg.timestamped = true;
}
}
if ((!msg.timestamped && batch->points) || !influx_batch_add(batch, msg.line, monotonic_ms())) {
carry = msg; have_carry = true; flush = true;
} else {
batch_timestamped = msg.timestamped;
flush = !msg.timestamped || influx_batch_due(batch, monotonic_ms());
}
}
if (!flush || !batch->points) continue;
/* 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) {
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);
}
/* ---------------- Public API ---------------- */
esp_err_t net_influx_init(const net_influx_cfg_t* cfg) {
if (!cfg || !cfg->url_base || !cfg->org || !cfg->bucket || !cfg->token) {
return ESP_ERR_INVALID_ARG;
}
if (!s_http_lock) {
s_http_lock = xSemaphoreCreateMutex();
if (!s_http_lock) return ESP_ERR_NO_MEM;
}
net_influx_state_t next = {0};
safe_copy(next.url_base, sizeof(next.url_base), cfg->url_base);
safe_copy(next.org, sizeof(next.org), cfg->org);
safe_copy(next.bucket, sizeof(next.bucket), cfg->bucket);
safe_copy(next.token, sizeof(next.token), cfg->token);
trim_inplace(next.url_base);
next.use_tls = cfg->use_tls;
next.ca_cert_pem = cfg->ca_cert_pem;
next.http_timeout_ms = cfg->http_timeout_ms > 0 ? cfg->http_timeout_ms : 3000;
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);
return ESP_OK;
}
esp_err_t net_influx_write_fields(const char* measurement,
const char* tags,
uint64_t ts_ms,
const char* fields_fmt,
...)
{
// --- pessimistisch starten ---
bool ok = false;
if (!measurement || !fields_fmt) {
sys_status_set_influx_ok(false);
return ESP_ERR_INVALID_ARG;
}
if (s.url_base[0] == 0 || s.org[0] == 0 || s.bucket[0] == 0 || s.token[0] == 0) {
sys_status_set_influx_ok(false);
return ESP_ERR_INVALID_STATE;
}
// 1) Fields formatieren
char fields[256];
va_list ap;
va_start(ap, fields_fmt);
int fields_length = vsnprintf(fields, sizeof(fields), fields_fmt, ap);
va_end(ap);
if (fields_length < 0 || (size_t)fields_length >= sizeof(fields)) return ESP_ERR_INVALID_SIZE;
// 2) Line Protocol
char line[512];
int off = 0;
// measurement escaping (space/comma)
char meas[96];
if (esc_copy(meas, sizeof(meas), measurement, false) == SIZE_MAX) return ESP_ERR_INVALID_SIZE;
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 (tags && *tags) {
off += snprintf(line + off, sizeof(line) - off, ",%s", tags);
if (off < 0 || off >= (int)sizeof(line)) { sys_status_set_influx_ok(false); return ESP_FAIL; }
}
off += snprintf(line + off, sizeof(line) - off, " %s", fields);
if (off < 0 || off >= (int)sizeof(line)) { sys_status_set_influx_ok(false); return ESP_FAIL; }
if (ts_ms != 0) {
off += snprintf(line + off, sizeof(line) - off, " %llu", (unsigned long long)ts_ms);
if (off < 0 || off >= (int)sizeof(line)) { sys_status_set_influx_ok(false); return ESP_FAIL; }
}
esp_err_t err = net_influx_write_line(line);
ok = (err == ESP_OK);
sys_status_set_influx_ok(ok);
return ok ? ESP_OK : ESP_FAIL;
}
// Aus NVS: URL (service_url), org/bucket/token → net_influx_init()
esp_err_t net_influx_init_from_nvs(const char* ca_cert_pem_opt, int timeout_ms)
{
char *url = NULL, *org = NULL, *bucket = NULL, *token = NULL;
if (!storage_load_service_url(&url)) {
ESP_LOGW(TAG, "keine Service-URL in NVS gefunden (mDNS noch nicht fertig?)");
return ESP_ERR_NOT_FOUND;
}
if (!storage_get_effective_influx(&org, &bucket, &token)) {
ESP_LOGE(TAG, "Influx-Konfiguration aus NVS nicht lesbar");
free(url);
return ESP_FAIL;
}
net_influx_cfg_t cfg = {
.url_base = url, // z.B. "http://192.168.1.10:8086"
.org = org,
.bucket = bucket,
.token = token,
.use_tls = false, // URL-Parser erkennt https automatisch; true erzwingt TLS
.ca_cert_pem = ca_cert_pem_opt,
.http_timeout_ms = (timeout_ms > 0) ? timeout_ms : 3000
};
esp_err_t err = net_influx_init(&cfg);
free(url);
free(org);
free(bucket);
free(token);
return err;
}
/* ---------------- NEW: Start/Stop/Submit (generic, multi-sensor) ---------------- */
esp_err_t net_influx_start(const net_influx_runtime_cfg_t* rt) {
if (s_task) return s_run ? ESP_OK : ESP_ERR_INVALID_STATE;
// runtime cfg übernehmen (mit Defaults)
if (rt) {
s_rt.queue_len = rt->queue_len ? rt->queue_len : s_rt.queue_len;
s_rt.task_stack = rt->task_stack ? rt->task_stack : s_rt.task_stack;
s_rt.task_prio = rt->task_prio ? rt->task_prio : s_rt.task_prio;
s_rt.init_retry_ms = rt->init_retry_ms ? rt->init_retry_ms : s_rt.init_retry_ms;
s_rt.backoff_start_ms = rt->backoff_start_ms ? rt->backoff_start_ms : s_rt.backoff_start_ms;
s_rt.backoff_max_ms = rt->backoff_max_ms ? rt->backoff_max_ms : s_rt.backoff_max_ms;
s_rt.fails_before_reinit = rt->fails_before_reinit ? rt->fails_before_reinit : s_rt.fails_before_reinit;
s_rt.ca_cert_pem_opt = rt->ca_cert_pem_opt;
s_rt.http_timeout_ms = (rt->http_timeout_ms > 0) ? rt->http_timeout_ms : s_rt.http_timeout_ms;
}
s_q = xQueueCreate(s_rt.queue_len, sizeof(influx_msg_t));
if (!s_q) return ESP_ERR_NO_MEM;
s_dropped = 0;
s_run = true;
if (xTaskCreate(net_influx_worker, "influx_worker", s_rt.task_stack, NULL, s_rt.task_prio, &s_task) != pdPASS) {
vQueueDelete(s_q);
s_q = NULL;
s_run = false;
return ESP_FAIL;
}
return ESP_OK;
}
void net_influx_stop(void)
{
s_run = false;
/* Worker owns its HTTP handle, batch and queue. Never delete it mid-request. */
for (unsigned i = 0; s_task && i < 50; ++i) vTaskDelay(pdMS_TO_TICKS(100));
if (s_task) ESP_LOGW(TAG, "Worker still finishing an HTTP request; cleanup deferred.");
}
esp_err_t net_influx_submit_point(const net_influx_point_t *point)
{
if (!point || !point->measurement || !*point->measurement || !point->fields || !point->num_fields || point->ts_ms > 9223372036854ULL)
return ESP_ERR_INVALID_ARG;
if (!s_run || !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. */
size_t cap = msg.timestamped ? sizeof(msg.line) : sizeof(msg.line) - 24;
esp_err_t err = build_line_protocol(point, msg.line, cap);
if (err != ESP_OK) return err;
if (xQueueSend(s_q, &msg, 0) != pdPASS) {
influx_msg_t old;
if (xQueueReceive(s_q, &old, 0) == pdTRUE) {
unsigned dropped = atomic_fetch_add(&s_dropped, 1) + 1;
if (dropped == 1 || dropped % 10 == 0)
ESP_LOGW(TAG, "Influx queue full: %u old pending points dropped since start.", dropped);
}
if (xQueueSend(s_q, &msg, 0) != pdPASS) return ESP_FAIL;
}
return ESP_OK;
}
@@ -0,0 +1,12 @@
idf_component_register(
SRCS
"src/net_mdns.c"
INCLUDE_DIRS
"include"
REQUIRES
mdns
esp_netif
esp_wifi
storage
)
@@ -0,0 +1,32 @@
// net_mdns.h (Ergänzungen)
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include "esp_err.h"
#include "mdns.h"
// bestehende APIs bleiben...
typedef struct {
const char *service; // z.B. "_myapp"
const char *proto; // z.B. "_tcp"
int enforce_port; // -1 oder 0 = egal
const char *fallback_service; // z.B. "_http"
const char *fallback_proto; // z.B. "_tcp"
int fallback_port; // z.B. 8086
const char *txt_key; // optional
const char *txt_value; // optional
uint32_t query_timeout_ms; // z.B. 2000
uint32_t retry_interval_ms; // z.B. 60000
int max_results; // z.B. 5
const char *instance_prefix; // z.B. "myapp-"
bool require_instance_prefix; // true/false
} net_mdns_discover_cfg_t;
esp_err_t net_mdns_autodiscover_start(const net_mdns_discover_cfg_t *cfg);
void net_mdns_autodiscover_stop(void);
esp_err_t net_mdns_autostart_init(const char* hostname, const char* instance_name);
+477
View File
@@ -0,0 +1,477 @@
// File: firmware/components/net_mdns/src/net_mdns.c
#include <string.h>
#include <stdio.h>
#include <stdbool.h>
#include "esp_log.h"
#include "esp_err.h"
#include "esp_event.h"
#include "esp_netif.h"
#include "esp_wifi.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "mdns.h"
#include "net_mdns.h"
#include "storage.h"
static const char *TAG = "net_mdns";
// -------------------- Global State --------------------
static char g_hostname[33] = {0};
static char g_instance[33] = {0};
static volatile bool g_mdns_running = false;
static volatile bool g_autostart_inited = false;
// Event handler instance handles (damit nicht mehrfach registriert wird)
static esp_event_handler_instance_t g_ip_handler = NULL;
static esp_event_handler_instance_t g_wifi_handler = NULL;
// Discovery task state
static TaskHandle_t g_discover_task = NULL;
// Konfiguration für Discovery-Retry (interne Kopie)
typedef struct {
char service[32];
char proto[8];
int enforce_port;
char fallback_service[32];
char fallback_proto[8];
int fallback_port;
// optional TXT filter (können leer sein)
char txt_key[32];
char txt_value[64];
uint32_t query_timeout_ms;
uint32_t retry_interval_ms;
int max_results;
// optional: Instanzpräfix-Filter
char instance_prefix[16]; // z.B. "myapp-"; leer = kein Filter
bool require_instance_prefix;
} discover_cfg_t;
static discover_cfg_t g_discover_cfg = {0};
static volatile bool g_discover_enabled = false;
// -------------------- Forward Declarations (C needs this) --------------------
static void mdns_start_if_needed(void);
static void mdns_stop_if_running(void);
static bool have_sta_ip(void);
static void mdns_discover_task(void *arg);
static void on_ip_event(void *arg, esp_event_base_t base, int32_t id, void *data);
static void on_wifi_event(void *arg, esp_event_base_t base, int32_t id, void *data);
// These are public (declared in net_mdns.h), but used before their definition in this .c
esp_err_t net_mdns_autodiscover_and_store(const char *service, const char *proto,
int enforce_port,
const char *txt_key, const char *txt_value,
uint32_t timeout_ms);
bool net_mdns_find_service_url(const char *service, const char *proto,
int enforce_port, const char *txt_key, const char *txt_value,
uint32_t timeout_ms, int max_results,
char *url_out, size_t url_out_size);
// -------------------- Internal Helpers --------------------
static void mdns_start_if_needed(void)
{
if (g_mdns_running) return;
esp_err_t err = mdns_init();
if (err != ESP_OK) {
ESP_LOGE(TAG, "mdns_init failed: %s", esp_err_to_name(err));
return;
}
if (g_hostname[0]) mdns_hostname_set(g_hostname);
if (g_instance[0]) mdns_instance_name_set(g_instance);
g_mdns_running = true;
ESP_LOGI(TAG, "mDNS started (host=%s, inst=%s)", g_hostname, g_instance);
}
static void mdns_stop_if_running(void)
{
if (!g_mdns_running) return;
mdns_free();
g_mdns_running = false;
ESP_LOGI(TAG, "mDNS stopped");
}
static bool have_sta_ip(void)
{
esp_netif_t *sta = esp_netif_get_handle_from_ifkey("WIFI_STA_DEF");
if (!sta) return false;
esp_netif_ip_info_t ip;
if (esp_netif_get_ip_info(sta, &ip) != ESP_OK) return false;
return (ip.ip.addr != 0);
}
// Platzhalter: sys_status wird bewusst NICHT in diesem Component gesetzt.
static void set_mdns_ok(bool ok)
{
(void)ok;
}
// -------------------- Discovery Task --------------------
static void mdns_discover_task(void *arg)
{
(void)arg;
const uint32_t retry_ms = g_discover_cfg.retry_interval_ms ? g_discover_cfg.retry_interval_ms : 60000;
const TickType_t retry_delay = pdMS_TO_TICKS(retry_ms);
ESP_LOGI(TAG,
"mDNS discover task started: primary=%s.%s port=%d fallback=%s.%s port=%d retry=%u ms",
g_discover_cfg.service, g_discover_cfg.proto, g_discover_cfg.enforce_port,
g_discover_cfg.fallback_service, g_discover_cfg.fallback_proto, g_discover_cfg.fallback_port,
(unsigned)retry_ms);
for (;;) {
// Wenn Discovery deaktiviert wurde → sauber beenden
if (!g_discover_enabled) {
ESP_LOGI(TAG, "mDNS discover disabled; exiting task.");
g_discover_task = NULL;
vTaskDelete(NULL);
return;
}
// Wenn STA nicht online ist → warten
if (!have_sta_ip()) {
set_mdns_ok(false);
vTaskDelay(retry_delay);
continue;
}
// mDNS sicherstellen
mdns_start_if_needed();
if (!g_mdns_running) {
set_mdns_ok(false);
vTaskDelay(retry_delay);
continue;
}
// 1) Primary service
esp_err_t err = net_mdns_autodiscover_and_store(
g_discover_cfg.service,
g_discover_cfg.proto,
g_discover_cfg.enforce_port,
(g_discover_cfg.txt_key[0] ? g_discover_cfg.txt_key : NULL),
(g_discover_cfg.txt_value[0] ? g_discover_cfg.txt_value : NULL),
g_discover_cfg.query_timeout_ms ? g_discover_cfg.query_timeout_ms : 2000
);
// 2) Fallback service (wenn primary nicht gefunden)
if (err != ESP_OK && g_discover_cfg.fallback_service[0] && g_discover_cfg.fallback_proto[0]) {
err = net_mdns_autodiscover_and_store(
g_discover_cfg.fallback_service,
g_discover_cfg.fallback_proto,
g_discover_cfg.fallback_port,
NULL,
NULL,
g_discover_cfg.query_timeout_ms ? g_discover_cfg.query_timeout_ms : 2000
);
}
if (err == ESP_OK) {
set_mdns_ok(true);
ESP_LOGI(TAG, "mDNS: service found & stored; stopping discover task.");
g_discover_enabled = false; // Einmal finden reicht (wie zuvor in wifi_mgr)
g_discover_task = NULL;
vTaskDelete(NULL);
return;
} else {
set_mdns_ok(false);
ESP_LOGW(TAG, "mDNS: no service found; retry in %u ms", (unsigned)retry_ms);
vTaskDelay(retry_delay);
}
}
}
// -------------------- Event Handlers --------------------
static void on_ip_event(void *arg, esp_event_base_t base, int32_t id, void *data)
{
(void)arg;
(void)data;
if (base == IP_EVENT && id == IP_EVENT_STA_GOT_IP) {
// mDNS starten
mdns_start_if_needed();
// Optional: Discovery-Task starten, wenn enabled
if (g_discover_enabled && g_discover_task == NULL) {
BaseType_t ok = xTaskCreate(mdns_discover_task, "mdns_discover", 3072, NULL, 4, &g_discover_task);
if (ok != pdPASS) {
g_discover_task = NULL;
ESP_LOGE(TAG, "Failed to create mdns_discover task");
}
}
}
}
static void on_wifi_event(void *arg, esp_event_base_t base, int32_t id, void *data)
{
(void)arg;
(void)data;
if (base == WIFI_EVENT && id == WIFI_EVENT_STA_DISCONNECTED) {
// Beim Disconnect mDNS stoppen
mdns_stop_if_running();
// Status: nicht ok (No-op in diesem Component)
set_mdns_ok(false);
// Discovery Task NICHT hart killen (kann in mdns_query hängen).
// Bei nächstem GOT_IP kann sie erneut starten; oder sie schläft und merkt g_discover_enabled später.
}
}
// -------------------- Public API --------------------
esp_err_t net_mdns_autostart_init(const char *hostname, const char *instance_name)
{
// idempotent: mehrfacher Aufruf ist ok, registriert aber nur einmal Handler
if (hostname) {
strncpy(g_hostname, hostname, sizeof(g_hostname) - 1);
g_hostname[sizeof(g_hostname) - 1] = '\0';
}
if (instance_name) {
strncpy(g_instance, instance_name, sizeof(g_instance) - 1);
g_instance[sizeof(g_instance) - 1] = '\0';
}
if (!g_autostart_inited) {
esp_err_t e1 = esp_event_handler_instance_register(IP_EVENT, IP_EVENT_STA_GOT_IP,
on_ip_event, NULL, &g_ip_handler);
esp_err_t e2 = esp_event_handler_instance_register(WIFI_EVENT, WIFI_EVENT_STA_DISCONNECTED,
on_wifi_event, NULL, &g_wifi_handler);
if (e1 != ESP_OK || e2 != ESP_OK) {
ESP_LOGE(TAG, "Failed to register event handlers (ip=%s wifi=%s)",
esp_err_to_name(e1), esp_err_to_name(e2));
return (e1 != ESP_OK) ? e1 : e2;
}
g_autostart_inited = true;
ESP_LOGI(TAG, "mDNS autostart initialized");
} else {
ESP_LOGD(TAG, "mDNS autostart already initialized");
}
// Falls IP schon vorhanden → mDNS direkt starten (+ ggf. discovery task)
if (have_sta_ip()) {
mdns_start_if_needed();
if (g_discover_enabled && g_discover_task == NULL) {
BaseType_t ok = xTaskCreate(mdns_discover_task, "mdns_discover", 3072, NULL, 4, &g_discover_task);
if (ok != pdPASS) {
g_discover_task = NULL;
ESP_LOGE(TAG, "Failed to create mdns_discover task");
}
}
}
return ESP_OK;
}
bool net_mdns_is_running(void)
{
return g_mdns_running;
}
bool net_mdns_wait_started(uint32_t timeout_ms)
{
uint32_t waited = 0;
const uint32_t step = 50;
while (!g_mdns_running && waited < timeout_ms) {
vTaskDelay(pdMS_TO_TICKS(step));
waited += step;
}
return g_mdns_running;
}
esp_err_t net_mdns_add_service(const char *service, const char *proto,
uint16_t port, mdns_txt_item_t *txt, size_t txt_count)
{
if (!g_mdns_running) {
mdns_start_if_needed();
if (!g_mdns_running) return ESP_ERR_INVALID_STATE;
}
esp_err_t err = mdns_service_add(NULL, service, proto, port, txt, txt_count);
if (err != ESP_OK) {
ESP_LOGE(TAG, "mdns_service_add %s.%s:%u failed: %s",
service, proto, (unsigned)port, esp_err_to_name(err));
} else {
ESP_LOGI(TAG, "mDNS service announced: %s.%s:%u", service, proto, (unsigned)port);
}
return err;
}
esp_err_t net_mdns_autodiscover_and_store(const char *service, const char *proto,
int enforce_port,
const char *txt_key, const char *txt_value,
uint32_t timeout_ms)
{
char url[96] = {0};
bool ok = net_mdns_find_service_url(service, proto, enforce_port,
txt_key, txt_value,
timeout_ms, 5,
url, sizeof(url));
if (!ok) {
ESP_LOGW(TAG, "Auto-Discover: kein Treffer für %s.%s", service, proto);
return ESP_ERR_NOT_FOUND;
}
esp_err_t err = storage_save_service_url(url);
if (err == ESP_OK) {
ESP_LOGI(TAG, "Auto-Discover: URL '%s' in NVS gespeichert.", url);
}
return err;
}
bool net_mdns_find_service_url(const char *service, const char *proto,
int enforce_port, const char *txt_key, const char *txt_value,
uint32_t timeout_ms, int max_results,
char *url_out, size_t url_out_size)
{
if (!service || !proto || !url_out || url_out_size < 16) return false;
if (!g_mdns_running) {
ESP_LOGW(TAG, "mDNS not running yet; waiting...");
if (!net_mdns_wait_started(3000)) {
ESP_LOGW(TAG, "mDNS still not running; abort query");
return false;
}
}
mdns_result_t *results = NULL;
esp_err_t err = mdns_query_ptr(service, proto, timeout_ms, max_results, &results);
if (err != ESP_OK) {
ESP_LOGW(TAG, "mdns_query_ptr error: %s", esp_err_to_name(err));
return false;
}
if (!results) {
ESP_LOGI(TAG, "mDNS query OK but no results for %s.%s", service, proto);
return false;
}
bool found = false;
for (mdns_result_t *r = results; r && !found; r = r->next) {
// TXT filter
bool txt_ok = true;
if (txt_key && txt_value) {
txt_ok = false;
for (int i = 0; i < r->txt_count; ++i) {
if (r->txt[i].key && r->txt[i].value &&
strcmp(r->txt[i].key, txt_key) == 0 &&
strcmp(r->txt[i].value, txt_value) == 0) {
txt_ok = true;
break;
}
}
}
if (!txt_ok) continue;
// Optional: Instance prefix filter (nur wenn konfiguriert)
if (g_discover_cfg.require_instance_prefix && g_discover_cfg.instance_prefix[0]) {
size_t pfx_len = strlen(g_discover_cfg.instance_prefix);
if (!r->instance_name || strncmp(r->instance_name, g_discover_cfg.instance_prefix, pfx_len) != 0) {
continue;
}
}
for (mdns_ip_addr_t *a = r->addr; a && !found; a = a->next) {
if (a->addr.type != ESP_IPADDR_TYPE_V4) continue;
uint16_t port = r->port ? r->port : 80;
if (enforce_port > 0 && port != (uint16_t)enforce_port) port = (uint16_t)enforce_port;
snprintf(url_out, url_out_size, "http://" IPSTR ":%u",
IP2STR(&a->addr.u_addr.ip4), (unsigned)port);
ESP_LOGI(TAG, "mDNS URL: %s", url_out);
found = true;
}
}
mdns_query_results_free(results);
return found;
}
void net_mdns_stop(void)
{
// Discovery stoppen (soft)
g_discover_enabled = false;
// mDNS stoppen
mdns_stop_if_running();
set_mdns_ok(false);
}
// -------------------- New Public: Discovery Retry --------------------
esp_err_t net_mdns_autodiscover_start(const net_mdns_discover_cfg_t *cfg)
{
if (!cfg || !cfg->service || !cfg->proto) return ESP_ERR_INVALID_ARG;
// config übernehmen (interne Kopie)
memset(&g_discover_cfg, 0, sizeof(g_discover_cfg));
strlcpy(g_discover_cfg.service, cfg->service, sizeof(g_discover_cfg.service));
strlcpy(g_discover_cfg.proto, cfg->proto, sizeof(g_discover_cfg.proto));
g_discover_cfg.enforce_port = cfg->enforce_port;
if (cfg->fallback_service && cfg->fallback_proto) {
strlcpy(g_discover_cfg.fallback_service, cfg->fallback_service, sizeof(g_discover_cfg.fallback_service));
strlcpy(g_discover_cfg.fallback_proto, cfg->fallback_proto, sizeof(g_discover_cfg.fallback_proto));
g_discover_cfg.fallback_port = cfg->fallback_port;
}
if (cfg->txt_key && cfg->txt_value) {
strlcpy(g_discover_cfg.txt_key, cfg->txt_key, sizeof(g_discover_cfg.txt_key));
strlcpy(g_discover_cfg.txt_value, cfg->txt_value, sizeof(g_discover_cfg.txt_value));
}
g_discover_cfg.query_timeout_ms = (cfg->query_timeout_ms ? cfg->query_timeout_ms : 2000);
g_discover_cfg.retry_interval_ms = (cfg->retry_interval_ms ? cfg->retry_interval_ms : 60000);
g_discover_cfg.max_results = (cfg->max_results ? cfg->max_results : 5);
if (cfg->instance_prefix && cfg->instance_prefix[0]) {
strlcpy(g_discover_cfg.instance_prefix, cfg->instance_prefix, sizeof(g_discover_cfg.instance_prefix));
g_discover_cfg.require_instance_prefix = cfg->require_instance_prefix;
} else {
g_discover_cfg.require_instance_prefix = false;
}
// enable
g_discover_enabled = true;
set_mdns_ok(false);
// Wenn wir schon IP haben: Task sofort starten, sonst wird er bei GOT_IP gestartet
if (have_sta_ip()) {
mdns_start_if_needed();
if (g_discover_task == NULL) {
BaseType_t ok = xTaskCreate(mdns_discover_task, "mdns_discover", 3072, NULL, 4, &g_discover_task);
if (ok != pdPASS) {
g_discover_task = NULL;
ESP_LOGE(TAG, "Failed to create mdns_discover task");
return ESP_FAIL;
}
}
}
return ESP_OK;
}
void net_mdns_autodiscover_stop(void)
{
g_discover_enabled = false;
// Task beendet sich selbst (kein hartes Kill)
}
+22
View File
@@ -0,0 +1,22 @@
idf_component_register(
SRCS
"sen5x_i2c.c"
"sen66_i2c.c"
"sensirion_common.c"
"sensirion_i2c.c"
"sensirion_i2c_hal.c"
"sensor_soft_i2c.c"
"i2cdev.c"
"air_sensor_app.c"
INCLUDE_DIRS
"."
REQUIRES
driver
freertos
log
net_influx
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`.
+387
View File
@@ -0,0 +1,387 @@
// File: src/air_sensor_app.c
#include "air_sensor_app.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h" // bleibt drin (Header-Kompat / ggf. künftig wieder genutzt)
#include "esp_log.h"
#include "sensirion_i2c_hal.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"
#endif
#include "net_influx.h"
#include "storage.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h> // NAN, isfinite, lround
#include "vars.h"
#include "ui_model.h"
#include "esp_timer.h"
static const char* TAG = "air_sensor_app";
/* ====================== Konfiguration ====================== */
#define AIR_SENSOR_PROD_STACK 4096
#define AIR_SENSOR_PROD_PRIO 6 // Producer leicht höher priorisiert
// Influx worker runtime (läuft in net_influx.c)
#define INFLUX_QUEUE_LEN 32
#define INFLUX_TASK_STACK 8192
#define INFLUX_TASK_PRIO 5
#define INFLUX_INIT_RETRY_MS 1000
#define INFLUX_FAILS_REDISCOVER 5
#define INFLUX_BACKOFF_START_MS 2000
#define INFLUX_BACKOFF_MAX_MS 300000
#define INFLUX_HTTP_TIMEOUT_MS 3000
/* ====================== Typen & State ====================== */
typedef struct {
uint16_t pm1p0, pm2p5, pm4p0, pm10p0; // Rohwerte (x10)
float temp_c, rh_pct; // skaliert
int16_t voc_idx, nox_idx; // Rohwerte (x10)
} air_sensor_sample_t;
static bool g_inited = false;
static bool g_run = false;
static TaskHandle_t g_task_prod = NULL;
// App-Context
static char* g_device_tag = NULL; // z.B. "device=xyz"
/* ====================== Helfer ====================== */
#define CHECK_ESP_OR_RET(x) do { \
esp_err_t __e = (x); \
if (__e != ESP_OK) { \
ESP_LOGE(TAG, "%s failed: %s", #x, esp_err_to_name(__e)); \
return __e; \
} \
} while (0)
#define CHECK_SEN_OR_RET(x) do { \
int16_t __rc = (x); \
if (__rc != 0) { \
ESP_LOGE(TAG, "%s failed: %d", #x, (int)__rc); \
return ESP_FAIL; \
} \
} while (0)
/* One selected command set; shared HAL and presentation/Influx pipeline. */
static int16_t sensor_ready(bool *ready) {
#if NANOPSX_SENSOR == NANOPSX_SENSOR_SEN66
uint8_t padding;
return sen66_get_data_ready(&padding, ready);
#else
return sen5x_read_data_ready(ready);
#endif
}
static int16_t sensor_read(uint16_t *pm1, uint16_t *pm2, uint16_t *pm4,
uint16_t *pm10, int16_t *rh, int16_t *temp,
int16_t *voc, int16_t *nox, uint16_t *co2) {
#if NANOPSX_SENSOR == NANOPSX_SENSOR_SEN66
return sen66_read_measured_values_as_integers(pm1, pm2, pm4, pm10,
rh, temp, voc, nox, co2);
#else
*co2 = UINT16_MAX; // SEN54 has no CO2 channel: never submit a fake zero.
return sen5x_read_measured_values(pm1, pm2, pm4, pm10, rh, temp, voc, nox);
#endif
}
static int16_t sensor_start(void) {
#if NANOPSX_SENSOR == NANOPSX_SENSOR_SEN66
sen66_init(NANOPSX_SENSOR_ADDRESS);
// 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
}
static int16_t sensor_stop(void) {
#if NANOPSX_SENSOR == NANOPSX_SENSOR_SEN66
return sen66_stop_measurement();
#else
return sen5x_stop_measurement();
#endif
}
/* ====================== App-Context: Device Tag ====================== */
static esp_err_t make_device_tag_once(void) {
if (g_device_tag) return ESP_OK;
char* dev = NULL;
if (storage_load_device_name(&dev) && dev && dev[0]) {
size_t need = strlen("device=") + strlen(dev) + 1;
g_device_tag = (char*)malloc(need);
if (!g_device_tag) {
if (dev) free(dev);
return ESP_ERR_NO_MEM;
}
snprintf(g_device_tag, need, "device=%s", dev);
free(dev);
return ESP_OK;
}
g_device_tag = strdup("device=unknown");
return g_device_tag ? ESP_OK : ESP_ERR_NO_MEM;
}
/* ====================== Producer-Task ====================== */
static void air_sensor_task_producer(void* arg) {
(void)arg;
const TickType_t period = pdMS_TO_TICKS(1000); // exakt 1 Hz
TickType_t last_wake = xTaskGetTickCount();
ESP_LOGI(TAG, "Producer started (1 Hz).");
for (; g_run; ) {
bool ready = false;
int16_t rc = sensor_ready(&ready);
if (rc != 0) {
ESP_LOGW(TAG, "sensor_ready error: %d", (int)rc);
} else if (ready) {
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;
rc = sensor_read(&pm1p0, &pm2p5, &pm4p0, &pm10p0,
&rh_raw, &t_raw, &voc_idx, &nox_idx, &co2_raw);
if (rc != 0) {
ESP_LOGW(TAG, "sensor_read error: %d", (int)rc);
} else {
// Roh → Struct (wie bisher)
air_sensor_sample_t s = {
.pm1p0 = pm1p0,
.pm2p5 = pm2p5,
.pm4p0 = pm4p0,
.pm10p0 = pm10p0,
.temp_c = (t_raw == INT16_MAX) ? NAN : ((float)t_raw) / 200.0f,
.rh_pct = (rh_raw == INT16_MAX) ? NAN : ((float)rh_raw) / 100.0f,
.voc_idx = voc_idx,
.nox_idx = nox_idx
};
/* === GUI-Variablen jede Sekunde updaten (skaliert) === */
char buf[24];
float pm1f = (s.pm1p0 == 0xFFFF) ? NAN : s.pm1p0 / 10.0f;
float pm2f = (s.pm2p5 == 0xFFFF) ? NAN : s.pm2p5 / 10.0f;
float pm4f = (s.pm4p0 == 0xFFFF) ? NAN : s.pm4p0 / 10.0f;
float pm10f = (s.pm10p0 == 0xFFFF) ? NAN : s.pm10p0 / 10.0f;
float vocf = (s.voc_idx == 0x7FFF) ? NAN : s.voc_idx / 10.0f;
// float noxf = (s.nox_idx == 0x7FFF) ? NAN : s.nox_idx / 10.0f; // bei Bedarf anzeigen
// Temperatur
if (isfinite(s.temp_c)) snprintf(buf, sizeof(buf), "%.1f", (double)s.temp_c);
else snprintf(buf, sizeof(buf), "--");
set_var_temp(buf);
// Feuchte
if (isfinite(s.rh_pct)) snprintf(buf, sizeof(buf), "%.1f", (double)s.rh_pct);
else snprintf(buf, sizeof(buf), "--");
set_var_humidity(buf);
// VOC-Index (gerundet), nicht verfügbare Werte als "--"
if (!isfinite(vocf)) snprintf(buf, sizeof(buf), "--");
else snprintf(buf, sizeof(buf), "%d", (int)lround(vocf));
set_var_voc_ind(buf);
// PM (µg/m³) mit einer Nachkommastelle
if (!isfinite(pm10f)) snprintf(buf, sizeof(buf), "--"); else snprintf(buf, sizeof(buf), "%.1f", (double)pm10f);
set_var_pm10p0(buf);
if (!isfinite(pm4f)) snprintf(buf, sizeof(buf), "--"); else snprintf(buf, sizeof(buf), "%.1f", (double)pm4f);
set_var_pm4p0(buf);
if (!isfinite(pm2f)) snprintf(buf, sizeof(buf), "--"); else snprintf(buf, sizeof(buf), "%.1f", (double)pm2f);
set_var_pm2p5(buf);
if (!isfinite(pm1f)) snprintf(buf, sizeof(buf), "--"); else snprintf(buf, sizeof(buf), "%.1f", (double)pm1f);
set_var_pm1p0(buf);
/* === Influx submit (generisch, variabel viele Felder) === */
const double pm1 = (s.pm1p0 == 0xFFFF) ? NAN : ((double)s.pm1p0 / 10.0);
const double pm2_5 = (s.pm2p5 == 0xFFFF) ? NAN : ((double)s.pm2p5 / 10.0);
const double pm4 = (s.pm4p0 == 0xFFFF) ? NAN : ((double)s.pm4p0 / 10.0);
const double pm10 = (s.pm10p0 == 0xFFFF) ? NAN : ((double)s.pm10p0 / 10.0);
const double voc = (s.voc_idx == 0x7FFF) ? NAN : ((double)s.voc_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 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[] = {
{ .key="pm1", .type=NET_INFLUX_F_FLOAT, .precision=1, .v.f=pm1 },
{ .key="pm2_5", .type=NET_INFLUX_F_FLOAT, .precision=1, .v.f=pm2_5 },
{ .key="pm4", .type=NET_INFLUX_F_FLOAT, .precision=1, .v.f=pm4 },
{ .key="pm10", .type=NET_INFLUX_F_FLOAT, .precision=1, .v.f=pm10 },
{ .key="temp", .type=NET_INFLUX_F_FLOAT, .precision=3, .v.f=temp },
{ .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="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 = {
.measurement = "air",
.tags = g_device_tag ? g_device_tag : "device=unknown",
.ts_ms = 0, // Messzeitpunkt; Worker richtet UTC an Server-HTTP-Date aus
.fields = f,
.num_fields = sizeof(f) / sizeof(f[0]),
};
(void)net_influx_submit_point(&p);
}
}
vTaskDelayUntil(&last_wake, period); // präzise 1 Hz
}
ESP_LOGI(TAG, "Producer stopping.");
g_task_prod = NULL;
vTaskDelete(NULL);
}
/* ====================== Öffentliche API ====================== */
esp_err_t air_sensor_app_init(const air_sensor_i2c_cfg_t* cfg) {
if (g_inited) {
ESP_LOGW(TAG, "already initialized");
return ESP_OK;
}
if (!cfg) return ESP_ERR_INVALID_ARG;
ESP_LOGI(TAG, "Initializing selected air sensor...");
// 1) I2C-Subsystem
// 2) HAL-Konfiguration
struct esp32_i2c_config hal_cfg = {
.addr = cfg->addr,
.port = cfg->port,
.sda = cfg->sda,
.scl = cfg->scl,
.sda_pullup = cfg->sda_pullup,
.scl_pullup = cfg->scl_pullup,
.freq = cfg->freq
};
CHECK_ESP_OR_RET(sensirion_i2c_config_esp32(&hal_cfg));
// 3) HAL init
sensirion_i2c_hal_init();
CHECK_ESP_OR_RET(sensirion_i2c_esp32_ok());
// 4) Messung starten
CHECK_SEN_OR_RET(sensor_start());
ESP_LOGI(TAG, "Measurement started.");
// 5) Device Tag (App-Kontext)
CHECK_ESP_OR_RET(make_device_tag_once());
// 6) Influx Worker starten (Influx-spezifische Init/Retry/Backoff läuft intern)
net_influx_runtime_cfg_t rt = {
.queue_len = INFLUX_QUEUE_LEN,
.task_stack = INFLUX_TASK_STACK,
.task_prio = INFLUX_TASK_PRIO,
.init_retry_ms = INFLUX_INIT_RETRY_MS,
.backoff_start_ms = INFLUX_BACKOFF_START_MS,
.backoff_max_ms = INFLUX_BACKOFF_MAX_MS,
.fails_before_reinit = INFLUX_FAILS_REDISCOVER,
.ca_cert_pem_opt = NULL,
.http_timeout_ms = INFLUX_HTTP_TIMEOUT_MS,
};
CHECK_ESP_OR_RET(net_influx_start(&rt));
g_run = true;
g_inited = true;
return ESP_OK;
}
void air_sensor_app_deinit(void) {
if (!g_inited) return;
ESP_LOGI(TAG, "Deinitializing SEN5x app...");
g_run = false;
for (int i = 0; i < 50 && g_task_prod; i++) {
vTaskDelay(pdMS_TO_TICKS(10));
}
if (g_task_prod) {
ESP_LOGW(TAG, "Producer did not stop in time; skip sensor_stop/HAL free");
// Hier NICHT sensor_stop() / HAL free, weil Task evtl. noch I2C nutzt
return;
}
net_influx_stop();
if (g_device_tag) {
free(g_device_tag);
g_device_tag = NULL;
}
sensor_stop();
sensirion_i2c_hal_free();
// i2cdev_done(); // NICHT hier, da Bus global genutzt wird
g_inited = false;
ESP_LOGI(TAG, "Air sensor app deinitialized.");
}
/**
* Kompatibilität zur bisherigen main.c:
* Diese Task fungiert nun als "Launcher": startet Producer und beendet sich dann.
* In main.c bleibt der Aufruf von xTaskCreate(air_sensor_app_task, ...) unverändert.
*/
void air_sensor_app_task(void* arg) {
(void)arg;
if (!g_inited) {
ESP_LOGE(TAG, "air_sensor_app_task called before air_sensor_app_init()");
vTaskDelete(NULL);
return;
}
// Producer starten
if (xTaskCreate(air_sensor_task_producer, "air_sensor_prod",
AIR_SENSOR_PROD_STACK, NULL, AIR_SENSOR_PROD_PRIO, &g_task_prod) != pdPASS) {
ESP_LOGE(TAG, "Failed to create producer task");
vTaskDelete(NULL);
return;
}
ESP_LOGI(TAG, "Launcher done (producer started).");
vTaskDelete(NULL); // Launcher beendet sich selbst
}
@@ -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);
+798
View File
@@ -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;
}
+899
View File
@@ -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 "slope" and "offset" are the values set with this command, smoothed
* with the specified time constant. All temperatures
* ("T_Ambient_Compensated", "T_Ambient" and "offset") are represented in
* °C. There are 5 temperature offset slots available that all contribute
* additively to "T_Ambient_Compensated". The default values for the
* temperature offset parameters are all zero, meaning that
* "T_Ambient_Compensated" is equal to "T_Ambient" by default. The
* parameters can be changed in any state of the device, i.e. both in idle mode
* and in measure mode.
*
* @param[in] offset Constant temperature offset scaled with factor 200 (T [°C]
* = value / 200).
* @param[in] slope Normalized temperature offset slope scaled with factor 10000
* (applied factor = value / 10000).
* @param[in] time_constant The time constant determines how fast the new slope
* and offset will be applied. After the specified value in seconds, 63% of the
* new slope and offset are applied. A time constant of zero means the new
* values will be applied immediately (within the next measure interval of 1
* second).
* @param[in] slot The temperature offset slot to be modified. Valid values are
* 0 .. 4. If the value is outside this range, the parameters will not be
* applied.
*
* @note This configuration is volatile, i.e. the parameters will be reverted to
* their default value of zero after a device reset.
*
* @return error_code 0 on success, an error code otherwise.
*
* Example:
* --------
*
* @code{.c}
*
* int16_t local_error = 0;
*
* local_error = sen66_set_temperature_offset_parameters(1, 10, 1, 0);
* if (local_error != NO_ERROR) {
* return local_error;
* }
*
* @endcode
*
*/
int16_t sen66_set_temperature_offset_parameters(int16_t offset, int16_t slope,
uint16_t time_constant,
uint16_t slot);
/**
* @brief sen66_set_temperature_acceleration_parameters
*
* This command allows to set custom temperature acceleration parameters of the
* RH/T engine. It overwrites the default temperature acceleration parameters of
* the RH/T engine with custom values. This configuration is volatile, i.e. the
* parameters will be reverted to their default values after a device reset.
*
* @param[in] k Filter constant K scaled with factor 10 (K = value / 10).
* @param[in] p Filter constant P scaled with factor 10 (P = value / 10).
* @param[in] t1 Time constant T1 scaled with factor 10 (T1 [s] = value / 10).
* @param[in] t2 Time constant T2 scaled with factor 10 (T2 [s] = value / 10).
*
* @note The command is only available in idle mode.
*
* @return error_code 0 on success, an error code otherwise.
*
* Example:
* --------
*
* @code{.c}
*
* int16_t local_error = 0;
*
* local_error = sen66_set_temperature_acceleration_parameters(1, 1, 1, 1);
* if (local_error != NO_ERROR) {
* return local_error;
* }
*
* @endcode
*
*/
int16_t sen66_set_temperature_acceleration_parameters(uint16_t k, uint16_t p,
uint16_t t1, uint16_t t2);
/**
* @brief sen66_get_product_type
*
* Gets the product type from the device.
*
* The following product types are expected: - SEN62: '00085800' - SEN63C:
* '00085700' - SEN65: '00085200' - SEN66: '00085300' - SEN68: '00085400' -
* SEN69C: '00085900'
*
* @param[out] product_type Null-terminated ASCII string containing the product
* type. Up to 32 characters can be read from the device.
*
* @return error_code 0 on success, an error code otherwise.
*/
int16_t sen66_get_product_type(int8_t* product_type,
uint16_t product_type_size);
/**
* @brief sen66_get_product_name
*
* Gets the product name from the device.
*
* @param[out] product_name Null-terminated ASCII string containing the product
* name. Up to 32 characters can be read from the device.
*
* @return error_code 0 on success, an error code otherwise.
*/
int16_t sen66_get_product_name(int8_t* product_name,
uint16_t product_name_size);
/**
* @brief sen66_get_serial_number
*
* Gets the serial number from the device.
*
* @param[out] serial_number Null-terminated ASCII string containing the serial
* number. Up to 32 characters can be read from the device.
*
* @return error_code 0 on success, an error code otherwise.
*/
int16_t sen66_get_serial_number(int8_t* serial_number,
uint16_t serial_number_size);
/**
* @brief sen66_read_device_status
*
* Reads the current device status. Use this command to get detailed information
* about the device status. The device status is encoded in flags. Each device
* status flag represents a single bit in a 32-bit integer value. If more than
* one error is present, the device status register value is the sum of the
* corresponding flag values. For details about the available flags, refer to
* the device status flags documentation in the data sheet.
*
* @param[out] device_status Device status (32 flags as an integer value). For
* details, please refer to the device status flags documentation in the
* datasheet.
*
* @note The status flags of type "Error" are sticky, i.e. they are not cleared
* automatically even if the error condition no longer exists. So they can only
* be cleared manually with the command "Read And Clear Device Status" or with a
* device reset. All other flags are not sticky, i.e. they are cleared
* automatically if the trigger condition disappears.
*
* @return error_code 0 on success, an error code otherwise.
*/
int16_t sen66_read_device_status(sen66_device_status* device_status);
/**
* @brief sen66_read_and_clear_device_status
*
* Reads the current device status (like command 0xD206 "Read Device Status")
* and afterwards clears all flags.
*
* @param[out] device_status Device status (32 flags as an integer value)
* **before** clearing it. For details, please refer to the device status flags
* documentation.
*
* @return error_code 0 on success, an error code otherwise.
*/
int16_t sen66_read_and_clear_device_status(sen66_device_status* device_status);
/**
* @brief sen66_get_version
*
* Gets the version information for the firmware.
*
* @param[out] firmware_major Firmware major version number.
* @param[out] firmware_minor Firmware minor version number.
*
* @return error_code 0 on success, an error code otherwise.
*/
int16_t sen66_get_version(uint8_t* firmware_major, uint8_t* firmware_minor);
/**
* @brief sen66_device_reset
*
* Executes a reset on the device. This has the same effect as a power cycle.
*
* @return error_code 0 on success, an error code otherwise.
*/
int16_t sen66_device_reset(void);
/**
* @brief sen66_start_fan_cleaning
*
* This command triggers fan cleaning. The fan is set to the maximum speed for
* 10 seconds and then automatically stopped. Wait at least 10s after this
* command before starting a measurement.
*
* @note This command is only available in idle mode.
*
* @return error_code 0 on success, an error code otherwise.
*/
int16_t sen66_start_fan_cleaning(void);
/**
* @brief Activate SHT Heater
*
* Activate the heater feature of the SHT4x sensor. This command allows to use
* the inbuilt heater in SHT sensor to decontaminate and reverse creep at high
* humidity. This command activates the SHT sensor heater with 200mW for 1s. The
* SHT heater measurement done just before deactivation can be read using the
* command "Get SHT Heater Measurements" after the duration of the heating
* feature as specified in the SHT4x datasheet. Wait at least 20s after this
* command before starting a measurement to get coherent temperature values
* (heating consequence to disappear).
*
* @note This command is only available in idle mode.
*
* @return error_code 0 on success, an error code otherwise.
*/
int16_t sen66_activate_sht_heater(void);
/**
* @brief Get SHT Heater Measurements
*
* Get the measurement values when the SHT sensor heating is finished.
*
* @param[out] sht_relative_humidity If the sht heating is completed, this value
* indicates the scaled relative humidity of the SHT4x sensor. Value is scaled
* with factor 100: RH [%] = value / 100 *Note: If this value is not available,
* 0x7FFF is returned.*
* @param[out] sht_temperature If the sht heating is completed, this value
* indicates the scaled temperature of the SHT4x sensor. Value is scaled with
* factor 200: T [°C] = value / 200 *Note: If this value is not available,
* 0x7FFF is returned.*
*
* @note This command must be used after the "Activate SHT Heater" command.
* The get sht heater measurements command can be queried every 0.05s to get the
* measurements. This command is only available in idle mode.
*
* @return error_code 0 on success, an error code otherwise.
*/
int16_t sen66_get_sht_heater_measurements(int16_t* sht_relative_humidity,
int16_t* sht_temperature);
/**
* @brief Read measured values as integers.
*
* Returns the measured values. The command "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, 0x7FFF for int16).
*
* @param[out] mass_concentration_pm1p0 Value is scaled with factor 10: PM1.0
* [µg/m³] = value / 10 *Note: If this value is unknown, 0xFFFF is returned.*
* @param[out] mass_concentration_pm2p5 Value is scaled with factor 10: PM2.5
* [µg/m³] = value / 10 *Note: If this value is unknown, 0xFFFF is returned.*
* @param[out] mass_concentration_pm4p0 Value is scaled with factor 10: PM4.0
* [µg/m³] = value / 10 *Note: If this value is unknown, 0xFFFF is returned.*
* @param[out] mass_concentration_pm10p0 Value is scaled with factor 10: PM10.0
* [µg/m³] = value / 10 *Note: If this value is unknown, 0xFFFF is returned.*
* @param[out] ambient_humidity Value is scaled with factor 100: RH [%] = value
* / 100 *Note: If this value is unknown, 0x7FFF is returned.*
* @param[out] ambient_temperature Value is scaled with factor 200: T [°C] =
* value / 200 *Note: If this value is unknown, 0x7FFF is returned.*
* @param[out] voc_index Value is scaled with factor 10: VOC Index = value / 10
* *Note: If this value is unknown, 0x7FFF is returned.*
* @param[out] nox_index Value is scaled with factor 10: NOx Index = value / 10
* *Note: If this value is unknown, 0x7FFF is returned. During the first 10..11
* seconds after power-on or device reset, this value will be 0x7FFF as well.*
* @param[out] co2 CO₂ concentration [ppm] *Note: If this value is unknown,
* 0xFFFF is returned. During the first 5..6 seconds after power-on or device
* reset, this value will be 0xFFFF as well.*
*
* @return error_code 0 on success, an error code otherwise.
*/
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);
/**
* @brief sen66_read_measured_raw_values
*
* Returns the measured raw values. The command "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, 0x7FFF for int16).
*
* @param[out] raw_humidity Value is scaled with factor 100: RH [%] = value /
* 100 *Note: If this value is unknown, 0x7FFF is returned.*
* @param[out] raw_temperature Value is scaled with factor 200: T [°C] = value /
* 200 *Note: If this value is unknown, 0x7FFF is returned.*
* @param[out] raw_voc Raw measured VOC ticks without scale factor. *Note: If
* this value is unknown, 0xFFFF is returned.*
* @param[out] raw_nox Raw measured NOx ticks without scale factor. *Note: If
* this value is unknown, 0xFFFF is returned. During the first 10..11 seconds
* after power-on or device reset, this value will be 0xFFFF as well.*
* @param[out] raw_co2 Not interpolated CO₂ concentration [ppm] updated every
* five seconds. *Note: If this value is unknown, 0xFFFF is returned. During the
* first 5..6 seconds after power-on or device reset, this value will be 0xFFFF
* as well.*
*
* @return error_code 0 on success, an error code otherwise.
*/
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);
#ifdef __cplusplus
}
#endif
#endif // SEN66_I2C_H
@@ -28,7 +28,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
// File: src/sensirion_common.c
#include "sensirion_common.h" #include "sensirion_common.h"
#include "sensirion_config.h" #include "sensirion_config.h"
@@ -60,27 +60,27 @@ float sensirion_common_bytes_to_float(const uint8_t* bytes) {
} }
void sensirion_common_uint32_t_to_bytes(const uint32_t value, uint8_t* bytes) { void sensirion_common_uint32_t_to_bytes(const uint32_t value, uint8_t* bytes) {
bytes[0] = value >> 24; bytes[0] = (uint8_t)(value >> 24);
bytes[1] = value >> 16; bytes[1] = (uint8_t)(value >> 16);
bytes[2] = value >> 8; bytes[2] = (uint8_t)(value >> 8);
bytes[3] = value; bytes[3] = (uint8_t)(value);
} }
void sensirion_common_uint16_t_to_bytes(const uint16_t value, uint8_t* bytes) { void sensirion_common_uint16_t_to_bytes(const uint16_t value, uint8_t* bytes) {
bytes[0] = value >> 8; bytes[0] = (uint8_t)(value >> 8);
bytes[1] = value; bytes[1] = (uint8_t)value;
} }
void sensirion_common_int32_t_to_bytes(const int32_t value, uint8_t* bytes) { void sensirion_common_int32_t_to_bytes(const int32_t value, uint8_t* bytes) {
bytes[0] = value >> 24; bytes[0] = (uint8_t)(value >> 24);
bytes[1] = value >> 16; bytes[1] = (uint8_t)(value >> 16);
bytes[2] = value >> 8; bytes[2] = (uint8_t)(value >> 8);
bytes[3] = value; bytes[3] = (uint8_t)value;
} }
void sensirion_common_int16_t_to_bytes(const int16_t value, uint8_t* bytes) { void sensirion_common_int16_t_to_bytes(const int16_t value, uint8_t* bytes) {
bytes[0] = value >> 8; bytes[0] = (uint8_t)(value >> 8);
bytes[1] = value; bytes[1] = (uint8_t)value;
} }
void sensirion_common_float_to_bytes(const float value, uint8_t* bytes) { void sensirion_common_float_to_bytes(const float value, uint8_t* bytes) {
@@ -99,3 +99,22 @@ void sensirion_common_copy_bytes(const uint8_t* source, uint8_t* destination,
destination[i] = source[i]; destination[i] = source[i];
} }
} }
void sensirion_common_to_integer(const uint8_t* source, uint8_t* destination,
INT_TYPE int_type, uint8_t data_length) {
if (data_length > int_type) {
data_length = 0; // we do not read at all if data_length is bigger than
// the provided integer!
}
// pad missing bytes
uint8_t offset = int_type - data_length;
for (uint8_t i = 0; i < offset; i++) {
destination[int_type - i - 1] = 0;
}
for (uint8_t i = 1; i <= data_length; i++) {
destination[int_type - offset - i] = source[i - 1];
}
}
@@ -50,6 +50,11 @@ extern "C" {
#define SENSIRION_NUM_WORDS(x) (sizeof(x) / SENSIRION_WORD_SIZE) #define SENSIRION_NUM_WORDS(x) (sizeof(x) / SENSIRION_WORD_SIZE)
#define SENSIRION_MAX_BUFFER_WORDS 32 #define SENSIRION_MAX_BUFFER_WORDS 32
/**
* Enum to describe the type of an integer
*/
typedef enum { BYTE = 1, SHORT = 2, INTEGER = 4, LONG_INTEGER = 8 } INT_TYPE;
/** /**
* sensirion_common_bytes_to_int16_t() - Convert an array of bytes to an int16_t * sensirion_common_bytes_to_int16_t() - Convert an array of bytes to an int16_t
* *
@@ -174,6 +179,17 @@ void sensirion_common_float_to_bytes(const float value, uint8_t* bytes);
void sensirion_common_copy_bytes(const uint8_t* source, uint8_t* destination, void sensirion_common_copy_bytes(const uint8_t* source, uint8_t* destination,
uint16_t data_length); uint16_t data_length);
/**
* sensirion_common_to_integer() - Copy bytes from byte array to integer.
*
* @param source Array of bytes to be copied.
* @param int_value Pointer to integer of bytes to be copied to.
* @param int_type Type (size) of the integer to be copied.
* @param data_length Number of bytes to copy.
*/
void sensirion_common_to_integer(const uint8_t* source, uint8_t* destination,
INT_TYPE int_type, uint8_t data_length);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
@@ -28,7 +28,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
// File: src/sensirion_i2c.c
#include "sensirion_i2c.h" #include "sensirion_i2c.h"
#include "sensirion_common.h" #include "sensirion_common.h"
#include "sensirion_config.h" #include "sensirion_config.h"
@@ -177,6 +177,19 @@ uint16_t sensirion_i2c_add_command_to_buffer(uint8_t* buffer, uint16_t offset,
return offset; return offset;
} }
uint16_t sensirion_i2c_add_command16_to_buffer(uint8_t* buffer, uint16_t offset,
uint16_t command) {
buffer[offset++] = (uint8_t)((command & 0xFF00) >> 8);
buffer[offset++] = (uint8_t)((command & 0x00FF) >> 0);
return offset;
}
uint16_t sensirion_i2c_add_command8_to_buffer(uint8_t* buffer, uint16_t offset,
uint8_t command) {
buffer[offset++] = command;
return offset;
}
uint16_t sensirion_i2c_add_uint32_t_to_buffer(uint8_t* buffer, uint16_t offset, uint16_t sensirion_i2c_add_uint32_t_to_buffer(uint8_t* buffer, uint16_t offset,
uint32_t data) { uint32_t data) {
buffer[offset++] = (uint8_t)((data & 0xFF000000) >> 24); buffer[offset++] = (uint8_t)((data & 0xFF000000) >> 24);
@@ -181,6 +181,39 @@ int16_t sensirion_i2c_read_cmd(uint8_t address, uint16_t cmd,
uint16_t sensirion_i2c_add_command_to_buffer(uint8_t* buffer, uint16_t offset, uint16_t sensirion_i2c_add_command_to_buffer(uint8_t* buffer, uint16_t offset,
uint16_t command); uint16_t command);
/**
* sensirion_i2c_add_command16_to_buffer() - Add a command to the buffer at
* the specified offset. This function is equivalent to the
* function sensirion_i2c_add_command_to_buffer().
*
* @param buffer Pointer to buffer in which the write frame will be prepared.
* Caller needs to make sure that there is enough space after
* offset left to write the data into the buffer.
* @param offset Offset of the next free byte in the buffer.
* @param command Command to be written into the buffer.
*
* @return Offset of next free byte in the buffer after writing the data.
*/
uint16_t sensirion_i2c_add_command16_to_buffer(uint8_t* buffer, uint16_t offset,
uint16_t command);
/**
* sensirion_i2c_add_command8_to_buffer() - Add a command to the buffer at
* offset. Adds one bytes command to the buffer.
* This is used for sensor that only take one command byte such as
* SHT.
*
* @param buffer Pointer to buffer in which the write frame will be prepared.
* Caller needs to make sure that there is enough space after
* offset left to write the data into the buffer.
* @param offset Offset of the next free byte in the buffer.
* @param command Command to be written into the buffer.
*
* @return Offset of next free byte in the buffer after writing the data.
*/
uint16_t sensirion_i2c_add_command8_to_buffer(uint8_t* buffer, uint16_t offset,
uint8_t command);
/** /**
* sensirion_i2c_add_uint32_t_to_buffer() - Add a uint32_t to the buffer at * sensirion_i2c_add_uint32_t_to_buffer() - Add a uint32_t to the buffer at
* offset. Adds 6 bytes to the buffer. * offset. Adds 6 bytes to the buffer.
@@ -0,0 +1,286 @@
// File: sensirion_i2c_hal.c
#include "sensirion_i2c_hal.h"
#include "sensirion_common.h"
#include "sensirion_config.h"
#include <esp_log.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <string.h>
#include <inttypes.h>
#include "sensirion_i2c_esp32_config.h"
#include "hardware_config.h"
#include "sensor_soft_i2c.h"
#include "esp_rom_sys.h"
static const char* TAG = "sensirion_i2c_hal";
#define SLEEP_MS(ms) vTaskDelay(((ms) + portTICK_PERIOD_MS - 1) / portTICK_PERIOD_MS)
/*
* Sensirion HAL uses int8_t return codes:
* - 0 (NO_ERROR) on success
* - !=0 on failure
*
* sensirion_common.h defines only NO_ERROR and NOT_IMPLEMENTED_ERROR,
* so we provide one stable generic error that fits in int8_t.
*/
#define SENSIRION_I2C_HAL_ERROR ((int8_t)-1)
// Global (single) i2cdev device context
static i2c_dev_t dev = {0};
static struct esp32_i2c_config i2c_cfg = {0};
static esp_err_t i2c_ok = ESP_OK;
#if NANOPSX_SENSOR_SOFT_I2C
static SemaphoreHandle_t soft_mutex;
static void soft_sda(void *ctx, int release) {
struct esp32_i2c_config *p = ctx;
gpio_set_level(p->sda, release);
}
static void soft_scl(void *ctx, int release) {
struct esp32_i2c_config *p = ctx;
gpio_set_level(p->scl, release);
}
static int soft_read_sda(void *ctx) {
return gpio_get_level(((struct esp32_i2c_config *)ctx)->sda);
}
static int soft_read_scl(void *ctx) {
return gpio_get_level(((struct esp32_i2c_config *)ctx)->scl);
}
static void soft_delay(void *ctx, unsigned us) {
(void)ctx;
esp_rom_delay_us(us);
}
static int8_t soft_transfer(uint8_t address, uint8_t *data, uint16_t count, bool read) {
if (!soft_mutex || !xSemaphoreTake(soft_mutex, pdMS_TO_TICKS(1000)))
return SENSIRION_I2C_HAL_ERROR;
const sensor_soft_i2c_t port = {
.context = &i2c_cfg, .sda = soft_sda, .scl = soft_scl,
.read_sda = soft_read_sda, .read_scl = soft_read_scl,
.delay_us = soft_delay,
.half_period_us = (1000000U + 2 * i2c_cfg.freq - 1) / (2 * i2c_cfg.freq),
.stretch_timeout_us = 5000,
};
int rc = sensor_soft_i2c_transfer(&port, address, data, count, read);
xSemaphoreGive(soft_mutex);
i2c_ok = rc == 0 ? ESP_OK : ESP_FAIL;
if (rc) ESP_LOGW(TAG, "GPIO I2C %s failed addr=0x%02x rc=%d",
read ? "read" : "write", address, rc);
return rc == 0 ? 0 : SENSIRION_I2C_HAL_ERROR;
}
#endif
static int8_t sensirion_map_esp_err(esp_err_t err) {
return (err == ESP_OK) ? (int8_t)NO_ERROR : SENSIRION_I2C_HAL_ERROR;
}
/**
* Select the current i2c bus by index.
* Optional for single-bus setups.
*/
int16_t sensirion_i2c_hal_select_bus(uint8_t bus_idx) {
#if NANOPSX_SENSOR_SOFT_I2C
return bus_idx == i2c_cfg.port ? NO_ERROR : SENSIRION_I2C_HAL_ERROR;
#endif
/*
* NOTE:
* - This only switches the I2C port number.
* - If "bus_idx" implies different pins/frequency, update i2c_cfg accordingly
* and call sensirion_i2c_hal_init() again.
*/
dev.port = (i2c_port_t)bus_idx;
i2c_cfg.port = (i2c_port_t)bus_idx;
ESP_LOGI(TAG, "Selected I2C bus index/port: %u", (unsigned)bus_idx);
return NO_ERROR;
}
esp_err_t sensirion_i2c_config_esp32(struct esp32_i2c_config* cfg) {
if (cfg == NULL) {
return ESP_ERR_INVALID_ARG;
}
memcpy(&i2c_cfg, cfg, sizeof(*cfg));
return ESP_OK;
}
esp_err_t sensirion_i2c_esp32_ok(void) {
return i2c_ok;
}
/**
* Initialize all hard- and software components that are needed for the I2C
* communication.
*/
void sensirion_i2c_hal_init(void) {
#if NANOPSX_SENSOR_SOFT_I2C
if (!i2c_cfg.freq || i2c_cfg.freq > 100000 ||
!GPIO_IS_VALID_OUTPUT_GPIO(i2c_cfg.sda) || !GPIO_IS_VALID_OUTPUT_GPIO(i2c_cfg.scl) ||
i2c_cfg.sda == i2c_cfg.scl) {
i2c_ok = ESP_ERR_INVALID_ARG;
return;
}
gpio_set_level(i2c_cfg.sda, 1);
gpio_set_level(i2c_cfg.scl, 1);
gpio_config_t pins = {
.pin_bit_mask = (1ULL << i2c_cfg.sda) | (1ULL << i2c_cfg.scl),
.mode = GPIO_MODE_INPUT_OUTPUT_OD,
.pull_up_en = GPIO_PULLUP_ENABLE,
.pull_down_en = GPIO_PULLDOWN_DISABLE,
.intr_type = GPIO_INTR_DISABLE,
};
i2c_ok = gpio_config(&pins);
if (i2c_ok != ESP_OK) return;
soft_mutex = xSemaphoreCreateMutex();
if (!soft_mutex) { i2c_ok = ESP_ERR_NO_MEM; return; }
ESP_LOGI(TAG, "GPIO I2C ready SDA=%d SCL=%d target=%lu Hz; touch uses hardware I2C",
i2c_cfg.sda, i2c_cfg.scl, (unsigned long)i2c_cfg.freq);
return;
#endif
memset(&dev, 0, sizeof(dev));
// Minimal sanity check
if (i2c_cfg.freq == 0) {
ESP_LOGE(TAG, "Invalid I2C frequency: 0 Hz");
i2c_ok = ESP_ERR_INVALID_ARG;
return;
}
// i2cdev supports 7-bit and 10-bit; Sensirion drivers use 7-bit addresses.
dev.addr_bit_len = I2C_ADDR_BIT_LEN_7;
dev.port = i2c_cfg.port;
// Pins: i2cdev supports -1 meaning "use Kconfig default"
dev.cfg.sda_io_num = i2c_cfg.sda;
dev.cfg.scl_io_num = i2c_cfg.scl;
dev.cfg.sda_pullup_en = i2c_cfg.sda_pullup;
dev.cfg.scl_pullup_en = i2c_cfg.scl_pullup;
dev.cfg.master.clk_speed = (uint32_t)i2c_cfg.freq;
esp_err_t err = i2c_dev_create_mutex(&dev);
if (err == ESP_OK) {
ESP_LOGI(TAG,
"Sensirion I2C HAL ready. Port=%d SDA=%d SCL=%d Freq=%" PRIu32 " Hz",
(int)i2c_cfg.port, (int)i2c_cfg.sda, (int)i2c_cfg.scl, (uint32_t)i2c_cfg.freq);
} else {
ESP_LOGE(TAG,
"Sensirion I2C HAL init error. Port=%d SDA=%d SCL=%d (err=%s)",
(int)i2c_cfg.port, (int)i2c_cfg.sda, (int)i2c_cfg.scl, esp_err_to_name(err));
}
i2c_ok = err;
}
/**
* Release all resources initialized by sensirion_i2c_hal_init().
*/
void sensirion_i2c_hal_free(void) {
#if NANOPSX_SENSOR_SOFT_I2C
gpio_set_level(i2c_cfg.sda, 1);
gpio_set_level(i2c_cfg.scl, 1);
if (soft_mutex) { vSemaphoreDelete(soft_mutex); soft_mutex = NULL; }
return;
#endif
esp_err_t err = i2c_dev_delete_mutex(&dev);
if (err != ESP_OK) {
ESP_LOGW(TAG, "i2c_dev_delete_mutex failed: %s", esp_err_to_name(err));
}
}
/**
* Execute one read transaction on the I2C bus.
*
* @returns 0 on success, error code otherwise
*/
int8_t sensirion_i2c_hal_read(uint8_t address, uint8_t* data, uint16_t count) {
if (count > 0 && data == NULL) {
return SENSIRION_I2C_HAL_ERROR;
}
#if NANOPSX_SENSOR_SOFT_I2C
return soft_transfer(address, data, count, true);
#endif
dev.addr = address;
esp_err_t err = i2c_dev_take_mutex(&dev);
if (err != ESP_OK) {
ESP_LOGW(TAG, "take_mutex failed: %s", esp_err_to_name(err));
i2c_ok = err;
return sensirion_map_esp_err(err);
}
err = i2c_dev_read(&dev, NULL, 0, data, (size_t)count);
esp_err_t give_err = i2c_dev_give_mutex(&dev);
if (give_err != ESP_OK) {
ESP_LOGW(TAG, "give_mutex failed: %s", esp_err_to_name(give_err));
i2c_ok = give_err;
return sensirion_map_esp_err(give_err);
}
if (err != ESP_OK) {
ESP_LOGW(TAG, "I2C READ failed addr=0x%02x len=%u: %s",
address, (unsigned)count, esp_err_to_name(err));
i2c_ok = err;
}
return sensirion_map_esp_err(err);
}
/**
* Execute one write transaction on the I2C bus.
*
* @returns 0 on success, error code otherwise
*/
int8_t sensirion_i2c_hal_write(uint8_t address, const uint8_t* data, uint16_t count) {
if (count > 0 && data == NULL) {
return SENSIRION_I2C_HAL_ERROR;
}
#if NANOPSX_SENSOR_SOFT_I2C
return soft_transfer(address, (uint8_t *)data, count, false);
#endif
dev.addr = address;
esp_err_t err = i2c_dev_take_mutex(&dev);
if (err != ESP_OK) {
ESP_LOGW(TAG, "take_mutex failed: %s", esp_err_to_name(err));
i2c_ok = err;
return sensirion_map_esp_err(err);
}
err = i2c_dev_write(&dev, NULL, 0, data, (size_t)count);
esp_err_t give_err = i2c_dev_give_mutex(&dev);
if (give_err != ESP_OK) {
ESP_LOGW(TAG, "give_mutex failed: %s", esp_err_to_name(give_err));
i2c_ok = give_err;
return sensirion_map_esp_err(give_err);
}
if (err != ESP_OK) {
ESP_LOGW(TAG, "I2C WRITE failed addr=0x%02x len=%u: %s",
address, (unsigned)count, esp_err_to_name(err));
i2c_ok = err;
}
return sensirion_map_esp_err(err);
}
/**
* Sleep for a given number of microseconds.
* Despite the unit, a <10 millisecond precision is sufficient.
*/
void sensirion_i2c_hal_sleep_usec(uint32_t useconds) {
// at-least semantics: ceil to milliseconds
uint32_t ms = (useconds + 999U) / 1000U;
if (ms == 0 && useconds > 0) {
ms = 1;
}
SLEEP_MS(ms);
}
@@ -0,0 +1,82 @@
#include "sensor_soft_i2c.h"
#include <stddef.h>
static void delay(const sensor_soft_i2c_t *p) {
p->delay_us(p->context, p->half_period_us);
}
static int high(const sensor_soft_i2c_t *p) {
p->scl(p->context, 1);
for (unsigned n = 0; n <= p->stretch_timeout_us; n++) {
if (p->read_scl(p->context)) {
delay(p);
return 0;
}
p->delay_us(p->context, 1);
}
return -1;
}
static int write_bit(const sensor_soft_i2c_t *p, int bit) {
p->sda(p->context, bit);
delay(p);
if (high(p)) return -1;
p->scl(p->context, 0);
return 0;
}
static int read_bit(const sensor_soft_i2c_t *p) {
p->sda(p->context, 1);
delay(p);
if (high(p)) return -1;
int bit = p->read_sda(p->context) != 0;
p->scl(p->context, 0);
return bit;
}
static int write_byte(const sensor_soft_i2c_t *p, uint8_t byte) {
for (int n = 7; n >= 0; n--)
if (write_bit(p, (byte >> n) & 1)) return -1;
return read_bit(p); // ACK=0, NACK=1, bus failure=-1.
}
int sensor_soft_i2c_transfer(const sensor_soft_i2c_t *p, uint8_t address,
uint8_t *data, uint16_t count, bool read) {
if (!p || !p->sda || !p->scl || !p->read_sda || !p->read_scl ||
!p->delay_us || !p->half_period_us || address > 127 || (count && !data))
return -1;
p->sda(p->context, 1);
if (high(p) || !p->read_sda(p->context)) {
p->sda(p->context, 1);
p->scl(p->context, 1);
return -1;
}
p->sda(p->context, 0); // START while clock is high.
delay(p);
p->scl(p->context, 0);
int error = write_byte(p, (uint8_t)((address << 1) | read));
for (uint16_t i = 0; i < count && !error; i++) {
if (!read) {
error = write_byte(p, data[i]);
continue;
}
uint8_t byte = 0;
for (unsigned n = 0; n < 8; n++) {
int bit = read_bit(p);
if (bit < 0) { error = -1; break; }
byte = (uint8_t)((byte << 1) | bit);
}
if (!error) {
data[i] = byte;
error = write_bit(p, i + 1 == count); // NACK only the final byte.
}
}
// STOP on both success and failure; leave neither line driven low.
p->scl(p->context, 0);
p->sda(p->context, 0);
delay(p);
int stop_error = high(p);
p->sda(p->context, 1);
delay(p);
return error ? error : stop_error;
}
@@ -0,0 +1,21 @@
#pragma once
#include <stdbool.h>
#include <stdint.h>
/* Single-master, open-drain GPIO bus. 1 means release, never drive high.
* Port callbacks make the wire protocol testable without ESP hardware.
*/
typedef struct {
void *context;
void (*sda)(void *, int);
void (*scl)(void *, int);
int (*read_sda)(void *);
int (*read_scl)(void *);
void (*delay_us)(void *, unsigned);
unsigned half_period_us;
unsigned stretch_timeout_us;
} sensor_soft_i2c_t;
/* 0 success, 1 NACK, -1 bus/argument error. Always releases lines on failure. */
int sensor_soft_i2c_transfer(const sensor_soft_i2c_t *io, uint8_t address,
uint8_t *data, uint16_t count, bool read);
@@ -0,0 +1,9 @@
idf_component_register(
SRCS
"src/storage.c"
INCLUDE_DIRS
"include"
REQUIRES
nvs_flash
)
@@ -0,0 +1,8 @@
idf_component_register(
SRCS
"src/sys_status.c"
INCLUDE_DIRS
"include"
REQUIRES esp_timer
)
@@ -1,5 +1,7 @@
// File: firmware/components/sys_status/include/sys_status.h
#pragma once #pragma once
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h>
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
#include "freertos/event_groups.h" #include "freertos/event_groups.h"
@@ -24,6 +26,10 @@ static inline bool sys_status_get_wifi_ok(void) { return (xEventGroupGetBits(s
static inline bool sys_status_get_influx_ok(void) { return (xEventGroupGetBits(sys_status_group()) & SYS_STATUS_INFLUX_OK) != 0; } static inline bool sys_status_get_influx_ok(void) { return (xEventGroupGetBits(sys_status_group()) & SYS_STATUS_INFLUX_OK) != 0; }
static inline bool sys_status_get_mdns_ok(void) { return (xEventGroupGetBits(sys_status_group()) & SYS_STATUS_MDNS_OK) != 0; } static inline bool sys_status_get_mdns_ok(void) { return (xEventGroupGetBits(sys_status_group()) & SYS_STATUS_MDNS_OK) != 0; }
/* Monotonic timestamp of a confirmed HTTP 204, never merely a WLAN connection. */
void sys_status_record_influx_success(void);
uint64_t sys_status_last_influx_success_ms(void);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
@@ -0,0 +1,42 @@
// Field: firmware/components/sys_status/src/sys_status.c
#include "freertos/FreeRTOS.h"
#include "freertos/event_groups.h"
#include "esp_check.h"
#include "sys_status.h"
static EventGroupHandle_t s_status_group = NULL;
void sys_status_init(void)
{
if (!s_status_group) {
s_status_group = xEventGroupCreate();
/* Initial: alles auf 0 */
xEventGroupClearBits(s_status_group, SYS_STATUS_WIFI_OK | SYS_STATUS_INFLUX_OK | SYS_STATUS_MDNS_OK);
}
}
EventGroupHandle_t sys_status_group(void)
{
if (!s_status_group) sys_status_init();
return s_status_group;
}
#include "esp_timer.h"
#include "freertos/portmacro.h"
static portMUX_TYPE influx_time_mux = portMUX_INITIALIZER_UNLOCKED;
static uint64_t last_influx_success;
void sys_status_record_influx_success(void)
{
uint64_t now = (uint64_t)(esp_timer_get_time() / 1000);
portENTER_CRITICAL(&influx_time_mux);
last_influx_success = now;
portEXIT_CRITICAL(&influx_time_mux);
}
uint64_t sys_status_last_influx_success_ms(void)
{
portENTER_CRITICAL(&influx_time_mux);
uint64_t result = last_influx_success;
portEXIT_CRITICAL(&influx_time_mux);
return result;
}
@@ -0,0 +1,16 @@
idf_component_register(
SRCS
"src/wifi_mgr.c"
INCLUDE_DIRS
"include"
REQUIRES
esp_wifi
esp_event
esp_netif
esp_timer
lwip
storage
net_mdns
sys_status
dns_captive
)

Some files were not shown because too many files have changed in this diff Show More