Skip to content

Commit

Permalink
Add mainDeviceSelected field to CO2_Gadget_WIFI.h and update status.h…
Browse files Browse the repository at this point in the history
…tml to display the selected sensor
  • Loading branch information
melkati committed May 10, 2024
1 parent dcb61fe commit a5e4130
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions CO2_Gadget_Preferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ void initPreferences() {
displayReverse = preferences.getBool("displayReverse", false);
showFahrenheit = preferences.getBool("showFahrenheit", false);
measurementInterval = preferences.getUInt("measInterval", 10);
if (sampleInterval < 10) sampleInterval = 2; // Minimum sample interval is 2 seconds
sampleInterval = preferences.getUInt("sampInterval", 60);
outputsModeRelay = preferences.getBool("outModeRelay", false);
channelESPNow = preferences.getUInt("channelESPNow", ESPNOW_WIFI_CH);
Expand Down
3 changes: 2 additions & 1 deletion CO2_Gadget_WIFI.h
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,8 @@ void WiFiStationDisconnected(WiFiEvent_t event, WiFiEventInfo_t info) {
}

String getCO2GadgetStatusAsJson() {
StaticJsonDocument<512> doc;
StaticJsonDocument<512> doc;
doc["mainDeviceSelected"] = mainDeviceSelected;
doc["CO2"] = co2;
doc["Temperature"] = temp;
doc["Humidity"] = hum;
Expand Down
9 changes: 8 additions & 1 deletion data/status.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
</div>

<div class="content">
<h1>Status Information</h1>
<div class="status-item" id="mainDeviceSelectedItem">
<span class="status-label">Sensor Selected:</span> <span id="mainDeviceSelected"></span>
</div>
<div class="status-item" id="co2Item">
<span class="status-label">CO2:</span> <span id="co2"></span>
</div>
Expand Down Expand Up @@ -136,6 +138,11 @@ <h1>Status Information</h1>
.then(data => {
console.log('Fetching data successful!');
// Update DOM with status data
if (data.mainDeviceSelected !== undefined) {
document.getElementById('mainDeviceSelected').textContent = data.mainDeviceSelected;
} else {
document.getElementById('mainDeviceSelected').style.display = 'none';
}
if (data.CO2 !== undefined) {
document.getElementById('co2').textContent = data.CO2;
} else {
Expand Down

0 comments on commit a5e4130

Please sign in to comment.