Check GitHub for updates

This commit is contained in:
iranl
2024-02-07 22:08:54 +01:00
parent cb4d8cc55c
commit 8c601ece4c
4 changed files with 28 additions and 0 deletions

View File

@@ -1,6 +1,8 @@
#pragma once #pragma once
#define NUKI_HUB_VERSION "8.32-pre-3" #define NUKI_HUB_VERSION "8.32-pre-3"
#define GITHUB_LATEST_RELEASE_URL "https://github.com/technyon/nuki_hub/releases/latest"
#define GITHUB_RELEASE_TAG_URL "https://github.com/technyon/nuki_hub/releases/tag/"
#define MQTT_QOS_LEVEL 1 #define MQTT_QOS_LEVEL 1
#define MQTT_CLEAN_SESSIONS false #define MQTT_CLEAN_SESSIONS false

View File

@@ -41,6 +41,7 @@
#define mqtt_topic_info_hardware_version "/info/hardwareVersion" #define mqtt_topic_info_hardware_version "/info/hardwareVersion"
#define mqtt_topic_info_firmware_version "/info/firmwareVersion" #define mqtt_topic_info_firmware_version "/info/firmwareVersion"
#define mqtt_topic_info_nuki_hub_version "/info/nukiHubVersion" #define mqtt_topic_info_nuki_hub_version "/info/nukiHubVersion"
#define mqtt_topic_info_nuki_hub_latest "/info/nukiHubLatest"
#define mqtt_topic_keypad "/keypad" #define mqtt_topic_keypad "/keypad"
#define mqtt_topic_keypad_command_action "/keypad/command/action" #define mqtt_topic_keypad_command_action "/keypad/command/action"

View File

@@ -358,6 +358,25 @@ bool Network::update()
_lastMaintenanceTs = ts; _lastMaintenanceTs = ts;
} }
if(_lastUpdateCheckTs == 0 || (ts - _lastUpdateCheckTs) > 86400000)
{
_lastUpdateCheckTs = ts;
https.collectHeaders(headerKeys, 1);
https.setFollowRedirects(HTTPC_DISABLE_FOLLOW_REDIRECTS);
https.begin(GITHUB_LATEST_RELEASE_URL);
int httpResponseCode = https.GET();
if (httpResponseCode==302) {
_latestVersion = https.header("location");
_latestVersion.replace(GITHUB_RELEASE_TAG_URL, "");
publishString(_maintenancePathPrefix, mqtt_topic_info_nuki_hub_latest, _latestVersion);
}
https.end();
}
for(const auto& gpioTs : _gpioTs) for(const auto& gpioTs : _gpioTs)
{ {
uint8_t pin = gpioTs.first; uint8_t pin = gpioTs.first;

View File

@@ -8,6 +8,7 @@
#include "networkDevices/IPConfiguration.h" #include "networkDevices/IPConfiguration.h"
#include "MqttTopics.h" #include "MqttTopics.h"
#include "Gpio.h" #include "Gpio.h"
#include <HTTPClient.h>
enum class NetworkDeviceType enum class NetworkDeviceType
{ {
@@ -111,6 +112,10 @@ private:
char _mqttConnectionStateTopic[211] = {0}; char _mqttConnectionStateTopic[211] = {0};
String _lockPath; String _lockPath;
const char* headerKeys[] = {"location"};
String _latestVersion;
HTTPClient https;
Preferences* _preferences; Preferences* _preferences;
Gpio* _gpio; Gpio* _gpio;
IPConfiguration* _ipConfiguration = nullptr; IPConfiguration* _ipConfiguration = nullptr;
@@ -137,6 +142,7 @@ private:
unsigned long _lastConnectedTs = 0; unsigned long _lastConnectedTs = 0;
unsigned long _lastMaintenanceTs = 0; unsigned long _lastMaintenanceTs = 0;
unsigned long _lastUpdateCheckTs = 0;
unsigned long _lastRssiTs = 0; unsigned long _lastRssiTs = 0;
bool _mqttEnabled = true; bool _mqttEnabled = true;
static unsigned long _ignoreSubscriptionsTs; static unsigned long _ignoreSubscriptionsTs;