Giter Site home page Giter Site logo

acekid / esp-wifi-neopixel-control Goto Github PK

View Code? Open in Web Editor NEW

This project forked from terr4/esp-wifi-neopixel-control

1.0 1.0 0.0 13.63 MB

NodeMCU script to control NeoPixel ws2812b led strips. Control colors, brightness and some effects with HTTP calls.

License: GNU General Public License v3.0

C++ 100.00%

esp-wifi-neopixel-control's Introduction

ESP-WIFI-NEOPIXEL-CONTROL

NodeMCU script to control NeoPixel ws2812b led strips.
Control colors, brightness and some effects with HTTP or MQTT calls.

Video of Script in Action

https://www.youtube.com/watch?v=9A8iUpCb1MI
Alexa control in the video is not part of this description.

Config

The http server gets initialzed on port 5001, this can be changed in the code.
You should change the following variables to your needs:
- wifi_ssid
- wifi_password
- mqtt_server
- mqtt_user
- mqtt_password
- OTA_hostname
- OTA_password
- PixelCount



MQTT VERSION

The MQTT version uses 3 topics:
home/ledcontroller/ -> you will receive status changes on this topic
home/ledcontroller/set -> control effects, brightness, animation, color on this topic
home/ledcontroller/log -> receive log messages and errors on this topic

Control LED effects

Send JSON commands to the MQTT SET topic to change the effect and brightness:

Set animation FUN:

{"animation":"fun"}

Possible values: off, beam, fun, cylon, pulse, fire, aqua

Set brightness (0-100):

{"brightness":20}

Set static color with predefined color values:

{"animation":"colorred"}
{"animation":"colorblue"}
{"animation":"colorgreen"}
{"animation":"colorwhite"}
{"animation":"colorblack"}

Set static color with RGB values:

{"animation":"color","color":{"r":200,"g":200,"b":10}}

Set all at once:

{"animation":"color","brightness":34,"color":{"r":200,"g":200,"b":10}}

Note: color values only get considered when animation=color is selected

Status of LED controller

During startup and in case an effect changes the controller sends a status message to the MQTT topic. The status in a JSON message and looks like the following. The "uptime" value are the milliseconds since the controller was started, "uptimeH" are the hours since it was started. The "brightness" value is the percent value between 0 and 100, brightnessraw is the actual set value between 0 and 255
{
  "uptime":143248,
  "uptimeH":0,
  "animation":"fun",
  "brightness":34,
  "brightnessraw":86,
  "color":{
    "r":9,
    "g":49,
    "b":9
  }
}



Example OpenHAB2 Config

ITEMS

String  Light_L_Digiledstrip_Anim       "Current Animation [%s]"          {mqtt="<[openhab2:home/ledcontroller:state:JSONPATH($.animation)]"}
String  Light_L_Digiledstrip_Bright     "Brightness [%s]"                 {mqtt="<[openhab2:home/ledcontroller:state:JSONPATH($.brightness)]"}
String  Light_L_Digiledstrip_Uptime     "Uptime [%s h]"                   {mqtt="<[openhab2:home/ledcontroller:state:JSONPATH($.uptimeH)]"}
Color   Light_L_Digiledstrip_Color      "Color"                         

String Light_L_Digiledstrip "LED Animation" { mqtt=">[openhab2:home/ledcontroller/set:command:*:{animation\:${command}}]" }

SITEMAP

Frame label="LED Light" icon="light" {
  Selection item=Light_L_Digiledstrip mappings=[off="off", colorblue="Movie", beam="Beam", fun="Party", cylon="Cylon", pulse="Pulse", fire="Fire", aqua="Aqua"]
  Colorpicker item=Light_L_Digiledstrip_Color
  Slider item=Light_L_Digiledstrip_Bright
  Text item=Light_L_Digiledstrip_Uptime
}

RULES

import java.awt.Color

rule "LED controller Brightness" when Item Light_L_Digiledstrip_Bright received command then logInfo( "FILE", "RULE: LED controller Brightness triggered") publish("openhab2","home/ledcontroller/set","{brightness:" + Light_L_Digiledstrip_Bright.state + "}") end

rule "LED controller Color" when Item Light_L_Digiledstrip_Color received command then logInfo( "FILE", "RULE: LED controller Color triggered") var hsbValue = Light_L_Digiledstrip_Color.state as HSBType var Color color = Color::getHSBColor(hsbValue.hue.floatValue / 360, hsbValue.saturation.floatValue / 100, hsbValue.brightness.floatValue / 100)

var String redValue = String.format("%03d", ((color.red.floatValue / 2.55).intValue)) var String greenValue = String.format("%03d", ((color.green.floatValue / 2.55).intValue)) var String blueValue = String.format("%03d", ((color.blue.floatValue / 2.55).intValue)) logInfo("FILE", "RED: "+ redValue + " GREEN: "+ greenValue + " BLUE: "+ blueValue + "")

publish("openhab2","home/ledcontroller/set","{animation:color,color:{r:" + redValue + ",g:" + greenValue + ",b:" + blueValue + "}}") end

3D Printed Case

See included STL file for a case for the Node MCU V2 (small version)

WIFI VERSION (legacy)

Start Effects

Effects were mainly taken from the standard NeoPixelBus example library and slightly changed
http://[ip]:5001/control?animationid=fun
http://[ip]:5001/control?animationid=beam
http://[ip]:5001/control?animationid=fire
http://[ip]:5001/control?animationid=aqua
http://[ip]:5001/control?animationid=pulse
http://[ip]:5001/control?animationid=cylon

Set Predefined Colors

http://[ip]:5001/control?animationid=colorred
http://[ip]:5001/control?animationid=colorblue
http://[ip]:5001/control?animationid=colorgreen
http://[ip]:5001/control?animationid=colorblack
http://[ip]:5001/control?animationid=colorwhite

Set Custom Colors

You can add an RGB color code (9 digits) at the end of the color command to set a custom color
http://[ip]:5001/control?animationid=color255255255

Set Brightness

Value is a percent value between 0 and 100)
http://[ip]:5001/control?brightness=20

Turn LED Strip off

http://[ip]:5001/control?animationid=off

Get current status as JSON with

http://[ip]:5001/control?status

The returned message is the same as in the MQTT version



Stefan Schmidhammer 2017

esp-wifi-neopixel-control's People

Contributors

terr4 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.