Skip to content

ESP8266 RGB+W led strip control, with control website hosted on ESP8266

Notifications You must be signed in to change notification settings

wvdv2002/ESP8266-LED-Websockets

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

94 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ESP8266-LED-Websockets

Code for a ESP8266 controlled LED light with RGB + white SK2812 led strips. This code makes it controllable from any webbrowser, with the files hosted on the ESP8266. So no external server needed. Control via MQTT is also possible. The current LED color is persistent and survives a reboot. Maybe somebody with some experience can add some CSS code to the website to make it look somewhat nicer. For now it is very basic but functional.

Screenshot

Basic usage

To use the program, make sure the following Arduino libraries are installed:

  • Fastled
  • Adafruit Neopixel
  • ESP libraries
  • Websockets
  • WifiManager

Connect your ledstrip to the ESP, remember the data GPIO pin used. Update the ledstrip part of the code, set the amount of leds and the GPIO pin. You can also update the sort of controller, anything the Adafruit library supports should work. Compile the code with at least 512kb of SPIFFS space (if this takes up too much space, remove everything from the data folder except index.htm) Upload the code to a ESP8266. Use the following Arduino plugin to upload the data folder to the ESP as well: https://github.com/esp8266/arduino-esp8266fs-plugin Now, connect to wifi acces point setup by the ESP WifiManager library and use any webbrowser to goto http://192.168.4.1 and setup your wifi connection. Let the ESP connect, find out the ip address and goto that ip using the webbrowser. You can now control the leds using the sliders on the website.

Animations

The website queries the ESP8266 to populate the list of supported animations. This query can later also be used by the MQTT system, so a possible home automation system can just query the ESP for the available animations. Animations can be added by adding a name and a function to the simpleanimationlist.

Websocket

The website shown to the user uses a websocket to send data to the ESP module. This feels very 'snappy', when manipulating the sliders the reaction is almost instant. You can of course also connect to the websocket server directly and send commands. Please check the index.htm file and the Ledwebsockets.h file for information on which commands can be send or received. The websocket interface can be used to set the settings for mqtt: IP address, Port and Topic. See chapter MQTT for usage

RGBW strip support

I used my own way of hacking support into the firmware for the SK6812 led, which is a real nice RGBWW led with the white leds also individually adressable. Fastled has no support for this yet. The fastled library is used for all animations and calculations etcetera and the Adafruit Neopixel library is used to actually drive the leds. Which is a good enough compromise for now. The white leds of the strip are driven as one led, they can only be controlled by a seperate slider, so no calculating W from RGB, this is hard anyway because you have SK6812 leds with different color temperatures. But if anybody wants to use this anyway there is only one function where the code has to be changed.

MQTT

There is basic MQTT support now as well. If you do not need MQTT, please comment out the #define USE_MQTT line in the ledcontrol.ino file. Mqtt settings can be set using the websocket interface.

First you define the mqtt server and the topics in the MQTTServer.h file. At boot, the animationNames will be posted to the mqttAnimationNamesTopic. Every time the state of the settings changes, via websocket or MQTT, a new status message will be posted with a JSON string in the mqttStatTopic.

{"animation":1,"r":0,"g":31,"b":0,"h":96,"s":255,"v":88,"white":0,"speed":50,"sleep":28}

Commands can be send to the mqttCmdTopic path, for example "/livingroom/tree/cmd/hue".

The following commands can be used:

  • hue: The brightness in HSB, value from
  • saturation: The brightness in HSB, value from 0 to 255.
  • brightness: The brightness in HSB, value from 0 to 255.
  • sleep: The time until fading out all leds, value from 1 to 1000; (Not tested)
  • animation: The number of the animation to be selected (0 is off, 1 is solid, rest are animations).
  • speed: The speed of the animation (does not do much yet).
  • white: The intensity from 0-1023 of the white leds.
  • hsv: Comma seperated HSV values ("128,94,16").
  • rgb: Comma seperated RGB values ("128,128,128").
  • demo: Enable demo mode ("0", "1")
  • demotime: Amount of seconds between each animation for the demo
  • firecooling: The fire animation 'cooling' parameter (best between 5 and 30, not limited)
  • firesparking: The fire animation 'sparking' parameter (best between 40 and 150)

Buttons

Three buttons are defined to be able to control the led strip without a wifi connection

  • Button 1: Switch to next animation (off, solid, white, fire, ...)
  • In combination with button 3, switch to off
  • Button 2: Function depends on animation
  • Solid: Control dim value, in combination with button 3: Control hue
  • White: Control dim value
  • Fire: Control 'cooling' parameter, in combination with button 3: control 'sparking' parameter
  • Others: Control speed
  • Button 3: Used in combintion with button 2 and 1.

TODO:

  • Add config page to set settings instead of hard coding them.

Development:

This work was forked from https://github.com/wvdv2002/ESP8266-LED-Websockets This work was forked from https://github.com/TheAustrian/ESP8266-LED-Websockets/

About

ESP8266 RGB+W led strip control, with control website hosted on ESP8266

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 54.6%
  • CSS 21.5%
  • C++ 15.3%
  • C 5.6%
  • HTML 3.0%