MQTT to control four channel relay

Hi, I am currently writing a code to control and RGB led strip with a four channel relay using MQTT.
Can someone check whether my code is valid? Any help is appreciated

/Code is using a Wemos D1 mini/

#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <WiFiClientSecure.h>

// Connect to the WiFi
const char* ssid = "ssid";
const char* password = "pswd";
const char* mqtt_server = "";

WiFiClient espClient;
PubSubClient client(espClient);

//Pins are connected to relays
const int RED_PIN = 12;    //D6: Red Pin
const int GREEN_PIN = 14;  //D5: Green Pin
const int BLUE_PIN = 13; //D7: Blue Pin

// The function below connects your NodeMCU to the wireless network
void setup_wifi(){

    Serial.print("connecting to ");
    WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED) {
    Serial.println("WiFi connected");
    Serial.println("IP address: ");

void callback(char* topic, byte* payload, unsigned int length) {
  Serial.print("Message arrived [");
  Serial.print("] ");
  for (int i = 0; i < length; i++) {
    char receivedChar = (char)payload[i];
      Serial.print("Relays On");
    Serial.print("Relays Off");

void reconnect() {
  // Loop until we're reconnected
  while (!client.connected()) {
    Serial.println("Attempting MQTT connection...");
    // Attempt to connect
    if (client.connect("Reception")) {    // "explicit name for each client"
      Serial.println("Reception is connected to MQTT server");
      // ... and subscribe to topic
      client.subscribe("RGB/Output");//Topic subscribed to
    } else {
      Serial.print("Failed to connect to MQTT...");
      Serial.println("Attempting to connect again in 3 seconds.");
      // Wait  seconds before retrying

//Led starts by lighting up Green
void InitialLedState(){
  digitalWrite(RED_PIN, HIGH);
  digitalWrite(GREEN_PIN, LOW);
  digitalWrite(BLUE_PIN, HIGH);
  client.publish("RGB/Output", "Green");
void OnRelays(){
  digitalWrite(RED_PIN, LOW);
  digitalWrite(GREEN_PIN, LOW);
  digitalWrite(BLUE_PIN, LOW);
void OffRelays(){
  digitalWrite(RED_PIN, HIGH);
  digitalWrite(GREEN_PIN, HIGH);
  digitalWrite(BLUE_PIN, HIGH);
void setup()
  client.setServer(mqtt_server, 1883);
  pinMode(RED_PIN, OUTPUT);
  pinMode(BLUE_PIN, OUTPUT);

void loop() {
  if (!client.connected()) {

void RGB_color(int red_light_value, int green_light_value, int blue_light_value)
  analogWrite(RED_PIN, red_light_value);
  analogWrite(GREEN_PIN, green_light_value);
  analogWrite(BLUE_PIN, blue_light_value);

void ColourChange(){
  RGB_color(255, 0, 0); // Red
    RGB_color(0, 255, 0); // Green
    RGB_color(0, 0, 255); // Blue
    RGB_color(255, 255, 125); // Raspberry
    RGB_color(0, 255, 255); // Cyan
    RGB_color(255, 0, 255); // Magenta
    RGB_color(255, 255, 0); // Yellow
    RGB_color(255, 255, 255); // White

What do you mean, “whether my code is valid”? Does it work?

You have posted code without using code tags. The code tags make the code look

like this

when posting source code files. It makes it easier to read, and can be copied with a single mouse click. Also, if you don’t do it, some of the character sequences in the code can be misinterpred by the forum code as italics or funny emoticons. The “Code: [Select]” feature allows someone to select the entire sketch so it can be easily copied and pasted into the IDE for testing.
If you have already posted without using code tags, open your message and select “modify” from the pull down menu labelled, “More”, at the lower right corner of the message. Highlight your code by selecting it (it turns blue), and then click on the “</>” icon at the upper left hand corner. Click on the “Save” button. Code tags can also be inserted manually in the forum text using the code and /code metatags.

The hardware for my project is not yet complete, but I just want to know if my logic here seems valid.