initial commit
This commit is contained in:
+73
@@ -0,0 +1,73 @@
|
||||
#include <stdio.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
#include "sensirion_i2c_hal.h"
|
||||
#include "sen66_i2c.h"
|
||||
|
||||
static const char *TAG = "SEN66_APP";
|
||||
|
||||
#ifndef SEN66_ADDR
|
||||
#define SEN66_ADDR 0x6B
|
||||
#endif
|
||||
|
||||
static void print_values(uint16_t pm1, uint16_t pm25, uint16_t pm4, uint16_t pm10,
|
||||
int16_t rh, int16_t t, int16_t voc, int16_t nox, uint16_t co2) {
|
||||
// Skalierung laut Datenblatt :contentReference[oaicite:1]{index=1}
|
||||
float pm1_f = (pm1 == 0xFFFF) ? -1.0f : (pm1 / 10.0f);
|
||||
float pm25_f = (pm25 == 0xFFFF) ? -1.0f : (pm25 / 10.0f);
|
||||
float pm4_f = (pm4 == 0xFFFF) ? -1.0f : (pm4 / 10.0f);
|
||||
float pm10_f = (pm10 == 0xFFFF) ? -1.0f : (pm10 / 10.0f);
|
||||
|
||||
float rh_f = (rh == 0x7FFF) ? -1.0f : (rh / 100.0f);
|
||||
float t_f = (t == 0x7FFF) ? -1000.0f : (t / 200.0f);
|
||||
|
||||
float voc_f = (voc == 0x7FFF) ? -1.0f : (voc / 10.0f);
|
||||
float nox_f = (nox == 0x7FFF) ? -1.0f : (nox / 10.0f);
|
||||
|
||||
ESP_LOGI(TAG,
|
||||
"PM1=%.1f PM2.5=%.1f PM4=%.1f PM10=%.1f [ug/m3] | RH=%.2f%% | T=%.2fC | VOC=%.1f | NOx=%.1f | CO2=%u ppm",
|
||||
pm1_f, pm25_f, pm4_f, pm10_f, rh_f, t_f, voc_f, nox_f, co2);
|
||||
}
|
||||
|
||||
void app_main(void) {
|
||||
sensirion_i2c_hal_init();
|
||||
|
||||
sen66_init(SEN66_ADDR);
|
||||
|
||||
int16_t err = sen66_start_continuous_measurement();
|
||||
if (err) {
|
||||
ESP_LOGE(TAG, "sen66_start_continuous_measurement failed: %d", err);
|
||||
return;
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "SEN66 measurement started.");
|
||||
|
||||
while (1) {
|
||||
uint8_t padding = 0;
|
||||
bool ready = false;
|
||||
|
||||
err = sen66_get_data_ready(&padding, &ready);
|
||||
if (err) {
|
||||
ESP_LOGE(TAG, "sen66_get_data_ready failed: %d", err);
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ready) {
|
||||
uint16_t pm1, pm25, pm4, pm10, co2;
|
||||
int16_t rh, t, voc, nox;
|
||||
|
||||
err = sen66_read_measured_values_as_integers(&pm1, &pm25, &pm4, &pm10,
|
||||
&rh, &t, &voc, &nox, &co2);
|
||||
if (err) {
|
||||
ESP_LOGE(TAG, "sen66_read_measured_values_as_integers failed: %d", err);
|
||||
} else {
|
||||
print_values(pm1, pm25, pm4, pm10, rh, t, voc, nox, co2);
|
||||
}
|
||||
}
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user