@@ -274,6 +274,7 @@ void setup() {
274274 // Topic defaults se fetch falhar
275275 String macDashes = String (macStr);
276276 macDashes.replace (" :" , " -" );
277+ macDashes.toLowerCase (); // Backend usa minúsculas para tópicos
277278 topicDeviceSub = " campus/device/" + macDashes + " /#" ;
278279 topicConfigSub = " campus/config/" + macDashes + " /#" ;
279280
@@ -338,14 +339,24 @@ void setup() {
338339 }
339340
340341 if (connected) {
341- client.subscribe (topicConfigSub.c_str ());
342- client.subscribe (topicDeviceSub.c_str ());
342+ if (topicConfigSub.length () > 0 ) {
343+ client.subscribe (topicConfigSub.c_str ());
344+ fmtSerial.println (" [MQTT] Subscrito em: " + topicConfigSub);
345+ }
346+ if (topicDeviceSub.length () > 0 ) {
347+ client.subscribe (topicDeviceSub.c_str ());
348+ fmtSerial.println (" [MQTT] Subscrito em: " + topicDeviceSub);
349+ }
343350 long sala_id = preferences.getLong (" salaId" , 0 );
344351 if (sala_id > 0 ) {
345- client.subscribe ((String (" campus/sala/" ) + sala_id + " /admin/#" ).c_str ());
352+ String roomSub = String (" campus/sala/" ) + sala_id + " /admin/#" ;
353+ client.subscribe (roomSub.c_str ());
354+ fmtSerial.println (" [MQTT] Subscrito em: " + roomSub);
346355 }
347356 client.subscribe (" campus/all/admin/#" );
357+ fmtSerial.println (" [MQTT] Subscrito em: campus/all/admin/#" );
348358 client.subscribe (" campus/config/all/#" );
359+ fmtSerial.println (" [MQTT] Subscrito em: campus/config/all/#" );
349360 tft.fillRect (10 , 140 , 220 , 30 , ST77XX_BLACK ); tft.setCursor (10 , 140 ); tft.setTextColor (ST77XX_GREEN , ST77XX_BLACK ); tft.print (" MQTT: Ligado!" );
350361 } else {
351362 tft.fillRect (10 , 140 , 220 , 30 , ST77XX_BLACK ); tft.setCursor (10 , 140 ); tft.setTextColor (ST77XX_RED , ST77XX_BLACK ); tft.print (" MQTT: Falhou" );
0 commit comments