Hallo,
ich habe versucht meinen BME680 zum laufen zu bringen aber nach nun mehr
als 4h bleibt der IAQ Wert immer noch bei dem initial start als aauch
die accuracy. Was amche ich falsch....? Hier ist mein code
#define STATE_SAVE_PERIOD UINT32_C(360 * 60 * 1000) // 360 minutes - 4 times a day
#include <WiFi.h>
#include <ESPmDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <EEPROM.h>
#include "bsec.h"
/* Configure the BSEC library with information about the sensor
18v/33v = Voltage at Vdd. 1.8V or 3.3V
3s/300s = BSEC operating mode, BSEC_SAMPLE_RATE_LP or BSEC_SAMPLE_RATE_ULP
4d/28d = Operating age of the sensor in days
generic_18v_3s_4d
generic_18v_3s_28d
generic_18v_300s_4d
generic_18v_300s_28d
generic_33v_3s_4d
generic_33v_3s_28d
generic_33v_300s_4d
generic_33v_300s_28d
*/
const uint8_t bsec_config_iaq[] = {
#include "config/generic_33v_3s_4d/bsec_iaq.txt"
};
// Helper functions declarations
void checkIaqSensorStatus(void);
void errLeds(void);
void loadState(void);
void updateState(void);
// Create an object of the class Bsec
Bsec iaqSensor;
uint8_t bsecState[BSEC_MAX_STATE_BLOB_SIZE] = {0};
uint16_t stateUpdateCounter = 0;
String output;
const char* ssid = "xxxxx";
const char* password = "xxxxx";
uint8_t i;
bool ConnectionEstablished; // Flag for successfully handled connection
#define MAX_TELNET_CLIENTS 2
WiFiServer TelnetServer(23);
WiFiClient TelnetClient[MAX_TELNET_CLIENTS];
void setup()
{
Serial.begin(115200);
Serial.println("Over The Air and Telnet Example");
Serial.printf("Sketch size: %u\n", ESP.getSketchSize());
Serial.printf("Free size: %u\n", ESP.getFreeSketchSpace());
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Wire.begin();
iaqSensor.begin(BME680_I2C_ADDR_SECONDARY, Wire);
output = "\nBSEC library version " + String(iaqSensor.version.major) + "." + String(iaqSensor.version.minor) + "." + String(iaqSensor.version.major_bugfix) + "." + String(iaqSensor.version.minor_bugfix);
Serial.println(output);
checkIaqSensorStatus();
iaqSensor.setConfig(bsec_config_iaq);
checkIaqSensorStatus();
loadState();
bsec_virtual_sensor_t sensorList[10] = {
BSEC_OUTPUT_RAW_TEMPERATURE,
BSEC_OUTPUT_RAW_PRESSURE,
BSEC_OUTPUT_RAW_HUMIDITY,
BSEC_OUTPUT_RAW_GAS,
BSEC_OUTPUT_IAQ,
BSEC_OUTPUT_STATIC_IAQ,
BSEC_OUTPUT_CO2_EQUIVALENT,
BSEC_OUTPUT_BREATH_VOC_EQUIVALENT,
BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_TEMPERATURE,
BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_HUMIDITY,
};
iaqSensor.updateSubscription(sensorList, 10, BSEC_SAMPLE_RATE_LP);
checkIaqSensorStatus();
// ... Give ESP 10 seconds to connect to station.
unsigned long startTime = millis();
Serial.print("Waiting for wireless connection ");
while (WiFi.status() != WL_CONNECTED && millis() - startTime < 10000)
{
delay(200);
Serial.print(".");
}
Serial.println();
while (WiFi.status() != WL_CONNECTED)
{
Serial.println("Connection Failed! Rebooting...");
delay(3000);
ESP.restart();
}
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
Serial.println("Starting Telnet server");
TelnetServer.begin();
TelnetServer.setNoDelay(true);
pinMode(LED_BUILTIN, OUTPUT); // initialize onboard LED as output
// OTA
// Port defaults to 8266
// ArduinoOTA.setPort(8266);
// Hostname defaults to esp8266-[ChipID]
// ArduinoOTA.setHostname("myesp8266");
// No authentication by default
ArduinoOTA.setPassword((const char *)"1234");
ArduinoOTA.onStart([]() {
Serial.println("Start");
});
ArduinoOTA.onEnd([]() {
Serial.println("\nEnd");
});
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
});
ArduinoOTA.onError([](ota_error_t error) {
Serial.printf("Error[%u]: ", error);
if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
else if (error == OTA_END_ERROR) Serial.println("End Failed");
});
ArduinoOTA.begin();
}
void loop() {
//ArduinoOTA.handle(); // Wait for OTA connection
blinkLED(); // Blink LED
Telnet(); // Handle telnet connections
unsigned long time_trigger = millis();
if (iaqSensor.run()) { // If new data is available
output = "time=" +String(time_trigger);
output += ", rawTemperature=" + String(iaqSensor.rawTemperature);
output += ", pressure=" + String(iaqSensor.pressure);
output += ", rawHumidity=" + String(iaqSensor.rawHumidity);
output += ", gasResistance=" + String(iaqSensor.gasResistance);
output += ", iaq=" + String(iaqSensor.iaq);
output += ", iaqAccuracy=" + String(iaqSensor.iaqAccuracy);
output += ", temperature=" + String(iaqSensor.temperature);
output += ", humidity=" + String(iaqSensor.humidity);
output += ", staticIaq=" + String(iaqSensor.staticIaq);
output += ", co2Equivalent=" + String(iaqSensor.co2Equivalent);
output += ", breathVocEquivalent=" + String(iaqSensor.breathVocEquivalent);
TelnetMsg(output);
} else {
checkIaqSensorStatus();
}
delay(30000);
}
void TelnetMsg(String text)
{
for(i = 0; i < MAX_TELNET_CLIENTS; i++)
{
if (TelnetClient[i] || TelnetClient[i].connected())
{
TelnetClient[i].println(text);
}
}
delay(10); // to avoid strange characters left in buffer
}
void Telnet()
{
// Cleanup disconnected session
for(i = 0; i < MAX_TELNET_CLIENTS; i++)
{
if (TelnetClient[i] && !TelnetClient[i].connected())
{
Serial.print("Client disconnected ... terminate session "); Serial.println(i+1);
TelnetClient[i].stop();
}
}
// Check new client connections
if (TelnetServer.hasClient())
{
ConnectionEstablished = false; // Set to false
for(i = 0; i < MAX_TELNET_CLIENTS; i++)
{
// Serial.print("Checking telnet session "); Serial.println(i+1);
// find free socket
if (!TelnetClient[i])
{
TelnetClient[i] = TelnetServer.available();
Serial.print("New Telnet client connected to session "); Serial.println(i+1);
TelnetClient[i].flush(); // clear input buffer, else you get strange characters
TelnetClient[i].println("Welcome!");
TelnetClient[i].print("Millis since start: ");
TelnetClient[i].println(millis());
TelnetClient[i].print("Free Heap RAM: ");
TelnetClient[i].println(ESP.getFreeHeap());
TelnetClient[i].println("----------------------------------------------------------------");
ConnectionEstablished = true;
break;
}
else
{
// Serial.println("Session is in use");
}
}
if (ConnectionEstablished == false)
{
Serial.println("No free sessions ... drop connection");
TelnetServer.available().stop();
// TelnetMsg("An other user cannot connect ... MAX_TELNET_CLIENTS limit is reached!");
}
}
for(i = 0; i < MAX_TELNET_CLIENTS; i++)
{
if (TelnetClient[i] && TelnetClient[i].connected())
{
if(TelnetClient[i].available())
{
//get data from the telnet client
while(TelnetClient[i].available())
{
Serial.write(TelnetClient[i].read());
}
}
}
}
}
////////////////////////////////////////////////////////////////////////////////////////
// Blink function with telnet output
const long interval = 2000;
int ledState = LOW;
unsigned long previousMillis = 0;
void blinkLED()
{
unsigned long currentMillis = millis();
// if enough millis have elapsed
if (currentMillis - previousMillis >= interval)
{
previousMillis = currentMillis;
// toggle the LED
ledState = !ledState;
digitalWrite(LED_BUILTIN, ledState);
String ledStateMsg = "LED State = ";
ledStateMsg += ledState;
TelnetMsg(ledStateMsg);
}
}
// Helper function definitions
void checkIaqSensorStatus(void)
{
if (iaqSensor.status != BSEC_OK) {
if (iaqSensor.status < BSEC_OK) {
output = "BSEC error code : " + String(iaqSensor.status);
Serial.println(output);
for (;;)
errLeds(); /* Halt in case of failure */
} else {
output = "BSEC warning code : " + String(iaqSensor.status);
Serial.println(output);
}
}
if (iaqSensor.bme680Status != BME680_OK) {
if (iaqSensor.bme680Status < BME680_OK) {
output = "BME680 error code : " + String(iaqSensor.bme680Status);
Serial.println(output);
for (;;)
errLeds(); /* Halt in case of failure */
} else {
output = "BME680 warning code : " + String(iaqSensor.bme680Status);
Serial.println(output);
}
}
iaqSensor.status = BSEC_OK;
}
void errLeds(void)
{
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
delay(100);
digitalWrite(LED_BUILTIN, LOW);
delay(100);
}
void loadState(void)
{
if (EEPROM.read(0) == BSEC_MAX_STATE_BLOB_SIZE) {
// Existing state in EEPROM
Serial.println("Reading state from EEPROM");
for (uint8_t i = 0; i < BSEC_MAX_STATE_BLOB_SIZE; i++) {
bsecState[i] = EEPROM.read(i + 1);
Serial.println(bsecState[i], HEX);
}
iaqSensor.setState(bsecState);
checkIaqSensorStatus();
} else {
// Erase the EEPROM with zeroes
Serial.println("Erasing EEPROM");
for (uint8_t i = 0; i < BSEC_MAX_STATE_BLOB_SIZE + 1; i++)
EEPROM.write(i, 0);
EEPROM.commit();
}
}
void updateState(void)
{
bool update = false;
/* Set a trigger to save the state. Here, the state is saved every STATE_SAVE_PERIOD with the first state being saved once the algorithm achieves full calibration, i.e. iaqAccuracy = 3 */
if (stateUpdateCounter == 0) {
if (iaqSensor.iaqAccuracy >= 3) {
update = true;
stateUpdateCounter++;
}
} else {
/* Update every STATE_SAVE_PERIOD milliseconds */
if ((stateUpdateCounter * STATE_SAVE_PERIOD) < millis()) {
update = true;
stateUpdateCounter++;
}
}
if (update) {
iaqSensor.getState(bsecState);
checkIaqSensorStatus();
Serial.println("Writing state to EEPROM");
for (uint8_t i = 0; i < BSEC_MAX_STATE_BLOB_SIZE ; i++) {
EEPROM.write(i + 1, bsecState[i]);
Serial.println(bsecState[i], HEX);
}
EEPROM.write(0, BSEC_MAX_STATE_BLOB_SIZE);
EEPROM.commit();
}
}