diff --git a/.github/workflows/build_fw.yml b/.github/workflows/build_fw.yml index 6ef044c..a922eb2 100644 --- a/.github/workflows/build_fw.yml +++ b/.github/workflows/build_fw.yml @@ -2,12 +2,12 @@ name: Build, release, push firmware permissions: contents: write - + on: workflow_dispatch: push: tags: - - '*' # Push events to matching *, any + - "*" jobs: build_release_push: @@ -16,7 +16,24 @@ jobs: - name: Clone repository uses: actions/checkout@v3 with: - submodules: 'recursive' + submodules: "recursive" + + - name: Get Release tag + id: get_tag + shell: bash + run: | + value=${GITHUB_REF#refs/tags/} + echo "tag=$value" >> $GITHUB_OUTPUT + + - name: Display src/version.h before update + run: cat src/version.h + + - name: Update version in source code + run: | + sed -i 's/#define VERSION.*/#define VERSION "${{ steps.get_tag.outputs.tag }}"/' src/version.h + + - name: Display src/version.h after update + run: cat src/version.h - name: Install Node JS uses: actions/setup-node@v3 @@ -33,7 +50,7 @@ jobs: - name: Install Python uses: actions/setup-python@v4 with: - python-version: '3.9' + python-version: "3.9" - name: Install PlatformIO Core run: pip install --upgrade platformio==6.1.11 @@ -41,20 +58,6 @@ jobs: - name: Build PlatformIO Project run: pio run - - name: Get Release Version - id: get_version - shell: bash - run: | - value=$(grep '#define VERSION' src/version.h | awk -F '"' '{print $2}') - echo "version=$value" >> $GITHUB_OUTPUT - - - name: Get Release tag - id: get_tag - shell: bash - run: | - value=${GITHUB_REF#refs/tags/} - echo "tag=$value" >> $GITHUB_OUTPUT - - name: Get last commit message id: get_commit_message run: | @@ -84,7 +87,7 @@ jobs: "improv": false, "parts": [ { - "path": "https://raw.githubusercontent.com/${{ github.repository }}/releases/${{ steps.get_tag.outputs.tag }}/XZG_${{ steps.get_version.outputs.version }}.full.bin", + "path": "https://raw.githubusercontent.com/${{ github.repository }}/releases/${{ steps.get_tag.outputs.tag }}/XZG_${{ steps.get_tag.outputs.tag }}.full.bin", "offset": 0 } ] @@ -98,11 +101,11 @@ jobs: uses: softprops/action-gh-release@v1 with: generate_release_notes: false - name: "${{ steps.get_version.outputs.version }}" + name: "${{ steps.get_tag.outputs.tag }}" body: ${{ env.releaseMessage }} files: | - bin/XZG_${{ steps.get_version.outputs.version }}.ota.bin - bin/XZG_${{ steps.get_version.outputs.version }}.full.bin + bin/XZG_${{ steps.get_tag.outputs.tag }}.ota.bin + bin/XZG_${{ steps.get_tag.outputs.tag }}.full.bin - name: Checkout releases branch uses: actions/checkout@v3 @@ -113,7 +116,7 @@ jobs: - name: Copy files to releases directory run: | mkdir -p releases/${{ steps.get_tag.outputs.tag }} - cp ./bin/XZG_${{ steps.get_version.outputs.version }}.full.bin releases/${{ steps.get_tag.outputs.tag }}/ + cp ./bin/XZG_${{ steps.get_tag.outputs.tag }}.full.bin releases/${{ steps.get_tag.outputs.tag }}/ cp manifest.json releases/${{ steps.get_tag.outputs.tag }}/ echo "Files copied to releases directory." @@ -135,4 +138,4 @@ jobs: message: | ${{ env.commitMessage }} - [${{ steps.get_tag.outputs.tag }}](https://github.com/${{ github.repository }}/releases/tag/${{ steps.get_tag.outputs.tag }}) \ No newline at end of file + [${{ steps.get_tag.outputs.tag }}](https://github.com/${{ github.repository }}/releases/tag/${{ steps.get_tag.outputs.tag }}) diff --git a/src/main.cpp b/src/main.cpp index 23b0179..34e8c2f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -123,7 +123,7 @@ void startServers(bool usb = false) mqttConnectSetup(); } } - mDNS_start(); + initWebServer(); startAP(false); @@ -162,6 +162,7 @@ void handleTmrNetworkOverseer() if (WiFi.isConnected()) { LOGD("WIFI CONNECTED"); + mDNS_start(); tmrNetworkOverseer.stop(); } else @@ -181,6 +182,7 @@ void handleTmrNetworkOverseer() if (vars.connectedEther) { LOGD("LAN CONNECTED"); + mDNS_start(); tmrNetworkOverseer.stop(); } else @@ -279,7 +281,6 @@ void NetworkEvent(WiFiEvent_t event) WiFi.localIP().toString().c_str(), WiFi.subnetMask().toString().c_str(), WiFi.gatewayIP().toString().c_str()); - break; case ARDUINO_EVENT_WIFI_STA_DISCONNECTED: // SYSTEM_EVENT_STA_DISCONNECTED: LOGD("%s STA DISCONNECTED", wifiKey); @@ -415,7 +416,6 @@ void connectWifi() void mDNS_start() { - String tag = "mDNS"; const char *host = "_xzg"; const char *http = "_http"; const char *tcp = "_tcp"; @@ -425,7 +425,7 @@ void mDNS_start() } else { - LOGD("mDNS responder started"); + LOGI("mDNS responder started on %s.local", String(systemCfg.hostname)); //----- WEB ------ mDNS.addService(http, tcp, 80); //--zeroconf zha-- diff --git a/src/version.h b/src/version.h index cb3463e..8a9d211 100644 --- a/src/version.h +++ b/src/version.h @@ -1,4 +1,4 @@ // AUTO GENERATED FILE #ifndef VERSION - #define VERSION "20240525" + #define VERSION "20240525.1" #endif diff --git a/src/websrc/html/PAGE_ABOUT.html b/src/websrc/html/PAGE_ABOUT.html index 3f140d6..b0bf499 100644 --- a/src/websrc/html/PAGE_ABOUT.html +++ b/src/websrc/html/PAGE_ABOUT.html @@ -48,7 +48,7 @@

