send raw and formatted

This commit is contained in:
grove5_admin committed 2026-04-30 18:53:52 -07:00
1 parent 9717ef5549
commit d97b4a545a
5 files changed
+381 -164

No files matched your search

BIN
View File
Binary file not shown.
+272 -97
View File
@@ -45,17 +45,18 @@ bool CultivarEnv::begin(TwoWire &wire, uint8_t sda, uint8_t scl, uint8_t bme_add
_scl = scl; _scl = scl;
_bme_addr = bme_addr; _bme_addr = bme_addr;
#ifndef ARDUINO_ARCH_ZEPHYR // Initialize the user-supplied wire. On ESP32 this also assigns SDA/SCL
// pins; on Zephyr (Arduino UNO Q) sda/scl are unused (pins are board-fixed
// via device tree) and Wire1.begin() is idempotent if the bridge sketch
// already called it — calling again is harmless.
#ifdef ARDUINO_ARCH_ZEPHYR
_wire->begin();
#else
_wire->begin(_sda, _scl); _wire->begin(_sda, _scl);
_wire->setClock(100000);
#endif #endif
_wire->setClock(100000);
bme_ok = _initBME690(); bme_ok = _initBME690();
#ifdef ARDUINO_ARCH_ZEPHYR
_wire->begin(); // SCD4x Sensirion lib uses Wire — init after BME690 native i2c_transfer calls
#endif
scd4x_ok = _initSCD4x(); scd4x_ok = _initSCD4x();
return bme_ok; return bme_ok;
@@ -65,13 +66,6 @@ bool CultivarEnv::begin(TwoWire &wire, uint8_t sda, uint8_t scl, uint8_t bme_add
bool CultivarEnv::_initBME690() { bool CultivarEnv::_initBME690() {
_i2c_handle.wire = _wire; _i2c_handle.wire = _wire;
_i2c_handle.addr = _bme_addr; _i2c_handle.addr = _bme_addr;
#ifdef ARDUINO_ARCH_ZEPHYR
_i2c_handle.i2c_dev = DEVICE_DT_GET(DT_NODELABEL(i2c4)); // Wire1 = i2c4 (0x40008400) on UNO Q
if (!device_is_ready(_i2c_handle.i2c_dev)) {
CULTIVAR_SERIAL_PRINTF("[cultivar_env] Zephyr i2c4 (Wire1) device not ready\n");
return false;
}
#endif
_dev.intf = BME69X_I2C_INTF; _dev.intf = BME69X_I2C_INTF;
_dev.read = _i2cRead; _dev.read = _i2cRead;
@@ -80,15 +74,8 @@ bool CultivarEnv::_initBME690() {
_dev.intf_ptr = &_i2c_handle; _dev.intf_ptr = &_i2c_handle;
_dev.amb_temp = 25; _dev.amb_temp = 25;
#ifdef ARDUINO_ARCH_ZEPHYR
// STM32 doesn't power-cycle on reset — soft-reset the sensor so
// bme69x_init reads calibration from a clean state.
int8_t sr = bme69x_soft_reset(&_dev);
CULTIVAR_SERIAL_PRINTF("[cultivar_env] soft_reset=%d\n", sr);
_dev.delay_us(BME69X_PERIOD_RESET, _dev.intf_ptr); // 10ms reset recovery per datasheet
#endif
bme_status = bme69x_init(&_dev); bme_status = bme69x_init(&_dev);
CULTIVAR_SERIAL_PRINTF("[cultivar_env] bme69x_init=%d\n", bme_status);
if (bme_status != BME69X_OK) { if (bme_status != BME69X_OK) {
CULTIVAR_SERIAL_PRINTF("[cultivar_env] bme69x_init failed: status=%d intf_rslt=%d\n", CULTIVAR_SERIAL_PRINTF("[cultivar_env] bme69x_init failed: status=%d intf_rslt=%d\n",
bme_status, (int)_dev.intf_rslt); bme_status, (int)_dev.intf_rslt);
@@ -99,6 +86,9 @@ bool CultivarEnv::_initBME690() {
CULTIVAR_SERIAL_PRINTF("[cultivar_env] Warning: variant_id=0x%02X (expected 0x02 for BME690)\n", CULTIVAR_SERIAL_PRINTF("[cultivar_env] Warning: variant_id=0x%02X (expected 0x02 for BME690)\n",
_dev.variant_id); _dev.variant_id);
} }
CULTIVAR_SERIAL_PRINTF("[cultivar_env] calib: par_t1=%u par_t2=%d par_t3=%d par_h1=%d par_h2=%d\n",
_dev.calib.par_t1, (int)_dev.calib.par_t2, (int)_dev.calib.par_t3,
(int)_dev.calib.par_h1, (int)_dev.calib.par_h2);
_conf.os_temp = BME69X_OS_2X; _conf.os_temp = BME69X_OS_2X;
_conf.os_pres = BME69X_OS_16X; _conf.os_pres = BME69X_OS_16X;
@@ -120,74 +110,221 @@ bool CultivarEnv::_initSCD4x() {
} }
// ── _forcedRead ─────────────────────────────────────────────────────────── // ── _forcedRead ───────────────────────────────────────────────────────────
// Polling variant: trigger forced mode, wait the bare minimum, then poll
// bme69x_get_data on a short interval until NEW_DATA_MSK is set.
//
// The original implementation used a single monolithic delay() of
// (meas_dur + heat_dur). On Zephyr (Arduino UNO Q / STM32U585) this caused
// the i2c4 peripheral to be idle long enough that subsequent multi-byte reads
// silently returned zero buffers — manifesting as ambient T/H/P ≈ 0 and the
// long-heater sweep points returning the calc_gas_resistance(0,0) sentinel.
// Polling keeps the bus active and is also more accurate (returns as soon as
// the chip latches new data instead of always waiting the worst case).
bool CultivarEnv::_forcedRead(struct bme69x_data &data) { bool CultivarEnv::_forcedRead(struct bme69x_data &data) {
int8_t r = bme69x_set_op_mode(BME69X_FORCED_MODE, &_dev); int8_t r = bme69x_set_op_mode(BME69X_FORCED_MODE, &_dev);
if (r != BME69X_OK) return false; if (r != BME69X_OK) return false;
uint32_t meas_dur = bme69x_get_meas_dur(BME69X_FORCED_MODE, &_conf, &_dev); uint32_t meas_dur_us = bme69x_get_meas_dur(BME69X_FORCED_MODE, &_conf, &_dev);
uint32_t heat_dur = (uint32_t)_heatr.heatr_dur * 1000; uint32_t heat_dur_ms = (uint32_t)_heatr.heatr_dur;
_dev.delay_us(meas_dur + heat_dur + 5000, _dev.intf_ptr); uint32_t expected_ms = (meas_dur_us / 1000) + heat_dur_ms;
uint32_t timeout_ms = expected_ms + 100; // generous margin
// Build sentinel — bump this string when iterating so we can confirm the
// freshly-built library is what's actually flashed.
CULTIVAR_SERIAL_PRINTF("[cultivar_env] _forcedRead v5 int-math: meas=%lums heat=%lums\n",
(unsigned long)(meas_dur_us / 1000),
(unsigned long)heat_dur_ms);
// Short initial settle — at most 20ms — then start polling.
uint32_t initial_wait = (heat_dur_ms / 4);
if (initial_wait > 20) initial_wait = 20;
if (initial_wait > 0) delay(initial_wait);
uint8_t n_data = 0; uint8_t n_data = 0;
r = bme69x_get_data(BME69X_FORCED_MODE, &data, &n_data, &_dev); uint32_t start = millis();
return r == BME69X_OK && n_data > 0; while ((millis() - start) < timeout_ms) {
r = bme69x_get_data(BME69X_FORCED_MODE, &data, &n_data, &_dev);
if (r == BME69X_OK && n_data > 0 && (data.status & BME69X_NEW_DATA_MSK)) {
return true;
}
// BME69X_W_NO_NEW_DATA (positive) just means "not ready yet" — poll on.
delay(5);
}
return false;
}
// ── _readRawField0 ────────────────────────────────────────────────────────
// Read raw ADC values from FIELD0 registers directly, bypassing Bosch driver
// compensation. Used for time-series storage and future reprocessing.
static bool _readRawField0(const bme69x_dev &dev,
uint32_t &adc_temp, uint32_t &adc_pres,
uint16_t &adc_hum, uint16_t &adc_gas_res,
uint8_t &gas_range, uint8_t &status) {
uint8_t buf[BME69X_LEN_FIELD] = {0};
int8_t r = bme69x_get_regs(BME69X_REG_FIELD0, buf, BME69X_LEN_FIELD, (bme69x_dev *)&dev);
if (r != BME69X_OK) return false;
status = buf[0];
adc_pres = ((uint32_t)buf[2] << 16) | ((uint32_t)buf[3] << 8) | (uint32_t)buf[4];
adc_temp = ((uint32_t)buf[5] << 16) | ((uint32_t)buf[6] << 8) | (uint32_t)buf[7];
adc_hum = ((uint16_t)buf[8] << 8) | (uint16_t)buf[9];
adc_gas_res = ((uint16_t)buf[15] << 2) | ((uint16_t)buf[16] >> 6);
gas_range = buf[16] & BME69X_GAS_RANGE_MSK;
return true;
} }
// ── _readAmbient ────────────────────────────────────────────────────────── // ── _readAmbient ──────────────────────────────────────────────────────────
// Use a heater-enabled forced cycle with a low temperature and very short
// duration. Per the datasheet (Section 3.6), the BME690 always samples
// T/P/H *before* the heater fires, so the T/P/H ADCs are unaffected by the
// heater pulse — we get a true ambient reading even with the heater "on".
// Any gas measurement that piggybacks on the cycle is discarded.
//
// Why not heater-disabled? Calling bme69x_set_heatr_conf with enable=DISABLE
// passes through Bosch's internal set_conf, which writes res_heat_0/gas_wait_0
// from the (zero) heater config. nb_conv then points at gas_wait_0=0, which
// can leave the chip's TPHG state machine in a state where T/P/H ADCs come
// back as garbage. The heater-enabled path with a sane gas_wait avoids that
// entirely and is what _runSweep already uses successfully.
bool CultivarEnv::_readAmbient(CultivarAmbient &out) { bool CultivarEnv::_readAmbient(CultivarAmbient &out) {
out.valid = false; out.valid = false;
if (!bme_ok) return false; if (!bme_ok) return false;
struct bme69x_conf saved_conf = _conf; // save — restore after ambient read CULTIVAR_SERIAL_PRINTF("[cultivar_env] _readAmbient start\n");
_conf.os_temp = BME69X_OS_8X; struct bme69x_conf saved_conf = _conf;
_conf.os_pres = BME69X_OS_16X; struct bme69x_heatr_conf saved_heatr = _heatr;
_conf.os_hum = BME69X_OS_4X;
_conf.filter = BME69X_FILTER_SIZE_7; // Match the sweep's oversampling settings exactly. High-precision
// ambient values (OS_8X/16X/4X, filter 7) seem to interact badly with
// _forcedRead on this chip — values come back as near-zero despite the
// FIELD0 status byte reporting NEW_DATA. Using the sweep's lower-
// precision settings produces correct ambient. If you need higher
// ambient precision later, re-investigate — this is the workaround.
_conf.os_temp = BME69X_OS_2X;
_conf.os_pres = BME69X_OS_4X;
_conf.os_hum = BME69X_OS_1X;
_conf.filter = BME69X_FILTER_SIZE_3;
int8_t r = bme69x_set_conf(&_conf, &_dev); int8_t r = bme69x_set_conf(&_conf, &_dev);
if (r != BME69X_OK) { _conf = saved_conf; return false; } if (r != BME69X_OK) { _conf = saved_conf; _heatr = saved_heatr; return false; }
_heatr.enable = BME69X_DISABLE; // Heater config identical to sweep[0]: 200 °C, 150 ms. Per datasheet
_heatr.heatr_temp = 0; // T/P/H are sampled BEFORE the heater fires, so the heater being on
_heatr.heatr_dur = 0; // doesn't affect the ambient T/P/H reading. We discard the gas result.
// Matching sweep[0] exactly guarantees the chip's TPHG state machine is
// in a known-good configuration for the read.
_heatr.enable = BME69X_ENABLE;
_heatr.heatr_temp = 200;
_heatr.heatr_dur = 150;
r = bme69x_set_heatr_conf(BME69X_FORCED_MODE, &_heatr, &_dev); r = bme69x_set_heatr_conf(BME69X_FORCED_MODE, &_heatr, &_dev);
if (r != BME69X_OK) { _conf = saved_conf; return false; } if (r != BME69X_OK) { _conf = saved_conf; _heatr = saved_heatr; return false; }
delay(CULTIVAR_AMBIENT_SETTLE_MS);
struct bme69x_data data; struct bme69x_data data;
bool ok = _forcedRead(data); bool ok = _forcedRead(data);
_conf = saved_conf; // restore sweep config // Cross-check Bosch's calc_temperature against a known-good ADC value.
// From prior FIELD0 dumps we know adc_temp=6,881,408 should give ~24.4 °C.
// If Bosch's float math is broken on this target, using the same formula
// here with the same calibration should reproduce the bug.
{
uint32_t adc_temp_probe = 6881408UL; // 0x690080 from a real ambient dump
int32_t do1 = (int32_t)_dev.calib.par_t1 << 8;
double dtk1 = (double)_dev.calib.par_t2 / (double)(1ULL << 30);
double dtk2 = (double)_dev.calib.par_t3 / (double)(1ULL << 48);
double cf = (double)adc_temp_probe - (double)do1;
double t1 = cf * dtk1;
double t2 = cf * cf * dtk2;
double tsum = t1 + t2;
CULTIVAR_SERIAL_PRINTF("[cultivar_env] probe: do1=%ld cf=%.1f dtk1=%.9f dtk2=%.15f t1=%.4f t2=%.4f sum=%.4f\n",
(long)do1, cf, dtk1, dtk2, t1, t2, tsum);
}
// Integer path: temperature is int16_t °C×100, humidity uint32_t %RH×1000,
// pressure uint32_t Pa.
CULTIVAR_SERIAL_PRINTF("[cultivar_env] _readAmbient done ok=%d T=%.2f RH=%.2f P=%.2f\n",
(int)ok,
(double)data.temperature / 100.0,
(double)data.humidity / 1000.0,
(double)data.pressure / 100.0);
CULTIVAR_SERIAL_PRINTF("[cultivar_env] calib in use: par_t1=%u par_t2=%u par_t3=%d amb_temp=%d\n",
(unsigned)_dev.calib.par_t1,
(unsigned)_dev.calib.par_t2,
(int)_dev.calib.par_t3,
(int)_dev.amb_temp);
// Restore caller's config for subsequent sweep.
_conf = saved_conf;
_heatr = saved_heatr;
bme69x_set_conf(&_conf, &_dev); bme69x_set_conf(&_conf, &_dev);
if (!ok) return false; if (!ok) return false;
out.temperature = data.temperature; out.temperature = (float)data.temperature / 100.0f; // int16_t °C×100 → °C
out.humidity = data.humidity; out.humidity = (float)data.humidity / 1000.0f; // uint32_t %RH×1000 → %RH
out.pressure = data.pressure / 100.0f; out.pressure = (float)data.pressure / 100.0f; // uint32_t Pa → hPa
out.valid = true;
// Also capture raw ADCs for time-series / Linux-side reprocessing
uint32_t r_temp, r_pres;
uint16_t r_hum, r_gas;
uint8_t r_range, r_status;
if (_readRawField0(_dev, r_temp, r_pres, r_hum, r_gas, r_range, r_status)) {
out.adc_temp = r_temp;
out.adc_hum = r_hum;
out.adc_pres = r_pres;
}
out.valid = true;
return true; return true;
} }
// ── _readCO2 ───────────────────────────────────────────────────────────── // ── _readCO2 ─────────────────────────────────────────────────────────────
bool CultivarEnv::_readCO2(CultivarCO2 &out) { bool CultivarEnv::_readCO2(CultivarCO2 &out) {
out.valid = false; out.valid = false;
if (!scd4x_ok) return false; if (!scd4x_ok) {
CULTIVAR_SERIAL_PRINTF("[cultivar_env] _readCO2 skipped, scd4x_ok=false\n");
return false;
}
bool ready = false; bool ready = false;
uint16_t err = _scd4x.getDataReadyStatus(ready); uint16_t err = _scd4x.getDataReadyStatus(ready);
if (err || !ready) return false; if (err) {
CULTIVAR_SERIAL_PRINTF("[cultivar_env] _readCO2 getDataReadyStatus err=%u\n", (unsigned)err);
return false;
}
if (!ready) {
// No new data — return buffered value if available
if (_co2_buffer.valid) {
out = _co2_buffer;
CULTIVAR_SERIAL_PRINTF("[cultivar_env] _readCO2 using buffered co2=%u (age=%lums)\n",
(unsigned)out.co2_ppm,
(unsigned long)(millis() - _co2_buffer_time_ms));
return true;
}
CULTIVAR_SERIAL_PRINTF("[cultivar_env] _readCO2 data not ready yet, no buffer\n");
return false;
}
uint16_t co2; uint16_t co2;
float temp, hum; float temp, hum;
err = _scd4x.readMeasurement(co2, temp, hum); err = _scd4x.readMeasurement(co2, temp, hum);
if (err || co2 == 0) return false; if (err) {
CULTIVAR_SERIAL_PRINTF("[cultivar_env] _readCO2 readMeasurement err=%u\n", (unsigned)err);
return false;
}
if (co2 == 0) {
CULTIVAR_SERIAL_PRINTF("[cultivar_env] _readCO2 co2=0 (sensor not warmed up?)\n");
return false;
}
CULTIVAR_SERIAL_PRINTF("[cultivar_env] _readCO2 fresh co2=%u T=%.2f RH=%.2f\n",
(unsigned)co2, (double)temp, (double)hum);
out.co2_ppm = co2; out.co2_ppm = co2;
out.temperature = temp; out.temperature = temp;
out.humidity = hum; out.humidity = hum;
out.valid = true; out.valid = true;
// Update buffer
_co2_buffer = out;
_co2_buffer_time_ms = millis();
return true; return true;
} }
@@ -246,6 +383,19 @@ bool CultivarEnv::_runSweep(CultivarGasPoint *out, uint8_t &count) {
out[i].heater_stable = heater_stable; out[i].heater_stable = heater_stable;
out[i].valid = gas_valid; out[i].valid = gas_valid;
// Capture raw gas ADC for Linux-side modelling
uint32_t r_temp, r_pres;
uint16_t r_hum, r_gas;
uint8_t r_range, r_status;
if (_readRawField0(_dev, r_temp, r_pres, r_hum, r_gas, r_range, r_status)) {
out[i].adc_gas_res = r_gas;
out[i].gas_range = r_range;
}
CULTIVAR_SERIAL_PRINTF("[cultivar_env] sweep[%d] res_heat=%u idac=%u gas_wait=%u gas_res=%lu status=0x%02X\n",
i, (unsigned)data.res_heat, (unsigned)data.idac, (unsigned)data.gas_wait,
(unsigned long)data.gas_resistance, (unsigned)data.status);
count++; count++;
delay(50); delay(50);
} }
@@ -286,8 +436,14 @@ size_t CultivarEnv::toJSON(const CultivarEnvPayload &p, char *buf, size_t len) {
// Ambient — always emit all fields; daemon model requires temp_c/humidity_pct/pressure_hpa // Ambient — always emit all fields; daemon model requires temp_c/humidity_pct/pressure_hpa
n += snprintf(buf + n, len - n, n += snprintf(buf + n, len - n,
"\"ambient\":{\"temp_c\":%.2f,\"humidity_pct\":%.2f,\"pressure_hpa\":%.2f,\"valid\":%s},", "\"ambient\":{"
"\"temp_c\":%.2f,\"humidity_pct\":%.2f,\"pressure_hpa\":%.2f,"
"\"adc_temp\":%lu,\"adc_hum\":%lu,\"adc_pres\":%lu,"
"\"valid\":%s},",
p.ambient.temperature, p.ambient.humidity, p.ambient.pressure, p.ambient.temperature, p.ambient.humidity, p.ambient.pressure,
(unsigned long)p.ambient.adc_temp,
(unsigned long)p.ambient.adc_hum,
(unsigned long)p.ambient.adc_pres,
p.ambient.valid ? "true" : "false"); p.ambient.valid ? "true" : "false");
// CO2 — full field names, null if not present // CO2 — full field names, null if not present
@@ -328,6 +484,8 @@ size_t CultivarEnv::toJSON(const CultivarEnvPayload &p, char *buf, size_t len) {
"\"heater_dur_ms\":%u," "\"heater_dur_ms\":%u,"
"\"zone\":%u," "\"zone\":%u,"
"\"resistance_raw\":%.0f," "\"resistance_raw\":%.0f,"
"\"adc_gas_res\":%u,"
"\"gas_range\":%u,"
"\"heater_stable\":%s," "\"heater_stable\":%s,"
"\"valid\":%s" "\"valid\":%s"
"}", "}",
@@ -336,6 +494,8 @@ size_t CultivarEnv::toJSON(const CultivarEnvPayload &p, char *buf, size_t len) {
p.sweep[i].heater_dur_ms, p.sweep[i].heater_dur_ms,
p.sweep[i].zone, p.sweep[i].zone,
p.sweep[i].resistance, p.sweep[i].resistance,
(unsigned)p.sweep[i].adc_gas_res,
(unsigned)p.sweep[i].gas_range,
p.sweep[i].heater_stable ? "true" : "false", p.sweep[i].heater_stable ? "true" : "false",
p.sweep[i].valid ? "true" : "false"); p.sweep[i].valid ? "true" : "false");
} }
@@ -348,29 +508,29 @@ size_t CultivarEnv::toJSON(const CultivarEnvPayload &p, char *buf, size_t len) {
void CultivarEnv::printPayload(const CultivarEnvPayload &p) { void CultivarEnv::printPayload(const CultivarEnvPayload &p) {
CULTIVAR_SERIAL_PRINTF("\n══ Cultivar ENV payload [t=%lums] ══\n", p.timestamp_ms); CULTIVAR_SERIAL_PRINTF("\n══ Cultivar ENV payload [t=%lums] ══\n", p.timestamp_ms);
Serial.println("── Ambient (BME690, heater off) ──────"); if (CULTIVAR_ENV_DEBUG) Serial.println("── Ambient (BME690, heater off) ──────");
if (p.ambient.valid) { if (p.ambient.valid) {
CULTIVAR_SERIAL_PRINTF(" Temperature: %.2f °C\n", p.ambient.temperature); CULTIVAR_SERIAL_PRINTF(" Temperature: %.2f °C\n", p.ambient.temperature);
CULTIVAR_SERIAL_PRINTF(" Humidity: %.2f %%RH\n", p.ambient.humidity); CULTIVAR_SERIAL_PRINTF(" Humidity: %.2f %%RH\n", p.ambient.humidity);
CULTIVAR_SERIAL_PRINTF(" Pressure: %.2f hPa\n", p.ambient.pressure); CULTIVAR_SERIAL_PRINTF(" Pressure: %.2f hPa\n", p.ambient.pressure);
} else { } else {
Serial.println(" [invalid]"); if (CULTIVAR_ENV_DEBUG) Serial.println(" [invalid]");
} }
Serial.println("── CO2 (SCD43) ───────────────────────"); if (CULTIVAR_ENV_DEBUG) Serial.println("── CO2 (SCD43) ───────────────────────");
if (p.health.scd43_present) { if (p.health.scd43_present) {
if (p.co2.valid) { if (p.co2.valid) {
CULTIVAR_SERIAL_PRINTF(" CO2: %u ppm\n", p.co2.co2_ppm); CULTIVAR_SERIAL_PRINTF(" CO2: %u ppm\n", p.co2.co2_ppm);
CULTIVAR_SERIAL_PRINTF(" Temperature: %.2f °C\n", p.co2.temperature); CULTIVAR_SERIAL_PRINTF(" Temperature: %.2f °C\n", p.co2.temperature);
CULTIVAR_SERIAL_PRINTF(" Humidity: %.2f %%RH\n", p.co2.humidity); CULTIVAR_SERIAL_PRINTF(" Humidity: %.2f %%RH\n", p.co2.humidity);
} else { } else {
Serial.println(" [no data]"); if (CULTIVAR_ENV_DEBUG) Serial.println(" [no data]");
} }
} else { } else {
Serial.println(" [not populated]"); if (CULTIVAR_ENV_DEBUG) Serial.println(" [not populated]");
} }
Serial.println("── Sensor Health ─────────────────────"); if (CULTIVAR_ENV_DEBUG) Serial.println("── Sensor Health ─────────────────────");
if (p.health.scd43_present && p.ambient.valid && p.co2.valid) { if (p.health.scd43_present && p.ambient.valid && p.co2.valid) {
CULTIVAR_SERIAL_PRINTF(" Temp delta: %.2f °C %s\n", CULTIVAR_SERIAL_PRINTF(" Temp delta: %.2f °C %s\n",
p.health.temp_delta, p.health.temp_delta,
@@ -379,14 +539,14 @@ void CultivarEnv::printPayload(const CultivarEnvPayload &p) {
p.health.humidity_delta, p.health.humidity_delta,
p.health.humidity_ok ? "✓" : "⚠ WARN"); p.health.humidity_ok ? "✓" : "⚠ WARN");
} else { } else {
Serial.println(" [single sensor mode]"); if (CULTIVAR_ENV_DEBUG) Serial.println(" [single sensor mode]");
} }
CULTIVAR_SERIAL_PRINTF("── Baseline [samples=%u, established=%s]\n", CULTIVAR_SERIAL_PRINTF("── Baseline [samples=%u, established=%s]\n",
p.baseline.samples_collected, p.baseline.samples_collected,
p.baseline.established ? "yes" : "no"); p.baseline.established ? "yes" : "no");
Serial.println("── Gas Sweep (BME690) ────────────────"); if (CULTIVAR_ENV_DEBUG) Serial.println("── Gas Sweep (BME690) ────────────────");
CULTIVAR_SERIAL_PRINTF(" %-6s %-6s %-5s %-16s %-7s %s\n", CULTIVAR_SERIAL_PRINTF(" %-6s %-6s %-5s %-16s %-7s %s\n",
"Temp°C", "Dur ms", "Zone", "Resistance Ω", "Stable", "Valid"); "Temp°C", "Dur ms", "Zone", "Resistance Ω", "Stable", "Valid");
for (uint8_t i = 0; i < p.sweep_count; i++) { for (uint8_t i = 0; i < p.sweep_count; i++) {
@@ -398,7 +558,7 @@ void CultivarEnv::printPayload(const CultivarEnvPayload &p) {
p.sweep[i].heater_stable ? "✓" : "✗", p.sweep[i].heater_stable ? "✓" : "✗",
p.sweep[i].valid ? "✓" : "✗"); p.sweep[i].valid ? "✓" : "✗");
} }
Serial.println("─────────────────────────────────────"); if (CULTIVAR_ENV_DEBUG) Serial.println("─────────────────────────────────────");
} }
// ── scanI2C ─────────────────────────────────────────────────────────────── // ── scanI2C ───────────────────────────────────────────────────────────────
@@ -421,63 +581,78 @@ void CultivarEnv::scanI2C() {
} }
// ── Bosch API I2C callbacks ─────────────────────────────────────────────── // ── Bosch API I2C callbacks ───────────────────────────────────────────────
//
// Single, unified Wire-based path for all targets. Originally the Zephyr
// branch used Zephyr's native `i2c_transfer` against `DEVICE_DT_GET(i2c4)`
// directly, on the theory that Arduino's Wire layer would force a STOP and
// break a required repeated-start. That theory turned out to be wrong:
//
// 1. The BME690 (and BME68x family) auto-increments its internal register
// address, so a STOP between write(reg_addr) and read(N) is fully
// supported and returns correct data.
// 2. On the Arduino UNO Q core (STM32U585, Zephyr), bypassing Wire1 to
// hit `i2c4` directly produced consistent but wrong reads — we believe
// `Wire1` and `DEVICE_DT_GET(i2c4)` either map to different physical
// buses on this board or interact poorly with the core's I2C state.
// The same `Wire1` path that the user's I2C scan + chip-ID probe use
// (and that returns the correct 0x61 chip-id) works correctly here.
//
// Net: route everything through the user-supplied TwoWire instance. This is
// the same path the ESP32-S3 build was using all along, which is why that
// target has always worked.
int8_t CultivarEnv::_i2cRead(uint8_t reg_addr, uint8_t *data, int8_t CultivarEnv::_i2cRead(uint8_t reg_addr, uint8_t *data,
uint32_t len, void *intf_ptr) { uint32_t len, void *intf_ptr) {
CultivarI2CHandle *h = (CultivarI2CHandle *)intf_ptr; CultivarI2CHandle *h = (CultivarI2CHandle *)intf_ptr;
#ifdef ARDUINO_ARCH_ZEPHYR
// Zephyr Wire always sends STOP between endTransmission and requestFrom — // Sentinel-fill so we can distinguish "Wire wrote zeros" from "Wire
// stopBit param is ARG_UNUSED. BME690 requires write+read as a single // silently didn't touch the buffer" if something goes sideways.
// atomic transaction (repeated start). Use i2c_transfer with two msgs. if (len > 0) memset(data, 0xAA, len);
struct i2c_msg msgs[2];
msgs[0].buf = &reg_addr;
msgs[0].len = 1;
msgs[0].flags = I2C_MSG_WRITE; // no STOP
msgs[1].buf = data;
msgs[1].len = (uint32_t)len;
msgs[1].flags = I2C_MSG_RESTART | I2C_MSG_READ | I2C_MSG_STOP; // repeated start + read + STOP
int rc = i2c_transfer(h->i2c_dev, msgs, 2, h->addr);
if (rc != 0) {
CULTIVAR_SERIAL_PRINTF("[cultivar_env] i2c_transfer read reg=0x%02X len=%u rc=%d\n", reg_addr, len, rc);
}
return (rc == 0) ? BME69X_OK : -1;
#else
h->wire->beginTransmission(h->addr); h->wire->beginTransmission(h->addr);
h->wire->write(reg_addr); h->wire->write(reg_addr);
if (h->wire->endTransmission(false) != 0) return -1; // STOP after the register write. BME690 auto-increments, so the
h->wire->requestFrom(h->addr, (uint8_t)len); // subsequent requestFrom() reads sequential bytes from reg_addr forward.
if (h->wire->endTransmission(true) != 0) {
CULTIVAR_SERIAL_PRINTF("[cultivar_env] wire write reg=0x%02X NACK\n", reg_addr);
return -1;
}
uint32_t got = h->wire->requestFrom((uint8_t)h->addr, (uint8_t)len);
if (got != len) {
CULTIVAR_SERIAL_PRINTF("[cultivar_env] wire requestFrom reg=0x%02X want=%u got=%u\n",
reg_addr, (unsigned)len, (unsigned)got);
}
for (uint32_t i = 0; i < len; i++) { for (uint32_t i = 0; i < len; i++) {
if (!h->wire->available()) return -1; if (!h->wire->available()) {
CULTIVAR_SERIAL_PRINTF("[cultivar_env] wire underflow reg=0x%02X at byte %u\n", reg_addr, (unsigned)i);
return -1;
}
data[i] = h->wire->read(); data[i] = h->wire->read();
} }
// Diagnostic: dump FIELD0 reads (17 bytes from 0x1D). Disable once happy.
if (reg_addr == 0x1D && len == 17) {
CULTIVAR_SERIAL_PRINTF("[cultivar_env] FIELD0 dump:");
for (uint32_t i = 0; i < len; i++) {
CULTIVAR_SERIAL_PRINTF(" %02X", data[i]);
}
CULTIVAR_SERIAL_PRINTF("\n");
}
return BME69X_OK; return BME69X_OK;
#endif
} }
int8_t CultivarEnv::_i2cWrite(uint8_t reg_addr, const uint8_t *data, int8_t CultivarEnv::_i2cWrite(uint8_t reg_addr, const uint8_t *data,
uint32_t len, void *intf_ptr) { uint32_t len, void *intf_ptr) {
CultivarI2CHandle *h = (CultivarI2CHandle *)intf_ptr; CultivarI2CHandle *h = (CultivarI2CHandle *)intf_ptr;
#ifdef ARDUINO_ARCH_ZEPHYR
// Use i2c_transfer for consistency — Wire.endTransmission uses i2c_write
// internally anyway, but this avoids the ring buffer overhead.
if (len + 1 > 32) return -1; // Bosch driver never writes more than ~17 bytes
uint8_t buf[32];
buf[0] = reg_addr;
memcpy(buf + 1, data, len);
struct i2c_msg msg;
msg.buf = buf;
msg.len = len + 1;
msg.flags = I2C_MSG_WRITE | I2C_MSG_STOP;
int rc = i2c_transfer(h->i2c_dev, &msg, 1, h->addr);
if (rc != 0) {
CULTIVAR_SERIAL_PRINTF("[cultivar_env] i2c_transfer write reg=0x%02X len=%u rc=%d\n", reg_addr, len + 1, rc);
}
return (rc == 0) ? BME69X_OK : -1;
#else
h->wire->beginTransmission(h->addr); h->wire->beginTransmission(h->addr);
h->wire->write(reg_addr); h->wire->write(reg_addr);
for (uint32_t i = 0; i < len; i++) h->wire->write(data[i]); for (uint32_t i = 0; i < len; i++) h->wire->write(data[i]);
return (h->wire->endTransmission() == 0) ? BME69X_OK : -1; int rc = h->wire->endTransmission();
#endif if (rc != 0) {
CULTIVAR_SERIAL_PRINTF("[cultivar_env] wire write reg=0x%02X len=%u rc=%d\n", reg_addr, (unsigned)len, rc);
}
return (rc == 0) ? BME69X_OK : -1;
} }
void CultivarEnv::_delayUs(uint32_t period, void *intf_ptr) { void CultivarEnv::_delayUs(uint32_t period, void *intf_ptr) {
+28 -8
View File
@@ -25,16 +25,22 @@
#pragma once #pragma once
// ── Debug flag (set 1 for verbose logging during development) ────────────────
#ifndef CULTIVAR_ENV_DEBUG
#define CULTIVAR_ENV_DEBUG 0
#endif
// ── Platform shim (Zephyr/ESP32 portability) ────────────────────────────── // ── Platform shim (Zephyr/ESP32 portability) ──────────────────────────────
#ifdef ARDUINO_ARCH_ZEPHYR #ifdef ARDUINO_ARCH_ZEPHYR
#define CULTIVAR_SERIAL_PRINTF(fmt, ...) \ #define CULTIVAR_SERIAL_PRINTF(fmt, ...) \
do { char _b[128]; snprintf(_b, sizeof(_b), fmt, ##__VA_ARGS__); Serial.print(_b); } while(0) do { if (CULTIVAR_ENV_DEBUG) { char _b[128]; snprintf(_b, sizeof(_b), fmt, ##__VA_ARGS__); Serial.print(_b); } } while(0)
#define CULTIVAR_ENV_SDA 0 #define CULTIVAR_ENV_SDA 0
#define CULTIVAR_ENV_SCL 0 #define CULTIVAR_ENV_SCL 0
#define CULTIVAR_ENV_WIRE Wire1 #define CULTIVAR_ENV_WIRE Wire1
#include <zephyr/drivers/i2c.h> #include <zephyr/drivers/i2c.h>
#else #else
#define CULTIVAR_SERIAL_PRINTF(fmt, ...) Serial.printf(fmt, ##__VA_ARGS__) #define CULTIVAR_SERIAL_PRINTF(fmt, ...) \
do { if (CULTIVAR_ENV_DEBUG) { Serial.printf(fmt, ##__VA_ARGS__); } } while(0)
// ── Default I2C pins (ESP32S3 dev board — override for production) ───────── // ── Default I2C pins (ESP32S3 dev board — override for production) ─────────
#define CULTIVAR_ENV_SDA 42 #define CULTIVAR_ENV_SDA 42
#define CULTIVAR_ENV_SCL 41 #define CULTIVAR_ENV_SCL 41
@@ -58,7 +64,11 @@
#define CULTIVAR_HUMIDITY_DELTA_WARN 5.0f // %RH #define CULTIVAR_HUMIDITY_DELTA_WARN 5.0f // %RH
// ── Ambient settle time after heater off ────────────────────────────────── // ── Ambient settle time after heater off ──────────────────────────────────
#define CULTIVAR_AMBIENT_SETTLE_MS 3000 // 100ms is plenty for the BME690 with heater disabled. The forced read itself
// polls for data-ready, so this is just a small buffer for the heater to cool.
// On Zephyr (UNO Q) longer monolithic delays leave the i2c4 peripheral idle
// long enough that subsequent reads silently return zero buffers.
#define CULTIVAR_AMBIENT_SETTLE_MS 100
// ── Gas sweep configuration ─────────────────────────────────────────────── // ── Gas sweep configuration ───────────────────────────────────────────────
#define CULTIVAR_SWEEP_COUNT 10 #define CULTIVAR_SWEEP_COUNT 10
@@ -78,7 +88,9 @@ struct CultivarGasPoint {
uint16_t heater_temp_c; // Heater setpoint °C uint16_t heater_temp_c; // Heater setpoint °C
uint16_t heater_dur_ms; // Heater duration ms uint16_t heater_dur_ms; // Heater duration ms
uint8_t zone; // CULTIVAR_ZONE_* uint8_t zone; // CULTIVAR_ZONE_*
float resistance; // Raw resistance Ω float resistance; // Compensated resistance Ω (from Bosch)
uint16_t adc_gas_res; // Raw 10-bit gas ADC value
uint8_t gas_range; // Gas range (0-15, affects resistance calc)
bool heater_stable; // HEAT_STAB_MSK was set bool heater_stable; // HEAT_STAB_MSK was set
bool valid; // Gas measurement valid bool valid; // Gas measurement valid
}; };
@@ -86,12 +98,16 @@ struct CultivarGasPoint {
/** /**
* Ambient conditions — BME690 with heater off. * Ambient conditions — BME690 with heater off.
* Use for temp/humidity/pressure. No altitude — compute on Linux side. * Use for temp/humidity/pressure. No altitude — compute on Linux side.
* Raw ADC values included for time-series storage and future reprocessing.
*/ */
struct CultivarAmbient { struct CultivarAmbient {
float temperature; // °C float temperature; // °C (compensated)
float humidity; // %RH float humidity; // %RH (compensated)
float pressure; // hPa float pressure; // hPa (compensated)
bool valid; uint32_t adc_temp; // Raw 20-bit temperature ADC
uint32_t adc_hum; // Raw 16-bit humidity ADC
uint32_t adc_pres; // Raw 20-bit pressure ADC
bool valid;
}; };
/** /**
@@ -247,6 +263,10 @@ private:
// Baseline state // Baseline state
CultivarBaselineStatus _baseline; CultivarBaselineStatus _baseline;
// Buffered CO2 — updated asynchronously by pollCO2(), read by collect()
CultivarCO2 _co2_buffer = {0};
uint32_t _co2_buffer_time_ms = 0;
// Internal // Internal
bool _initBME690(); bool _initBME690();
bool _initSCD4x(); bool _initSCD4x();
+15
View File
@@ -86,6 +86,21 @@
#endif #endif
#endif #endif
/* ── Cultivar patch ──────────────────────────────────────────────────────
* Force integer math. Bosch's float compensation uses double-precision
* arithmetic that is software-emulated on STM32U585 (Cortex-M33, single-
* precision FPU only) under Zephyr, and is miscompiling / losing terms on
* this target — e.g. `t1 + t2` silently returning just `t1`. The integer
* path (int64_t intermediates, fixed-point) sidesteps this entirely.
*
* Output fields change type accordingly; see callers:
* temperature : int16_t, °C × 100
* pressure : uint32_t, Pa
* humidity : uint32_t, %RH × 1000
* gas_resistance : uint32_t, Ω
*/
#define BME69X_DO_NOT_USE_FPU
#ifndef BME69X_DO_NOT_USE_FPU #ifndef BME69X_DO_NOT_USE_FPU
/* Comment or un-comment the macro to provide floating point data output */ /* Comment or un-comment the macro to provide floating point data output */
+66 -59
View File
@@ -1,12 +1,15 @@
/** /**
* cultivar_env_bridge.ino * cultivar_env_bridge.ino
* Grove5 Cultivar — ENV sensor bridge for Arduino UNO Q * Grove5 Cultivar — ENV sensor bridge
* *
* STM32U585 collects BME690 + SCD43 data and streams JSON * Arduino UNO Q (Zephyr/STM32U585):
* payloads over a TCP bridge server to the Cultivar daemon * Streams JSON over BridgeTCPServer to the Cultivar daemon
* running on the QRB2210 Debian side. * running on the QRB2210 Debian side (localhost:5678).
*
* ESP32-S3 (debug / validation):
* Logs JSON payloads to Serial — no network required.
* Use to verify sensor readings independently of STM32 I2C issues.
* *
* Transport: BridgeTCPServer on localhost:5678
* Protocol: Newline-delimited JSON (one payload per line) * Protocol: Newline-delimited JSON (one payload per line)
* *
* Grove5 — Open source software, honest hardware. * Grove5 — Open source software, honest hardware.
@@ -14,50 +17,61 @@
*/ */
#include <Wire.h> #include <Wire.h>
#include <Arduino_RouterBridge.h>
#include "cultivar_env.h" #include "cultivar_env.h"
#define COLLECT_INTERVAL_MS (30UL * 1000UL) // 30s dev; use 300000 production #ifdef ARDUINO_ARCH_ZEPHYR
#define SCD43_WARMUP_MS (35UL * 1000UL) #include <Arduino_RouterBridge.h>
#define DBG Monitor
#else
#define DBG Serial
#endif
#define COLLECT_INTERVAL_MS (5UL * 60UL * 1000UL) // 30s dev; use 300000 production
#define SCD43_WARMUP_MS (60UL * 1000UL)
#define TCP_PORT 5678 #define TCP_PORT 5678
#define JSON_BUF_SIZE 2048 #define JSON_BUF_SIZE 2048
#ifdef ARDUINO_ARCH_ZEPHYR
IPAddress localhost(127, 0, 0, 1); IPAddress localhost(127, 0, 0, 1);
BridgeTCPServer<JSON_BUF_SIZE> server(Bridge, localhost, TCP_PORT); BridgeTCPServer<JSON_BUF_SIZE> server(Bridge, localhost, TCP_PORT);
#endif
CultivarEnv env; CultivarEnv env;
static char jsonBuf[JSON_BUF_SIZE]; static char jsonBuf[JSON_BUF_SIZE];
static unsigned long lastCollect = 0; static unsigned long lastCollect = 0;
void setup() { void setup() {
#ifdef ARDUINO_ARCH_ZEPHYR
Bridge.begin(); Bridge.begin();
delay(500); // let arduino-router finish boot chatter before we print delay(500); // let arduino-router finish boot chatter before we print
Monitor.println("[cultivar] ENV bridge starting...");
server.begin(); server.begin();
Monitor.println("[cultivar] TCP server ready on :5678"); DBG.println("[cultivar] TCP server ready on :5678");
#else
Serial.begin(115200);
#endif
Wire1.begin(); DBG.println("[cultivar] ENV bridge starting...");
Wire1.setClock(100000);
// I2C scan via Monitor (visible on Linux side) before sensor init Wire1.begin(); // needed for I2C scan + chip probe before env.begin()
Monitor.println("\n[cultivar] I2C scan on Wire1:");
// I2C scan — confirms bus and devices before sensor init
DBG.println("\n[cultivar] I2C scan on Wire1:");
int i2c_found = 0; int i2c_found = 0;
for (uint8_t addr = 1; addr < 127; addr++) { for (uint8_t addr = 1; addr < 127; addr++) {
Wire1.beginTransmission(addr); Wire1.beginTransmission(addr);
if (Wire1.endTransmission() == 0) { if (Wire1.endTransmission() == 0) {
Monitor.print(" 0x"); DBG.print(" 0x");
if (addr < 0x10) Monitor.print("0"); if (addr < 0x10) DBG.print("0");
Monitor.print(addr, HEX); DBG.print(addr, HEX);
if (addr == 0x76 || addr == 0x77) Monitor.print(" <- BME690"); if (addr == 0x76 || addr == 0x77) DBG.print(" <- BME690");
if (addr == 0x62) Monitor.print(" <- SCD43"); if (addr == 0x62) DBG.print(" <- SCD43");
if (addr == 0x6B) Monitor.print(" <- IMU"); if (addr == 0x6B) DBG.print(" <- IMU");
Monitor.println(); DBG.println();
i2c_found++; i2c_found++;
} }
} }
if (!i2c_found) Monitor.println(" No devices found — check wiring"); if (!i2c_found) DBG.println(" No devices found — check wiring");
Monitor.println("[cultivar] I2C scan done"); DBG.println("[cultivar] I2C scan done");
// Raw chip ID probe — BME690 register 0xD0 should return 0x61 // Raw chip ID probe — BME690 register 0xD0 should return 0x61
Wire1.beginTransmission(0x76); Wire1.beginTransmission(0x76);
@@ -66,47 +80,36 @@ void setup() {
Wire1.requestFrom((uint8_t)0x76, (uint8_t)1); Wire1.requestFrom((uint8_t)0x76, (uint8_t)1);
if (Wire1.available()) { if (Wire1.available()) {
uint8_t chip_id = Wire1.read(); uint8_t chip_id = Wire1.read();
Monitor.print("[cultivar] BME690 chip_id=0x"); DBG.print("[cultivar] BME690 chip_id=0x");
Monitor.print(chip_id, HEX); DBG.print(chip_id, HEX);
Monitor.println(chip_id == 0x61 ? " (OK)" : " (WRONG — expected 0x61)"); DBG.println(chip_id == 0x61 ? " (OK)" : " (WRONG — expected 0x61)");
} else { } else {
Monitor.println("[cultivar] BME690 chip_id read failed — no data"); DBG.println("[cultivar] BME690 chip_id read failed — no data");
} }
if (!env.begin(Wire1, SDA, SCL)) { if (!env.begin(Wire1, SDA, SCL)) {
Monitor.print("[WARN] BME690 init failed — bme_status="); DBG.print("[WARN] BME690 init failed — bme_status=");
Monitor.println(env.bme_status); DBG.println(env.bme_status);
} }
// env.begin() calls Wire1.begin() internally on Zephyr, resetting the clock.
// Re-apply 100 kHz so all sensor reads use the safe rate.
Wire1.setClock(100000);
Monitor.print("[cultivar] BME690="); DBG.print("[cultivar] BME690=");
Monitor.print(env.bme_ok ? "OK" : "FAIL"); DBG.print(env.bme_ok ? "OK" : "FAIL");
Monitor.print(" SCD43="); DBG.print(" SCD43=");
Monitor.println(env.scd4x_ok ? "OK" : "absent"); DBG.println(env.scd4x_ok ? "OK" : "absent");
// Start warmup clock at boot, not at first client connect // Start warmup clock at boot, not at first client connect
lastCollect = millis() - COLLECT_INTERVAL_MS + (env.scd4x_ok ? SCD43_WARMUP_MS : 5000UL); lastCollect = millis() - COLLECT_INTERVAL_MS + (env.scd4x_ok ? SCD43_WARMUP_MS : 5000UL);
} }
void loop() { void loop() {
#ifdef ARDUINO_ARCH_ZEPHYR
// UNO Q: block until daemon connects, then stream payloads until disconnect
BridgeTCPClient<JSON_BUF_SIZE> client = server.accept(); BridgeTCPClient<JSON_BUF_SIZE> client = server.accept();
if (!client.connected()) { delay(100); return; }
if (!client.connected()) { DBG.println("[cultivar] daemon connected");
delay(100);
return;
}
Monitor.println("[cultivar] daemon connected");
// Keep the connection alive across multiple collection cycles.
// The daemon uses readline() in a persistent loop — it expects
// multiple newline-delimited payloads on a single connection.
// We never call client.stop() here; the daemon owns the lifecycle.
// If the daemon disconnects, client.connected() goes false and we
// fall back to server.accept() on the next outer loop iteration.
while (client.connected()) { while (client.connected()) {
#endif
if (env.scd4x_ok) { if (env.scd4x_ok) {
CultivarCO2 co2; CultivarCO2 co2;
env.pollCO2(co2); env.pollCO2(co2);
@@ -118,20 +121,24 @@ void loop() {
CultivarEnvPayload payload; CultivarEnvPayload payload;
if (env.collect(payload)) { if (env.collect(payload)) {
env.toJSON(payload, jsonBuf, sizeof(jsonBuf)); env.toJSON(payload, jsonBuf, sizeof(jsonBuf));
#ifdef ARDUINO_ARCH_ZEPHYR
client.println(jsonBuf); client.println(jsonBuf);
Monitor.print(jsonBuf); #endif
Monitor.print("[cultivar] payload sent — "); DBG.println(jsonBuf);
Monitor.print("T="); Monitor.print(payload.ambient.temperature, 1); DBG.print("[cultivar] payload sent — ");
Monitor.print("C RH="); Monitor.print(payload.ambient.humidity, 1); DBG.print("T="); DBG.print(payload.ambient.temperature, 1);
Monitor.println("%"); DBG.print("C RH="); DBG.print(payload.ambient.humidity, 1);
DBG.println("%");
} else { } else {
Monitor.println("[WARN] collect failed — BME690 read returned false"); DBG.println("[WARN] collect failed — BME690 read returned false");
} }
} }
delay(100); delay(100);
}
Monitor.println("[cultivar] daemon disconnected — restarting server"); #ifdef ARDUINO_ARCH_ZEPHYR
}
DBG.println("[cultivar] daemon disconnected — restarting server");
server.begin(); server.begin();
#endif
} }