Skip to content

Commit

Permalink
Merge pull request #373 from y34hbuddy/main
Browse files Browse the repository at this point in the history
Provide IP Address in MQTT/HA
  • Loading branch information
Blueforcer authored Nov 19, 2023
2 parents 7911dd0 + 2df7896 commit 827ca96
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM mcr.microsoft.com/devcontainers/cpp:1-debian-11

ARG REINSTALL_CMAKE_VERSION_FROM_SOURCE="none"

RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends python3-venv
23 changes: 23 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -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": "awtrix-light",
"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"
}
5 changes: 5 additions & 0 deletions src/Dictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ 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"};
const char HAipAddrIcon[] PROGMEM = {"mdi:wifi"};

// JSON properites
#ifndef awtrix2_upgrade
const char BatKey[] PROGMEM = {"bat"};
Expand All @@ -150,3 +154,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"};
5 changes: 5 additions & 0 deletions src/Dictionary.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ extern const char HAramName[];
extern const char HAramClass[];
extern const char HAramUnit[];

extern const char HAipAddrRID[];
extern const char HAipAddrName[];
extern const char HAipAddrIcon[];

// JSON properites
#ifndef awtrix2_upgrade
extern const char BatKey[];
Expand All @@ -147,4 +151,5 @@ extern const char UpdateKey[];
extern const char MessagesKey[];
extern const char VersionKey[];
extern const char RamKey[];
extern const char IpAddrKey[];
#endif
1 change: 1 addition & 0 deletions src/DisplayManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1591,6 +1591,7 @@ String DisplayManager_::getStats()
doc[F("app")] = CURRENT_APP;
doc[F("uid")] = uniqueID;
doc[F("matrix")] = !MATRIX_OFF;
doc[IpAddrKey] = WiFi.localIP();
String jsonString;
serializeJson(doc, jsonString);
return jsonString;
Expand Down
12 changes: 9 additions & 3 deletions src/MQTTManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
Expand Down Expand Up @@ -487,6 +487,7 @@ void MQTTManager_::sendStats()
sprintf(uptimeStr, "%ld", uptimeValue);
uptime->setValue(uptimeStr);
transition->setState(AUTO_TRANSITION, false);
ipAddr->setValue(ServerManager.myIP.toString().c_str());
}

publish(StatsTopic, DisplayManager.getStats().c_str());
Expand Down Expand Up @@ -678,6 +679,11 @@ void MQTTManager_::setup()
ram->setIcon(HAramIcon);
ram->setName(HAramName);
ram->setUnitOfMeasurement(HAramUnit);

sprintf(ipAddrID, HAipAddrRID, macStr);
ipAddr = new HASensor(ipAddrID);
ipAddr->setName(HAipAddrName);
ipAddr->setIcon(HAipAddrIcon);
}
else
{
Expand Down

0 comments on commit 827ca96

Please sign in to comment.