diff --git a/Config.h b/Config.h index 07f9518..9c28fa0 100644 --- a/Config.h +++ b/Config.h @@ -1,6 +1,8 @@ #pragma once #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_CLEAN_SESSIONS false diff --git a/MqttTopics.h b/MqttTopics.h index b5ae1ff..d8d0470 100644 --- a/MqttTopics.h +++ b/MqttTopics.h @@ -41,6 +41,7 @@ #define mqtt_topic_info_hardware_version "/info/hardwareVersion" #define mqtt_topic_info_firmware_version "/info/firmwareVersion" #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_command_action "/keypad/command/action" diff --git a/Network.cpp b/Network.cpp index e951574..cd7e110 100644 --- a/Network.cpp +++ b/Network.cpp @@ -357,7 +357,26 @@ bool Network::update() } _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) { uint8_t pin = gpioTs.first; diff --git a/Network.h b/Network.h index c9aa133..7cda6a7 100644 --- a/Network.h +++ b/Network.h @@ -8,6 +8,7 @@ #include "networkDevices/IPConfiguration.h" #include "MqttTopics.h" #include "Gpio.h" +#include enum class NetworkDeviceType { @@ -111,6 +112,10 @@ private: char _mqttConnectionStateTopic[211] = {0}; String _lockPath; + const char* headerKeys[] = {"location"}; + String _latestVersion; + HTTPClient https; + Preferences* _preferences; Gpio* _gpio; IPConfiguration* _ipConfiguration = nullptr; @@ -137,6 +142,7 @@ private: unsigned long _lastConnectedTs = 0; unsigned long _lastMaintenanceTs = 0; + unsigned long _lastUpdateCheckTs = 0; unsigned long _lastRssiTs = 0; bool _mqttEnabled = true; static unsigned long _ignoreSubscriptionsTs;