MQTT (was WiFi) interference when using two nodeMCU devices I have two nodeMCU boards, one from LoLin (192.168.1.52) and one from Amica (192.168.1.53). For each nodeMCU, I have mapped its MAC address to a fixed IP address using my Movistar WiFi router. I confirm from the serial monitor that each nodeMCU is being correctly assigned to the correct IP address

My sketch is a simple IoT/MQTT client. 

My problem is that if I power up both nodeMCUs, the WiFi connection is broken on both.

The WiFi portion of my sketch is 

void setup_wifi() {
  Serial.println(" Booting..");
  WiFi.mode(WIFI_STA);
  WiFi.begin(SSID, PASSWORD);
  while (WiFi.waitForConnectResult() != WL_CONNECTED) {
    Serial.println("Connection Failed! Rebooting...");
    myBlink(LED_PIN, 20, 100);
    delay(5000);
    ESP.restart();
  }
  WiFi.printDiag(Serial);
  Serial.println(WiFi.localIP());
}


The output is 

Mode: STA PHY mode: 
N Channel: 1 
AP id: 0 
Status: 5 
Auto connect: 1
SSID (13): MOVISTAR_xxxx 
Passphrase (20): 509A8EC4Exxxxxxxxx 
BSSID set: 0

192.168.1.53 (or .52 on the other device)


I realise that the symptoms are consistent with clashing IP addresses, but to confirm, both the serial diagnostics and the DHCP report from my router confirm that the two devices are on different IP addresses.
My bad!

Although my symptoms were consistent with WiFi interference, the interference was actually at the MQTT level.  

The root cause was that I hadn't realised that each MQTT client must have a unique client ID. When the 2nd nodeMCU connected, it disconnected the first nodeMCU from MQTT, which then went into a reboot sequence to recover, which then returned the favour to the other nodeMCU.