From b43b035bf5b38bedac7819b80544ef7138e56ee0 Mon Sep 17 00:00:00 2001 From: Daniel Jones Date: Wed, 9 Oct 2024 19:01:25 +1100 Subject: html changes create function to send post requests, use it for reset and toggling. --- src/index.h | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'src/index.h') diff --git a/src/index.h b/src/index.h index 3dc9d10..9a8edf3 100755 --- a/src/index.h +++ b/src/index.h @@ -202,14 +202,12 @@ const char index_html[] PROGMEM = R"rawliteral( --> - - -
- -
+
Customisation: +   +
Wireless (required for time sync):
  @@ -419,6 +417,32 @@ const char index_html[] PROGMEM = R"rawliteral( document.getElementById("datep").valueAsDate = new Date(); + function sendPostRequest(key, value) { + const data = { + [key]: value + }; + + fetch('/cmd', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(data) + }) + .then(response => { + if (!response.ok) { + throw new Error('Network response was not ok'); + } + return response.json(); + }) + .then(data => { + console.log('Success:', data); + }) + .catch((error) => { + console.error('Error:', error); + }); +} + -- cgit v1.2.3