Skip to content

Commit

Permalink
fix clockwise update bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthas committed Apr 2, 2023
1 parent 56d4b60 commit d69abef
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 40 deletions.
17 changes: 5 additions & 12 deletions firmware/lib/cw-commons/CWWebServer.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#pragma once

#define HTTP_GET_SIZE 3
#define HTTP_POST_SIZE 4

#include <WiFi.h>
#include <CWPreferences.h>
#include "StatusController.h"
Expand Down Expand Up @@ -47,8 +44,6 @@ struct ClockwiseWebServer

if (c == '\n')
{
//Serial.println(httpBuffer);

uint8_t method_pos = httpBuffer.indexOf(' ');
uint8_t path_pos = httpBuffer.indexOf(' ', method_pos + 1);

Expand All @@ -57,7 +52,7 @@ struct ClockwiseWebServer
String key = "";
String value = "";

if (method == "POST")
if (method == "POST" && path.indexOf('?') > 0)
{
key = path.substring(path.indexOf('?') + 1, path.indexOf('='));
value = path.substring(path.indexOf('=') + 1, ' ');
Expand All @@ -77,19 +72,17 @@ struct ClockwiseWebServer

void processRequest(WiFiClient client, String method, String path, String key, String value)
{

// Serial.println(method);
// Serial.println(path);
// Serial.println(key);
// Serial.println(value);

if (method == "GET" && path == "/") {
client.println("HTTP/1.0 200 OK");
client.println("Content-Type: text/html");
client.println();
client.println(SETTINGS_PAGE);
} else if (method == "GET" && path == "/get") {
getCurrentSettings(client);
} else if (method == "POST" && path == "/restart") {
client.println("HTTP/1.0 204 No Content");
delay(1000);
ESP.restart();
} else if (method == "POST" && path == "/set") {
ClockwiseParams::getInstance()->load();
//a baby seal has died due this ifs
Expand Down
23 changes: 15 additions & 8 deletions firmware/lib/cw-commons/SettingsWebPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,24 @@ const char SETTINGS_PAGE[] PROGMEM = R""""(
href="https://github.com/jnthas/clockwise/raw/gh-pages/static/images/favicon.png">

<body>
<div class="w3-container" style="background-image: linear-gradient(120deg, #155799, #159957)">
<div class="w3-container" style="background-image: linear-gradient(120deg, #155799, #159957);">
<img class="w3-animate-zoom w3-padding w3-image"
src="https://github.com/jnthas/clockwise/raw/gh-pages/static/images/clockwise_logo_not.png" alt="Logo"
style="width:50%;max-width:600px">
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOcAAAA4CAYAAAAGnO/aAAABhGlDQ1BJQ0MgcHJvZmlsZQAAKJF9kT1Iw0AcxV/TilIqDnYQcchQxcGCqIijVqEIFUKt0KqDyaVf0KQhSXFxFFwLDn4sVh1cnHV1cBUEwQ8QVxcnRRcp8X9JoUWMB8f9eHfvcfcOEBoVplmhcUDTbTOdTIjZ3KrY/YoQBEQwirDMLGNOklLwHV/3CPD1Ls6z/M/9OXrVvMWAgEg8ywzTJt4gnt60Dc77xFFWklXic+Ixky5I/Mh1xeM3zkWXBZ4ZNTPpeeIosVjsYKWDWcnUiKeIY6qmU76Q9VjlvMVZq9RY6578hZG8vrLMdZpDSGIRS5AgQkENZVRgI06rToqFNO0nfPyDrl8il0KuMhg5FlCFBtn1g//B726twuSElxRJAF0vjvMxDHTvAs2643wfO07zBAg+A1d6219tADOfpNfbWuwI6NsGLq7bmrIHXO4AA0+GbMquFKQpFArA+xl9Uw7ovwXCa15vrX2cPgAZ6ip1AxwcAiNFyl73eXdPZ2//nmn19wMblHKELbNVEQAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAAuIwAALiMBeKU/dgAAAAd0SU1FB+cEAgwqMNi06jEAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAPeklEQVR42u2de7jVVZnHP+8+Fw54RAFJYLgYpKGGWopGHJmAZyClNPOCYJn0FKaNqM8Mo073mryFjxCOaCSjOOXdUixEMLUSQxkcFJXBAAVBAUFAOMC57O/88Vs7Npvfde/N4XjO7/s859GHva7vWt+13vWud70/o8yQlAFOBgYDxwP9gR5AZ6ASaAS2A+8Bq4FlwIvAEjMTKVK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b0lCC3IsckqaWOK43hvShiklln1boLwlXRSjgN2SLmghYk6I+a5yVEgZRUVCcCb/i11/k+IdSZ9N0M+hMZ3E87E4N3lV5Pc53fkmiqC3RBHULWabA85bR0QsTq+XwwiZgJwZd+Yr5h3trHyNJWQz+bCIq6IL43SytXw8d2bMjv13RFmXO4OE39/kGG3p7Ej6Sozd7GlJowNN49ETfJyzrobhBUlj8utwhqy3A/r4XES9k0Pkk/ubFKP9V/jkmx5TM1pbkO/hIuS3PKT9NQHW2iudsS5qrj8s751v3LYc5oxv70aUvdJdcx3u49fkf4Yg2WfnLzKzV8rpZID32fmjYySP/Ox8mReNI5xcugO5c9QOYAOwymxf/80S6ukDfBzvVYfhPc7dCKyOCi6Voih593Xj2gXv9U4D3gugDU7mu0souz/eu80unocR9XieZmvN7L1iChwgaWcCa+Tjkj5ZooBOlDQ/gSqwSVKPdGqlaI+rySkJPUBy56BrJfVK4NnyA3nRypJgm6SB6SilaKuIY4UbjBfnplMR5b8LrHL/3YIX1qMjXsiSnnhhLT5WRLkfAHWt7RsuKVK0KDkdQY/Be0nfGh5er8R7V7kmHb4UKfi79WmODi7ui/O6IEWK9krSSxIYisqFrQqJsJ0iRYq9BO3mnKMPNJqcS1TnVOopUiQjaV/n3lVfZlJ+KOmG9JokRYrSSVoj6ULni7qrSELulPSQe/hdlUo1RXuHHQCiZvAikw8GjsfzcumBF/W8Cu/bhNvwos+txvMwehF4Of0gbooUe/H/giwrLYVKpfgAAAAASUVORK5CYII=" alt="Logo"
style="width:20%">
</div>

<div class="w3-bar w3-black w3-large">
<div class="w3-bar w3-black w3-medium">
<div class="w3-bar-item w3-black w3-hover-red"><i class="fa fa-wrench"></i> Settings Page</div>
<div id="ssid" class="w3-bar-item w3-hover-blue w3-right"></div>
<div class="w3-bar-item w3-button w3-hover-yellow w3-right" onclick="restartDevice();"><i class='fa fa-power-off'></i> Restart</div>
<div id="status" class="w3-bar-item w3-green" style="display:none"><i class='fa fa-floppy-o'></i> Saved! Restart your device</div>
</div>

<div class="w3-row-padding w3-padding">
<div id="base" class="w3-col s3 m3 s12" style="display: none;">
<div class="w3-card-4 w3-margin-bottom">
<header class="w3-container w3-blue-gray">
<h3 id="title">{{TITLE}}</h3>
<h4 id="title">{{TITLE}}</h4>
</header>
<div class="w3-container">
<p style="min-height: 45px;" id="description">{{DESCRIPTION}}</p>
Expand Down Expand Up @@ -62,7 +63,7 @@ const char SETTINGS_PAGE[] PROGMEM = R""""(
title: "Use 24h format?",
description: "Changes the hour format to show 20:00 instead of 8:00PM",
formInput: "<input class='w3-check' type='checkbox' id='use24h' " + (settings.use24hFormat == 1 ? "checked" : "") + "><label for='use24h'> Yep</label>",
icon: "fa-calendar",
icon: "fa-clock-o",
save: "updatePreference('use24hFormat', Number(use24h.checked))",
property: "use24hFormat"
},
Expand All @@ -77,8 +78,8 @@ const char SETTINGS_PAGE[] PROGMEM = R""""(
{
title: "Timezone",
description: "Consult your TZ identifier <a href='https://en.wikipedia.org/wiki/List_of_tz_database_time_zones'>here.</a> Examples: America/Sao_Paulo, Europe/Lisbon",
formInput: "<input id='tz' class='w3-input' name='tz' type='text' placeholder='Timezone' value='" + settings.timeZone + "''>",
icon: "fa-clock-o",
formInput: "<input id='tz' class='w3-input w3-light-grey' name='tz' type='text' placeholder='Timezone' value='" + settings.timeZone + "''>",
icon: "fa-globe",
save: "updatePreference('timeZone', tz.value)",
property: "timeZone"
}
Expand Down Expand Up @@ -132,6 +133,12 @@ const char SETTINGS_PAGE[] PROGMEM = R""""(
xmlhttp.send();
}

function restartDevice() {
const xhr = new XMLHttpRequest();
xhr.open('POST', '/restart');
xhr.send();
}

//Local
//createCards({ "displayBright": 30, "swapBlueGreen": 1, "use24hFormat": 0, "timeZone": "Europe/Lisbon", "wifiSsid": "test" });

Expand Down
5 changes: 4 additions & 1 deletion firmware/lib/cw-commons/WiFiController.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ ImprovWiFi improvSerial(&Serial);

struct WiFiController
{
bool connectionSucessfulOnce;

static void onImprovWiFiErrorCb(ImprovTypes::Error err)
{
ClockwiseWebServer::getInstance()->stopWebServer();
Expand Down Expand Up @@ -39,7 +41,7 @@ struct WiFiController
WiFi.mode(WIFI_STA);
WiFi.disconnect();

improvSerial.setDeviceInfo(ImprovTypes::ChipFamily::CF_ESP32, "CW-20230324", "1.1.0", "Clockwise");
improvSerial.setDeviceInfo(ImprovTypes::ChipFamily::CF_ESP32, "CW-20230402", "1.1.0", "Clockwise");
improvSerial.onImprovError(onImprovWiFiErrorCb);
improvSerial.onImprovConnected(onImprovWiFiConnectedCb);

Expand All @@ -48,6 +50,7 @@ struct WiFiController
if (!ClockwiseParams::getInstance()->wifiSsid.isEmpty()) {
if (improvSerial.tryConnectToWifi(ClockwiseParams::getInstance()->wifiSsid.c_str(), ClockwiseParams::getInstance()->wifiPwd.c_str()))
{
connectionSucessfulOnce = true;
ClockwiseWebServer::getInstance()->startWebServer();
return true;
}
Expand Down
29 changes: 10 additions & 19 deletions firmware/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ CWDateTime cwDateTime;

void displaySetup(bool swapBlueGreen, uint8_t displayBright)
{
HUB75_I2S_CFG mxconfig(
64, // module width
64, // module height
1 // Chain length
);
HUB75_I2S_CFG mxconfig(64, 64, 1);

if (swapBlueGreen)
{
Expand Down Expand Up @@ -52,13 +48,6 @@ void setup()
StatusController::getInstance()->blink_led(5, 100);

ClockwiseParams::getInstance()->load();

// Serial.println(ClockwiseParams::getInstance()->swapBlueGreen);
// Serial.println(ClockwiseParams::getInstance()->use24hFormat);
// Serial.println(ClockwiseParams::getInstance()->displayBright);
// Serial.println(ClockwiseParams::getInstance()->timeZone);
// Serial.println(ClockwiseParams::getInstance()->wifiSsid);
// Serial.println(ClockwiseParams::getInstance()->wifiPwd);

displaySetup(ClockwiseParams::getInstance()->swapBlueGreen, ClockwiseParams::getInstance()->displayBright);
clockface = new Clockface(dma_display);
Expand All @@ -67,13 +56,12 @@ void setup()
delay(1000);

StatusController::getInstance()->wifiConnecting();
wifi.begin();

if (WiFiController::isConnected())
if (wifi.begin())
{
StatusController::getInstance()->ntpConnecting();

//cwDateTime.begin(ClockwiseParams::getInstance()->timeZone.c_str(), ClockwiseParams::getInstance()->use24hFormat);
//clockface->setup(&cwDateTime);
cwDateTime.begin(ClockwiseParams::getInstance()->timeZone.c_str(), ClockwiseParams::getInstance()->use24hFormat);
clockface->setup(&cwDateTime);
}
}

void loop()
Expand All @@ -85,5 +73,8 @@ void loop()
ClockwiseWebServer::getInstance()->handleHttpRequest();
}

//clockface->update();
if (wifi.connectionSucessfulOnce)
{
clockface->update();
}
}

0 comments on commit d69abef

Please sign in to comment.