Selaa lähdekoodia

track version

Chris Mullins 8 vuotta sitten
vanhempi
commit
02339e171d

+ 8 - 0
lib/Settings/Settings.h

@@ -5,6 +5,14 @@
 #ifndef _SETTINGS_H_INCLUDED
 #define _SETTINGS_H_INCLUDED
 
+#ifndef FIRMWARE_VARIANT
+#define FIRMWARE_VARIANT "unknown"
+#endif
+
+#ifndef MILIGHT_HUB_VERSION
+#define MILIGHT_HUB_VERSION "unknown"
+#endif
+
 #define SETTINGS_FILE  "/config.json"
 #define SETTINGS_TERMINATOR '\0'
 

+ 14 - 0
lib/WebServer/MiLightHttpServer.cpp

@@ -18,6 +18,7 @@ void MiLightHttpServer::begin() {
   server.onPattern("/gateways/:device_id/:type", HTTP_PUT, [this](const UrlTokenBindings* b) { handleUpdateGateway(b); });
   server.onPattern("/send_raw/:type", HTTP_PUT, [this](const UrlTokenBindings* b) { handleSendRaw(b); });
   server.on("/web", HTTP_POST, [this]() { server.send(200, "text/plain", "success"); }, handleUpdateFile(WEB_INDEX_FILENAME));
+  server.on("/about", HTTP_GET, [this]() { handleAbout(); });
   server.on("/firmware", HTTP_POST, 
     [this](){
       server.sendHeader("Connection", "close");
@@ -68,6 +69,19 @@ void MiLightHttpServer::onSettingsSaved(SettingsSavedHandler handler) {
   this->settingsSavedHandler = handler;
 }
   
+void MiLightHttpServer::handleAbout() {
+  DynamicJsonBuffer buffer;
+  JsonObject& response = buffer.createObject();
+  
+  response["version"] = MILIGHT_HUB_VERSION;
+  response["variant"] = FIRMWARE_VARIANT;
+  
+  String body;
+  response.printTo(body);
+  
+  server.send(200, "application", body); 
+}
+  
 void MiLightHttpServer::handleGetRadioConfigs() {
   DynamicJsonBuffer buffer;
   JsonArray& arr = buffer.createArray();

+ 1 - 0
lib/WebServer/MiLightHttpServer.h

@@ -33,6 +33,7 @@ protected:
   
   void handleUpdateSettings();
   void handleGetRadioConfigs();
+  void handleAbout();
   void handleListenGateway(const UrlTokenBindings* urlBindings);
   void handleSendRaw(const UrlTokenBindings* urlBindings);
   void handleUpdateGroup(const UrlTokenBindings* urlBindings);

+ 5 - 2
platformio.ini

@@ -16,6 +16,7 @@ lib_deps_external =
   RF24
   WiFiManager
   ArduinoJson
+build_flags = -D MILIGHT_HUB_VERSION=\"1.1.0\"
 
 [env:nodemcuv2]
 platform = espressif8266
@@ -24,6 +25,7 @@ board = nodemcuv2
 lib_deps =
   ${common.lib_deps_builtin}
   ${common.lib_deps_external}
+build_flags = ${common.build_flags} -D FIRMWARE_VARIANT=\"nodemcuv2\"
 
 [env:d1_mini]
 platform = espressif8266
@@ -32,12 +34,13 @@ board = d1_mini
 lib_deps =
   ${common.lib_deps_builtin}
   ${common.lib_deps_external}
+build_flags = ${common.build_flags} -D FIRMWARE_VARIANT=\"d1_mini\"
 
 [env:esp12]
 platform = espressif8266
 board = esp12e
 framework = arduino
-build_flags = -Wl,-Tesp8266.flash.4m1m.ld
+build_flags = ${common.build_flags} -Wl,-Tesp8266.flash.4m1m.ld -D FIRMWARE_VARIANT=\"esp12\"
 lib_deps =
   ${common.lib_deps_builtin}
   ${common.lib_deps_external}
@@ -46,7 +49,7 @@ lib_deps =
 platform = espressif8266
 board = esp07
 framework = arduino
-build_flags = -Wl,-Tesp8266.flash.1m64.ld
+build_flags = ${common.build_flags} -Wl,-Tesp8266.flash.1m64.ld -D FIRMWARE_VARIANT=\"esp07\"
 lib_deps =
   ${common.lib_deps_builtin}
   ${common.lib_deps_external}