Skip to content
Permalink
Browse files

Tweak http update response

  • Loading branch information...
buxtronix committed Oct 2, 2015
1 parent a27f84f commit aa649b93939bcff6eed566f89b2be2212c2bca97
Showing with 15 additions and 10 deletions.
  1. +9 −8 esp8266-ledclock/esp8266-ledclock.ino
  2. +6 −2 esp8266-ledclock/mainPage.h
@@ -26,6 +26,7 @@ ESP8266WebServer server (80);
String clockName = "";
String w_ssid;
String w_psk;
String httpUpdateResponse;
long timezone;
IPAddress timeServer(129, 6, 15, 28);
time_t prevDisplay = 0;
@@ -41,38 +42,38 @@ void handleRoot() {
s.replace("@@NTPINT@@", String(syncInterval));
s.replace("@@SYNCSTATUS@@", timeStatus() == timeSet ? "OK" : "Overdue");
s.replace("@@CLOCKNAME@@", clockName);
s.replace("@@UPDATERESPONSE@@", httpUpdateResponse);
httpUpdateResponse = "";
server.send(200, "text/html", s);
}

void handleForm() {
String response = "The following was changed:\r\n\r\n";
String update_wifi = server.arg("update_wifi");
String t_ssid = server.arg("ssid");
String t_psk = server.arg("psk");
timeServer = parseIP(server.arg("ntpsrv"));
if (update_wifi == "1") {
response += "Wifi SSID set to: " + t_ssid + "\r\n";
response += "Wifi PSK set to : " + t_psk + "\r\n";
w_ssid = t_ssid;
w_psk = t_psk;
}
String tz = server.arg("timezone");

if (tz.length()) {
response += "The timezone set to: " + tz + "h\r\n";
timezone = tz.toInt();
}
response += "The NTP server is set to: " + ipToString(timeServer) + "\r\n";
setTime(getNtpTime());

String syncInt = server.arg("ntpint");
syncInterval = syncInt.toInt();
response += "The NTP sync interval is: " + syncInt + "s\r\n";

clockName = server.arg("clockname");
response += "Clock name is: " + clockName;

server.send(200, "text/plain", response);
httpUpdateResponse = "The configuration was updated.";

//server.send(200, "text/plain", response);
server.sendHeader("Location", "/");
server.send(302, "text/plain", "Moved");
//handleRoot();
saveSettings();
if (update_wifi == "1") {
delay(500);
@@ -7,10 +7,14 @@ const char MAIN_page[] PROGMEM = R"=====(
body {font-family: helvetica,arial,sans-serif;}
table {border-collapse: collapse; border: 1px solid black;}
td {padding: 0.25em;}
.title { font-size: 2em; font-weight: bold;}
.name {padding: 0.5em;}
.heading {font-weight: bold; background: #c0c0c0; padding: 0.5em;}
.update {color: #dd3333; font-size: 0.75em;}
</style>
</head>
<h1>NTP Clock</h1>
<div class=title>NTP Clock</div>
<div class=name>Location: @@CLOCKNAME@@</div>
<form method="post" action="/form">
<table>
<tr><td colspan=2 class=heading>Status</td></tr>
@@ -31,7 +35,7 @@ const char MAIN_page[] PROGMEM = R"=====(
<p/>
<input type="submit" value="Update">
</form>
<div class="update">@@UPDATERESPONSE@@</div>
</html>
)=====";

0 comments on commit aa649b9

Please sign in to comment.
You can’t perform that action at this time.