Publish refactoring (#298)
* factoring of the publishing function * integration of json publishing to MQTT * receiving and transcode json messages from mqtt * replace the TRACE runtime condition by a buildtime one so as to decrease program size * remove retainFlag parameter not necessary for the moment * Increase the scope of tests for arduino mega and esp32 * Update arduinojson library to 5.13.3 * add macros to choose between simple or json publishing or both * differentiate build test for ATmega2560 * correct wrong sprintf definition * change IDE version for continuous integration * let default warning level in arduino ide * correct pins for ESP32 * reorganize user_config
This commit is contained in:
1 parent
f77df7347f
commit
d8dba15a81
182 files changed
+2701
-20768
No files matched your search
+11
-18
@@ -108,6 +108,7 @@ void MeasureTempHumAndPressure()
|
||||
{
|
||||
|
||||
if (millis() > (timebme280 + TimeBetweenReadingbme280)) {
|
||||
|
||||
timebme280 = millis();
|
||||
static float persisted_bme_tempc;
|
||||
static float persisted_bme_tempf;
|
||||
@@ -127,38 +128,33 @@ void MeasureTempHumAndPressure()
|
||||
if (isnan(BmeTempC) || isnan(BmeTempF) || isnan(BmeHum) || isnan(BmePa) || isnan(BmeAltiM) || isnan(BmeAltiFt)) {
|
||||
trc(F("Failed to read from Weather Sensor BME280!"));
|
||||
}else{
|
||||
trc(F("Creating BME280 buffer"));
|
||||
StaticJsonBuffer<JSON_MSG_BUFFER> jsonBuffer;
|
||||
JsonObject& BME280data = jsonBuffer.createObject();
|
||||
// Generate Temperature in degrees C
|
||||
if(BmeTempC != persisted_bme_tempc || bme280_always){
|
||||
trc(F("Sending Degrees C to MQTT"));
|
||||
trc(BmeTempC);
|
||||
client.publish(TEMPBMEC, String(BmeTempC).c_str());
|
||||
BME280data.set("tempc", (float)BmeTempC);
|
||||
}else{
|
||||
trc(F("Same Degrees C don't send it"));
|
||||
}
|
||||
|
||||
// Generate Temperature in degrees F
|
||||
if(BmeTempF != persisted_bme_tempf || bme280_always){
|
||||
trc(F("Sending Degrees F to MQTT"));
|
||||
trc(BmeTempF);
|
||||
client.publish(TEMPBMEF,String(BmeTempF).c_str());
|
||||
BME280data.set("tempf", (float)BmeTempF);
|
||||
}else{
|
||||
trc(F("Same Degrees F don't send it"));
|
||||
}
|
||||
|
||||
// Generate Humidity in percent
|
||||
if(BmeHum != persisted_bme_hum || bme280_always){
|
||||
trc(F("Sending Humidity to MQTT"));
|
||||
trc(BmeHum);
|
||||
client.publish(HUMBME, String(BmeHum).c_str());
|
||||
BME280data.set("hum", (float)BmeHum);
|
||||
}else{
|
||||
trc(F("Same Humidity don't send it"));
|
||||
}
|
||||
|
||||
// Generate Pressure in Pa
|
||||
if(BmePa != persisted_bme_pa || bme280_always){
|
||||
trc(F("Sending Pressure to MQTT"));
|
||||
trc(BmePa);
|
||||
client.publish(PRESSBME, String(BmePa).c_str());
|
||||
BME280data.set("pa", (float)BmePa);
|
||||
}else{
|
||||
trc(F("Same Pressure don't send it"));
|
||||
}
|
||||
@@ -166,21 +162,18 @@ void MeasureTempHumAndPressure()
|
||||
// Generate Altitude in Meter
|
||||
if(BmeAltiM != persisted_bme_altim || bme280_always){
|
||||
trc(F("Sending Altitude Meter to MQTT"));
|
||||
trc(BmeAltiM);
|
||||
client.publish(ALTIBMEM, String(BmeAltiM).c_str());
|
||||
BME280data.set("altim", (float)BmeAltiM);
|
||||
}else{
|
||||
trc(F("Same Altitude Meter don't send it"));
|
||||
}
|
||||
|
||||
// Generate Altitude in Feet
|
||||
if(BmeAltiFt != persisted_bme_altift || bme280_always){
|
||||
trc(F("Sending Altitude Feet to MQTT"));
|
||||
trc(BmeAltiFt);
|
||||
client.publish(ALTIBMEFT, String(BmeAltiFt).c_str());
|
||||
BME280data.set("altift", (float)BmeAltiFt);
|
||||
}else{
|
||||
trc(F("Same Altitude Feet don't send it"));
|
||||
}
|
||||
|
||||
if(BME280data.size()>0) pub(BME,BME280data);
|
||||
}
|
||||
persisted_bme_tempc = BmeTempC;
|
||||
persisted_bme_tempf = BmeTempF;
|
||||
|
||||
Reference in new issue
Block a user