Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unique topic Generation #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 0 additions & 128 deletions README_ru.md

This file was deleted.

13 changes: 10 additions & 3 deletions src/Helpers/MqttHelper.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
#include "MqttHelper.h"
uint32_t MqttHelper::getChipID(){
uint32_t chipId = 0;
for(int i=0; i<17; i=i+8) {
chipId |= ((ESP.getEfuseMac() >> (40 - i)) & 0xff) << i;
}
return chipId;
}

boolean MqttHelper::reconnect() {
boolean isLoginNeeded = false;
Expand All @@ -7,7 +14,7 @@ boolean MqttHelper::reconnect() {
isLoginNeeded = true;
}
if (!getClient().connected()) {
String clientId = "ESP-Blinds-" + String(ESP_getChipId());
String clientId = "ESP-Blinds-" + String(getChipID());
Serial.printf("MQTT connecting (login: '%s', pass: '%s')...\r\n", mqttUser.c_str(), mqttPwd.c_str());
// Attempt to connect
if ((isLoginNeeded ? getClient().connect(clientId.c_str(), mqttUser.c_str(), mqttPwd.c_str())
Expand Down Expand Up @@ -36,7 +43,7 @@ boolean MqttHelper::reconnect() {
}

void MqttHelper::sendAvailabilityMessage() {
publishMsg(prefix + "/" + String(ESP_getChipId()) + "/available", "online");
publishMsg(prefix + "/" + String(getChipID()) + "/available", "online");
}

void MqttHelper::loop() {
Expand Down Expand Up @@ -88,7 +95,7 @@ PubSubClient &MqttHelper::getClient() {
}

String MqttHelper::getTopicPath(const String &suffix) {
return prefix + "/" + String(ESP_getChipId()) + "/" + suffix;
return prefix + "/" + String(getChipID()) + "/" + suffix;
}

void MqttHelper::publishMsg(String topic, String payload, bool isRetained) {
Expand Down
1 change: 1 addition & 0 deletions src/Helpers/MqttHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class MqttHelper {
unsigned long mqttLastConnectAttempt = 0;
PubSubClient* client = nullptr;
unsigned long lastAvailableMsgTime = 0;
uint32_t getChipID();

public:
typedef std::function<void(void)> TCallback;
Expand Down
10 changes: 9 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ ESP8266WebServer server(80); // TCP server at port 80 will respond

WebSocketsServer webSocket = WebSocketsServer(81); // WebSockets will respond on port 81

uint32_t getChipID(){
uint32_t chipId = 0;
for(int i=0; i<17; i=i+8) {
chipId |= ((ESP.getEfuseMac() >> (40 - i)) & 0xff) << i;
}
return chipId;
}

bool loadConfig() {
if (!helper.loadconfig()) {
return false;
Expand Down Expand Up @@ -382,7 +390,7 @@ void sendHADiscovery() {

isHADiscoveryWasSent = true;
String haConfig;
uint32_t chipId = ESP_getChipId();
uint32_t chipId = getChipID();

uint8_t num = 0;
for (StepperHelper stepperHelper : stepperHelpers) {
Expand Down