- +

diff --git a/tools/build/version_update.py b/tools/build/version_update.py index fc0972d..e43a432 100644 --- a/tools/build/version_update.py +++ b/tools/build/version_update.py @@ -1,5 +1,4 @@ """ Create version header and tracker file if missing """ - import datetime import os import sys @@ -9,37 +8,54 @@ VERSION_HEADER = "version.h" sys.path.append("./tools") -from func import print_logo -from func import print_colored +from func import print_logo, print_colored print_logo() def get_formatted_date(dateTimeBuild): - formatted_date = dateTimeBuild.strftime("%Y%m%d") - return formatted_date - -dateTimeBuild = datetime.datetime.now() - -HEADER_FILE = """// AUTO GENERATED FILE + return dateTimeBuild.strftime("%Y%m%d") + +def read_version_from_file(file_path): + if os.path.exists(file_path): + with open(file_path, "r") as file: + for line in file: + if "#define VERSION" in line: + version = line.split('"')[1] + return version + return None + +def write_version_to_file(file_path, version): + header_content = f"""// AUTO GENERATED FILE #ifndef VERSION - #define VERSION "{}" + #define VERSION "{version}" #endif -""".format( - get_formatted_date(dateTimeBuild) -) +""" + with open(file_path, "w") as file: + file.write(header_content) + +dateTimeBuild = datetime.datetime.now() +current_date = get_formatted_date(dateTimeBuild) if os.environ.get("PLATFORMIO_INCLUDE_DIR") is not None: - VERSION_HEADER = ( - os.environ.get("PLATFORMIO_INCLUDE_DIR") + os.sep + VERSION_HEADER - ) + VERSION_HEADER = os.environ.get("PLATFORMIO_INCLUDE_DIR") + os.sep + VERSION_HEADER elif os.path.exists("src"): VERSION_HEADER = "src" + os.sep + VERSION_HEADER else: PROJECT_DIR = env.subst("$PROJECT_DIR") - os.mkdir(PROJECT_DIR + os.sep + "include") + if not os.path.exists(PROJECT_DIR + os.sep + "include"): + os.mkdir(PROJECT_DIR + os.sep + "include") VERSION_HEADER = "include" + os.sep + VERSION_HEADER -with open(VERSION_HEADER, "w+") as FILE: - FILE.write(HEADER_FILE) +current_version = read_version_from_file(VERSION_HEADER) + +if current_version: + if current_version.startswith(current_date): + new_version = current_version + else: + new_version = current_date +else: + new_version = current_date + +write_version_to_file(VERSION_HEADER, new_version) -print_colored("Build: {}".format(str(get_formatted_date(dateTimeBuild))), "magenta") +print_colored(f"Build: {new_version}", "magenta")