Hi all,
I am using a WemosD1 to control Led strip, the programming for FASTLed modes is complete and working. Now having issue of using MQTT to select the correct mode to operate my leds.
Note:
- WIfi connection has been made
- Connected to mqtt server
- Led modes (scenes) 0 ~ 6 switching is done with "switch" function in the main loop.
- Mqtt is not selecting the correct scenes. The selected scene is always says default.
#include <SPI.h>
#include <PubSubClient.h>
#include <ESP8266WiFi.h> // Include the Wi-Fi library
#include <FastLED.h>
#define DATA_PIN 0 // hardware Data pin
#define NUM_LEDS 150 // Total No. of LEDs
IPAddress server(10, 0, 0, xx); //MQTT broker IP Address
struct CRGB leds[NUM_LEDS];
int currentScene=0;
int previousScene=0;
int selectedScene=0;
const char* ssid = "xxxxxxxxx";
const char* password = "xxxxxxxxx";
void callback(char* topic, byte* payload, unsigned int length)
{
//================Print whatever received to serial Monitor =========
Serial.print("Message arrived [");
Serial.print(topic);
Serial.print("] ");
for (int i=0;i<length;i++)
{
Serial.print((char)payload*);*
-
}*
-
Serial.println();*
//=============== MQTT SUBSCRIBE================
String strTopic = String((char*)topic); -
if (strTopic == "cmnd/WemosD1/LEDscene")*
-
{*
-
if (((char)payload[0]) != previousScene)*
-
{*
-
if(((char)payload[0]) == 1)*
-
{*
-
selectedScene = 1;*
-
Serial.println("Scene Selection = 1");*
-
}*
-
else if (((char)payload[0]) == 2)*
-
{*
-
selectedScene = 2;*
-
Serial.println("Scene Selection = 2");*
-
}*
-
else if (((char)payload[0]) == 3)*
-
{*
-
selectedScene = 3;*
-
Serial.println("Scene Selection = 3");*
-
}*
-
else if (((char)payload[0]) == 4)*
-
{*
-
selectedScene = 4;*
-
Serial.println("Scene Selection = 4");*
-
}*
-
else if (((char)payload[0]) == 5)*
-
{*
-
selectedScene = 5;*
-
Serial.println("Scene Selection = 5");*
-
} *
-
else*
-
{*
-
selectedScene = 0;*
-
Serial.println("Scene Selection = Default");*
-
} *
-
previousScene = ((char)payload[0]);*
-
} *
}
} -
WiFiClient espClient;*
-
PubSubClient client(espClient);*