Centralized the creation of a hostname to a global variable hostname, set in pitrix.cpp. Added an mDNS record for the webserver.
This commit is contained in:
14
src/mqtt.cpp
14
src/mqtt.cpp
@ -87,18 +87,8 @@ void mqtt_callback(char* original_topic, byte* pl, unsigned int length) {
|
||||
}
|
||||
|
||||
boolean mqtt_connect() {
|
||||
char client_id[30];
|
||||
int chipid;
|
||||
#if defined( ESP8266 )
|
||||
chipid = ESP.getChipId();
|
||||
#elif defined( ESP32 )
|
||||
chipid = ESP.getEfuseMac() & 0xFFFFFF;
|
||||
#else
|
||||
#error Neither ESP32 nor ESP8266 set.
|
||||
#endif
|
||||
snprintf(client_id, 30, HOSTNAME, chipid);
|
||||
LOG("MQTT * Connecting to MQTT server with client id "); LOGln(client_id);
|
||||
if (mqtt_client.connect(client_id, MQTT_USER, MQTT_PASS, MQTT_TOPIC "status", 0, true, "OFFLINE", true)) {
|
||||
LOG("MQTT * Connecting to MQTT server with client id "); LOGln(hostname);
|
||||
if (mqtt_client.connect(hostname, MQTT_USER, MQTT_PASS, MQTT_TOPIC "status", 0, true, "OFFLINE", true)) {
|
||||
LOGln("MQTT * Connected.");
|
||||
mqtt_client.publish(MQTT_TOPIC "status", "ONLINE");
|
||||
mqtt_client.subscribe(MQTT_TOPIC "+");
|
||||
|
Reference in New Issue
Block a user