Skip to content

Commit

Permalink
chore: Add mqttShowInConsole preference to CO2_Gadget_Preferences.h a…
Browse files Browse the repository at this point in the history
…nd logic to show or not show
  • Loading branch information
melkati committed May 29, 2024
1 parent c83652d commit 0e5e038
Show file tree
Hide file tree
Showing 14 changed files with 203 additions and 161 deletions.
1 change: 1 addition & 0 deletions CO2_Gadget.ino
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ bool mqttDiscoverySent = false;
uint16_t timeBetweenMQTTPublish = 60; // Time in seconds between MQTT transmissions
uint16_t timeToKeepAliveMQTT = 3600; // Maximum time in seconds between MQTT transmissions - Default: 1 Hour
uint64_t lastTimeMQTTPublished = 0; // Time of last MQTT transmission
bool mqttShowInConsole = false;

// ESP-NOW options
bool activeESPNOW = false;
Expand Down
8 changes: 4 additions & 4 deletions CO2_Gadget_MQTT.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void publishIntMQTT(String topic, int64_t payload) {
#ifdef SUPPORT_MQTT
dtostrf(payload, 0, 0, charPublish);
topic = rootTopic + topic;
if (!inMenu) {
if (!inMenu && mqttShowInConsole) {
Serial.printf("-->[MQTT] Publishing %d to ", payload);
Serial.println("topic: " + topic);
}
Expand All @@ -103,7 +103,7 @@ void publishFloatMQTT(String topic, float payload) {
#ifdef SUPPORT_MQTT
dtostrf(payload, 0, 2, charPublish);
topic = rootTopic + topic;
if (!inMenu) {
if (!inMenu && mqttShowInConsole) {
Serial.printf("-->[MQTT] Publishing %.0f to ", payload);
Serial.println("topic: " + topic);
}
Expand All @@ -114,7 +114,7 @@ void publishFloatMQTT(String topic, float payload) {
void publishStrMQTT(String topic, String payload) {
#ifdef SUPPORT_MQTT
topic = rootTopic + topic;
if (!inMenu) {
if (!inMenu && mqttShowInConsole) {
Serial.printf("-->[MQTT] Publishing %s to ", payload.c_str());
Serial.println("topic: " + topic);
}
Expand All @@ -124,7 +124,7 @@ void publishStrMQTT(String topic, String payload) {

void publishStrDiscoveryMQTT(String topic, String payload, int qos) {
#ifdef SUPPORT_MQTT
if (!inMenu) {
if (!inMenu && mqttShowInConsole) {
// Serial.printf("-->[MQTT] Publishing discovery %s to ", payload.c_str());
// Serial.println("topic: " + topic);
}
Expand Down
10 changes: 8 additions & 2 deletions CO2_Gadget_Preferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ void printActualSettings() {
Serial.println("-->[PREF] batDischgd:\t #" + String(batteryDischargedMillivolts) + "#");
Serial.println("-->[PREF] batChargd:\t #" + String(batteryFullyChargedMillivolts) + "#");
Serial.println("-->[PREF] vRef:\t #" + String(vRef) + "#");
Serial.println("-->[PREF] mqttClientId:\t#" + mqttClientId + "#");
Serial.println("-->[PREF] mqttClientId:\t#" + mqttClientId + "#");
Serial.println("-->[PREF] mqttShowInConsole:\t#" + String(mqttShowInConsole ? "Enabled" : "Disabled") + "# (" + String(mqttShowInConsole) + ")");
Serial.println("-->[PREF] mqttBroker:\t#" + mqttBroker + "#");
Serial.println("-->[PREF] mqttUser:\t#" + mqttUser + "#");
#ifndef WIFI_PRIVACY
Expand Down Expand Up @@ -283,6 +284,7 @@ void initPreferences() {
activeOTA = preferences.getBool("activeOTA", activeOTA);
rootTopic = preferences.getString("rootTopic", rootTopic);
mqttClientId = preferences.getString("mqttClientId", mqttClientId);
mqttShowInConsole = preferences.getBool("mqttShowInCon", false);
mqttBroker = preferences.getString("mqttBroker", mqttBroker).c_str();
mqttUser = preferences.getString("mqttUser", mqttUser).c_str();
mqttPass = preferences.getString("mqttPass", mqttPass).c_str();
Expand Down Expand Up @@ -413,6 +415,7 @@ void putPreferences() {
preferences.putUInt("batChargd", batteryFullyChargedMillivolts);
preferences.putUInt("vRef", vRef);
preferences.putString("mqttClientId", mqttClientId);
preferences.putBool("mqttShowInCon", mqttShowInConsole);
preferences.putString("mqttBroker", mqttBroker);
preferences.putString("mqttUser", mqttUser);
preferences.putString("mqttPass", mqttPass);
Expand Down Expand Up @@ -517,6 +520,7 @@ String getCO2GadgetVersionAsJson() {
// doc["batChargd"] = preferences.getInt("batChargd", 4200);
// doc["vRef"] = preferences.getInt("vRef", 930);
// doc["mqttClientId"] = preferences.getString("mqttClientId", mqttClientId);
// doc["mqttShowInCon"] = preferences.getBool("mqttShowInCon", false);
// doc["mqttBroker"] = preferences.getString("mqttBroker", mqttBroker);
// doc["mqttUser"] = preferences.getString("mqttUser", mqttUser);
// // doc["mqttPass"] = preferences.getString("mqttPass", mqttPass);
Expand Down Expand Up @@ -601,6 +605,7 @@ String getActualSettingsAsJson(bool includePasswords = false) {
doc["batChargd"] = batteryFullyChargedMillivolts;
doc["vRef"] = vRef;
doc["mqttClientId"] = mqttClientId;
doc["mqttShowInCon"] = mqttShowInConsole;
doc["mqttBroker"] = mqttBroker;
doc["mqttUser"] = mqttUser;
// if includePasswords is false, do not include the password
Expand Down Expand Up @@ -727,8 +732,9 @@ bool handleSavePreferencesFromJSON(String jsonPreferences) {
battery.begin(vRef, voltageDividerRatio, &asigmoidal);
readBatteryVoltage();
}
vRef = JsonDocument["vRef"];
mqttShowInConsole = JsonDocument["mqttShowInCon"];
mqttClientId = JsonDocument["mqttClientId"].as<String>().c_str();
mqttShowInConsole = JsonDocument["mqttShowInCon"];
mqttBroker = JsonDocument["mqttBroker"].as<String>().c_str();
mqttUser = JsonDocument["mqttUser"].as<String>().c_str();
timeToDisplayOff = JsonDocument["tToDispOff"];
Expand Down
8 changes: 4 additions & 4 deletions CO2_Gadget_WIFI.h
Original file line number Diff line number Diff line change
Expand Up @@ -1000,10 +1000,10 @@ void initWebServer() {

server.on("/captiveportal.js", HTTP_GET, [](AsyncWebServerRequest *request) {
if (request != nullptr) {
// /** GZIPPED CONTENT ***/
// AsyncWebServerResponse *response = request->beginResponse(SPIFFS, "/captiveportal.js.gz", "application/javascript");
// response->addHeader("Content-Encoding", "gzip");
AsyncWebServerResponse *response = request->beginResponse(SPIFFS, "/captiveportal.js", "application/javascript");
/** GZIPPED CONTENT ***/
AsyncWebServerResponse *response = request->beginResponse(SPIFFS, "/captiveportal.js.gz", "application/javascript");
response->addHeader("Content-Encoding", "gzip");
// AsyncWebServerResponse *response = request->beginResponse(SPIFFS, "/captiveportal.js", "application/javascript");
request->send(response);
} else {
Serial.println("---> [WiFi] Error: request is null");
Expand Down
Binary file modified data/captiveportal.js.gz
Binary file not shown.
Binary file modified data/index.html.gz
Binary file not shown.
Binary file modified data/main.js.gz
Binary file not shown.
Binary file modified data/ota.html.gz
Binary file not shown.
Loading

0 comments on commit 0e5e038

Please sign in to comment.