- add self updating function. You can start an update from onscreen menu
This commit is contained in:
Stephan Mühl
2023-03-23 22:11:46 +01:00
parent e590e22923
commit 396e1f1cf9
13 changed files with 214 additions and 22 deletions

View File

@@ -15,7 +15,7 @@ The JSON object has the following properties:
| `rainbow` | boolean | Fades each letter in the text differently through the entire RGB spectrum. | false | | `rainbow` | boolean | Fades each letter in the text differently through the entire RGB spectrum. | false |
| `duration` | number | Sets how long the page should be displayed. | 5 | | `duration` | number | Sets how long the page should be displayed. | 5 |
| `color` | string | A color hex string for the text color. | "#FFFFFF" | | `color` | string | A color hex string for the text color. | "#FFFFFF" |
| `hold` | boolean | Set it to true, to hold your notification on top until you press the middle button or dismiss it via HomeAssistant. | false | | `hold` | boolean | Set it to true, to hold your notification on top until you press the middle button or dismiss it via HomeAssistant. This key only belongs to notification. | false |
| `sound` | string | The filename of your RTTTL ringtone file (without extension). | | | `sound` | string | The filename of your RTTTL ringtone file (without extension). | |
| `pushIcon` | number | 0 = Icon doesn't move. 1 = Icon moves with text and will not appear again. 2 = Icon moves with text but appears again when the text starts to scroll again. | 0 | | `pushIcon` | number | 0 = Icon doesn't move. 1 = Icon moves with text and will not appear again. 2 = Icon moves with text but appears again when the text starts to scroll again. | 0 |

View File

@@ -25,6 +25,12 @@ To change the color, use the left and right buttons to navigate through the avai
#### SWITCH #### SWITCH
This setting determines whether the pages should automatically switch after the specified time. To save your setting, press and hold the middle button for 2 seconds. This will exit the menu and store your setting. This setting determines whether the pages should automatically switch after the specified time. To save your setting, press and hold the middle button for 2 seconds. This will exit the menu and store your setting.
#### T-SPEED
In this menu you can change the transisiton speed between apps.
#### T_SPEED
In this menu, you can adjust the duration for which an app is displayed before switching to the next one.
#### REBOOT #### UPDATE
This will reboot your clock :-) Here you can check and download a new firmware if available.

View File

@@ -1,6 +1,6 @@
# Quick start # Quick start
1. :computer: Flashing. Connect your device to your PC or Mac and [use the online flahser](flasher.md) 1. :computer: Connect your device to your PC or Mac and [use the online flahser](flasher.md)
2. :signal_strength: After flashing, Awtrix will open an access point with the name "AWTRIX LIGHT". Connect with PW "12345678". 2. :signal_strength: After flashing, Awtrix will open an access point with the name "AWTRIX LIGHT". Connect with PW "12345678".
3. :mag: Open a browser and navigate to 192.168.4.1. Enter your WiFi information and reboot the clock. 3. :mag: Open a browser and navigate to 192.168.4.1. Enter your WiFi information and reboot the clock.
4. :clock1: Your clock is accessible via http://awtrixlight.local/. 4. :clock1: Your clock is accessible via http://awtrixlight.local/.

View File

@@ -262,7 +262,6 @@ void MatrixDisplayUi::drawApp()
y *= dir; y *= dir;
x1 *= dir; x1 *= dir;
y1 *= dir; y1 *= dir;
Serial.println(progress);
bool FirstFrame = progress < 0.2; bool FirstFrame = progress < 0.2;
bool LastFrame = progress > 0.8; bool LastFrame = progress > 0.8;
this->matrix->drawRect(x, y, x1, y1, matrix->Color(0, 0, 0)); this->matrix->drawRect(x, y, x1, y1, matrix->Color(0, 0, 0));

View File

@@ -390,6 +390,17 @@ void DisplayManager_::tick()
} }
} }
void DisplayManager_::clear()
{
matrix.clear();
}
void DisplayManager_::show()
{
matrix.show();
}
void DisplayManager_::leftButton() void DisplayManager_::leftButton()
{ {
if (!MenuManager.inMenu) if (!MenuManager.inMenu)
@@ -512,4 +523,17 @@ void DisplayManager_::setNewSettings(String Payload)
AUTO_TRANSITION = doc.containsKey("autotransition") ? doc["autotransition"] : AUTO_TRANSITION; AUTO_TRANSITION = doc.containsKey("autotransition") ? doc["autotransition"] : AUTO_TRANSITION;
applyAllSettings(); applyAllSettings();
saveSettings(); saveSettings();
}
void DisplayManager_::drawProgressBar(int cur, int total)
{
matrix.clear();
int progress = (cur * 100) / total;
char progressStr[5];
snprintf(progressStr, 5, "%d%%", progress); // Formatieren des Prozentzeichens
printText(0, 6, progressStr, true, false);
int leds_for_progress = (progress * MATRIX_WIDTH * MATRIX_HEIGHT) / 100;
matrix.drawFastHLine(0, 7, MATRIX_WIDTH, matrix.Color(100, 100, 100));
matrix.drawFastHLine(0, 7, leds_for_progress / MATRIX_HEIGHT, matrix.Color(0, 255, 0));
matrix.show();
} }

