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

make MQTT port configurable #36

Merged
merged 6 commits into from
Aug 11, 2023
Merged
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
4 changes: 2 additions & 2 deletions MQTTClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ void MQTTClient::subscriptionUpdate(char* topic, byte* message, unsigned int len
publications.erase(willTopic);
}

void MQTTClient::setup(const char* mqttServer,const char* mqttUsername, const char* mqttPassword, const char* cid, const char* wt, const char* wm)
void MQTTClient::setup(const char* mqttServer, const char* mqttPort, const char* mqttUsername, const char* mqttPassword, const char* cid, const char* wt, const char* wm)
{
mqttuser = mqttUsername;
mqttpw = mqttPassword;
clientId = cid;
willTopic = wt;
willMessage = wm;

mqttClient.setServer(mqttServer, 1883);
mqttClient.setServer(mqttServer, atoi(mqttPort));
mqttClient.setCallback(std::bind(&MQTTClient::subscriptionUpdate, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
}

Expand Down
2 changes: 1 addition & 1 deletion MQTTClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class MQTTClient
void addSubscriber(const char* topic, void (*setter)(bool value));
void addSubscriber(const char* topic, void (*setter)(int value));

void setup(const char* mqttServer, const char* mqttUsername, const char* mqttPassword,const char* clientId, const char* willTopic, const char* willMessage);
void setup(const char* mqttServer, const char* mqttPort, const char* mqttUsername, const char* mqttPassword,const char* clientId, const char* willTopic, const char* willMessage);
void loop();

bool isConnected();
Expand Down
1 change: 1 addition & 0 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ namespace CONFIG_TAG
const char WIFI_OTA_URL[] = "firmwareURL";

const char MQTT_SERVER[] = "mqttServer";
const char MQTT_PORT[] = "mqttPort";
const char MQTT_USER[] = "mqttUser";
const char MQTT_PASSWORD[] = "mqttPassword";
const char MQTT_RETAIN[] = "mqttRetain";
Expand Down
3 changes: 2 additions & 1 deletion data/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
"wifiSSID": "WiFi-SSID",
"wifiPassphrase": "WiFi-Secret",
"mqttServer": "mqtt.at.home",
"mqttPort": "1883",
"mqttUser": "leave blank if you don't have authentication",
"mqttPassword": "leave blank if you don't have authentication",
"mqttRetain": "no",
"firmwareURL": "http://192.168.0.1/firmware/esp8266-intexsbh20.bin",
"errorLanguage": "EN"
}
}
2 changes: 1 addition & 1 deletion esp8266-intexsbh20.ino
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void setup()
username = config.get(CONFIG_TAG::MQTT_USER);
password = config.get(CONFIG_TAG::MQTT_PASSWORD);
}
mqttClient.setup(config.get(CONFIG_TAG::MQTT_SERVER), username.c_str(), password.c_str(), pureSpaIO.getModelName(), MQTT_TOPIC::STATE, "offline");
mqttClient.setup(config.get(CONFIG_TAG::MQTT_SERVER), config.get(CONFIG_TAG::MQTT_PORT), username.c_str(), password.c_str(), pureSpaIO.getModelName(), MQTT_TOPIC::STATE, "offline");

// init NTC thermometer
thermometer.setup(22000, 3.33f, 320.f/100.f); // measured: 21990, 3.327f, 319.f/99.6f
Expand Down