# A Reference to your ESP32 MQTT-based Mood Lights ## MQTT There are separate topics for clients to publish and subscribe to, even if they pertain to the same data. As an examle, "MoodLight/RedChange" is published to by clients for changing the red value in static color mode. "MoodLight/Red" is subscribed to by clients, and is only published to by the mood light. The mood light status topic will hold one of two values, "Online" or "Offline". The mode topic holds one of four values, "Static Color", "Random Color", "Red Alert", and "Blue Alert". Publishes made to the mode change topic must have a payload of one of these values, matching the case. The mode changes to static color whenever a publish is made to the red, green, blue, or intensity change topics. The red, green, and blue topics only accept numbers from 0 to 25. The intensity topic only accepts numbers from 0 to 10. The ESP automatically tries to reconnect to WiFi and/or the MQTT broker whenever it loses connection. ## Touch controls Red Alert mode can be activated and deactivated by by touching the Red Alert pad, but I didn't need to tell you that. The up and down pads can be pressed simultaneously while in static color mode to activate random color mode. The up, down, and next pads can be used to change the color while in static color mode. Blue Alert mode can only be activated through MQTT, but can be deactivated by pressing the Red Alert touch pad. I intended for that to be a kind of warning alert for other events that are registered by my "smart" home system. Any inputs made in the touch interface will update the appropriate MQTT topics as well. ## Required libraries I use the ESP32 standard WiFi library, along with the [PubSubClient](https://pubsubclient.knolleary.net/) and [ESP8266 and ESP32 OLED driver for SSD1306 displays](https://github.com/ThingPulse/esp8266-oled-ssd1306) libraries, both of which are available through Arduino's built-in library manager. ## Things for you to change WiFi SSID and password can be set in the first few lines of ESP32MQTTMoodLighting.ino, along with all of the pins used. MQTT topic names can be changed in MQTTStuff.ino. Feel free to copy or change my code, though I doubt you will :)