RGB LED Strip Driver over MQTT

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

const char* ssid = "ASUS";
const char* password = "97983740";
const char* mqtt_server = "broker.mqttdashboard.com";
const char* mqtt_user = "Zaia_Enterprise";
const char* mqtt_pswd = "87177972";
char messageBuffer[50];

WiFiClient espClient;
PubSubClient client(espClient);

// DIN=GPIO16, CIN=GPIO14 in this example
LEDStripDriver led = LEDStripDriver(16, 14);

unsigned long currentTime;
unsigned long startTime;
unsigned long period = 1000;

bool power = false;

int countR;
int countG;
int countB;

void setup_wifi()
{
  Serial.begin(115200);
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.println();
  Serial.print("connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
  delay(2000);
}

void setup()
{
  setup_wifi();
  client.setServer(mqtt_server, 1883);
  client.setCallback(callback);
}
void loop()
{
  client.loop();
  if (!client.connected())
  {
    reconnect();
  }
  if (power == true)
  {
    RainbowEffect();
  }
}

void reconnect()
{
  while (!client.connected())
  {
    Serial.println("Attempting MQTT connection...");
    if (client.connect("Reception"))
    {
      Serial.println("Connected to MQTT server");
      client.subscribe("RGB/Output");
    }
    else
    {
      Serial.print("Failed to connect to MQTT...");
      Serial.println();
      Serial.println("Attempting to connect again in 3 seconds.");
      delay(3000);
    }
  }
}

void callback(char* topic, byte* payload, unsigned int length)
{
  Serial.println();
  Serial.print("Message arrived [");
  Serial.print(topic);
  Serial.print("] ");
  Serial.print("length : ");
  Serial.println(length);
  memcpy(messageBuffer, payload, length);
  messageBuffer[length] = '\0';
  Serial.print("the payload is : ");
  Serial.println(messageBuffer);
  if (strcmp(messageBuffer, "on") == 0)
  {
    {
      Serial.print("turning ");
      Serial.println(messageBuffer);
      digitalWrite(LED_BUILTIN, LOW);
      power = true; //activate rainbow 
    }
  }
  else if (strcmp(messageBuffer, "off") == 0)
  {
    {
      Serial.print("turning ");
      Serial.println(messageBuffer);
      digitalWrite(LED_BUILTIN, HIGH);
      OffRainbow();
      power = false;  //stop the rainbow
    }
  }

}
void OffRainbow()
{
  led.setColor(); // turn off
}
void RainbowEffect()
{
  int ledcolor = random(6); //this randomly selects a number between 0 and 5
  currentTime = millis();
  if (currentTime - startTime >= period)
  {
    switch (ledcolor) {
case 0: //if ledcolor equals 0 transition to red
  led.setColor(255,0,0);
break;
case 1: //if ledcolor equals 1 transition to green
  led.setColor(0,255,0);
break;
case 2: //if ledcolor equals 2 transition to blue
  led.setColor(0,0,255);
break;
case 3: //if ledcolor equals 3 transition to yellow
  led.setColor(255,255,0);
break;
case 4: //if ledcolor equals 4 transition to cyan
  led.setColor(0,255,255);
break;
case 5: //if ledcolor equals 5 transition magenta
  led.setColor(250,160,250);
break;
}//rainbow here
    startTime = currentTime;
}
}

I need help troubleshooting void RainbowEffect(). The strip does not light up when given command

Once you are sure the void callback is working, I'd get rid of those serial print statements, time waster.

Instead, I'd put some serial prints in

void RainbowEffect()
{
  int ledcolor = random(6); //this randomly selects a number between 0 and 5
  currentTime = millis();
Serial.println( "did a thing");
  if (currentTime - startTime >= period)
  {
Serial.println( "millis times up doing more things" );
Serial.println( ledcolor );
    switch (ledcolor) {
case 0: //if ledcolor equals 0 transition to red
  led.setColor(255,0,0);
break;
case 1: //if ledcolor equals 1 transition to green
  led.setColor(0,255,0);
break;
case 2: //if ledcolor equals 2 transition to blue
  led.setColor(0,0,255);
break;
case 3: //if ledcolor equals 3 transition to yellow
  led.setColor(255,255,0);
break;
case 4: //if ledcolor equals 4 transition to cyan
  led.setColor(0,255,255);
break;
case 5: //if ledcolor equals 5 transition magenta
  led.setColor(250,160,250);
break;
}//rainbow here
    startTime = currentTime;
}
}

A few serial.prints to see what's going on.

3fffff70:  00000000 00000000 00000001 402058f8  
3fffff80:  feefeffe 00000000 3ffee388 402010d6  
3fffff90:  3fffdad0 00000000 3ffee388 40201285  
3fffffa0:  feefeffe feefeffe 3ffee508 40203e18  
3fffffb0:  feefeffe feefeffe 3ffe84f8 40100bfd  
<<<stack<<<

 ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1392, room 16 
tail 0
chksum 0xd0
csum 0xd0
v3d128e5c
~ld

This is what I got from Serial when I publish 'on'

Looks like a memory dump of a debug thingy. Info that would have been good to know when you made the original posting. Where in the code posted is a topic published??

inside void callback whenever I type in a payload "on"/"off" and click publish on MQTT Box. The code below then receives the payload published and triggers the if-else statement

void callback(char* topic, byte* payload, unsigned int length)
{
  Serial.println();
  Serial.print("Message arrived [");
  Serial.print(topic);
  Serial.print("] ");
  Serial.print("length : ");
  Serial.println(length);
  memcpy(messageBuffer, payload, length);
  messageBuffer[length] = '\0';
  Serial.print("the payload is : ");
  Serial.println(messageBuffer);
  if (strcmp(messageBuffer, "on") == 0)
  {
    {
      Serial.print("turning ");
      Serial.println(messageBuffer);
      digitalWrite(LED_BUILTIN, LOW);
      power = true; //activate rainbow
    }
  }
  else if (strcmp(messageBuffer, "off") == 0)
  {
    {
      Serial.print("turning ");
      Serial.println(messageBuffer);
      digitalWrite(LED_BUILTIN, HIGH);
      OffRainbow();
      power = false;  //stop the rainbow
    }
  }

You should treat this void callback(char* topic, byte* payload, unsigned int length)
as an ISR and get rid of all the serial prints. Just use serial prints in an ISR to see if the ISR worked, then get rid of them.

BTW: I am guessing that the MQTT publish button is on another device? I am guessing that when you press MQTT Publish the subscriber fails? I am guessing that the code in post 1 for the subscriber? I am guessing that the subscriber does a memory dump every time it receives a MQTT package?

void callback(char* topic, byte* payload, unsigned int length)
{
  if (strcmp(messageBuffer, "on") == 0)
  {
    {
      digitalWrite(LED_BUILTIN, LOW);
      power = true; //activate rainbow 
    }
  }
  else if (strcmp(messageBuffer, "off") == 0)
  {
    {
      digitalWrite(LED_BUILTIN, HIGH);
      OffRainbow();
      power = false;  //stop the rainbow
    }
  }

Mqtt Box aka my publisher is an online app you can download it here: http://workswithweb.com/

Idahowalker:
You should treat this void callback(char* topic, byte* payload, unsigned int length)
as an ISR and get rid of all the serial prints. Just use serial prints in an ISR to see if the ISR worked, then get rid of them.

BTW: I am guessing that the MQTT publish button is on another device? I am guessing that when you press MQTT Publish the subscriber fails? I am guessing that the code in post 1 for the subscriber? I am guessing that the subscriber does a memory dump every time it receives a MQTT package?

Have tested it with serial prints and it works

Now that you've stripped down the callback to bare minimum, does it work? Or do you still get a memory dump?

What are the extra brackets for in the if statement?

void callback(char* topic, byte* payload, unsigned int length)
{
  if (strcmp(messageBuffer, "on") == 0)
  {
    { <<<<<<<<<<
      digitalWrite(LED_BUILTIN, LOW);
      power = true; //activate rainbow
    } <<<<<<<<<<<<<<<
  }
  else if (strcmp(messageBuffer, "off") == 0)
  {
    { <<<<<<<<<<<<<<
      digitalWrite(LED_BUILTIN, HIGH);
      OffRainbow();
      power = false;  //stop the rainbow
    } <<<<<<<<<<<<<<<
  }

extra brackets marked with <<<<<<<<<<

If the removal of the extra brackets does not resolve the issue what does this do:

void callback(char* topic, byte* payload, unsigned int length)
{
  if (strcmp(messageBuffer, "on") == 0)
  {
      // digitalWrite(LED_BUILTIN, LOW);
      // power = true; //activate rainbow
  }
  else if (strcmp(messageBuffer, "off") == 0)
  {
      // digitalWrite(LED_BUILTIN, HIGH);
      // OffRainbow();
      // power = false;  //stop the rainbow
  }

if that does not work then what does this do

void callback(char* topic, byte* payload, unsigned int length)
{
  if (strcmp(messageBuffer, "on") == 0)
  {
      digitalWrite(LED_BUILTIN, LOW);
      // power = true; //activate rainbow
  }
  else if (strcmp(messageBuffer, "off") == 0)
  {
      digitalWrite(LED_BUILTIN, HIGH);
      // OffRainbow();
      // power = false;  //stop the rainbow
  }

and so on and so forth till you find the offending thingy.


w3c schools c++ if statement

I tried all 3 codes above. They give me the same error.

Does this give the same error

void callback(char* topic, byte* payload, unsigned int length)
{
  //if (strcmp(messageBuffer, "on") == 0)
  //{
      digitalWrite(LED_BUILTIN, LOW);
      // power = true; //activate rainbow
  //}
  //else if (strcmp(messageBuffer, "off") == 0)
  //{
  //    digitalWrite(LED_BUILTIN, HIGH);
      // OffRainbow();
      // power = false;  //stop the rainbow
  //}
}

If so then its one of the libraries, most likely an Adafruit library. Time to configure the unit to just receive MQTT, once the only thing done is receipt of MQTT, add in one other functionality at a time. Process of elimination.

I still get the same error.

Idahowalker:
If so then its one of the libraries, most likely an Adafruit library. Time to configure the unit to just receive MQTT, once the only thing done is receipt of MQTT, add in one other functionality at a time. Process of elimination.

In this code I blocked out LEDDriver.h and received the same error?

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

const char* ssid = "ASUS";
const char* password = "97983740";
const char* mqtt_server = "broker.mqttdashboard.com";
const char* mqtt_user = "Zaia_Enterprise";
const char* mqtt_pswd = "87177972";
char messageBuffer[50];

WiFiClient espClient;
PubSubClient client(espClient);

// DIN=GPIO16, CIN=GPIO14 in this example
//LEDStripDriver led = LEDStripDriver(16, 14);

unsigned long currentTime;
unsigned long startTime;
unsigned long period = 1000;

bool power = false;

int countR;
int countG;
int countB;

void setup_wifi()
{
  Serial.begin(115200);
  pinMode(LED_BUILTIN, OUTPUT);
  WiFi.begin(ssid, password);
}

void setup()
{
  setup_wifi();
  client.setServer(mqtt_server, 1883);
  client.setCallback(callback);
}
void loop()
{
  client.loop();
  if (!client.connected())
  {
    reconnect();
  }
  if (power == true)
  {
    RainbowEffect();
  }
}

void reconnect()
{
  while (!client.connected())
  {
    if (client.connect("Reception"))
    {
      client.subscribe("RGB/Output");
    }
  }
}

void callback(char* topic, byte* payload, unsigned int length)
{
  if (strcmp(messageBuffer, "on") == 0)
  {
      digitalWrite(LED_BUILTIN, LOW);
      // power = true; //activate rainbow
  }
  else if (strcmp(messageBuffer, "off") == 0)
  {
     digitalWrite(LED_BUILTIN, HIGH);
      // OffRainbow();
      // power = false;  //stop the rainbow
  }
}
void OffRainbow()
{
  //led.setColor(); // turn off
  Serial.print("off da thing");
}
void RainbowEffect()
{
  /*int ledcolor = random(6); //this randomly selects a number between 0 and 5
  currentTime = millis();*/
Serial.println( "did a thing");
 /* if (currentTime - startTime >= period)
  {
Serial.println( "millis times up doing more things" );
Serial.println( ledcolor );
    switch (ledcolor) {
case 0: //if ledcolor equals 0 transition to red
  led.setColor(255,0,0);
break;
case 1: //if ledcolor equals 1 transition to green
  led.setColor(0,255,0);
break;
case 2: //if ledcolor equals 2 transition to blue
  led.setColor(0,0,255);
break;
case 3: //if ledcolor equals 3 transition to yellow
  led.setColor(255,255,0);
break;
case 4: //if ledcolor equals 4 transition to cyan
  led.setColor(0,255,255);
break;
case 5: //if ledcolor equals 5 transition magenta
  led.setColor(250,160,250);
break;
}//rainbow here
    startTime = currentTime;
}*/
}
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <WiFiClientSecure.h>

const char* ssid = "ASUS";
const char* password = "97983740";
const char* mqtt_server = "broker.mqttdashboard.com";
const char* mqtt_user = "Zaia_Enterprise";
const char* mqtt_pswd = "87177972";
char messageBuffer[50];

WiFiClient espClient;
PubSubClient client(espClient);

unsigned long currentTime;
unsigned long startTime;
unsigned long period = 1000;

bool power = false;

void setup_wifi()
{
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.print("Connecting to ");
    Serial.println(ssid);
    WiFi.begin(ssid, password);
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

void setup() {
  Serial.begin(115200);
  setup_wifi();
  client.setServer(mqtt_server, 1883);
  client.setCallback(callback);
}

void loop()
{
  if (!client.connected())
  {
    reconnect();
  }
  client.loop();
  if (power == true)
  {
    RainbowEffect();
  }
}

void reconnect()
{
  while (!client.connected())
  {
    if (client.connect("Reception"))
    {
      Serial.println("connected");
      client.subscribe("RGB/Output");
    }
    else {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 5 seconds");
      delay(5000);
    }
  }
}

void callback(char* topic, byte* payload, unsigned int length)
{
  //Serial.println();
  Serial.print("Message arrived [");
  Serial.print(topic);
  Serial.print("] ");
  Serial.print("length : ");
  Serial.println(length);
  memcpy(messageBuffer, payload, length);
  messageBuffer[length] = '\0';
  Serial.print("the payload is : ");
  Serial.println(messageBuffer);
  if (strcmp(messageBuffer, "on") == 0)
  {
      Serial.print("turning ");
      Serial.println(messageBuffer);
      digitalWrite(LED_BUILTIN, LOW);
      power = true; //activate rainbow 
  }
  else if (strcmp(messageBuffer, "off") == 0)
  {
      Serial.print("turning ");
      Serial.println(messageBuffer);
      digitalWrite(LED_BUILTIN, HIGH);
      OffRainbow();
      power = false;  //stop the rainbow
    }
  }

void OffRainbow()
{
  Serial.print("RainbowOff");
  Serial.println();
}

void RainbowEffect()
{
  currentTime = millis();
  if (currentTime - startTime >= period)
  {
    Serial.print("RainbowOn");
    Serial.println();
    startTime = currentTime;
  }
}

After some troubleshooting, I found that whenever I publish a payload, somehow the program does not trigger RainbowEffect() & OffRainbow().

void loop()
{
  if (!client.connected())
  {
    reconnect();
  }
  client.loop();
  if (power == true)
  {
    RainbowEffect();
  }
}
if (strcmp(messageBuffer, "on") == 0)
  {
      Serial.print("turning ");
      Serial.println(messageBuffer);
      digitalWrite(LED_BUILTIN, LOW);
      power = true; //activate rainbow 
  }
  else if (strcmp(messageBuffer, "off") == 0)
  {
      Serial.print("turning ");
      Serial.println(messageBuffer);
      digitalWrite(LED_BUILTIN, HIGH);
      OffRainbow();
      power = false;  //stop the rainbow
    }

I thought you got errors when receiving a MQTT payload?

Suggestion.

Add a new tab to your project. Name it certs.h. Put your secret info into certs.h; like your password. Then, after saving, include the certs.h file. Now you can reference by variable name, your secret info, and you won't be posting your password on the internet.

here is the ESP32 code I use that does not produce error to receive published info from a MQTT broker

#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <PubSubClient.h>
#include "certs.h"
#include "sdkconfig.h"
#include "esp_system.h" //This inclusion configures the peripherals in the ESP system.
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/timers.h"
#include "freertos/event_groups.h"
#include "esp_sleep.h"
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1351.h>
#include "esp32-hal-psram.h"
#include "esp_himem.h"
//
EventGroupHandle_t eg;
#define evtDoDisplay ( 1 << 1 )
#define evtCollectHistory ( 1 << 2 )
//
const int SCREEN_WIDTH = 128;
const int SCREEN_HEIGHT = 128;
const int SCLK_PIN = 14;
const int MOSI_PIN = 13;
const int DC_PIN   = 12;
const int CS_PIN   = 27;
const int RST_PIN  = 26;
#define BLACK           0x0000
#define BLUE            0x001F
#define RED              0xF800
#define GREEN           0x07E0
#define CYAN            0x07FF
#define MAGENTA         0xF81F
#define YELLOW          0xFFE0
#define WHITE           0xFFFF
#define LightYellow 0xFFFFD8
Adafruit_SSD1351 tft = Adafruit_SSD1351(SCREEN_WIDTH, SCREEN_HEIGHT, CS_PIN, DC_PIN, MOSI_PIN, SCLK_PIN, RST_PIN);
////
Adafruit_BME280 bme( GPIO_NUM_5 ); // hardware SPI
////
WiFiClientSecure secureClient = WiFiClientSecure();
WiFiClient wifiClient;
PubSubClient MQTTclient(mqtt_server, 1883, wifiClient); // 1883 is the listener port for the Broker
////pointers to memory locations on the PSRAM module
float *iTempPtr;
float *iPressurePtr;
float *iHumidityPtr;
float *oTempPtr;
float *oPressurePtr;
float *oHumidityPtr;
float *oGasResistancePtr;
float *oPressureHistoryPtr;
float *oIAQ_HistoryPtr;
const int DataCells = 50;
int arrayCellPtr = 0;
////
void setup()
{
  log_i("before Free PSRAM: %d", ESP.getFreePsram());
  oPressureHistoryPtr = (float*)ps_calloc( DataCells, sizeof(float) );
  oIAQ_HistoryPtr = (float*)ps_calloc( DataCells, sizeof(float) );
  oTempPtr =  (float*)ps_calloc( 1, sizeof(float) );
  oPressurePtr =  (float*)ps_calloc( 1, sizeof(float) );
  oHumidityPtr =  (float*)ps_calloc( 1, sizeof(float) );
  oGasResistancePtr =  (float*)ps_calloc( 1, sizeof(float) );
  iTempPtr =  (float*)ps_calloc( 1, sizeof(float) );
  iPressurePtr =  (float*)ps_calloc( 1, sizeof(float) );
  iHumidityPtr =  (float*)ps_calloc( 1, sizeof(float) );
  log_i("after Free PSRAM: %d", ESP.getFreePsram());
  for (int i = 0; i < 37; ++i)
  {
    oPressureHistoryPtr[i] = 0.0f;
    oIAQ_HistoryPtr[1] = 0.0f;
  }
  eg = xEventGroupCreate();
  SPI.begin();
  bme.begin();
  while (!bme.begin())
  {
    log_i( "Waiting on response from BME280");
    vTaskDelay( 1000 );
  }
  tft.begin();
  tft.fillScreen(BLACK);
  pinMode( GPIO_NUM_0, OUTPUT );
  digitalWrite( GPIO_NUM_0, HIGH );
  connectToWiFi();
  connectToMQTT();
  xTaskCreatePinnedToCore( MQTTkeepalive, "MQTTkeepalive", 30000, NULL, 3, NULL, 1 ); // assign all to core 1, WiFi in use.
  xTaskCreatePinnedToCore( fUpdateDisplay, "fUpdateDisplay", 50000, NULL, 3, NULL, 1 ); // assign all to core 1, WiFi in use.
  xTaskCreatePinnedToCore( DoTheBME280Thing, "DoTheBME280Thing", 50000, NULL, 4, NULL, 1 ); // assign all to core 1, WiFi in use.
  xTaskCreatePinnedToCore( fCollectHistory, "fCollectHistory", 40000, NULL, 3, NULL, 1 ); // assign all to core 1, WiFi in use.
  // resd message and process
} //setup()
////
////
/*
   RPi sends data once every 5.7 seconds. rounded to 6 seconds.
   10 packets received is about 1 minute.
   10 counts of StorageTriggerCount is abot 1 minute
   arrayCellPtr == 60 is the number of data points to keep
*/
void fCollectHistory( void * parameter )
{
  int StorageTriggerCount = 0;
  for (;;)
  {
    xEventGroupWaitBits (eg, evtCollectHistory, pdTRUE, pdTRUE, portMAX_DELAY );
    if ( StorageTriggerCount == 0 )
    {
      oPressureHistoryPtr[arrayCellPtr] = oPressurePtr[0];
      oIAQ_HistoryPtr[1] = oGasResistancePtr[0];
      arrayCellPtr++;
      if ( arrayCellPtr == DataCells )
      {
        arrayCellPtr = 0;
      }
    }
    StorageTriggerCount++;
    if ( StorageTriggerCount == 600 )
    {
      StorageTriggerCount = 0;
    }
  }
  vTaskDelete( NULL );
} //void fCollectHistory( void * parameter )
////
void fUpdateDisplay( void * parameter )
{
  for (;;)
  {
    xEventGroupWaitBits (eg, evtDoDisplay, pdTRUE, pdTRUE, portMAX_DELAY ); //
    tft.fillScreen(BLACK);
    tft.setTextColor( WHITE );
    tft.setCursor( 0, 0 );
    tft.print( "Inside"  );
    tft.setTextColor( GREEN );
    tft.setCursor( 0, 15 );
    tft.print( "Temp: " + String(iTempPtr[0]) + "C " + ( (iTempPtr[0] * 9 / 5) + 32) + "F"  );
    tft.setCursor( 0, 25 );
    tft.print( "Humidity " + String(iHumidityPtr[0]) + "%" );
    //
    tft.setTextColor( WHITE );
    tft.setCursor( 0,  40 );
    tft.print( "Outside" );
    tft.setTextColor( YELLOW );
    tft.setCursor( 0, 55 );
    tft.print( "Temperature: " + String(oTempPtr[0]) + "F" );
    tft.setTextColor( RED );
    tft.setCursor( 0, 65 );
    tft.print( "Humidity " + String(oHumidityPtr[0]) + "%" );
    tft.setCursor( 0, 75 );
    tft.setTextColor( BLUE );
    tft.print( "Pres. " + String(oPressurePtr[0]) + "mmHg" );
    tft.setCursor( 0, 86 );
    //set the color of the value to be displayed
    if ( oGasResistancePtr[0] < 51.0f )
    {
      tft.setTextColor( GREEN );
    }
    if ( (oGasResistancePtr[0] >= 50.0f) && (oGasResistancePtr[0] <= 100.0f) )
    {
      tft.setTextColor( YELLOW );
    }
    if ( (oGasResistancePtr[0] >= 100.0f) && (oGasResistancePtr[0] <= 150.0f) )
    {
      tft.setTextColor( CYAN );
    }
    if ( (oGasResistancePtr[0] >= 150.0f) && (oGasResistancePtr[0] <= 200.0f) )
    {
      tft.setTextColor( RED );
    }
    if ( (oGasResistancePtr[0] >= 200.00f) && (oGasResistancePtr[0] <= 300.0f) )
    {
      tft.setTextColor( MAGENTA );
    }
    if ( (oGasResistancePtr[0] > 300.0f) )
    {
      tft.setTextColor( WHITE );
    }
    tft.print( "AQ Index " + String(oGasResistancePtr[0]) );
    tft.setTextColor( BLUE ); //set graph line color
    int rowRef = 110;
    int hRef = int( oPressureHistoryPtr[0] );
    int nextPoint = 2;
    int nextCol = 0;
    //post humidity data
    for (int i = 0; i < DataCells; i++)
    {
      int hDisplacement = hRef - int( oPressureHistoryPtr[i] ); // cell height displacement from base line
      tft.setCursor( nextCol , (rowRef + hDisplacement) );
      tft.print( "." );
      nextCol += nextPoint;
    }
    tft.setCursor( (arrayCellPtr * nextPoint), (rowRef + 3) );
    tft.print( "I" );
    xEventGroupSetBits( eg, evtCollectHistory ); // trigger task
  }
  vTaskDelete( NULL );
} // void fUpdateDisplay( void * parameter )
////
void WiFiEvent(WiFiEvent_t event)
{
  log_i( "[WiFi-event] event: %d\n", event );
  switch (event) {
    case SYSTEM_EVENT_WIFI_READY:
      log_i("WiFi interface ready");
      break;
    case SYSTEM_EVENT_SCAN_DONE:
      log_i("Completed scan for access points");
      break;
    case SYSTEM_EVENT_STA_START:
      log_i("WiFi client started");
 break;
    case SYSTEM_EVENT_STA_STOP:
      log_i("WiFi clients stopped");
      break;
    case SYSTEM_EVENT_STA_CONNECTED:
      log_i("Connected to access point");
      break;
    case SYSTEM_EVENT_STA_DISCONNECTED:
      log_i("Disconnected from WiFi access point");
      break;
    case SYSTEM_EVENT_STA_AUTHMODE_CHANGE:
      log_i("Authentication mode of access point has changed");
      break;
    case SYSTEM_EVENT_STA_GOT_IP:
      log_i ("Obtained IP address: %s",  WiFi.localIP() );
      break;
    case SYSTEM_EVENT_STA_LOST_IP:
      log_i("Lost IP address and IP address is reset to 0");
      vTaskDelay( 5000 );
      ESP.restart();
      break;
    case SYSTEM_EVENT_STA_WPS_ER_SUCCESS:
      log_i("WiFi Protected Setup (WPS): succeeded in enrollee mode");
      break;
    case SYSTEM_EVENT_STA_WPS_ER_FAILED:
      log_i("WiFi Protected Setup (WPS): failed in enrollee mode");
      ESP.restart();
      break;
    case SYSTEM_EVENT_STA_WPS_ER_TIMEOUT:
      log_i("WiFi Protected Setup (WPS): timeout in enrollee mode");
      break;
    case SYSTEM_EVENT_STA_WPS_ER_PIN:
      log_i("WiFi Protected Setup (WPS): pin code in enrollee mode");
      break;
    case SYSTEM_EVENT_AP_START:
      log_i("WiFi access point started");
      break;
    case SYSTEM_EVENT_AP_STOP:
      log_i("WiFi access point  stopped");
      WiFi.mode(WIFI_OFF);
      esp_sleep_enable_timer_wakeup( 1000000 * 2 ); // 1 second times how many seconds wanted
      esp_deep_sleep_start();
      break;
    case SYSTEM_EVENT_AP_STACONNECTED:
      log_i("Client connected");
      break;
    case SYSTEM_EVENT_AP_STADISCONNECTED:
      log_i("Client disconnected");
      WiFi.mode(WIFI_OFF);
      esp_sleep_enable_timer_wakeup( 1000000 * 2 ); // 1 second times how many seconds wanted
      esp_deep_sleep_start();      
      break;
    case SYSTEM_EVENT_AP_STAIPASSIGNED:
      log_i("Assigned IP address to client");
      break;
    case SYSTEM_EVENT_AP_PROBEREQRECVED:
      log_i("Received probe request");
      break;
    case SYSTEM_EVENT_GOT_IP6:
      log_i("IPv6 is preferred");
      break;
    case SYSTEM_EVENT_ETH_START:
      log_i("Ethernet started");
      break;
    case SYSTEM_EVENT_ETH_STOP:
      log_i("Ethernet stopped");
      break;
    case SYSTEM_EVENT_ETH_CONNECTED:
      log_i("Ethernet connected");
      break;
    case SYSTEM_EVENT_ETH_DISCONNECTED:
      log_i("Ethernet disconnected");
      break;
    case SYSTEM_EVENT_ETH_GOT_IP:
      log_i("Obtained IP address");
      break;
    default: break;
  }
}
////
void DoTheBME280Thing( void *pvParameters )
{
  for (;;)
  {
    iTempPtr[0] = bme.readTemperature();
    iPressurePtr[0] = bme.readPressure() / 133.3223684; // mmHg
    iHumidityPtr[0] = bme.readHumidity();
    MQTTclient.publish( "Home/iTemperature", String(iTempPtr[0]).c_str() );
    vTaskDelay( 2 ); // gives the Raspberry Pi 4 time to receive the message and process
    MQTTclient.publish( "Home/iHumidity", String(iHumidityPtr[0]).c_str() );
    vTaskDelay( 2 ); // no delay and RPi is still processing previous message
    MQTTclient.publish( "Home/iPressure", String(iPressurePtr[0]).c_str() );
    //log_i( "Inernal Temperature %f C Pressure %f hPa Humidity %f %", iTempPtr[0],iPressurePtr[0], iHumidityPtr[0] );
    //    log_i( "Signal strength %d", WiFi.RSSI() );
    vTaskDelay( 60000 ); // = 1 minute
  }
  vTaskDelete ( NULL );
}
////
void MQTTkeepalive( void *pvParameters )
{
  for (;;)
  {
    vTaskDelay( 20 );
    MQTTclient.loop();
  }
  vTaskDelete ( NULL );
}
void connectToMQTT()
{
  MQTTclient.setCallback( mqttCallback );
  if ( !(MQTTclient.connect( clientID, mqtt_username, mqtt_password)) )
  {
    log_i("Connection to MQTT Broker failed...");
  }
  MQTTclient.setCallback( mqttCallback );
  MQTTclient.subscribe( mqtt_topic ); //seems to need to want some topic to subscribe to but does not care in the callback
  ;
}
//
void connectToWiFi()
{
  int retryCount = 0;
  WiFi.begin( SSID, PASSWORD );
  vTaskDelay( 4000 );
  while ( WiFi.status() != WL_CONNECTED )
  {
    log_i(".");
    vTaskDelay( 1000 );
    retryCount ++;
    if
    ( retryCount == 10 )
    {
      ESP.restart();
    }
  }
  WiFi.onEvent( WiFiEvent );
}
////
void mqttCallback(char* topic, byte* payload, unsigned int length)
{
  String messageTemp;
  for (int i = 0; i < length; i++)
  {
    // log_i((char)message[i]);
    messageTemp += (char)payload[i];
  }
  // log_i( "Message arrived in topic: %s payload %s", topic,  messageTemp );
  if ( String(topic) == "Home/Inside/OutsideTemp" )
  {
    oTempPtr[0] = messageTemp.toFloat();
  }
  if ( String(topic) == "Home/Inside/OutsideHumidity" )
  {
    oHumidityPtr[0] = messageTemp.toFloat();
  }
  if ( String(topic) == "Home/Inside/OutsidePressure" )
  {
    oPressurePtr[0] = messageTemp.toFloat();
    xEventGroupSetBits( eg, evtDoDisplay ); // trigger tasks
  }
  if ( String(topic) == "Home/Inside/OutsideGasResistance" )
  {
    oGasResistancePtr[0] = messageTemp.toFloat();
  }
  if (String(topic) == "Home/Inside/stateLED")
  {
    if ( messageTemp == "1")
    {
      digitalWrite( GPIO_NUM_0, LOW );
    }
    if (messageTemp == "0")
    {
      digitalWrite( GPIO_NUM_0, HIGH );
    }
    //}
  }
}
////
void loop() { }

Idahowalker:
I thought you got errors when receiving a MQTT payload?

Suggestion.

Add a new tab to your project. Name it certs.h. Put your secret info into certs.h; like your password. Then, after saving, include the certs.h file. Now you can reference by variable name, your secret info, and you won't be posting your password on the internet.

The program is able to receive MQTT payloads, it is just that RainbowEffect & OffRainbow are not printing the respective things

char messageBuffer[50];
memcpy(messageBuffer, payload, length);
  messageBuffer[length] = '\0';
  Serial.print("the payload is : ");
  Serial.println(messageBuffer);
if (strcmp(messageBuffer, "on") == 0)
  {
      Serial.print("turning ");
      Serial.println(messageBuffer);
      digitalWrite(LED_BUILTIN, LOW);
      power = true; //activate rainbow 
  }
  else if (strcmp(messageBuffer, "off") == 0)
  {
      Serial.print("turning ");
      Serial.println(messageBuffer);
      digitalWrite(LED_BUILTIN, HIGH);
      OffRainbow();
      power = false;  //stop the rainbow
    }

so I think my error is with strcmp. The Serial is able to receive "the payload is : " messageBuffer. But thats it everything else in the if statements are not working.