Merge branch 'development' of https://github.com/Blueforcer/awtrix-light into development
This commit is contained in:
@@ -69,6 +69,17 @@ const char HAtransID[] PROGMEM = {"%s_tra"};
|
||||
const char HAtransName[] PROGMEM = {"Transition"};
|
||||
const char HAtransIcon[] PROGMEM = {"mdi:swap-vertical"};
|
||||
|
||||
const char HAupdateID[] PROGMEM = {"%s_upd"};
|
||||
const char HAupdateName[] PROGMEM = {"Update"};
|
||||
const char HAupdateClass[] PROGMEM = {"update"};
|
||||
const char HAupdateIcon[] PROGMEM = {"mdi:update"};
|
||||
|
||||
|
||||
const char HAdoUpID[] PROGMEM = {"%s_doupd"};
|
||||
const char HAdoUpName[] PROGMEM = {"Start Update"};
|
||||
const char HAdoUpIcon[] PROGMEM = {"mdi:update"};
|
||||
|
||||
|
||||
const char HAsigID[] PROGMEM = {"%s_sig"};
|
||||
const char HAsigIcon[] PROGMEM = {"mdi:sun-wireless"};
|
||||
const char HAsigName[] PROGMEM = {"WiFi strength"};
|
||||
@@ -104,3 +115,4 @@ const char TempKey[] PROGMEM = {"temp"};
|
||||
const char HumKey[] PROGMEM = {"hum"};
|
||||
const char UpTimeKey[] PROGMEM = {"uptime"};
|
||||
const char SignalStrengthKey[] PROGMEM = {"wifi_signal"};
|
||||
const char UpdateKey[] PROGMEM = {"up_available"};
|
||||
|
||||
@@ -77,10 +77,19 @@ extern const char HAupID[];
|
||||
extern const char HAupName[];
|
||||
extern const char HAupClass[];
|
||||
|
||||
extern const char HAdoUpID[];
|
||||
extern const char HAdoUpName[];
|
||||
extern const char HAdoUpIcon[];
|
||||
|
||||
extern const char HAtransID[];
|
||||
extern const char HAtransName[];
|
||||
extern const char HAtransIcon[];
|
||||
|
||||
extern const char HAupdateID[];
|
||||
extern const char HAupdateName[];
|
||||
extern const char HAupdateClass[];
|
||||
extern const char HAupdateIcon[];
|
||||
|
||||
extern const char HAbtnLID[];
|
||||
extern const char HAbtnLName[];
|
||||
|
||||
@@ -106,5 +115,5 @@ extern const char TempKey[];
|
||||
extern const char HumKey[];
|
||||
extern const char UpTimeKey[];
|
||||
extern const char SignalStrengthKey[];
|
||||
|
||||
extern const char UpdateKey[];
|
||||
#endif
|
||||
|
||||
@@ -298,7 +298,7 @@ void DisplayManager_::generateCustomPage(String name, const char *json)
|
||||
customApp.barSize = 0;
|
||||
}
|
||||
|
||||
customApp.duration = doc.containsKey("duration") ? doc["duration"].as<int>() * 1000 : -1;
|
||||
customApp.duration = doc.containsKey("duration") ? doc["duration"].as<int>() * 1000 : 0;
|
||||
int pos = doc.containsKey("pos") ? doc["pos"].as<uint8_t>() : -1;
|
||||
customApp.rainbow = doc.containsKey("rainbow") ? doc["rainbow"] : false;
|
||||
customApp.pushIcon = doc.containsKey("pushIcon") ? doc["pushIcon"] : 0;
|
||||
@@ -519,7 +519,7 @@ void DisplayManager_::loadNativeApps()
|
||||
|
||||
void DisplayManager_::setup()
|
||||
{
|
||||
|
||||
|
||||
TJpgDec.setCallback(jpg_output);
|
||||
TJpgDec.setJpgScale(1);
|
||||
FastLED.addLeds<NEOPIXEL, MATRIX_PIN>(leds, MATRIX_WIDTH * MATRIX_HEIGHT);
|
||||
@@ -907,8 +907,10 @@ String DisplayManager_::getStat()
|
||||
{
|
||||
StaticJsonDocument<200> doc;
|
||||
char buffer[5];
|
||||
#ifdef ULANZI
|
||||
doc[BatKey] = BATTERY_PERCENT;
|
||||
doc[BatRawKey] = BATTERY_RAW;
|
||||
#endif
|
||||
snprintf(buffer, 5, "%.0f", CURRENT_LUX);
|
||||
doc[LuxKey] = buffer;
|
||||
doc[LDRRawKey] = LDR_RAW;
|
||||
@@ -920,6 +922,7 @@ String DisplayManager_::getStat()
|
||||
doc[HumKey] = buffer;
|
||||
doc[UpTimeKey] = PeripheryManager.readUptime();
|
||||
doc[SignalStrengthKey] = WiFi.RSSI();
|
||||
doc[UpdateKey] = UPDATE_AVAILABLE;
|
||||
String jsonString;
|
||||
serializeJson(doc, jsonString);
|
||||
return jsonString;
|
||||
|
||||
@@ -121,7 +121,7 @@ IPAddress gateway;
|
||||
IPAddress subnet;
|
||||
IPAddress primaryDNS;
|
||||
IPAddress secondaryDNS;
|
||||
const char *VERSION = "0.46";
|
||||
const char *VERSION = "0.47";
|
||||
String MQTT_HOST = "";
|
||||
uint16_t MQTT_PORT = 1883;
|
||||
String MQTT_USER;
|
||||
@@ -187,4 +187,5 @@ bool SOUND_ACTIVE;
|
||||
String BOOT_SOUND = "";
|
||||
uint8_t VOLUME;
|
||||
uint8_t VOLUME_PERCENT;
|
||||
int MATRIX_LAYOUT;
|
||||
int MATRIX_LAYOUT;
|
||||
bool UPDATE_AVAILABLE = false;
|
||||
@@ -71,6 +71,7 @@ extern String BOOT_SOUND;
|
||||
extern uint8_t VOLUME;
|
||||
extern uint8_t VOLUME_PERCENT;
|
||||
extern int MATRIX_LAYOUT;
|
||||
extern bool UPDATE_AVAILABLE;
|
||||
void loadSettings();
|
||||
void saveSettings();
|
||||
#endif // Globals_H
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <ArduinoJson.h>
|
||||
#include "Dictionary.h"
|
||||
#include "PeripheryManager.h"
|
||||
#include "UpdateManager.h"
|
||||
|
||||
WiFiClient espClient;
|
||||
uint8_t lastBrightness;
|
||||
@@ -36,6 +37,8 @@ HASensor *ram = nullptr;
|
||||
HABinarySensor *btnleft = nullptr;
|
||||
HABinarySensor *btnmid = nullptr;
|
||||
HABinarySensor *btnright = nullptr;
|
||||
HABinarySensor *update = nullptr;
|
||||
HAButton *doUpdate = nullptr;
|
||||
|
||||
// The getter for the instantiated singleton instance
|
||||
MQTTManager_ &MQTTManager_::getInstance()
|
||||
@@ -61,6 +64,11 @@ void onButtonCommand(HAButton *sender)
|
||||
{
|
||||
DisplayManager.previousApp();
|
||||
}
|
||||
else if (sender == doUpdate)
|
||||
{
|
||||
if (UPDATE_AVAILABLE)
|
||||
UpdateManager.updateFirmware();
|
||||
}
|
||||
}
|
||||
|
||||
void onSwitchCommand(bool state, HASwitch *sender)
|
||||
@@ -183,6 +191,12 @@ void onMqttMessage(const char *topic, const uint8_t *payload, uint16_t length)
|
||||
DisplayManager.previousApp();
|
||||
return;
|
||||
}
|
||||
if (strTopic == MQTT_PREFIX + "/doupdate")
|
||||
{
|
||||
if (UPDATE_AVAILABLE)
|
||||
UpdateManager.updateFirmware();
|
||||
return;
|
||||
}
|
||||
|
||||
else if (strTopic.startsWith(MQTT_PREFIX + "/custom"))
|
||||
{
|
||||
@@ -212,6 +226,7 @@ void onMqttConnected()
|
||||
"/settings",
|
||||
"/previousapp",
|
||||
"/nextapp",
|
||||
"/doupdate",
|
||||
"/nextapp",
|
||||
"/apps"};
|
||||
for (const char *topic : topics)
|
||||
@@ -222,7 +237,6 @@ void onMqttConnected()
|
||||
Serial.println(F("MQTT Connected"));
|
||||
}
|
||||
|
||||
|
||||
void connect()
|
||||
{
|
||||
mqtt.onMessage(onMqttMessage);
|
||||
@@ -241,7 +255,7 @@ void connect()
|
||||
}
|
||||
|
||||
char matID[40], briID[40];
|
||||
char btnAID[40], btnBID[40], btnCID[40], appID[40], tempID[40], humID[40], luxID[40], verID[40], ramID[40], upID[40], sigID[40], btnLID[40], btnMID[40], btnRID[40], transID[40];
|
||||
char btnAID[40], btnBID[40], btnCID[40], appID[40], tempID[40], humID[40], luxID[40], verID[40], ramID[40], upID[40], sigID[40], btnLID[40], btnMID[40], btnRID[40], transID[40], updateID[40], doUpdateID[40];
|
||||
#ifdef ULANZI
|
||||
char batID[40];
|
||||
#endif
|
||||
@@ -302,6 +316,12 @@ void MQTTManager_::setup()
|
||||
dismiss->setIcon(HAbtnaIcon);
|
||||
dismiss->setName(HAbtnaName);
|
||||
|
||||
sprintf(doUpdateID, HAdoUpID, macStr);
|
||||
doUpdate = new HAButton(doUpdateID);
|
||||
doUpdate->setIcon(HAdoUpIcon);
|
||||
doUpdate->setName(HAdoUpName);
|
||||
doUpdate->onCommand(onButtonCommand);
|
||||
|
||||
sprintf(transID, HAtransID, macStr);
|
||||
transition = new HASwitch(transID);
|
||||
transition->setIcon(HAtransIcon);
|
||||
@@ -376,6 +396,12 @@ void MQTTManager_::setup()
|
||||
btnleft = new HABinarySensor(btnLID);
|
||||
btnleft->setName(HAbtnLName);
|
||||
|
||||
sprintf(updateID, HAupdateID, macStr);
|
||||
update = new HABinarySensor(updateID);
|
||||
update->setIcon(HAupdateIcon);
|
||||
update->setName(HAupdateName);
|
||||
update->setDeviceClass(HAupdateClass);
|
||||
|
||||
sprintf(btnMID, HAbtnMID, macStr);
|
||||
btnmid = new HABinarySensor(btnMID);
|
||||
btnmid->setName(HAbtnMName);
|
||||
@@ -459,6 +485,8 @@ void MQTTManager_::sendStats()
|
||||
uptime->setValue(PeripheryManager.readUptime());
|
||||
version->setValue(VERSION);
|
||||
transition->setState(AUTO_TRANSITION, false);
|
||||
|
||||
update->setState(UPDATE_AVAILABLE, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -4,8 +4,9 @@
|
||||
#include <ServerManager.h>
|
||||
#include <DisplayManager.h>
|
||||
#include <PeripheryManager.h>
|
||||
#include <updater.h>
|
||||
//#include <update.h>
|
||||
#include <icons.h>
|
||||
#include <UpdateManager.h>
|
||||
|
||||
String menuText;
|
||||
int menuSelection;
|
||||
@@ -377,9 +378,9 @@ void MenuManager_::selectButton()
|
||||
#endif
|
||||
|
||||
case 13:
|
||||
if (FirmwareVersionCheck())
|
||||
if (UpdateManager.checkUpdate(true))
|
||||
{
|
||||
updateFirmware();
|
||||
UpdateManager.updateFirmware();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <LittleFS.h>
|
||||
#include <WiFi.h>
|
||||
#include "DisplayManager.h"
|
||||
#include "UpdateManager.h"
|
||||
|
||||
WebServer server(80);
|
||||
FSWebServer mws(LittleFS, server);
|
||||
@@ -37,7 +38,6 @@ void saveHandler()
|
||||
webRequest->send(200);
|
||||
}
|
||||
|
||||
|
||||
void ServerManager_::setup()
|
||||
{
|
||||
if (!local_IP.fromString(NET_IP) || !gateway.fromString(NET_GW) || !subnet.fromString(NET_SN) || !primaryDNS.fromString(NET_PDNS) || !secondaryDNS.fromString(NET_SDNS))
|
||||
@@ -53,7 +53,7 @@ void ServerManager_::setup()
|
||||
|
||||
if (isConnected)
|
||||
{
|
||||
|
||||
|
||||
mws.addOptionBox("Network");
|
||||
mws.addOption("Static IP", NET_STATIC);
|
||||
mws.addOption("Local IP", NET_IP);
|
||||
@@ -97,6 +97,9 @@ void ServerManager_::setup()
|
||||
{ DisplayManager.generateCustomPage(mws.webserver->arg("name"),mws.webserver->arg("plain").c_str()); mws.webserver->send(200,"OK"); });
|
||||
mws.addHandler("/api/stats", HTTP_GET, []()
|
||||
{ mws.webserver->sendContent(DisplayManager.getStat()); });
|
||||
mws.addHandler("/api/doupdate", HTTP_POST, []()
|
||||
{ if (UPDATE_AVAILABLE)
|
||||
UpdateManager.updateFirmware(); mws.webserver->send(200,"OK"); });
|
||||
Serial.println("Webserver loaded");
|
||||
}
|
||||
mws.addHandler("/version", HTTP_GET, versionHandler);
|
||||
|
||||
@@ -18,5 +18,5 @@ public:
|
||||
};
|
||||
|
||||
extern ServerManager_ &ServerManager;
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,20 +1,34 @@
|
||||
#include <UpdateManager.h>
|
||||
#include <WiFi.h>
|
||||
#include <HTTPClient.h>
|
||||
#include <HTTPUpdate.h>
|
||||
#include <WiFiClientSecure.h>
|
||||
#include "cert.h"
|
||||
#include "DisplayManager.h"
|
||||
#include <Ticker.h>
|
||||
#include "Globals.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"
|
||||
|
||||
Ticker UpdateTicker;
|
||||
|
||||
// The getter for the instantiated singleton instance
|
||||
UpdateManager_ &UpdateManager_::getInstance()
|
||||
{
|
||||
static UpdateManager_ instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
// Initialize the global shared instance
|
||||
UpdateManager_ &UpdateManager = UpdateManager.getInstance();
|
||||
|
||||
void update_started()
|
||||
{
|
||||
}
|
||||
|
||||
void update_finished()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void update_progress(int cur, int total)
|
||||
@@ -29,7 +43,7 @@ void update_error(int err)
|
||||
DisplayManager.show();
|
||||
}
|
||||
|
||||
void updateFirmware()
|
||||
void UpdateManager_::updateFirmware()
|
||||
{
|
||||
WiFiClientSecure client;
|
||||
client.setCACert(rootCACertificate);
|
||||
@@ -56,13 +70,15 @@ void updateFirmware()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool FirmwareVersionCheck()
|
||||
bool UpdateManager_::checkUpdate(bool withScreen)
|
||||
{
|
||||
if (withScreen)
|
||||
{
|
||||
DisplayManager.clear();
|
||||
DisplayManager.printText(0, 6, "CHECK", true, true);
|
||||
DisplayManager.show();
|
||||
}
|
||||
|
||||
DisplayManager.clear();
|
||||
DisplayManager.printText(0, 6, "CHECK", true, true);
|
||||
DisplayManager.show();
|
||||
String payload;
|
||||
int httpCode;
|
||||
String fwurl = "";
|
||||
@@ -103,20 +119,34 @@ bool FirmwareVersionCheck()
|
||||
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);
|
||||
UPDATE_AVAILABLE = false;
|
||||
Serial.printf("\nDevice already on latest firmware version: %s\n", VERSION);
|
||||
if (withScreen)
|
||||
{
|
||||
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);
|
||||
UPDATE_AVAILABLE = true;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
UPDATE_AVAILABLE = false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void checkUpdateNoReturn()
|
||||
{
|
||||
Serial.println("Check Update");
|
||||
UpdateManager.getInstance().checkUpdate(false);
|
||||
}
|
||||
|
||||
void UpdateManager_::setup()
|
||||
{
|
||||
UpdateTicker.attach(3600, checkUpdateNoReturn);
|
||||
}
|
||||
18
src/UpdateManager.h
Normal file
18
src/UpdateManager.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef UpdateManager_h
|
||||
#define UpdateManager_h
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
class UpdateManager_
|
||||
{
|
||||
private:
|
||||
UpdateManager_() = default;
|
||||
public:
|
||||
static UpdateManager_ &getInstance();
|
||||
void setup();
|
||||
bool checkUpdate(bool);
|
||||
void updateFirmware();
|
||||
};
|
||||
|
||||
extern UpdateManager_ &UpdateManager;
|
||||
#endif
|
||||
@@ -75,6 +75,8 @@ void setup()
|
||||
{
|
||||
MQTTManager.setup();
|
||||
DisplayManager.loadNativeApps();
|
||||
UpdateManager.setup();
|
||||
UpdateManager.checkUpdate(false);
|
||||
StopTask = true;
|
||||
float x = 4;
|
||||
while (x >= -85)
|
||||
@@ -101,7 +103,6 @@ void loop()
|
||||
PeripheryManager.tick();
|
||||
if (ServerManager.isConnected)
|
||||
{
|
||||
|
||||
MQTTManager.tick();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user