diff --git a/.github/workflows/arduino-report.yml b/.github/workflows/arduino-report.yml new file mode 100644 index 0000000..86a369a --- /dev/null +++ b/.github/workflows/arduino-report.yml @@ -0,0 +1,8 @@ +on: + schedule: + - cron: '*/5 * * * *' +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: arduino/report-size-deltas@v1 diff --git a/.github/workflows/arduino.yml b/.github/workflows/arduino.yml new file mode 100644 index 0000000..4d1df26 --- /dev/null +++ b/.github/workflows/arduino.yml @@ -0,0 +1,63 @@ +name: arduino +on: [ push, pull_request ] + +jobs: + build-for-esp32: + runs-on: ubuntu-latest + strategy: + matrix: + fqbn: + - esp32:esp32:esp32 + # - esp32:esp32:esp32s3 + # - esp32:esp32:esp32c3 + # future bluetooth chips + #- esp32:esp32:esp32c2 + #- esp32:esp32:esp32c6 + #- esp32:esp32:esp32h2 + + steps: + - uses: actions/checkout@v3 + - uses: arduino/compile-sketches@v1 + with: + enable-deltas-report: true + github-token: ${{ secrets.GITHUB_TOKEN }} + fqbn: ${{ matrix.fqbn }} + platforms: | + - name: esp32:esp32 + source-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json + sketch-paths: | + - nostrZapLamp + libraries: | + - name: WebSockets + - name: ArduinoJson + - name: uBitcoin + - name: base64 + - name: Button + - name: WiFiManager + - name: Nostr + # - name: QRCode + # - name: ESP32Ping + cli-compile-flags: | + - --warnings="none" + + - uses: actions/upload-artifact@v2 + with: + name: sketches-reports + path: sketches-reports + + + report: + needs: build-for-esp32 + if: github.event_name == 'pull_request' + runs-on: ubuntu-latest + steps: + # This step is needed to get the size data produced by the compile jobs + - name: Download sketches reports artifact + uses: actions/download-artifact@v2 + with: + name: sketches-reports + path: sketches-reports + + - uses: arduino/report-size-deltas@v1 + with: + sketches-reports-source: sketches-reports diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..7268a3a --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,58 @@ +name: release + +on: + push: + tags: + - "v[0-9]+.[0-9]+.[0-9]+" + +# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages +permissions: + contents: write + pages: write + id-token: write + +jobs: + release: + runs-on: ubuntu-latest + steps: + + - uses: actions/checkout@v3 + with: + ref: main + + - name: update version in repo + env: + tag: ${{ github.ref_name }} + run: | + tmp=$(mktemp) + jq --arg version $tag '.versions |= [$version] + .' versions.json > "$tmp" && mv "$tmp" versions.json + git config --global user.name 'Alan Bits' + git config --global user.email 'alan@lnbits.com' + git commit -am "[CHORE] update version to $tag" + git push + git push --delete origin $tag + git tag -fa $tag -m "update via workflow" + git push --tags + + - name: Install Arduino CLI + uses: arduino/setup-arduino-cli@v1 + + - name: build sketch with arduino cli + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + tag: ${{ github.ref_name }} + run: | + sh build.sh + sh release.sh $tag + + - name: Create github release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + tag: ${{ github.ref_name }} + run: | + gh release create "$tag" --generate-notes ./dist/$tag/bootloader.bin ./dist/$tag/boot_app0.bin \ + ./dist/$tag/nostrZapLamp.ino.bin ./dist/$tag/nostrZapLamp.ino.partitions.bin + + pages: + needs: [ release ] + uses: ./.github/workflows/static.yml diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml new file mode 100644 index 0000000..da5bc51 --- /dev/null +++ b/.github/workflows/static.yml @@ -0,0 +1,46 @@ +# Simple workflow for deploying static content to GitHub Pages +name: Deploy static content to Pages + +on: + # Runs on pushes targeting the default branch + push: + branches: ["main"] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + + # Allows you to run this workflow from other workflows + workflow_call: + +# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages +permissions: + contents: read + pages: write + id-token: write + +# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. +# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. +concurrency: + group: "pages" + cancel-in-progress: false + +jobs: + deploy: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: copy main assets + run: sh build-webinstaller.sh + - name: Setup Pages + uses: actions/configure-pages@v3 + - name: Upload artifact + uses: actions/upload-pages-artifact@v1 + with: + path: "hardware-installer" + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v2 diff --git a/.gitignore b/.gitignore index bd1531c..be6177f 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ .vscode/ipch pcb/*.lck pcb/NostrZapLamp-backups +build diff --git a/build-webinstaller.sh b/build-webinstaller.sh new file mode 100644 index 0000000..2c87476 --- /dev/null +++ b/build-webinstaller.sh @@ -0,0 +1,20 @@ +#!/bin/sh +INSTALLER_PATH=./hardware-installer/src/firmware/esp32 +REPO=https://github.com/lnbits/bitcoinswitch/releases/download +PROJECT_NAME=nostrZapLamp + +git clone https://github.com/lnbits/hardware-installer +mkdir -p $INSTALLER_PATH +cp versions.json ./hardware-installer/src/versions.json + +for version in $(jq -r '.versions[]' ./hardware-installer/src/versions.json); do + mkdir -p $INSTALLER_PATH/$version + wget $REPO/$version/bootloader.bin + mv bootloader.bin $INSTALLER_PATH/$version + wget $REPO/$version/boot_app0.bin + mv boot_app0.bin $INSTALLER_PATH/$version + wget $REPO/$version/$PROJECT_NAME.ino.bin + mv $PROJECT_NAME.ino.bin $INSTALLER_PATH/$version + wget $REPO/$version/$PROJECT_NAME.ino.partitions.bin + mv $PROJECT_NAME.ino.partitions.bin $INSTALLER_PATH/$version +done diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..e5d2a49 --- /dev/null +++ b/build.sh @@ -0,0 +1,8 @@ +#!/bin/sh +command -v arduino-cli >/dev/null 2>&1 || { echo >&2 "arduino-cli not found. Aborting."; exit 1; } +arduino-cli config --additional-urls https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json init +arduino-cli core update-index +arduino-cli core install esp32:esp32 +arduino-cli upgrade +arduino-cli lib install uBitcoin WebSockets ArduinoJson base64 Button WiFiManager Nostr # QRCode ESP32Ping +arduino-cli compile --build-path build --fqbn esp32:esp32:esp32 --build-properties build.partitions=min_spiffs,upload.maximum_size=1966080 nostrZapLamp diff --git a/code/include/README b/code/include/README deleted file mode 100644 index 194dcd4..0000000 --- a/code/include/README +++ /dev/null @@ -1,39 +0,0 @@ - -This directory is intended for project header files. - -A header file is a file containing C declarations and macro definitions -to be shared between several project source files. You request the use of a -header file in your project source file (C, C++, etc) located in `src` folder -by including it, with the C preprocessing directive `#include'. - -```src/main.c - -#include "header.h" - -int main (void) -{ - ... -} -``` - -Including a header file produces the same results as copying the header file -into each source file that needs it. Such copying would be time-consuming -and error-prone. With a header file, the related declarations appear -in only one place. If they need to be changed, they can be changed in one -place, and programs that include the header file will automatically use the -new version when next recompiled. The header file eliminates the labor of -finding and changing all the copies as well as the risk that a failure to -find one copy will result in inconsistencies within a program. - -In C, the usual convention is to give header files names that end with `.h'. -It is most portable to use only letters, digits, dashes, and underscores in -header file names, and at most one dot. - -Read more about using header files in official GCC documentation: - -* Include Syntax -* Include Operation -* Once-Only Headers -* Computed Includes - -https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/code/lib/README b/code/lib/README deleted file mode 100644 index 6debab1..0000000 --- a/code/lib/README +++ /dev/null @@ -1,46 +0,0 @@ - -This directory is intended for project specific (private) libraries. -PlatformIO will compile them to static libraries and link into executable file. - -The source code of each library should be placed in a an own separate directory -("lib/your_library_name/[here are source files]"). - -For example, see a structure of the following two libraries `Foo` and `Bar`: - -|--lib -| | -| |--Bar -| | |--docs -| | |--examples -| | |--src -| | |- Bar.c -| | |- Bar.h -| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html -| | -| |--Foo -| | |- Foo.c -| | |- Foo.h -| | -| |- README --> THIS FILE -| -|- platformio.ini -|--src - |- main.c - -and a contents of `src/main.c`: -``` -#include -#include - -int main (void) -{ - ... -} - -``` - -PlatformIO Library Dependency Finder will find automatically dependent -libraries scanning project source files. - -More information about PlatformIO Library Dependency Finder -- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/code/test/README b/code/test/README deleted file mode 100644 index 9b1e87b..0000000 --- a/code/test/README +++ /dev/null @@ -1,11 +0,0 @@ - -This directory is intended for PlatformIO Test Runner and project tests. - -Unit Testing is a software testing method by which individual units of -source code, sets of one or more MCU program modules together with associated -control data, usage procedures, and operating procedures, are tested to -determine whether they are fit for use. Unit testing finds problems early -in the development cycle. - -More information about PlatformIO Unit Testing: -- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html diff --git a/code/.gitignore b/nostrZapLamp/.gitignore similarity index 100% rename from code/.gitignore rename to nostrZapLamp/.gitignore diff --git a/code/.vscode/extensions.json b/nostrZapLamp/.vscode/extensions.json similarity index 100% rename from code/.vscode/extensions.json rename to nostrZapLamp/.vscode/extensions.json diff --git a/code/img/lamp.jpg b/nostrZapLamp/img/lamp.jpg similarity index 100% rename from code/img/lamp.jpg rename to nostrZapLamp/img/lamp.jpg diff --git a/code/src/main.cpp b/nostrZapLamp/nostrZapLamp.ino similarity index 96% rename from code/src/main.cpp rename to nostrZapLamp/nostrZapLamp.ino index 854cff3..27e1448 100644 --- a/code/src/main.cpp +++ b/nostrZapLamp/nostrZapLamp.ino @@ -9,11 +9,11 @@ #include "Bitcoin.h" #include "Hash.h" #include -#include "QRCode.h" +/* #include "QRCode.h" */ #include #include #include -#include +/* #include */ #include "wManager.h" @@ -26,7 +26,7 @@ #define BUZZER_PIN 2 // Connect the piezo buzzer to this GPIO pin. #define CLICK_DURATION 20 // Duration in milliseconds. -#define PARAM_FILE "/elements.json" +/* #define PARAM_FILE "/elements.json" */ int triggerAp = false; @@ -110,7 +110,7 @@ void WiFiEvent(WiFiEvent_t event) { click(225); delay(100); click(225); - connectToNostrRelays(); + connectToNostrRelays(); break; case SYSTEM_EVENT_STA_DISCONNECTED: Serial.println("Disconnected from WiFi"); @@ -138,7 +138,7 @@ void lampControlTask(void *pvParameters) { } } - // detect double tap on button + // detect double tap on button if (doubleTapDetected) { Serial.println("Double tap detected. REstarting"); // restart device @@ -180,7 +180,7 @@ void lampControlTask(void *pvParameters) { /** * @brief Create a Zap Event Request object - * + * */ void createZapEventRequest() { // Create the REQ @@ -210,7 +210,7 @@ void createZapEventRequest() { /** * @brief Connect to the Nostr relays - * + * */ void connectToNostrRelays() { // first disconnect from all relays @@ -250,7 +250,7 @@ void connectToNostrRelays() { bool adjustLightingBrightnessUp = true; /** * @brief change lamp brightness - * + * */ void changeBrightness() { // use lastLightingAdjustmentWasUp and max value of 255 to decide whether to adjust up or down @@ -272,7 +272,7 @@ void changeBrightness() { delay(500); // pause to let the user take their finger off the button } } - + // write to spiffs File file = SPIFFS.open("/brightness.txt", FILE_WRITE); if(!file){ @@ -364,8 +364,8 @@ void flashLightning(int zapAmountSats) { /** * @brief Flash the LED a random number of times with a random delay between flashes - * - * @param numFlashes + * + * @param numFlashes */ void signalWithLightning(int numFlashes, int duration = 500) { for (int i = 0; i < numFlashes; i++) { @@ -402,7 +402,7 @@ void relayConnectedEvent(const std::string& key, const std::string& message) { click(225); delay(100); click(225); - + Serial.print(F("Requesting events:")); Serial.println(serialisedEventRequest); @@ -463,9 +463,9 @@ String getBolt11InvoiceFromEvent(String jsonStr) { /** * @brief Get the Amount In Satoshis from a lightning bol11 invoice - * - * @param input - * @return int64_t + * + * @param input + * @return int64_t */ int64_t getAmountInSatoshis(const String &input) { int64_t number = -1; @@ -625,18 +625,18 @@ void loop() { // send ping to Quad9 9.9.9.9 every 10 seconds to check for internet connection if (millis() - lastInternetConnectionCheckTime > 10000) { if(WiFi.status() == WL_CONNECTED) { - IPAddress ip(9,9,9,9); // Quad9 DNS - bool ret = Ping.ping(ip); - if(ret) { - if(!lastInternetConnectionState) { - Serial.println("Internet connection has come back! :D"); - // reboot - ESP.restart(); - } + /* IPAddress ip(9,9,9,9); // Quad9 DNS */ + /* bool ret = Ping.ping(ip); */ + /* if(ret) { */ + /* if(!lastInternetConnectionState) { */ + /* Serial.println("Internet connection has come back! :D"); */ + /* // reboot */ + /* ESP.restart(); */ + /* } */ lastInternetConnectionState = true; - } else { - lastInternetConnectionState = false; - } + /* } else { */ + /* lastInternetConnectionState = false; */ + /* } */ } } @@ -649,4 +649,4 @@ void loop() { ESP.restart(); } -} \ No newline at end of file +} diff --git a/code/src/wManager.cpp b/nostrZapLamp/wManager.cpp similarity index 100% rename from code/src/wManager.cpp rename to nostrZapLamp/wManager.cpp diff --git a/code/src/wManager.h b/nostrZapLamp/wManager.h similarity index 100% rename from code/src/wManager.h rename to nostrZapLamp/wManager.h diff --git a/code/platformio.ini b/platformio.ini similarity index 94% rename from code/platformio.ini rename to platformio.ini index 94e824e..95ba975 100644 --- a/code/platformio.ini +++ b/platformio.ini @@ -7,6 +7,9 @@ ; ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html +; +[platformio] +src_dir = nostrZapLamp [env:esp32dev] platform = espressif32 @@ -14,7 +17,7 @@ build_type = debug board_build.partitions = huge_app.csv board = esp32dev framework = arduino -lib_deps = +lib_deps = https://github.com/micro-bitcoin/uBitcoin.git#master bblanchon/ArduinoJson@^6.21.0 links2004/WebSockets@^2.3.7