Skip to content

Commit 84d5777

Browse files
committed
gemini added: pump test button, app restart button
1 parent 3c0aa1f commit 84d5777

5 files changed

Lines changed: 75 additions & 8 deletions

File tree

src/main.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,8 @@ void setup() {
433433
s_app.web_server().on("/api/plants", HTTP_GET, apiGetPlants);
434434
s_app.web_server().on("/api/wifi", HTTP_GET, apiGetWifi);
435435
s_app.web_server().on("/api/mqtt", HTTP_GET, apiGetMqtt);
436-
s_app.web_server().on("/api/moisture", apiGetMoisture);
437-
s_app.web_server().on("/api/status", apiGetStatus);
436+
s_app.web_server().on("/api/moisture", HTTP_GET, apiGetMoisture);
437+
s_app.web_server().on("/api/status", HTTP_GET, apiGetStatus);
438438

439439
{ // Add pump test json callback.
440440
AsyncCallbackJsonWebHandler* pumpTestHandler = new AsyncCallbackJsonWebHandler("/test/pump");
@@ -470,6 +470,11 @@ void setup() {
470470
s_app.web_server().addHandler(handler);
471471
}
472472

473+
s_app.web_server().on("/api/restart", HTTP_POST, [](AsyncWebServerRequest* request) {
474+
request->send(200, "text/plain", "restarting");
475+
s_app.tasks().runIn(1000, []() { ESP.restart(); });
476+
});
477+
473478
// Run the og3 application setup code.
474479
s_app.setup();
475480
}

svelte/package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

svelte/src/components/Sidebar.svelte

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script>
22
import { createEventDispatcher } from 'svelte';
3-
import { Droplet, Wifi, Radio, Home } from 'lucide-svelte';
3+
import { Droplet, Wifi, Radio, Home, RefreshCw } from 'lucide-svelte';
44
55
export let currentPage;
66
export let plants;
@@ -14,6 +14,17 @@
1414
1515
$: plantsList = $plants;
1616
$: status = $systemStatus;
17+
18+
async function restartDevice() {
19+
if (!confirm('Are you sure you want to restart the device?')) return;
20+
try {
21+
await fetch('/api/restart', { method: 'POST' });
22+
alert('Device is restarting...');
23+
} catch (err) {
24+
console.error('Error restarting:', err);
25+
alert('Failed to restart device');
26+
}
27+
}
1728
</script>
1829

1930
<aside class="sidebar">
@@ -57,6 +68,11 @@
5768

5869
<div class="nav-section">Device</div>
5970

71+
<button class="nav-button" on:click={restartDevice}>
72+
<RefreshCw size={20} />
73+
<span>Restart Device</span>
74+
</button>
75+
6076
<div>
6177
<p>Software: v{status.software}</p>
6278
<p>Hardware: board v{status.hardware}</p>

svelte/src/pages/HomePage.svelte

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373

7474
<div class="card-grid">
7575
{#each plantsList as plant}
76-
<div class="overview-card">
76+
<div class="overview-card" class:disabled-card={!plant.enabled}>
7777
<div class="card-header">
7878
<Droplet size={24} class="text-green-600" />
7979
<h3>{plant.name}</h3>
@@ -159,6 +159,11 @@
159159
border: 1px solid #e5e7eb;
160160
}
161161
162+
.overview-card.disabled-card {
163+
opacity: 0.7;
164+
background: #f9fafb;
165+
}
166+
162167
@media (max-width: 768px) {
163168
.overview-card {
164169
padding: 1rem;

svelte/src/pages/PlantConfigPage.svelte

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script>
2-
import { Save } from 'lucide-svelte';
2+
import { Save, Play } from 'lucide-svelte';
33
import MoistureGauge from '../components/MoistureGauge.svelte';
44
55
// API base URL
@@ -60,6 +60,29 @@
6060
saving = false;
6161
}
6262
}
63+
64+
async function testPump() {
65+
try {
66+
const response = await fetch('/test/pump', {
67+
method: 'POST',
68+
headers: { 'Content-Type': 'application/json' },
69+
body: JSON.stringify({ pumpId: plant.id, duration: 1000 })
70+
});
71+
72+
if (!response.ok) throw new Error('Network error');
73+
74+
const result = await response.json();
75+
if (!result.isOk) {
76+
throw new Error(result.message || 'Pump test failed');
77+
}
78+
79+
saveMessage = 'Pump test started (1s)';
80+
setTimeout(() => saveMessage = '', 3000);
81+
} catch (err) {
82+
console.error('Error testing pump:', err);
83+
saveMessage = `Error: ${err.message}`;
84+
}
85+
}
6386
</script>
6487

6588
<div class="page">
@@ -209,6 +232,15 @@
209232
/>
210233
<div class="form-hint">Maximum doses while watering and per day</div>
211234
</div>
235+
236+
<div class="form-group">
237+
<label class="form-label">Test Pump</label>
238+
<button class="btn btn-secondary" on:click={testPump}>
239+
<Play size={20} />
240+
Test (1s)
241+
</button>
242+
<div class="form-hint">Run pump for 1 second</div>
243+
</div>
212244
</div>
213245
</div>
214246

@@ -392,6 +424,15 @@
392424
cursor: not-allowed;
393425
}
394426
427+
.btn-secondary {
428+
background: #4b5563;
429+
color: white;
430+
}
431+
432+
.btn-secondary:hover {
433+
background: #374151;
434+
}
435+
395436
.save-message {
396437
margin-top: 1rem;
397438
padding: 0.75rem 1rem;

0 commit comments

Comments
 (0)