Skip to content

Commit

Permalink
Merge pull request #5 from redmushie/master
Browse files Browse the repository at this point in the history
Embed API URL and firmware version from CI
  • Loading branch information
LucHeart authored Sep 20, 2023
2 parents bdee934 + 278947d commit c4031f4
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 8 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/ci-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,6 +26,8 @@ jobs:
with:
path: |
~/.cache/pip
~/.platformio/platforms
~/.platformio/packages
~/.platformio/cache
key: ${{ runner.os }}-arch

Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/ci-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,6 +22,8 @@ jobs:
with:
path: |
~/.cache/pip
~/.platformio/platforms
~/.platformio/packages
~/.platformio/cache
key: ${{ runner.os }}-arch

Expand Down
17 changes: 17 additions & 0 deletions embed_version.py
Original file line number Diff line number Diff line change
@@ -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))
])
2 changes: 2 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 6 additions & 7 deletions src/ShockLink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@
#include "SPIFFS.h"
#include "HTTPClient.h"
#include <LedManager.h>
#include <Version.h>

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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion src/Version.h

This file was deleted.

0 comments on commit c4031f4

Please sign in to comment.