__             __________           __
       / /   ___  ____/ / ____/ /___  _____/ /__
      / /   / _ \/ __  / /   / / __ \/ ___/ //_/
     / /___/  __/ /_/ / /___/ / /_/ / /__/ ,<
    /_____/\___/\__,_/\____/_/\____/\___/_/|_|
    

Wi-Fi and MQTT Controlled NeoPixel LED Clock

Introduction

This project implements a clock using NeoPixel LEDs, controlled via Wi-Fi and MQTT messages. It leverages several libraries to manage Wi-Fi connectivity, MQTT communication, JSON parsing, and time synchronization. The clock displays the current time with NeoPixel LEDs and allows for remote control over the display characteristics such as color and brightness.

Libraries Used

  • ESP8266WiFi.h: Manages Wi-Fi connections.
  • Wire.h: Facilitates I2C communication.
  • PubSubClient.h: Implements an MQTT client for communication with an MQTT broker.
  • ArduinoJson.h: Parses JSON payloads received via MQTT.
  • NTPClient.h and WiFiUdp.h: Utilizes Network Time Protocol (NTP) for synchronizing time.
  • RtcDS3231.h: Manages the Real-Time Clock (RTC).
  • Adafruit_NeoPixel.h: Controls NeoPixel LEDs.

Configuration

Wi-Fi and MQTT Configuration

  • wifi_ssid and wifi_password: Credentials for connecting to the Wi-Fi network.
  • mqtt_server, mqtt_user, and mqtt_password: Details for connecting to the MQTT broker.

LED Configuration

  • Defines the pin connected to the NeoPixel LEDs, the number of LEDs, and layout specifics.

Time Variables and NTP Client

  • Synchronizes time using NTP and updates the RTC.

Setup Function

The setup function performs the following tasks:

  • Initializes serial communication for debugging.
  • Connects to the specified Wi-Fi network using the provided credentials.
  • Connects to the MQTT broker with the given details.
  • Initializes the NTP client and synchronizes the RTC to ensure accurate timekeeping.
  • Sends auto-discovery messages to integrate with home automation systems.

MQTT Callback

The MQTT callback function handles incoming messages by:

  • Parsing the JSON payload to extract information about light state, brightness, and color.
  • Updating the NeoPixel display according to the received commands.

Reconnect Function

The reconnect function ensures the device maintains a connection to the MQTT broker. If the connection is lost, it attempts to reconnect until successful.

Main Loop

The loop function continuously:

  • Updates the clock display based on the current time.
  • Manages the MQTT connection, ensuring it remains active.
  • Publishes the current state of the lights, including brightness and color, to the MQTT broker.

Conclusion

This project successfully integrates several technologies to create a network-connected LED clock. The use of MQTT allows for seamless remote control of the display characteristics, making it a versatile addition to any smart home setup. The combination of NTP and RTC ensures accurate and reliable timekeeping. This clock can be easily customized and expanded for various applications, showcasing the power and flexibility of IoT (Internet of Things) devices.