From ce024214a2c97067e041224366cbea28ada648c8 Mon Sep 17 00:00:00 2001 From: Dan Quintas Date: Sat, 28 Oct 2023 01:14:34 +0000 Subject: [PATCH 1/7] add VSCode devcontainer config --- .devcontainer/Dockerfile | 18 ++++++++++ .devcontainer/devcontainer.json | 23 +++++++++++++ .devcontainer/reinstall-cmake.sh | 59 ++++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/reinstall-cmake.sh diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 00000000..cf51ba25 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,18 @@ +FROM mcr.microsoft.com/devcontainers/cpp:1-debian-11 + +ARG REINSTALL_CMAKE_VERSION_FROM_SOURCE="none" + +# Optionally install the cmake for vcpkg +COPY ./reinstall-cmake.sh /tmp/ + +RUN if [ "${REINSTALL_CMAKE_VERSION_FROM_SOURCE}" != "none" ]; then \ + chmod +x /tmp/reinstall-cmake.sh && /tmp/reinstall-cmake.sh ${REINSTALL_CMAKE_VERSION_FROM_SOURCE}; \ + fi \ + && rm -f /tmp/reinstall-cmake.sh + +# [Optional] Uncomment this section to install additional vcpkg ports. +# RUN su vscode -c "${VCPKG_ROOT}/vcpkg install " + +# [Optional] Uncomment this section to install additional packages. +# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ +# && apt-get -y install --no-install-recommends diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..26476611 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,23 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/cpp +{ + "name": "C++", + "build": { + "dockerfile": "Dockerfile" + }, + + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Use 'postCreateCommand' to run commands after the container is created. + "postCreateCommand": "sudo apt -y update && sudo apt-get -y install python3-venv" + + // Configure tool-specific properties. + // "customizations": {}, + + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} diff --git a/.devcontainer/reinstall-cmake.sh b/.devcontainer/reinstall-cmake.sh new file mode 100644 index 00000000..408b81d2 --- /dev/null +++ b/.devcontainer/reinstall-cmake.sh @@ -0,0 +1,59 @@ +#!/usr/bin/env bash +#------------------------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. +#------------------------------------------------------------------------------------------------------------- +# +set -e + +CMAKE_VERSION=${1:-"none"} + +if [ "${CMAKE_VERSION}" = "none" ]; then + echo "No CMake version specified, skipping CMake reinstallation" + exit 0 +fi + +# Cleanup temporary directory and associated files when exiting the script. +cleanup() { + EXIT_CODE=$? + set +e + if [[ -n "${TMP_DIR}" ]]; then + echo "Executing cleanup of tmp files" + rm -Rf "${TMP_DIR}" + fi + exit $EXIT_CODE +} +trap cleanup EXIT + + +echo "Installing CMake..." +apt-get -y purge --auto-remove cmake +mkdir -p /opt/cmake + +architecture=$(dpkg --print-architecture) +case "${architecture}" in + arm64) + ARCH=aarch64 ;; + amd64) + ARCH=x86_64 ;; + *) + echo "Unsupported architecture ${architecture}." + exit 1 + ;; +esac + +CMAKE_BINARY_NAME="cmake-${CMAKE_VERSION}-linux-${ARCH}.sh" +CMAKE_CHECKSUM_NAME="cmake-${CMAKE_VERSION}-SHA-256.txt" +TMP_DIR=$(mktemp -d -t cmake-XXXXXXXXXX) + +echo "${TMP_DIR}" +cd "${TMP_DIR}" + +curl -sSL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_BINARY_NAME}" -O +curl -sSL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_CHECKSUM_NAME}" -O + +sha256sum -c --ignore-missing "${CMAKE_CHECKSUM_NAME}" +sh "${TMP_DIR}/${CMAKE_BINARY_NAME}" --prefix=/opt/cmake --skip-license + +ln -s /opt/cmake/bin/cmake /usr/local/bin/cmake +ln -s /opt/cmake/bin/ctest /usr/local/bin/ctest From a69be1de0fc8ce3a728f8a7588957745c59082c5 Mon Sep 17 00:00:00 2001 From: Dan Quintas Date: Sat, 28 Oct 2023 23:53:33 +0000 Subject: [PATCH 2/7] added IP address to /stats (HTTP and MQTT) --- src/DisplayManager.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/DisplayManager.cpp b/src/DisplayManager.cpp index b71dcb69..83e22dfa 100644 --- a/src/DisplayManager.cpp +++ b/src/DisplayManager.cpp @@ -19,6 +19,7 @@ #include #include #include "base64.hpp" +#include unsigned long lastArtnetStatusTime = 0; const int numberOfChannels = 256 * 3; @@ -1591,6 +1592,7 @@ String DisplayManager_::getStats() doc[F("app")] = CURRENT_APP; doc[F("uid")] = uniqueID; doc[F("matrix")] = !MATRIX_OFF; + doc[F("ip_address")] = WiFi.localIP(); String jsonString; serializeJson(doc, jsonString); return jsonString; From 3ebd35d8eccd0c6ec4cbaa47ec68054a7c1a23c0 Mon Sep 17 00:00:00 2001 From: Dan Quintas Date: Sun, 29 Oct 2023 01:39:51 +0000 Subject: [PATCH 3/7] support IP address in HA --- src/Dictionary.cpp | 4 ++++ src/Dictionary.h | 4 ++++ src/DisplayManager.cpp | 2 +- src/MQTTManager.cpp | 15 ++++++++++++--- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/Dictionary.cpp b/src/Dictionary.cpp index 878bf4b4..a1dc8170 100644 --- a/src/Dictionary.cpp +++ b/src/Dictionary.cpp @@ -134,6 +134,9 @@ const char HAramName[] PROGMEM = {"Free ram"}; const char HAramClass[] PROGMEM = {"data_size"}; const char HAramUnit[] PROGMEM = {"B"}; +const char HAipAddrRID[] PROGMEM = {"%s_ip_address"}; +const char HAipAddrName[] PROGMEM = {"IP Address"}; + // JSON properites #ifndef awtrix2_upgrade const char BatKey[] PROGMEM = {"bat"}; @@ -150,3 +153,4 @@ const char UpdateKey[] PROGMEM = {"up_available"}; const char MessagesKey[] PROGMEM = {"messages"}; const char VersionKey[] PROGMEM = {"version"}; const char RamKey[] PROGMEM = {"ram"}; +const char IpAddrKey[] PROGMEM = {"ip_address"}; diff --git a/src/Dictionary.h b/src/Dictionary.h index 5f445d0d..8ce6fbdd 100644 --- a/src/Dictionary.h +++ b/src/Dictionary.h @@ -131,6 +131,9 @@ extern const char HAramName[]; extern const char HAramClass[]; extern const char HAramUnit[]; +extern const char HAipAddrRID[]; +extern const char HAipAddrName[]; + // JSON properites #ifndef awtrix2_upgrade extern const char BatKey[]; @@ -147,4 +150,5 @@ extern const char UpdateKey[]; extern const char MessagesKey[]; extern const char VersionKey[]; extern const char RamKey[]; +extern const char IpAddrKey[]; #endif diff --git a/src/DisplayManager.cpp b/src/DisplayManager.cpp index 83e22dfa..e9c9b0ee 100644 --- a/src/DisplayManager.cpp +++ b/src/DisplayManager.cpp @@ -1592,7 +1592,7 @@ String DisplayManager_::getStats() doc[F("app")] = CURRENT_APP; doc[F("uid")] = uniqueID; doc[F("matrix")] = !MATRIX_OFF; - doc[F("ip_address")] = WiFi.localIP(); + doc[IpAddrKey] = WiFi.localIP(); String jsonString; serializeJson(doc, jsonString); return jsonString; diff --git a/src/MQTTManager.cpp b/src/MQTTManager.cpp index 978b57ec..1c7dd22f 100644 --- a/src/MQTTManager.cpp +++ b/src/MQTTManager.cpp @@ -12,7 +12,7 @@ WiFiClient espClient; HADevice device; -HAMqtt mqtt(espClient, device, 25); +HAMqtt mqtt(espClient, device, 26); // HANumber *ScrollSpeed = nullptr; HALight *Matrix, *Indikator1, *Indikator2, *Indikator3 = nullptr; HASelect *BriMode, *transEffect = nullptr; @@ -21,10 +21,10 @@ HASwitch *transition = nullptr; #ifndef awtrix2_upgrade HASensor *battery = nullptr; #endif -HASensor *temperature, *humidity, *illuminance, *uptime, *strength, *version, *ram, *curApp, *myOwnID = nullptr; +HASensor *temperature, *humidity, *illuminance, *uptime, *strength, *version, *ram, *curApp, *myOwnID, *ipAddr = nullptr; HABinarySensor *btnleft, *btnmid, *btnright = nullptr; bool connected; -char matID[40], ind1ID[40], ind2ID[40], ind3ID[40], briID[40], btnAID[40], btnBID[40], btnCID[40], appID[40], tempID[40], humID[40], luxID[40], verID[40], ramID[40], upID[40], sigID[40], btnLID[40], btnMID[40], btnRID[40], transID[40], doUpdateID[40], batID[40], myID[40], sSpeed[40], effectID[40]; +char matID[40], ind1ID[40], ind2ID[40], ind3ID[40], briID[40], btnAID[40], btnBID[40], btnCID[40], appID[40], tempID[40], humID[40], luxID[40], verID[40], ramID[40], upID[40], sigID[40], btnLID[40], btnMID[40], btnRID[40], transID[40], doUpdateID[40], batID[40], myID[40], sSpeed[40], effectID[40], ipAddrID[40]; long previousMillis_Stats; // The getter for the instantiated singleton instance MQTTManager_ &MQTTManager_::getInstance() @@ -487,6 +487,11 @@ void MQTTManager_::sendStats() sprintf(uptimeStr, "%ld", uptimeValue); uptime->setValue(uptimeStr); transition->setState(AUTO_TRANSITION, false); + + IPAddress ip = WiFi.localIP(); + char ipAddrStr[16]; + sprintf(ipAddrStr, "%d.%d.%d.%d", ip & 0x000000FF, (ip & 0x0000FF00) >> 8, (ip & 0x00FF0000) >> 16, (ip & 0xFF000000) >> 24); + ipAddr->setValue(ipAddrStr); } publish(StatsTopic, DisplayManager.getStats().c_str()); @@ -678,6 +683,10 @@ void MQTTManager_::setup() ram->setIcon(HAramIcon); ram->setName(HAramName); ram->setUnitOfMeasurement(HAramUnit); + + sprintf(ipAddrID, HAipAddrRID, macStr); + ipAddr = new HASensor(ipAddrID); + ipAddr->setName(HAipAddrName); } else { From 31bc6651621f4935efc00ea7d0a0e6a3a89b9550 Mon Sep 17 00:00:00 2001 From: Dan Quintas Date: Sun, 29 Oct 2023 03:09:16 +0000 Subject: [PATCH 4/7] set appropriate icon for HA sensor --- src/Dictionary.cpp | 1 + src/Dictionary.h | 1 + src/MQTTManager.cpp | 1 + 3 files changed, 3 insertions(+) diff --git a/src/Dictionary.cpp b/src/Dictionary.cpp index a1dc8170..1fc8bc5f 100644 --- a/src/Dictionary.cpp +++ b/src/Dictionary.cpp @@ -136,6 +136,7 @@ const char HAramUnit[] PROGMEM = {"B"}; const char HAipAddrRID[] PROGMEM = {"%s_ip_address"}; const char HAipAddrName[] PROGMEM = {"IP Address"}; +const char HAipAddrIcon[] PROGMEM = {"mdi:wifi"}; // JSON properites #ifndef awtrix2_upgrade diff --git a/src/Dictionary.h b/src/Dictionary.h index 8ce6fbdd..5ed2aa1a 100644 --- a/src/Dictionary.h +++ b/src/Dictionary.h @@ -133,6 +133,7 @@ extern const char HAramUnit[]; extern const char HAipAddrRID[]; extern const char HAipAddrName[]; +extern const char HAipAddrIcon[]; // JSON properites #ifndef awtrix2_upgrade diff --git a/src/MQTTManager.cpp b/src/MQTTManager.cpp index 1c7dd22f..7ce2d2b0 100644 --- a/src/MQTTManager.cpp +++ b/src/MQTTManager.cpp @@ -687,6 +687,7 @@ void MQTTManager_::setup() sprintf(ipAddrID, HAipAddrRID, macStr); ipAddr = new HASensor(ipAddrID); ipAddr->setName(HAipAddrName); + ipAddr->setIcon(HAipAddrIcon); } else { From 71688911bdb2efea8fc425d7e17a72bd0e135c50 Mon Sep 17 00:00:00 2001 From: Dan Quintas Date: Wed, 1 Nov 2023 23:51:00 +0000 Subject: [PATCH 5/7] simplification: re-use existing ServerManager.myIP --- src/MQTTManager.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/MQTTManager.cpp b/src/MQTTManager.cpp index 7ce2d2b0..b5f04380 100644 --- a/src/MQTTManager.cpp +++ b/src/MQTTManager.cpp @@ -487,11 +487,7 @@ void MQTTManager_::sendStats() sprintf(uptimeStr, "%ld", uptimeValue); uptime->setValue(uptimeStr); transition->setState(AUTO_TRANSITION, false); - - IPAddress ip = WiFi.localIP(); - char ipAddrStr[16]; - sprintf(ipAddrStr, "%d.%d.%d.%d", ip & 0x000000FF, (ip & 0x0000FF00) >> 8, (ip & 0x00FF0000) >> 16, (ip & 0xFF000000) >> 24); - ipAddr->setValue(ipAddrStr); + ipAddr->setValue(ServerManager.myIP.toString().c_str()); } publish(StatsTopic, DisplayManager.getStats().c_str()); From 54394b7724111012b1087c5d9988d47521d1effc Mon Sep 17 00:00:00 2001 From: Dan Quintas Date: Wed, 1 Nov 2023 23:54:49 +0000 Subject: [PATCH 6/7] remove redundant include --- src/DisplayManager.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/DisplayManager.cpp b/src/DisplayManager.cpp index e9c9b0ee..fcd48159 100644 --- a/src/DisplayManager.cpp +++ b/src/DisplayManager.cpp @@ -19,7 +19,6 @@ #include #include #include "base64.hpp" -#include unsigned long lastArtnetStatusTime = 0; const int numberOfChannels = 256 * 3; From 2df78962e2f29969ec3f8840f1cc93eec1a8742f Mon Sep 17 00:00:00 2001 From: Dan Quintas Date: Thu, 2 Nov 2023 01:49:13 +0000 Subject: [PATCH 7/7] massively simplify devcontainer config --- .devcontainer/Dockerfile | 16 ++------- .devcontainer/devcontainer.json | 6 ++-- .devcontainer/reinstall-cmake.sh | 59 -------------------------------- 3 files changed, 5 insertions(+), 76 deletions(-) delete mode 100644 .devcontainer/reinstall-cmake.sh diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index cf51ba25..3ebc1778 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -2,17 +2,5 @@ FROM mcr.microsoft.com/devcontainers/cpp:1-debian-11 ARG REINSTALL_CMAKE_VERSION_FROM_SOURCE="none" -# Optionally install the cmake for vcpkg -COPY ./reinstall-cmake.sh /tmp/ - -RUN if [ "${REINSTALL_CMAKE_VERSION_FROM_SOURCE}" != "none" ]; then \ - chmod +x /tmp/reinstall-cmake.sh && /tmp/reinstall-cmake.sh ${REINSTALL_CMAKE_VERSION_FROM_SOURCE}; \ - fi \ - && rm -f /tmp/reinstall-cmake.sh - -# [Optional] Uncomment this section to install additional vcpkg ports. -# RUN su vscode -c "${VCPKG_ROOT}/vcpkg install " - -# [Optional] Uncomment this section to install additional packages. -# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ -# && apt-get -y install --no-install-recommends +RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ + && apt-get -y install --no-install-recommends python3-venv diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 26476611..704e51df 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,10 +1,10 @@ // For format details, see https://aka.ms/devcontainer.json. For config options, see the // README at: https://github.com/devcontainers/templates/tree/main/src/cpp { - "name": "C++", + "name": "awtrix-light", "build": { "dockerfile": "Dockerfile" - }, + } // Features to add to the dev container. More info: https://containers.dev/features. // "features": {}, @@ -13,7 +13,7 @@ // "forwardPorts": [], // Use 'postCreateCommand' to run commands after the container is created. - "postCreateCommand": "sudo apt -y update && sudo apt-get -y install python3-venv" + // "postCreateCommand": "sudo apt -y update && sudo apt-get -y install python3-venv" // Configure tool-specific properties. // "customizations": {}, diff --git a/.devcontainer/reinstall-cmake.sh b/.devcontainer/reinstall-cmake.sh deleted file mode 100644 index 408b81d2..00000000 --- a/.devcontainer/reinstall-cmake.sh +++ /dev/null @@ -1,59 +0,0 @@ -#!/usr/bin/env bash -#------------------------------------------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. -#------------------------------------------------------------------------------------------------------------- -# -set -e - -CMAKE_VERSION=${1:-"none"} - -if [ "${CMAKE_VERSION}" = "none" ]; then - echo "No CMake version specified, skipping CMake reinstallation" - exit 0 -fi - -# Cleanup temporary directory and associated files when exiting the script. -cleanup() { - EXIT_CODE=$? - set +e - if [[ -n "${TMP_DIR}" ]]; then - echo "Executing cleanup of tmp files" - rm -Rf "${TMP_DIR}" - fi - exit $EXIT_CODE -} -trap cleanup EXIT - - -echo "Installing CMake..." -apt-get -y purge --auto-remove cmake -mkdir -p /opt/cmake - -architecture=$(dpkg --print-architecture) -case "${architecture}" in - arm64) - ARCH=aarch64 ;; - amd64) - ARCH=x86_64 ;; - *) - echo "Unsupported architecture ${architecture}." - exit 1 - ;; -esac - -CMAKE_BINARY_NAME="cmake-${CMAKE_VERSION}-linux-${ARCH}.sh" -CMAKE_CHECKSUM_NAME="cmake-${CMAKE_VERSION}-SHA-256.txt" -TMP_DIR=$(mktemp -d -t cmake-XXXXXXXXXX) - -echo "${TMP_DIR}" -cd "${TMP_DIR}" - -curl -sSL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_BINARY_NAME}" -O -curl -sSL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_CHECKSUM_NAME}" -O - -sha256sum -c --ignore-missing "${CMAKE_CHECKSUM_NAME}" -sh "${TMP_DIR}/${CMAKE_BINARY_NAME}" --prefix=/opt/cmake --skip-license - -ln -s /opt/cmake/bin/cmake /usr/local/bin/cmake -ln -s /opt/cmake/bin/ctest /usr/local/bin/ctest