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:
2019-06-14 05:35:17 +02:00
parent 4fdd1d3739
commit 5ce3b0c1b3
5 changed files with 20 additions and 25 deletions

View File

@ -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 "+");