Yun and NodeMCU works over MQTT independently but not together autonomously

I have created a small prototype that triggers a remotely placed relay (ON/OFF) based on temperature sensed (if temperature is from 0° to 30°C, state ON, else OFF) at another location

Development boards: The temperature sensor is hooked on an Arduino Yun and the relay is hooked on NodeMCU (NodeMCU 1.0 ESP-12E module)
Communication: Mosquitto MQTT setup on my server

Setup and issue:
Step 1: Uploaded sketch on Yun for sensing temperature range and publishing on ON/OFF status on MQTT channel, monitored the published message on terminal from Mac, everything is perfect!
Step 2: Uploaded the sketch on NodeMCU, connected the relay on GPIO12 (tried on 13 and 14 as well, same behaviour on all ports - mentioned ahead), published message on the same channel via terminal from Mac. Relay gets triggered, perfect!

When I start the Yun and NodeMCU both to work together autonomously, it does not work! If I publish a message manually to the channel via terminal, relay is triggered and can monitor on terminal the same message on the subscribed channel on which Yun also publishes relay status.

Also, the manual trigger to NodeMCU via terminal works only for a couple of times, then I need to restart the module to make it work again.

Below are my codes.

Sketch on Yun

#include <SPI.h>
#include <PubSubClient.h>
#include <YunClient.h>

char* server = “dev.domain.com”;
int port = 1883;
char* pubTopicValveStatus = "valveStatus";
char* subTopic = "changeTempRange";
char* pubMessage = "Publish valve trigger...";
float temp;
int tempPin = 0;
float tempFrom = 0;  //send ON trigger - from value
float tempTo = 30;  //send OFF trigger - to value

YunClient yun;
PubSubClient mqtt(server, port, callback, yun);

void callback(char* topic, byte* payload, unsigned int length)
{
  //get temp range from "changeTempRange" topic and feed into ON/OFF loop
  payload[length] = '\0'; //convert byte to char
  String strPayload = String((char*)payload);
//  Serial.print("Range = "); //prints range published on range topic
//  Serial.print(strPayload); Serial.println();

  tempFrom = (strPayload.substring(0, strPayload.indexOf(','))).toFloat();
  tempTo = (strPayload.substring(',', strPayload.indexOf(',')+1)).toFloat();

  // handle received message
  if (strPayload == "ON")
  {
    digitalWrite(13, HIGH);
  }
  else if (strPayload == "OFF")
  {
    digitalWrite(13, LOW);
  }
  else
  {
    //do nothing
  }
}

void setup()
{
  flashingLED(5, 150);
  delay(120000);  //Yun taken about a minute or minute and half to connect to WiFi network after start, thus delay of 2 mins
  Serial.begin(9600);

  pinMode(13, OUTPUT);

  flashingLED(10, 150);

  Bridge.begin();

  if (mqtt.connect("arduinoClient"))
  {
    mqtt.publish(pubTopicValveStatus, pubMessage);
    Serial.println("Published Message: ");
    Serial.println(pubMessage);
    mqtt.subscribe(subTopic);

    flashingLED(2, 300);
  }
}

void loop()
{
  if(!mqtt.connected)
  {
    if (mqtt.connect("arduinoClient"))
    {
      mqtt.publish(pubTopicValveStatus, pubMessage);
      Serial.println("Published Message: ");
      Serial.println(pubMessage);
      mqtt.subscribe(subTopic);
  
      flashingLED(2, 300);
    }
  }

  mqtt.loop();

  //read temperature on sensor at A0 and convert into Celsius
  temp = analogRead(tempPin);
  temp = temp * 0.48828125;
  Serial.print("TEMPRATURE = ");
  Serial.print(temp);
  Serial.print("*C");
  Serial.println();
  
  //check whether temp is from
  if(temp >= tempFrom && temp <= tempTo)
  {
    mqtt.publish(pubTopicValveStatus, "ON");
  }
  else
  {
    mqtt.publish(pubTopicValveStatus, "OFF");
  }

  delay(5000);
}

int flashingLED(int n, int delayTime)
{
  for (int i = 1; i <= n; i++)
  {
    digitalWrite(13, HIGH);
    delay(delayTime);
    digitalWrite(13, LOW);
    delay(delayTime);
  }
}

Sketch on NodeMCU

#include <SPI.h>
#include <PubSubClient.h>
#include <ESP8266WiFi.h>
 
const char* ssid = “SSID”;
const char* password = “PASSWORD”;

int flashingLED(int n, int delayTime);

#define RELAY 12

char* server = "dev.domain.com";
int port = 1883;
char* subTopic = "valveStatus";

void callback(char* topic, byte* payload, unsigned int length)
{
  payload[length] = '\0';
  String strPayload = String((char*)payload);
  Serial.print("Status = ");
  Serial.print(strPayload);
  Serial.println();
  if (strPayload == "ON" || strPayload == "on" ||  strPayload == "1")
  {
    digitalWrite(RELAY, HIGH);          // Turns ON Relay
  }
  else if (strPayload == "OFF" || strPayload == "off" ||  strPayload == "0")
  {
    digitalWrite(RELAY, LOW);          // Turns Relay Off
  }
  else
  {
    //do nothing
  }
}
WiFiClient wifiClient;
PubSubClient mqtt(server, port, callback, wifiClient);

void setup()
{
  Serial.begin(9600);
  pinMode(RELAY, OUTPUT);

  delay(60000);
  if (RELAY == LOW)
  {
    digitalWrite(RELAY, HIGH);
    delay(2000);
    digitalWrite(RELAY, LOW);
  }

 WiFi.begin(ssid, password);

  if (mqtt.connect("arduinoClient"))
  {
    mqtt.subscribe(subTopic);
  }
}

void loop()
{
  mqtt.loop();
  if(mqtt.connect("arduinoClient") == false)
  {
    if (mqtt.connect("arduinoClient"))
  {
    mqtt.subscribe(subTopic);
  }
  }
  delay(5000);
}

What could possibly be wrong?

Also, I am not able to upload sketch to NodeMCU from Mac (OS Sierra, MBA). I have already tried differnt solutions by installing CH34X… package, also in recovery mode but doesn’t work. Any working solution for this? I have to go to a Windows machine everytime I want to upload a sketch to NodeMCU

Thanks