diff --git a/envisens/envisens_esp_fw/envisens_esp_fw.ino b/envisens/envisens_esp_fw/envisens_esp_fw.ino index 8d26b8a..c186f02 100644 --- a/envisens/envisens_esp_fw/envisens_esp_fw.ino +++ b/envisens/envisens_esp_fw/envisens_esp_fw.ino @@ -109,18 +109,21 @@ long lastSent = 0; bool published = false; bool forcePublish = false; -bool publish (String desc, char *topic, float val, float &val_r, int diff, bool force){ +bool publish (String desc, char *topic, float val, float &lastVal, float diff, bool force){ bool retval = false; - if (checkVariation(val, val_r, diff) or force) { - val_r = val; - Serial.print("New " + desc + ": "); - Serial.println(String(val).c_str()); - if (checkPlausibility(val, val_r, diff) or force) { + if (checkVariation(val, lastVal, diff) or force) { + lastVal = val; + Serial.println("New " + desc + ": " + String(val).c_str()); + if (checkPlausibility(val, lastVal, diff) or force) { + Serial.println("Value published"); client.publish(topic, String(val).c_str(), true); retval = true; } else { - Serial.println("** ERROR: Value out of bounds, not published **"); + Serial.print("** ERROR: Value out of bounds, not published. Last value :"); + Serial.println(String(lastVal).c_str()); } + } else { + Serial.println("Not enough variation for a publication"); } return retval; }