I set up an environmental sensor based on the ESP8266 and the BME680 with the official Bosch library.
Unfortunately, I experience crashes as soon as my IAQ value reaches 255.
This is my code:
void loop() {
if (bme.run()) { // If new data is available
INTERVAL(120000) {
Serial.print("Activating Wifi: ");
Serial.println(millis());
WiFi.forceSleepWake();
delay(1);
startNetwork(ssid,password,device_name);
delay(1);
mqtt_controller.handle();
publishBME(pubsubclient,bme);
wait(100); // loop calling shorter delays() and the mqtt handle function
Serial.print("Deactivating Wifi: ");
Serial.println(millis());
WiFi.mode( WIFI_OFF );
WiFi.forceSleepBegin();
delay(1);
}
}
delay(1000);
}
const char* mqtt_topic_temp = MQTT_TOPIC_BASE "temp";
const char* mqtt_topic_hum = MQTT_TOPIC_BASE "hum";
const char* mqtt_topic_pres = MQTT_TOPIC_BASE "pres";
const char* mqtt_topic_gas = MQTT_TOPIC_BASE "gas";
const char* mqtt_topic_iaq = MQTT_TOPIC_BASE "iaq";
const char* mqtt_topic_siaq = MQTT_TOPIC_BASE "siaq";
const char* mqtt_topic_co2 = MQTT_TOPIC_BASE "co2";
const char* mqtt_topic_breathVoc = MQTT_TOPIC_BASE "breathVoc";
const char* mqtt_topic_time = MQTT_TOPIC_BASE "time";
char pubchar[20];
void publishBME(PubSubClient &pubsubclient, Bsec &bme) {
dtostrf(bme.temperature-1.3, 1, 2, pubchar);
if(!pubsubclient.publish(mqtt_topic_temp, pubchar, true)) {
Serial.println("Send error");
}
dtostrf(bme.humidity, 1, 2, pubchar);
if(!pubsubclient.publish(mqtt_topic_hum, pubchar, true)) {
Serial.println("Send error");
}
dtostrf(bme.pressure/1000.0, 1, 4, pubchar);
if(!pubsubclient.publish(mqtt_topic_pres, pubchar, true)) {
Serial.println("Send error");
}
dtostrf(bme.gasResistance/1000.0, 1, 3, pubchar);
if(!pubsubclient.publish(mqtt_topic_gas, pubchar, true)) {
Serial.println("Send error");
}
dtostrf(bme.staticIaq, 1, 3, pubchar);
if(!pubsubclient.publish(mqtt_topic_siaq, pubchar, true)) {
Serial.println("Send error");
}
dtostrf(bme.iaq, 1, 3, pubchar);
if(!pubsubclient.publish(mqtt_topic_iaq, pubchar, true)) {
Serial.println("Send error");
}
dtostrf(bme.co2Equivalent, 1, 3, pubchar);
if(!pubsubclient.publish(mqtt_topic_co2, pubchar, true)) {
Serial.println("Send error");
}
dtostrf(bme.breathVocEquivalent, 1, 3, pubchar);
if(!pubsubclient.publish(mqtt_topic_breathVoc, pubchar, true)) {
Serial.println("Send error");
}
itoa(millis(), pubchar, 10);
if(!pubsubclient.publish(mqtt_topic_time, pubchar, true)) {
Serial.println("Send error");
}
}
wait() is just loop calling shorter delays() and the mqtt handle function.
INTERVAL is this.
The wifi is only briefly activated for thermal reasons. I don't have the hardware connection for deep sleep on the PCB and I don't think it is necessary for thermal reasons.
bme.iaq is a float. 255 or 256 should not matter inside the MQTT string, so I would say the first AND latest point where anything could crash is dtostr. Is there anything I should know about that, or can I safely file an issue with the library?