Skip to content

Commit

Permalink
Fix rootTopic space padding
Browse files Browse the repository at this point in the history
  • Loading branch information
melkati committed Nov 21, 2021
1 parent 31c0b02 commit 33584b3
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 56 deletions.
88 changes: 64 additions & 24 deletions CO2_Gadget_Menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ result doSetActiveWIFI(eventMask e, navNode &nav, prompt &item) {

result doSetWiFiSSID(eventMask e, navNode &nav, prompt &item) {
#ifndef DEBUG_ARDUINOMENU
Serial.printf("Setting WiFi SSID to %s\n", tempWiFiSSID);
Serial.printf("Setting WiFi SSID to #%s#\n", tempWiFiSSID);
Serial.print("action1 event:");
Serial.println(e);
Serial.flush();
Expand All @@ -242,7 +242,7 @@ result doSetWiFiSSID(eventMask e, navNode &nav, prompt &item) {

result doSetWiFiPasswrd(eventMask e, navNode &nav, prompt &item) {
#ifndef DEBUG_ARDUINOMENU
Serial.printf("Setting WiFi Password to %s\n", tempWiFiPasswrd);
Serial.printf("Setting WiFi Password to #%s#\n", tempWiFiPasswrd);
Serial.print("action1 event:");
Serial.println(e);
Serial.flush();
Expand Down Expand Up @@ -270,7 +270,7 @@ MENU(wifiConfigMenu, "WIFI Config", doNothing, noEvent, wrapStyle

result doSetMQTTTopic(eventMask e, navNode &nav, prompt &item) {
#ifndef DEBUG_ARDUINOMENU
Serial.printf("Setting MQTT Topic to %s\n", tempMQTTTopic);
Serial.printf("Setting MQTT Topic to #%s#\n", tempMQTTTopic);
Serial.print("action1 event:");
Serial.println(e);
Serial.flush();
Expand All @@ -287,7 +287,7 @@ result doSetMQTTTopic(eventMask e, navNode &nav, prompt &item) {

result doSetMQTTClientId(eventMask e, navNode &nav, prompt &item) {
#ifndef DEBUG_ARDUINOMENU
Serial.printf("Setting MQTT Client Id to %s\n", tempMQTTClientId);
Serial.printf("Setting MQTT Client Id to #%s#\n", tempMQTTClientId);
Serial.print("action1 event:");
Serial.println(e);
Serial.flush();
Expand All @@ -304,7 +304,7 @@ result doSetMQTTClientId(eventMask e, navNode &nav, prompt &item) {

result doSetMQTTBrokerIP(eventMask e, navNode &nav, prompt &item) {
#ifndef DEBUG_ARDUINOMENU
Serial.printf("Setting MQTT Broker IP to: %s\n", tempMQTTBrokerIP);
Serial.printf("Setting MQTT Broker IP to: #%s#\n", tempMQTTBrokerIP);
Serial.print("action1 event:");
Serial.println(e);
Serial.flush();
Expand All @@ -321,7 +321,7 @@ result doSetMQTTBrokerIP(eventMask e, navNode &nav, prompt &item) {

result doSetMQTTUser(eventMask e, navNode &nav, prompt &item) {
#ifndef DEBUG_ARDUINOMENU
Serial.printf("Setting MQTT User to: %s\n", tempMQTTBrokerIP);
Serial.printf("Setting MQTT User to: #%s#\n", tempMQTTBrokerIP);
Serial.print("action1 event:");
Serial.println(e);
Serial.flush();
Expand All @@ -338,7 +338,7 @@ result doSetMQTTUser(eventMask e, navNode &nav, prompt &item) {

result doSetMQTTPass(eventMask e, navNode &nav, prompt &item) {
#ifndef DEBUG_ARDUINOMENU
Serial.printf("Setting MQTT Pass to: %s\n", tempMQTTPass);
Serial.printf("Setting MQTT Pass to: #%s#\n", tempMQTTPass);
Serial.print("action1 event:");
Serial.println(e);
Serial.flush();
Expand Down Expand Up @@ -526,32 +526,72 @@ String rightPad(String aString,uint8_t aLenght) {
}

void loadTempArraysWithActualValues() {
rootTopic = rightPad(rootTopic, 30);
rootTopic.toCharArray(tempMQTTTopic, rootTopic.length());
String paddedString;

mqttClientId = rightPad(mqttClientId, 30);
mqttClientId.toCharArray(tempMQTTClientId, mqttClientId.length());

mqttBroker = rightPad(mqttBroker, 30);
mqttBroker.toCharArray(tempMQTTBrokerIP, mqttBroker.length());
paddedString = rightPad(rootTopic, 30);
paddedString.toCharArray(tempMQTTTopic, rootTopic.length());
#ifndef DEBUG_ARDUINOMENU
Serial.print("tempMQTTTopic: #");
Serial.print(tempMQTTTopic);
Serial.println("#");
#endif

mqttUser = rightPad(mqttUser, 30);
mqttUser.toCharArray(tempMQTTUser, mqttUser.length());
paddedString = rightPad(mqttClientId, 30);
paddedString.toCharArray(tempMQTTClientId, mqttClientId.length());
#ifndef DEBUG_ARDUINOMENU
Serial.print("tempMQTTClientId: #");
Serial.print(tempMQTTClientId);
Serial.println("#");
#endif

mqttPass = rightPad(mqttPass, 30);
mqttPass.toCharArray(tempMQTTPass, mqttPass.length());
paddedString = rightPad(mqttBroker, 30);
paddedString.toCharArray(tempMQTTBrokerIP, mqttBroker.length());
#ifndef DEBUG_ARDUINOMENU
Serial.print("tempMQTTBrokerIP: #");
Serial.print(tempMQTTBrokerIP);
Serial.println("#");
#endif

paddedString = rightPad(mqttUser, 30);
paddedString.toCharArray(tempMQTTUser, mqttUser.length());
#ifndef DEBUG_ARDUINOMENU
Serial.print("tempMQTTUser: #");
Serial.print(tempMQTTUser);
Serial.println("#");
#endif

paddedString = rightPad(mqttPass, 30);
paddedString.toCharArray(tempMQTTPass, mqttPass.length());
#ifndef DEBUG_ARDUINOMENU
Serial.print("tempMQTTPass: #");
Serial.print(tempMQTTPass);
Serial.println("#");
#endif

wifiSSID = rightPad(wifiSSID, 30);
wifiSSID.toCharArray(tempWiFiSSID, wifiSSID.length());
paddedString = rightPad(wifiSSID, 30);
paddedString.toCharArray(tempWiFiSSID, wifiSSID.length());
#ifndef DEBUG_ARDUINOMENU
Serial.print("tempWiFiSSID: #");
Serial.print(tempWiFiSSID);
Serial.println("#");
#endif

paddedString = rightPad(wifiPass, 30);
paddedString.toCharArray(tempWiFiPasswrd, wifiPass.length());
#ifndef DEBUG_ARDUINOMENU
Serial.print("tempWiFiPasswrd: #");
Serial.print(tempWiFiPasswrd);
Serial.println("#");
#endif

wifiPass = rightPad(wifiPass, 30);
wifiPass.toCharArray(tempWiFiPasswrd, wifiPass.length());
paddedString = rightPad(hostName, 30);
paddedString.toCharArray(tempHostName, hostName.length());
#ifndef DEBUG_ARDUINOMENU
Serial.print("tempHostName: #");
Serial.print(tempHostName);
Serial.println("#");
#endif

hostName = rightPad(hostName, 30);
hostName.toCharArray(tempHostName, hostName.length());
fillTempIPAddress();
}

Expand Down
72 changes: 41 additions & 31 deletions CO2_Gadget_Preferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,33 @@ Preferences preferences;
void printPreferences() {
Serial.println("");
Serial.println("LOADED PREFERENCES FROM NVR:");
Serial.printf("customCalibrationValue: %d\n", customCalibrationValue);
Serial.printf("altidudeMeters:\t %d\n", altidudeMeters);
Serial.printf("autoSelfCalibration:\t %s\n",
Serial.printf("customCalibrationValue: #%d#\n", customCalibrationValue);
Serial.printf("altidudeMeters:\t #%d#\n", altidudeMeters);
Serial.printf("autoSelfCalibration:\t #%s#\n",
((autoSelfCalibration) ? "Enabled" : "Disabled"));
Serial.printf("co2OrangeRange:\t %d\n", co2OrangeRange);
Serial.printf("co2RedRange:\t %d\n", co2RedRange);
Serial.printf("TFTBrightness:\t %d\n", TFTBrightness);
Serial.printf("activeBLE is:\t%s\n", ((activeBLE) ? "Enabled" : "Disabled"));
Serial.printf("activeWIFI is:\t%s\n", ((activeWIFI) ? "Enabled" : "Disabled"));
Serial.printf("activeMQTT is:\t%s\n", ((activeMQTT) ? "Enabled" : "Disabled"));
Serial.printf("rootTopic:\t%s\n", rootTopic.c_str());
Serial.printf("batDischgd:\t %d\n", batteryDischargedMillivolts);
Serial.printf("batChargd:\t %d\n", batteryFullyChargedMillivolts);
Serial.printf("vRef:\t %d\n", vRef);
Serial.printf("mqttClientId:\t%s\n", mqttClientId.c_str());
Serial.printf("mqttBroker:\t%s\n", mqttBroker.c_str());
Serial.printf("mqttUser:\t%s\n", mqttUser.c_str());
Serial.printf("mqttPass:\t%s\n", mqttPass.c_str());
Serial.printf("tToDispOff:\t %d\n", timeToDisplayOff);
Serial.printf("dispOffOnExP:\t%s\n", ((displayOffOnExternalPower) ? "Enabled" : "Disabled"));
Serial.printf("wifiSSID:\t%s\n", wifiSSID.c_str());
Serial.printf("co2OrangeRange:\t #%d#\n", co2OrangeRange);
Serial.printf("co2RedRange:\t #%d#\n", co2RedRange);
Serial.printf("TFTBrightness:\t #%d#\n", TFTBrightness);
Serial.printf("activeBLE is:\t#%s#\n", ((activeBLE) ? "Enabled" : "Disabled"));
Serial.printf("activeWIFI is:\t#%s#\n", ((activeWIFI) ? "Enabled" : "Disabled"));
Serial.printf("activeMQTT is:\t#%s#\n", ((activeMQTT) ? "Enabled" : "Disabled"));
Serial.printf("rootTopic:\t#%s#\n", rootTopic.c_str());
Serial.printf("batDischgd:\t #%d#\n", batteryDischargedMillivolts);
Serial.printf("batChargd:\t #%d#\n", batteryFullyChargedMillivolts);
Serial.printf("vRef:\t #%d#\n", vRef);
Serial.printf("mqttClientId:\t#%s#\n", mqttClientId.c_str());
Serial.printf("mqttBroker:\t#%s#\n", mqttBroker.c_str());
Serial.printf("mqttUser:\t#%s#\n", mqttUser.c_str());
#ifndef WIFI_PRIVACY
Serial.printf("wifiPass:\t%s\n", wifiPass.c_str());
Serial.printf("mqttPass:\t#%s#\n", mqttPass.c_str());
#endif
Serial.printf("hostName:\t%s\n", hostName.c_str());
Serial.printf("tToDispOff:\t #%d#\n", timeToDisplayOff);
Serial.printf("dispOffOnExP:\t#%s#\n", ((displayOffOnExternalPower) ? "Enabled" : "Disabled"));
Serial.printf("wifiSSID:\t#%s#\n", wifiSSID.c_str());
#ifndef WIFI_PRIVACY
Serial.printf("wifiPass:\t#%s#\n", wifiPass.c_str());
#endif
Serial.printf("hostName:\t#%s#\n", hostName.c_str());
Serial.println("");
}

Expand Down Expand Up @@ -58,24 +60,32 @@ void initPreferences() {
vRef = preferences.getUInt("vRef", 930); // Looks like, due to a bug, 930 is a goos starting number for vRef
timeToDisplayOff = preferences.getUInt("tToDispOff", 0);
displayOffOnExternalPower = preferences.getBool("dispOffOnExP", false);
if (wifiSSID=="") {
wifiSSID = " ";
};
if (wifiPass == "") {
wifiPass = " ";
};
if (hostName == "") {
hostName = " ";
};
wifiSSID = preferences.getString("wifiSSID", wifiSSID).c_str();
wifiPass = preferences.getString("wifiPass", wifiPass).c_str();
hostName = preferences.getString("hostName", hostName).c_str();
rootTopic.trim();
mqttClientId.trim();
mqttBroker.trim();
mqttUser.trim();
mqttPass.trim();
wifiSSID.trim();
wifiPass.trim();
hostName.trim();
preferences.end();
printPreferences();
}

void putPreferences() {
Serial.println("Saving preferences to NVR");
rootTopic.trim();
mqttClientId.trim();
mqttBroker.trim();
mqttUser.trim();
mqttPass.trim();
wifiSSID.trim();
wifiPass.trim();
hostName.trim();
preferences.end();
preferences.begin("CO2-Gadget", false);
preferences.putUInt("customCalValue", customCalibrationValue);
preferences.putUInt("altidudeMeters", altidudeMeters);
Expand Down
8 changes: 8 additions & 0 deletions CO2_Gadget_WIFI.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ void initWifi() {
if (connectionRetries==maxConnectionRetries) {
activeWIFI = false;
Serial.printf("\nNot possible to connect to WiFi after %d tries.\nDisabling WiFi.\n", connectionRetries);
Serial.print("wifiSSID: #");
Serial.print(wifiSSID);
Serial.println("#");
#ifndef WIFI_PRIVACY
Serial.print("wifiPass: #");
Serial.print(wifiPass);
Serial.println("#");
#endif
return;
}
Serial.print(".");
Expand Down
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ build_flags =

-D MQTT_BROKER_SERVER="\"192.168.1.145"\"
-D CO2_GADGET_VERSION="\"0.3."\"
-D CO2_GADGET_REV="\"076"\"
-D CO2_GADGET_REV="\"077"\"
-D CORE_DEBUG_LEVEL=0
-D TTGO_TDISPLAY=1
-D ENABLE_PIN=27 ; Reserved for the future to enable the sensor
Expand Down

0 comments on commit 33584b3

Please sign in to comment.