refactor: Move MQTT broker config to secrets.h.example

This commit is contained in:
Tanner Collin (aider) 2025-06-21 13:56:40 -06:00
parent 5fe3d3da8c
commit 5b45347914
2 changed files with 9 additions and 5 deletions

View File

@ -16,8 +16,9 @@ String deviceName;
#define OUTPUT_PIN 4 #define OUTPUT_PIN 4
const char broker[] = "192.168.69.106"; // Broker IP and port are now defined in secrets.h
int port = 1883; // const char broker[] = "192.168.69.106";
// int port = 1883;
String topic; // Changed from const char[] String topic; // Changed from const char[]
#define QOS_2 2 #define QOS_2 2
@ -103,9 +104,9 @@ void setup() {
mqttClient.setId(deviceName.c_str()); mqttClient.setId(deviceName.c_str());
Serial.print("[MQTT] Attempting to connect to the MQTT broker: "); Serial.print("[MQTT] Attempting to connect to the MQTT broker: ");
Serial.println(broker); Serial.println(SECRET_MQTT_BROKER_IP);
if (!mqttClient.connect(broker, port)) { if (!mqttClient.connect(SECRET_MQTT_BROKER_IP, SECRET_MQTT_PORT)) {
Serial.print("MQTT connection failed! Error code = "); Serial.print("MQTT connection failed! Error code = ");
Serial.println(mqttClient.connectError()); Serial.println(mqttClient.connectError());
Serial.println("Reseting..."); Serial.println("Reseting...");
@ -137,7 +138,7 @@ void loop() {
Serial.print("[MQTT] Not connected! Error code = "); Serial.print("[MQTT] Not connected! Error code = ");
Serial.println(mqttClient.connectError()); Serial.println(mqttClient.connectError());
Serial.println("[MQTT] Reconnecting..."); Serial.println("[MQTT] Reconnecting...");
mqttClient.connect(broker, port); mqttClient.connect(SECRET_MQTT_BROKER_IP, SECRET_MQTT_PORT);
delay(5000); delay(5000);
Serial.print("[MQTT] Subscribing to topic: "); Serial.print("[MQTT] Subscribing to topic: ");

View File

@ -1,2 +1,5 @@
#define SECRET_SSID "" #define SECRET_SSID ""
#define SECRET_PASS "" #define SECRET_PASS ""
#define SECRET_MQTT_BROKER_IP "192.168.69.106"
#define SECRET_MQTT_PORT 1883