View File

@@ -26,6 +26,8 @@ public:
static DisplayManager_ &getInstance(); static DisplayManager_ &getInstance();
void setup(); void setup();
void tick(); void tick();
void clear();
void show();
void applyAllSettings(); void applyAllSettings();
void rightButton(); void rightButton();
void dismissNotify(); void dismissNotify();
@@ -51,6 +53,7 @@ public:
void setNewSettings(String Payload); void setNewSettings(String Payload);
void drawGIF(uint16_t x, uint16_t y, fs::File gifFile); void drawGIF(uint16_t x, uint16_t y, fs::File gifFile);
void drawJPG(uint16_t x, uint16_t y, fs::File jpgFile); void drawJPG(uint16_t x, uint16_t y, fs::File jpgFile);
void drawProgressBar(int cur, int total);
}; };
extern DisplayManager_ &DisplayManager; extern DisplayManager_ &DisplayManager;

View File

@@ -34,7 +34,7 @@ IPAddress gateway;
IPAddress subnet; IPAddress subnet;
IPAddress primaryDNS; IPAddress primaryDNS;
IPAddress secondaryDNS; IPAddress secondaryDNS;
const char *VERSION = "0.36"; const char *VERSION = "0.37";
String MQTT_HOST = ""; String MQTT_HOST = "";
uint16_t MQTT_PORT = 1883; uint16_t MQTT_PORT = 1883;
String MQTT_USER; String MQTT_USER;

View File

