diff --git a/.github/workflows/ci-master.yml b/.github/workflows/ci-master.yml index 2f0be760..31bb4534 100644 --- a/.github/workflows/ci-master.yml +++ b/.github/workflows/ci-master.yml @@ -9,6 +9,10 @@ on: name: ci-master +env: + SHOCKLINK_API_URL: api.shocklink.net + SHOCKLINK_FW_VERSION: master-${{ github.sha }} + jobs: # Copied verbatim from https://docs.platformio.org/en/stable/integration/ci/github-actions.html @@ -22,6 +26,8 @@ jobs: with: path: | ~/.cache/pip + ~/.platformio/platforms + ~/.platformio/packages ~/.platformio/cache key: ${{ runner.os }}-arch diff --git a/.github/workflows/ci-tag.yml b/.github/workflows/ci-tag.yml index 4d9f7537..64636982 100644 --- a/.github/workflows/ci-tag.yml +++ b/.github/workflows/ci-tag.yml @@ -5,6 +5,10 @@ on: name: ci-tag +env: + SHOCKLINK_API_URL: api.shocklink.net + SHOCKLINK_FW_VERSION: ${{ github.ref_name }} + jobs: # Copied verbatim from https://docs.platformio.org/en/stable/integration/ci/github-actions.html @@ -18,6 +22,8 @@ jobs: with: path: | ~/.cache/pip + ~/.platformio/platforms + ~/.platformio/packages ~/.platformio/cache key: ${{ runner.os }}-arch diff --git a/embed_version.py b/embed_version.py new file mode 100644 index 00000000..eba1be54 --- /dev/null +++ b/embed_version.py @@ -0,0 +1,17 @@ +import os + +Import("env") + +# This file is invoked by PlatformIO during build. +# See "extra_scripts" in "platformio.ini". + +# Fetch environment variables, with sane defaults if not found. +# These variables should be defined by the CI. +shocklinkApiUrl = os.getenv('SHOCKLINK_API_URL') or "api.shocklink.net" +shocklinkFwVersion = os.getenv('SHOCKLINK_FW_VERSION') or "0.8.1" + +# Define these variables as macros for expansion during build time. +env.Append(CPPDEFINES=[ + ("SHOCKLINK_API_URL", env.StringifyMacro(shocklinkApiUrl)), + ("SHOCKLINK_FW_VERSION", env.StringifyMacro(shocklinkFwVersion)) +]) diff --git a/platformio.ini b/platformio.ini index 211d2181..991dcd61 100644 --- a/platformio.ini +++ b/platformio.ini @@ -19,3 +19,5 @@ lib_deps = links2004/WebSockets@^2.3.7 https://github.com/me-no-dev/ESPAsyncWebServer.git board_build.partitions = huge_app.csv +extra_scripts = + pre:embed_version.py \ No newline at end of file diff --git a/src/ShockLink.cpp b/src/ShockLink.cpp index 389c0f85..9c808e4d 100644 --- a/src/ShockLink.cpp +++ b/src/ShockLink.cpp @@ -14,10 +14,9 @@ #include "SPIFFS.h" #include "HTTPClient.h" #include -#include -const String apiUrl = "api.shocklink.net"; -const String devApiUrl = "dev-api.shocklink.net"; +const String shocklinkApiUrl = SHOCKLINK_API_URL; +const String shocklinkFwVersion = SHOCKLINK_FW_VERSION; WiFiMulti WiFiMulti; WebSocketsClient webSocket; @@ -229,7 +228,7 @@ void setup() Serial.println(); Serial.println(); Serial.print("==== ShockLink v"); - Serial.print(versionString); + Serial.print(shocklinkFwVersion); Serial.println(" ===="); LedManager::Loop(WL_IDLE_STATUS, false, 0); @@ -292,8 +291,8 @@ void setup() String authToken = authTokenFile.readString(); authTokenFile.close(); - webSocket.setExtraHeaders(("FirmwareVersion:" + versionString + "\r\nDeviceToken: " + authToken).c_str()); - webSocket.beginSSL(apiUrl, 443, "/1/ws/device"); + webSocket.setExtraHeaders(("FirmwareVersion:" + shocklinkFwVersion + "\r\nDeviceToken: " + authToken).c_str()); + webSocket.beginSSL(shocklinkApiUrl, 443, "/1/ws/device"); webSocket.onEvent(webSocketEvent); runner.addTask(keepalive); keepalive.enable(); @@ -421,7 +420,7 @@ void loop() SPIFFS.remove("/pairCode"); HTTPClient http; - String uri = "https://" + apiUrl + "/1/pair/" + pairCode; + String uri = "https://" + shocklinkApiUrl + "/1/pair/" + pairCode; Serial.print("Contacting pair code url: "); Serial.println(uri); diff --git a/src/Version.h b/src/Version.h deleted file mode 100644 index 5cac854c..00000000 --- a/src/Version.h +++ /dev/null @@ -1 +0,0 @@ -const String versionString = "0.8.0"; \ No newline at end of file