@@ -4,6 +4,7 @@
#include <Globals.h> #include <Globals.h>
#include <ServerManager.h> #include <ServerManager.h>
#include <DisplayManager.h> #include <DisplayManager.h>
#include <updater.h>
String menuText; String menuText;
int menuSelection; int menuSelection;
@@ -33,9 +34,10 @@ const char *menuItems[] = {
"COLOR", "COLOR",
"SWITCH", "SWITCH",
"T-SPEED", "T-SPEED",
"APPTIME"}; "APPTIME",
"UPDATE"};
byte menuItemCount = 6; byte menuItemCount = 7;
MenuState currentState = MainMenu; MenuState currentState = MainMenu;
@@ -248,6 +250,10 @@ void MenuManager_::selectButton()
{ {
currentState = AppTimeMenu; currentState = AppTimeMenu;
} }
else if (menuIndex == 6) // AppTIme
{
FirmwareVersionCheck();
}
} }
else if (currentState == StationSelection) else if (currentState == StationSelection)
{ {

View File

@@ -168,9 +168,7 @@ void PeripheryManager_::tick()
{ {
previousMillis_BatTempHum = currentMillis_BatTempHum; previousMillis_BatTempHum = currentMillis_BatTempHum;
uint16_t ADCVALUE = analogRead(BATTERY_PIN); uint16_t ADCVALUE = analogRead(BATTERY_PIN);
Serial.println(ADCVALUE);
BATTERY_PERCENT = min((int)map(ADCVALUE, 510, 665, 0, 100), 100); BATTERY_PERCENT = min((int)map(ADCVALUE, 510, 665, 0, 100), 100);
Serial.println(BATTERY_PERCENT);
CURRENT_LUX = (roundf(photocell.getSmoothedLux() * 1000) / 1000); CURRENT_LUX = (roundf(photocell.getSmoothedLux() * 1000) / 1000);
sht31.readBoth(&CURRENT_TEMP, &CURRENT_HUM); sht31.readBoth(&CURRENT_TEMP, &CURRENT_HUM);
CURRENT_TEMP -= 9.0; CURRENT_TEMP -= 9.0;

View File

@@ -213,4 +213,5 @@ void ServerManager_::loadSettings()
else else
Serial.println(F("Configuration file not exist")); Serial.println(F("Configuration file not exist"));
return; return;
} }

30
src/cert.h Normal file
View File

@@ -0,0 +1,30 @@
#ifndef CERT_H
#define CERT_H
//DigiCert root certificate has expiry date of 10 Nov 2031
const char * rootCACertificate = \
"-----BEGIN CERTIFICATE-----\n" \
"MIIDrzCCApegAwIBAgIQCDvgVpBCRrGhdWrJWZHHSjANBgkqhkiG9w0BAQUFADBh\n" \
"MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3\n" \
"d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBD\n" \
"QTAeFw0wNjExMTAwMDAwMDBaFw0zMTExMTAwMDAwMDBaMGExCzAJBgNVBAYTAlVT\n" \
"MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5j\n" \
"b20xIDAeBgNVBAMTF0RpZ2lDZXJ0IEdsb2JhbCBSb290IENBMIIBIjANBgkqhkiG\n" \
"9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4jvhEXLeqKTTo1eqUKKPC3eQyaKl7hLOllsB\n" \
"CSDMAZOnTjC3U/dDxGkAV53ijSLdhwZAAIEJzs4bg7/fzTtxRuLWZscFs3YnFo97\n" \
"nh6Vfe63SKMI2tavegw5BmV/Sl0fvBf4q77uKNd0f3p4mVmFaG5cIzJLv07A6Fpt\n" \
"43C/dxC//AH2hdmoRBBYMql1GNXRor5H4idq9Joz+EkIYIvUX7Q6hL+hqkpMfT7P\n" \
"T19sdl6gSzeRntwi5m3OFBqOasv+zbMUZBfHWymeMr/y7vrTC0LUq7dBMtoM1O/4\n" \
"gdW7jVg/tRvoSSiicNoxBN33shbyTApOB6jtSj1etX+jkMOvJwIDAQABo2MwYTAO\n" \
"BgNVHQ8BAf8EBAMCAYYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUA95QNVbR\n" \
"TLtm8KPiGxvDl7I90VUwHwYDVR0jBBgwFoAUA95QNVbRTLtm8KPiGxvDl7I90VUw\n" \
"DQYJKoZIhvcNAQEFBQADggEBAMucN6pIExIK+t1EnE9SsPTfrgT1eXkIoyQY/Esr\n" \
"hMAtudXH/vTBH1jLuG2cenTnmCmrEbXjcKChzUyImZOMkXDiqw8cvpOp/2PV5Adg\n" \
"06O/nVsJ8dWO41P0jmP6P6fbtGbfYmbW0W5BjfIttep3Sp+dWOIrWcBAI+0tKIJF\n" \
"PnlUkiaY4IBIqDfv8NZ5YBberOgOzW6sRBc4L0na4UU+Krk2U886UAb3LujEV0ls\n" \
"YSEY1QSteDwsOoBrp+uvFRTp2InBuThs4pFsiv9kuXclVzDAGySj4dzp30d8tbQk\n" \
"CAUw7C29C79Fv1C5qfPrmAESrciIxpg0X40KPMbp1ZWVbd4=\n" \
"-----END CERTIFICATE-----\n";
#endif

View File

@@ -1,15 +1,15 @@
/* ___ ___ ___ ___ /* ___ ___ ___ ___
/ /\ /__/\ ___ / /\ ___ /__/| / /\ /__/\ ___ / /\ ___ /__/|
/ /::\ _\_ \:\ / /\ / /::\ / /\ | |:| / /::\ _\_ \:\ / /\ / /::\ / /\ | |:|
/ /:/\:\ /__/\ \:\ / /:/ / /:/\:\ / /:/ | |:| / /:/\:\ /__/\ \:\ / /:/ / /:/\:\ / /:/ | |:|
/ /:/~/::\ _\_ \:\ \:\ / /:/ / /:/~/:/ /__/::\ __|__|:| / /:/~/::\ _\_ \:\ \:\ / /:/ / /:/~/:/ /__/::\ __|__|:|
/__/:/ /:/\:\ /__/\ \:\ \:\ / /::\ /__/:/ /:/___ \__\/\:\__ /__/::::\____ /__/:/ /:/\:\ /__/\ \:\ \:\ / /::\ /__/:/ /:/___ \__\/\:\__ /__/::::\____
\ \:\/:/__\/ \ \:\ \:\/:/ /__/:/\:\ \ \:\/:::::/ \ \:\/\ ~\~~\::::/ \ \:\/:/__\/ \ \:\ \:\/:/ /__/:/\:\ \ \:\/:::::/ \ \:\/\ ~\~~\::::/
\ \::/ \ \:\ \::/ \__\/ \:\ \ \::/~~~~ \__\::/ |~~|:|~~ \ \::/ \ \:\ \::/ \__\/ \:\ \ \::/~~~~ \__\::/ |~~|:|~~
\ \:\ \ \:\/:/ \ \:\ \ \:\ /__/:/ | |:| \ \:\ \ \:\/:/ \ \:\ \ \:\ /__/:/ | |:|
\ \:\ \ \::/ \__\/ \ \:\ \__\/ | |:| \ \:\ \ \::/ \__\/ \ \:\ \__\/ | |:|
\__\/ \__\/ \__\/ |__|/ \__\/ \__\/ \__\/ |__|/
*************************************************************************** ***************************************************************************
* * * *
@@ -22,7 +22,7 @@
* 4.0 International License. * * 4.0 International License. *
* * * *
* More information: * * More information: *
* https://github.com/Blueforcer/awtrix-light/blob/main/LICENSE.md * * https://github.com/Blueforcer/awtrix-light/blob/main/LICENSE.md *
* * * *
* This firmware is distributed in the hope that it will be useful, * * This firmware is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of * * but WITHOUT ANY WARRANTY; without even the implied warranty of *
@@ -30,7 +30,6 @@
* * * *
***************************************************************************/ ***************************************************************************/
#include <Arduino.h> #include <Arduino.h>
#include "DisplayManager.h" #include "DisplayManager.h"
#include "PeripheryManager.h" #include "PeripheryManager.h"
@@ -65,6 +64,8 @@ void setup()
loadSettings(); loadSettings();
ServerManager.loadSettings(); ServerManager.loadSettings();
DisplayManager.setup(); DisplayManager.setup();
DisplayManager.HSVtext(9, 6, VERSION, true);
delay(500);
PeripheryManager.playBootSound(); PeripheryManager.playBootSound();
xTaskCreatePinnedToCore(BootAnimation, "Task", 10000, NULL, 1, &taskHandle, 1); xTaskCreatePinnedToCore(BootAnimation, "Task", 10000, NULL, 1, &taskHandle, 1);
ServerManager.setup(); ServerManager.setup();

124
src/updater.h Normal file
View File

@@ -0,0 +1,124 @@
#include <WiFi.h>
#include <HTTPClient.h>
#include <HTTPUpdate.h>
#include <WiFiClientSecure.h>
#include "cert.h"
#include "DisplayManager.h"
#define URL_fw_Version "https://raw.githubusercontent.com/Blueforcer/awtrix-light/main/version"
#define URL_fw_Bin "https://raw.githubusercontent.com/Blueforcer/awtrix-light/main/docs/flasher/firmware/firmware.bin"
void update_started()
{
}
void update_finished()
{
Serial.println("CALLBACK: HTTP update process finished");
}
void update_progress(int cur, int total)
{
DisplayManager.drawProgressBar(cur, total);
}
void update_error(int err)
{
DisplayManager.clear();
DisplayManager.printText(0, 6, "FAIL", true, true);
DisplayManager.show();
}
void firmwareUpdate(void)
{
WiFiClientSecure client;
client.setCACert(rootCACertificate);
httpUpdate.onStart(update_started);
httpUpdate.onEnd(update_finished);
httpUpdate.onProgress(update_progress);
httpUpdate.onError(update_error);
t_httpUpdate_return ret = httpUpdate.update(client, URL_fw_Bin);
switch (ret)
{
case HTTP_UPDATE_FAILED:
Serial.printf("HTTP_UPDATE_FAILD Error (%d): %s\n", httpUpdate.getLastError(), httpUpdate.getLastErrorString().c_str());
break;
case HTTP_UPDATE_NO_UPDATES:
Serial.println("HTTP_UPDATE_NO_UPDATES");
break;
case HTTP_UPDATE_OK:
Serial.println("HTTP_UPDATE_OK");
break;
}
}
int FirmwareVersionCheck(void)
{
DisplayManager.clear();
DisplayManager.printText(0, 6, "CHECK", true, true);
DisplayManager.show();
String payload;
int httpCode;
String fwurl = "";
fwurl += URL_fw_Version;
fwurl += "?";
fwurl += String(rand());
Serial.println(fwurl);
WiFiClientSecure *client = new WiFiClientSecure;
if (client)
{
client->setCACert(rootCACertificate);
// Add a scoping block for HTTPClient https to make sure it is destroyed before WiFiClientSecure *client is
HTTPClient https;
if (https.begin(*client, fwurl))
{ // HTTPS
Serial.print("[HTTPS] GET...\n");
// start connection and send HTTP header
delay(100);
httpCode = https.GET();
delay(100);
if (httpCode == HTTP_CODE_OK) // if version received
{
payload = https.getString(); // save received version
}
else
{
Serial.print("error in downloading version file:");
Serial.println(httpCode);
}
https.end();
}
delete client;
}
if (httpCode == HTTP_CODE_OK) // if version received
{
payload.trim();
if (payload.equals(VERSION))
{
Serial.printf("\nDevice already on latest firmware version:%s\n", VERSION);
DisplayManager.clear();
DisplayManager.printText(0, 6, "NO UP :(", true, true);
DisplayManager.show();
delay(1000);
return 0;
}
else
{
Serial.println(payload);
Serial.println("New firmware detected");
DisplayManager.printText(0, 6, payload.c_str(), true, true);
firmwareUpdate();
return 1;
}
}
return 0;
}