Git Product home page Git Product logo

mclighting's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mclighting's Issues

Can I save the last set value?

Can I save the last set value?
ESP-12 automatically reopens after some time
LED light settings will run away after reopening

Random reboots

Hey folks!
I'm still experimenting with this project, currently I have the little LED matrix I mentioned before, plus a strip of 128 LEDs. Each of them are driven with a NodeMCU-Board with a sufficient power supply.
I wanted to drive them with a Node-RED server, which I deactivated for now, because I thought the constant WebSocket connection (MQTT will come) could be the problem.
What's the problem? If I turn the LEDs off ( -> ws: =off), after a more or less long while, the lights begin to use the "default" animation (rainbow cycle in my case). At the same time the WebSocket connection gets lost, so I assume the ESP just reboots. It does not seem to happen when I use a constant color, but I am not totally sure of that.
When I turn them off for the night, I can be >90% sure they are on when I wake up ;)

I will set the default to "off" for now, then I can maybe see if the problem persists or this works as a workaround for me. Does anybody else have such problems?

Thanks and best regards,
Yannick

Why do all LED's get looped through for a single pixel change?

I'm not a C (or embedded hardware) developer, so this is potentially a stupid question on it's way;

Why are we looping through all the LED's during handleSetSingleLED() as below:

    for (uint8_t i = 0; i < strip.numPixels(); i++) {
    strip.setPixelColor(i, ledstates[i].red, ledstates[i].green, ledstates[i].blue);
      //DBG_OUTPUT_PORT.printf("[%u]--[%u] [%u] [%u] [%u] LED index!\n", rgb, i, ledstates[i].red, ledstates[i].green, ledstates[i].blue);
    }
    strip.show();

To me, this makes sense included in the handleSetAllMode() function, which also has the loop.

I've tried removing it from handleSetSingleLED() and replaced it with the following, everything seems to keep working correctly:

    strip.setPixelColor(led, ledstates[led].red, ledstates[led].green, ledstates[led].blue);
    strip.show();

Am I missing something? the change seems to be standing up to a decent battering via MQTT.

2 modes of operation: McLighting + Other

Hi,
first of all, thank you for the great work. A very useful and easy to use framework. After trying it I decided to build a desk lamp based on it.

The lamp should have two modes: Funky (i.e. McLighting) and regular (i.e. white light, dimable with a poti). I want to switch between these two modes with a regular button/switch.

My initial idea was: Include a while loop in the somewhere inside the main lood which holds the very small dimable-white-light-code. while the button is in "regular-mode" only the code inside the while loop should be repeated. When I switch to "McLighting-Mode" everything except the code in the while-loop should run.
Like this:

while(digitalRead(buttonPin)==HIGH){
    // code for regular mode (poti --> dimable white lights
 
  }

But when I put this code in the main loop nothing works anymore.

Is there a place I can put this while-loop so it works as I want to?
Is it possible to use the analog-pin (A0)? It is used as an imput in the main sketch, but I don't know what for. (and what about the other pins? (at least one is needed as a "buttonPin".

Thanks!
Dimi

Does not go into AP mode / No Debug Output

Hey,

I do have a problem with your software. When I flash the sketch, the LED's start in rainbow mode but there is no debug output in the serial monitor and the esp does not open an AP. What could be wrong?

Arduino IDE: 1.8.2
all other Libraries are on the same version that you've posted

Request: More Modes via MQTT

Hi,

is it possible to add an NTP (Network Time Protocoll) Function? So that my lights turn on in the evening and turn off in the morning? So you can set the time in the Webinterface.

That would be really awesome.

Thanks.

How to add more libraries for countrolling the LED as a matrix?

Thank you very much for this fantastic code!

I am trying to add in the FastLED library to control a 10x10 WS2812 LED panel. Such function could be useful to display text input from the Http server, from an online value or just read analog value from ADC to display.

How can I modify the server page to get everything to work?

handleSetSingleLED not working correctly

Hi!
At first, many thanks, I like this project very much :)
While enhancing it a bit by open the possibility to manually set different colors to several specific LEDs at once via WebSockets, I think I found a bug in the handleSetSingleLED()-function.
I currently have small testing matrix connected to a NodeMCU with 3*12 LEDs.
Steps to reproduce:
(1) Send "!16aa6f46" via WS.
Reaction on serial monitor:

WS: [0] Connected from 192.168.1.169 url: /
WS: [0] get Text: !16aa6f46
WS: Set single led [22] to [170] [111] [70]!

Alternative testing snippet in JS:

var led = 0;
connection.onopen = function () {
  console.log("Connection opened");
  for (var i = 0; i < 37; i++) {
	setTimeout(function() {	
		var stringToSend = "!" + led + "0000FF";
		console.log(stringToSend);
		connection.send(stringToSend);
		led++;
	}, 50*i); //delay to avoid crashing the ESP because of too many requests
                    //which is the initial reason for the new command
	
}
};

With the snippet above only the following LEDs turn on: 1-10; 17-26; 33-36

I already tried to determine what exactly is causing this "conversion" from one Led-number to another, but wasn't able to. I don't get how this function works exactly ;)

Best regards,

Help!!! Control from the buttons

Please add a programme of control from the buttons

on/off GPIO5
brightness [-]GPIO6 [+]GPIO7
speed of effect [-]GPIO13 [+]GPIO15
switching of effects GPIO14
auto mode cycle GPIO12
Please help me, I want to do a garland for New Year very much

#include <WS2812FX.h>

#define LED_COUNT 587
#define LED_PIN 2

WS2812FX ws2812fx = WS2812FX(LED_COUNT, LED_PIN, NEO_RGB + NEO_KHZ800);

void setup() {
ws2812fx.init();
ws2812fx.setBrightness(255);
ws2812fx.setSpeed(200);
ws2812fx.setColor(0x007BFF);
ws2812fx.setMode(FX_MODE_STATIC);
ws2812fx.start();
}

void loop() {

ws2812fx.service();

}

Random Crashes - Red Pulsing LED Strip

Hello, i found out, that after a while (maybe 1 hour or more) something strange happens. The Strip turns into breathe mode with color red (as if he wants to say something is wrong). It happens when its in off mode and also when its running one of the effect modes. When i plug the esp8266 into the pc and leave it running i cannot reproduce the error. On my mqtt Server i can see serveral reconnects (approx. every hour).

Does someone know what is causing that? Maybe i try to disable MQTT (but with my mqtt connection everything is okay, even the controls via mqtt are working).

When i use the better-http-rgb plugin within homebridge i also face the issue that my devices are not responding when the strip starts breathing red, because the webserver is also not responding then. When i reboot the esp8266 manually then, everything is fine again until the next crash.

New Functions

Create drop-down list with effects instead of buttons. It will be better. Also selection of favourite effects by the tick and they could work by turns.

MQTT not working as expected.

After setting MQTT_MAX_PACKET_SIZE to 256 as discovered in #30 (comment) I am able to boot and partially connect to my MQTT server...

Attempting MQTT connection 1 / 4 ...
MQTT connected!
MQTT topic in: 
MQTT topic out: hostname/out
Attempting MQTT connection 2 / 4 ...
MQTT connected!
MQTT topic in: 
MQTT topic out: hostname/out
Attempting MQTT connection 3 / 4 ...
MQTT connected!
MQTT topic in: 
MQTT topic out: hostname/out
Attempting MQTT connection 4 / 4 ...
MQTT connected!
MQTT topic in: 
MQTT topic out: hostname/out
MQTT connection failed, giving up after 4 tries ...

When I subscribe to the hostname/out topic, I see "McLighting ready: hostname", however it never updates nor does publishing messages to hostname/in take any actions. Assuming things are the same as the WS API, do I just publish =mode, or #HEXRGB?

Swapped S and P parameters for /set_brightness

The Wiki of HTTP-REST-API#generic says the following:
Parameter:
c: Value from 0 (off) to 255 (full brightness)
p: Value from 0 (off) to 100 (full brightness)
However, when I send p=100, its not actually set to full brightness. When I send s=100, it does set to full brightness. I assume these values are swapped.

Request: More Modes via MQTT

Hello,

I just got MQTT working now and its perfectly working with Node-RED. Is it possible to get all the Modes working with MQTT? There are only the Modes which can be requested via Websocket but there are many more on the Mode Site.

unbenannt

unbenannt2

Thank you.

Bug in listStatusJSON() function

Hi, I've started playing with McLighting, and like it very much. It's going to make my Halloween project much easier. Thank you for sharing your hard work.

But I did find a bug I wanted to bring to your attention. If I knew GitHub a little better, I'd fix it and submit a pull request, but I'm not that familiar with GitHub.

Anyway, if I run McLighting and browse to http://{ESPHOSTNAME}/status, my ESP crashes. I peeked at the code and in request_handlers.h there's a function called listStatusJSON(), which is supposed to return a collection of status parameters in JSON format. The function uses snprintf() to compose the JSON string, which uses the WS2812FX function getModeName() to retrive the mode name. Unfortunately WS2812FX stores the mode names in FLASH (i.e. PROGMEM) memory and snprintf() expects the value returned by getModeName() to be in RAM. More about PROGMEM here: http://arduino-esp8266.readthedocs.io/en/latest/PROGMEM.html

I added a couple lines to listStatusJSON(), which copies the WS2812FX mode name from FLASH to RAM and uses the copy in snprintf(). That fixed the problem for me. Here's my version of listStatusJSON():

char* listStatusJSON() {
  char json[255];

  char modeName[30];
  strncpy_P(modeName, (PGM_P)strip.getModeName(strip.getMode()), sizeof(modeName)); // copy from progmem

  snprintf(json, sizeof(json), "{"mode":%d, "ws2812fx_mode":%d, "ws2812fx_mode_name":"%s", "speed":%d, "brightness":%d, "color":[%d, %d, %d]}",
    mode, strip.getMode(), modeName, ws2812fx_speed, brightness, main_color.red, main_color.green, main_color.blue);
  return json;
}

Hope that helps. If I'm not being clear, please let me know.

Unable to compile after all libraries are installed.

In file included from C:\Users\win7\Desktop\EE\WS2812LED\McLighting-master\Arduino\McLighting\McLighting.ino:97:0:

sketch\request_handlers.h: In function 'char* listStatusJSON()':

sketch\request_handlers.h:84:8: warning: address of local variable 'json' returned [-Wreturn-local-addr]

char json[255];

    ^

C:\Users\win7\Documents\Arduino\libraries\WebSockets\src\WebSocketsClient.cpp: In member function 'void WebSocketsClient::begin(const char*, uint16_t, const char*, const char*)':

C:\Users\win7\Documents\Arduino\libraries\WebSockets\src\WebSocketsClient.cpp:69:16: error: 'RANDOM_REG32' was not declared in this scope

 randomSeed(RANDOM_REG32);

            ^

What does it mean? How can I solve it?
Is "RANDOM" function not available?
Please help. Thank you.

MQTT for WS2812FX working

// MQTT control added to the MC-LIGHTING V2 from Tobias Blum, https://github.com/toblum/McLighting, In this setup
// i only changed this page, You only need to change extra the 'HOST' name on "definitions.h".
// On this page you need to change the:
// MQTTserver IP (now: 192.168.192.53)
// MQTT: user & passw (now: leon & 1122
// SUBscribe topic (now: "ws2812-set/mode") here you can set SPEED, COLOR and MODE
// PUBlish TOPICS ( now: "ws2812-set/state/ws2812-160") here will be feedback for MODE's on your MQTT broker.
// ( all above is random, only my name ;-)
// On "if (mode == OFF)" and "if (mode == ALL)" i have added MQTT control for (all) OFF and (all) ON (static, warm white, brightness 200)
// (because i can't get websocket running, yet, on my Raspberry-Pi Mosquitto (MQTT-broker) i use this from my CCU-2 (Homamatic controller),
// with java scripts control for normal garden lights, i have 10 ws2812 lights in my back garden, each with 2x 26 leds)
//
// For the different MODEs (effects) put/publish : m 0 for static
// m 1 for Blink
// m 2 for Breath etc...
// m 47 for FIRE
// So ALL 47 ws2812FX modes!!
// For ALL colors, just put "c 0xFFFFFF" for white, or any HEX code AFTER c 0x.
// For Brightness, use "b 0" (is off) or "b 255" (is brightesd) or any number in between) 0-255
// for speed, it's the same but then "s 0" (is slow) or "s 255" (is fastest)
//
// on the end the complete list off controls
//
// Good Luck Leon Vos, NL.

#include "definitions.h"

// ***************************************************************************
// Load libraries for: WebServer / WiFiManager / WebSockets /MQTT-broker
// ***************************************************************************
#include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino

// needed for library WiFiManager
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager

#include <WiFiClient.h>
#include <ESP8266mDNS.h>
#include <FS.h>
#include <PubSubClient.h>
#include <WebSockets.h> //https://github.com/Links2004/arduinoWebSockets
#include <WebSocketsServer.h>
#include <WS2812FX.h>
WS2812FX strip = WS2812FX(NUMLEDS, PIN, NEO_GRB + NEO_KHZ800);

IPAddress mqttserver(192, 168, 192, 53); // replace this with your MQTT brokers IP

WiFiClient wclient;
PubSubClient client(wclient, mqttserver);

#define BUFFER_SIZE 100

// Start handle MQTT message arrived
void callback(const MQTT::Publish& pub) {
Serial.println(pub.payload_string());
String command = pub.payload_string();

if(command == F("b+")) {
strip.increaseBrightness(25);
Serial.print(F("Increased brightness by 25 to: "));
Serial.println(strip.getBrightness());
}

if(command == F("b-")) {
strip.decreaseBrightness(25);
Serial.print(F("Decreased brightness by 25 to: "));
Serial.println(strip.getBrightness());
}

if(command.startsWith(F("b "))) {
uint8_t b = (uint8_t) command.substring(2, command.length()).toInt();
strip.setBrightness(b);
Serial.print(F("Set brightness to: "));
Serial.println(strip.getBrightness());
}

if(command == F("s+")) {
strip.increaseSpeed(10);
Serial.print(F("Increased speed by 10 to: "));
Serial.println(strip.getSpeed());
}

if(command == F("s-")) {
strip.decreaseSpeed(10);
Serial.print(F("Decreased speed by 10 to: "));
Serial.println(strip.getSpeed());
}

if(command.startsWith(F("s "))) {
uint8_t s = (uint8_t) command.substring(2, command.length()).toInt();
strip.setSpeed(s);
Serial.print(F("Set speed to: "));
Serial.println(strip.getSpeed());
}

if(command.startsWith(F("m "))) {
uint8_t m = (uint8_t) command.substring(2, command.length()).toInt();
strip.setMode(m);
Serial.print(F("Set mode to: "));
Serial.print(strip.getMode());
Serial.print(" - ");
Serial.println(strip.getModeName(strip.getMode()));
client.publish("ws2812-set/state/ws2812-160",strip.getModeName(strip.getMode()));
}

if(command.startsWith(F("c "))) {
uint32_t c = (uint32_t) strtol(&command.substring(2, command.length())[0], NULL,
16);
strip.setColor(c);
Serial.print(F("Set color to: "));
Serial.print(F("0x"));
if(strip.getColor() < 0x100000) { Serial.print(F("0")); }
if(strip.getColor() < 0x010000) { Serial.print(F("0")); }
if(strip.getColor() < 0x001000) { Serial.print(F("0")); }
if(strip.getColor() < 0x000100) { Serial.print(F("0")); }
if(strip.getColor() < 0x000010) { Serial.print(F("0")); }
Serial.println(strip.getColor(), HEX);
}
Serial.println("End of callback");
}
// End handle MQTT message arrived

// OTA
#ifdef ENABLE_OTA
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#endif

// ***************************************************************************
// Instanciate HTTP(80) / WebSockets(81) Server
// ***************************************************************************
ESP8266WebServer server ( 80 );
WebSocketsServer webSocket = WebSocketsServer(81);

// ***************************************************************************
// Load libraries / Instanciate WS2812FX library
// ***************************************************************************
// https://github.com/kitesurfer1404/WS2812FX

// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)

// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel. Avoid connecting
// on a live circuit...if you must, connect GND first.

// ***************************************************************************
// Load library "ticker" for blinking status led
// ***************************************************************************
#include <Ticker.h>
Ticker ticker;

void tick()
{
//toggle state
int state = digitalRead(BUILTIN_LED); // get the current state of GPIO1 pin
digitalWrite(BUILTIN_LED, !state); // set pin to the opposite state
}

// ***************************************************************************
// Callback for WiFiManager library when config mode is entered
// ***************************************************************************
//gets called when WiFiManager enters configuration mode
void configModeCallback (WiFiManager *myWiFiManager) {
DBG_OUTPUT_PORT.println("Entered config mode");
DBG_OUTPUT_PORT.println(WiFi.softAPIP());
//if you used auto generated SSID, print it
DBG_OUTPUT_PORT.println(myWiFiManager->getConfigPortalSSID());
//entered config mode, make led toggle faster
ticker.attach(0.2, tick);

uint16_t i;
for (i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, 0, 0, 255);
}
strip.show();
}

// ***************************************************************************
// Include: Webserver
// ***************************************************************************
#include "spiffs_webserver.h"

// ***************************************************************************
// Include: Request handlers
// ***************************************************************************
#include "request_handlers.h"

// ***************************************************************************
// Include: Color modes
// ***************************************************************************
#include "colormodes.h"

// ***************************************************************************
// MAIN
// ***************************************************************************
void setup() {
DBG_OUTPUT_PORT.begin(115200);

// set builtin led pin as output
pinMode(BUILTIN_LED, OUTPUT);
// start ticker with 0.5 because we start in AP mode and try to connect
ticker.attach(0.6, tick);

// ***************************************************************************
// Setup: Neopixel
// ***************************************************************************
strip.init();
strip.setBrightness(brightness);
strip.setSpeed(ws2812fx_speed);
//strip.setMode(FX_MODE_RAINBOW_CYCLE);
strip.start();

// ***************************************************************************
// Setup: WiFiManager
// ***************************************************************************
//Local intialization. Once its business is done, there is no need to keep it around
WiFiManager wifiManager;
//reset settings - for testing
//wifiManager.resetSettings();

//set callback that gets called when connecting to previous WiFi fails, and enters Access Point mode
wifiManager.setAPCallback(configModeCallback);

//fetches ssid and pass and tries to connect
//if it does not connect it starts an access point with the specified name
//here "AutoConnectAP"
//and goes into a blocking loop awaiting configuration
if (!wifiManager.autoConnect()) {
DBG_OUTPUT_PORT.println("failed to connect and hit timeout");
//reset and try again, or maybe put it to deep sleep
ESP.reset();
delay(1000);
}

//if you get here you have connected to the WiFi
DBG_OUTPUT_PORT.println("connected...yeey :)");
ticker.detach();
//keep LED on
digitalWrite(BUILTIN_LED, LOW);

// ***************************************************************************
// Configure OTA
// ***************************************************************************
#ifdef ENABLE_OTA
DBG_OUTPUT_PORT.println("Arduino OTA activated.");

// Port defaults to 8266
ArduinoOTA.setPort(8266);

// Hostname defaults to esp8266-[ChipID]
ArduinoOTA.setHostname(HOSTNAME);

// No authentication by default
 ArduinoOTA.setPassword("admin");

// Password can be set with it's md5 value as well
// MD5(admin) = 21232f297a57a5a743894a0e4a801fc3
//  ArduinoOTA.setPasswordHash("0638737163");

ArduinoOTA.onStart([]() {
  DBG_OUTPUT_PORT.println("Arduino OTA: Start updating");
});
ArduinoOTA.onEnd([]() {
  DBG_OUTPUT_PORT.println("Arduino OTA: End");
});
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
  DBG_OUTPUT_PORT.printf("Arduino OTA Progress: %u%%\r", (progress / (total / 100)));
});
ArduinoOTA.onError([](ota_error_t error) {
  DBG_OUTPUT_PORT.printf("Arduino OTA Error[%u]: ", error);
  if (error == OTA_AUTH_ERROR) DBG_OUTPUT_PORT.println("Arduino OTA: Auth Failed");
  else if (error == OTA_BEGIN_ERROR) DBG_OUTPUT_PORT.println("Arduino OTA: Begin Failed");
  else if (error == OTA_CONNECT_ERROR) DBG_OUTPUT_PORT.println("Arduino OTA: Connect Failed");
  else if (error == OTA_RECEIVE_ERROR) DBG_OUTPUT_PORT.println("Arduino OTA: Receive Failed");
  else if (error == OTA_END_ERROR) DBG_OUTPUT_PORT.println("Arduino OTA: End Failed");
});

ArduinoOTA.begin();
DBG_OUTPUT_PORT.println("");

#endif

// ***************************************************************************
// Setup: MDNS responder
// ***************************************************************************
MDNS.begin(HOSTNAME);
DBG_OUTPUT_PORT.print("Open http://");
DBG_OUTPUT_PORT.print(WiFi.localIP());
DBG_OUTPUT_PORT.println("/ to open McLighting.");

DBG_OUTPUT_PORT.print("Use http://");
DBG_OUTPUT_PORT.print(HOSTNAME);
DBG_OUTPUT_PORT.println(".local/ when you have Bobjour installed.");

DBG_OUTPUT_PORT.print("New users: Open http://");
DBG_OUTPUT_PORT.print(WiFi.localIP());
DBG_OUTPUT_PORT.println("/upload to upload the webpages first.");

DBG_OUTPUT_PORT.println("");

// ***************************************************************************
// Setup: WebSocket server
// ***************************************************************************
webSocket.begin();
webSocket.onEvent(webSocketEvent);

// ***************************************************************************
// Setup: SPIFFS
// ***************************************************************************
SPIFFS.begin();
{
Dir dir = SPIFFS.openDir("/");
while (dir.next()) {
String fileName = dir.fileName();
size_t fileSize = dir.fileSize();
DBG_OUTPUT_PORT.printf("FS File: %s, size: %s\n", fileName.c_str(), formatBytes(fileSize).c_str());
}
DBG_OUTPUT_PORT.printf("\n");
}

// ***************************************************************************
// Setup: SPIFFS Webserver handler
// ***************************************************************************
//list directory
server.on("/list", HTTP_GET, handleFileList);
//load editor
server.on("/edit", HTTP_GET, {
if (!handleFileRead("/edit.htm")) server.send(404, "text/plain", "FileNotFound");
});
//create file
server.on("/edit", HTTP_PUT, handleFileCreate);
//delete file
server.on("/edit", HTTP_DELETE, handleFileDelete);
//first callback is called after the request has ended with all parsed arguments
//second callback handles file uploads at that location
server.on("/edit", HTTP_POST, {
server.send(200, "text/plain", "");
}, handleFileUpload);
//get heap status, analog input value and all GPIO statuses in one json call
server.on("/esp_status", HTTP_GET, {
String json = "{";
json += ""heap":" + String(ESP.getFreeHeap());
json += ", "analog":" + String(analogRead(A0));
json += ", "gpio":" + String((uint32_t)(((GPI | GPO) & 0xFFFF) | ((GP16I & 0x01) << 16)));
json += "}";
server.send(200, "text/json", json);
json = String();
});

//called when the url is not defined here
//use it to load content from SPIFFS
server.onNotFound( {
if (!handleFileRead(server.uri()))
handleNotFound();
});

server.on("/upload", handleMinimalUpload);

server.on("/restart", {
DBG_OUTPUT_PORT.printf("/restart:\n");
server.send(200, "text/plain", "restarting..." );
ESP.restart();
});

server.on("/reset_wlan", {
DBG_OUTPUT_PORT.printf("/reset_wlan:\n");
server.send(200, "text/plain", "Resetting WLAN and restarting..." );
WiFiManager wifiManager;
wifiManager.resetSettings();
ESP.restart();
});

// ***************************************************************************
// Setup: SPIFFS Webserver handler
// ***************************************************************************
server.on("/set_brightness", {
if (server.arg("c").toInt() > 0) {
brightness = (int) server.arg("c").toInt() * 2.55;
} else {
brightness = server.arg("p").toInt();
}
if (brightness > 255) {
brightness = 255;
}
if (brightness < 0) {
brightness = 0;
}
strip.setBrightness(brightness);

if (mode == HOLD) {
  mode = ALL;
}

getStatusJSON();

});

server.on("/get_brightness", {
String str_brightness = String((int) (brightness / 2.55));
server.send(200, "text/plain", str_brightness );
DBG_OUTPUT_PORT.print("/get_brightness: ");
DBG_OUTPUT_PORT.println(str_brightness);
});

server.on("/get_switch", {
server.send(200, "text/plain", (mode == OFF) ? "0" : "1" );
DBG_OUTPUT_PORT.printf("/get_switch: %s\n", (mode == OFF) ? "0" : "1");
});

server.on("/get_color", {
String rgbcolor = String(main_color.red, HEX) + String(main_color.green, HEX) + String(main_color.blue, HEX);
server.send(200, "text/plain", rgbcolor );
DBG_OUTPUT_PORT.print("/get_color: ");
DBG_OUTPUT_PORT.println(rgbcolor);
});

server.on("/status", {
getStatusJSON();
});

server.on("/off", {
exit_func = true;
mode = OFF;
getArgs();
getStatusJSON();
});

server.on("/all", {
exit_func = true;
mode = ALL;
getArgs();
getStatusJSON();
});

server.on("/wipe", {
exit_func = true;
mode = WIPE;
getArgs();
getStatusJSON();
});

server.on("/rainbow", {
exit_func = true;
mode = RAINBOW;

getArgs();
getStatusJSON();

});

server.on("/rainbowCycle", {
exit_func = true;
mode = RAINBOWCYCLE;
getArgs();
getStatusJSON();
});

server.on("/theaterchase", {
exit_func = true;
mode = THEATERCHASE;
getArgs();
getStatusJSON();
});

server.on("/theaterchaseRainbow", {
exit_func = true;
mode = THEATERCHASERAINBOW;
getArgs();
getStatusJSON();
});

server.on("/tv", {
exit_func = true;
mode = TV;
getArgs();
getStatusJSON();
});

server.on("/get_modes", {
getModesJSON();
});

server.on("/set_mode", {
getArgs();
mode = SET_MODE;
getStatusJSON();
});

server.begin();
}

void loop() {
server.handleClient();
webSocket.loop();
#ifdef ENABLE_OTA
ArduinoOTA.handle();
#endif

// Simple statemachine that handles the different modes
if (mode == SET_MODE) {
DBG_OUTPUT_PORT.printf("SET_MODE: %d %d\n", ws2812fx_mode, mode);
strip.setMode(ws2812fx_mode);
mode = HOLD;
}
if (mode == OFF) {
strip.setColor(0,0,0);
strip.setMode(FX_MODE_STATIC);
// mode = HOLD;
client.publish("ws2812-set/mode","b 0"); // Change this, or //, if you DON"T need this for daily websocket control
}

if (mode == ALL) {
strip.setColor(main_color.red, main_color.green, main_color.blue);
strip.setMode(FX_MODE_STATIC);
mode = HOLD;
//Change this if you DON'T use DAILY websocket control
client.publish("ws2812-set/mode","b 200"); // Brightness 200, ALL subscribed lights will be set.
delay(1500);
client.publish("ws2812-set/mode","m 0"); // MODE static, ALL subscribed lights will be set.
delay(1500);
client.publish("ws2812-set/mode","c 0xFFFF40"); // Color WarmWhite, ALL subscribed lights will be set.
}
if (mode == WIPE) {
strip.setColor(main_color.red, main_color.green, main_color.blue);
strip.setMode(FX_MODE_COLOR_WIPE);
mode = HOLD;
}
if (mode == RAINBOW) {
strip.setMode(FX_MODE_RAINBOW);
mode = HOLD;
}
if (mode == RAINBOWCYCLE) {
strip.setMode(FX_MODE_RAINBOW_CYCLE);
mode = HOLD;
}
if (mode == THEATERCHASE) {
strip.setColor(main_color.red, main_color.green, main_color.blue);
strip.setMode(FX_MODE_THEATER_CHASE);
mode = HOLD;
}
if (mode == THEATERCHASERAINBOW) {
strip.setMode(FX_MODE_THEATER_CHASE_RAINBOW);
mode = HOLD;
}
if (mode == HOLD) {
if (exit_func) {
exit_func = false;
}
}
if (mode == TV) {
tv();
}

if (mode != TV) {
strip.service();
}
if (WiFi.status() == WL_CONNECTED) {
if (!client.connected()) {
Serial.println("Connecting to MQTT server");
if (client.connect(MQTT::Connect("ws2812fx-160")
.set_auth("leon", "1122"))) { // Change this to yours, or remove when not needed
Serial.println("Connected to MQTT server");
client.set_callback(callback);
client.publish("ws2812-set/state/ws2812-160","160 MC-Lighting Online");
client.subscribe("ws2812-set/mode");
} else {
Serial.println("MQTT error connecting");
}
}

if (client.connected())
  client.loop();

}
}
/*
Usage:

m : select mode , "m 8" runs Rainbow (without " " ;-)

b+ : increase brightness
b- : decrease brightness
b : set brightness to , "b 255" sets max brightness (without " " ;-)

s+ : increase speed
s- : decrease speed
s : set speed to , "s 255" sets max speed (without " " ;-)

c 0x007BFF : set color to 0x007BFF, "c 0xFFFFFF" sets color to white (without " " ;-)

Have a nice day.

0 Static
1 Blink
2 Breath
3 Color Wipe
4 Color Wipe Random
5 Random Color
6 Single Dynamic
7 Multi Dynamic
8 Rainbow
9 Rainbow Cycle
10 Scan
11 Dual Scan
12 Fade
13 Theater Chase
14 Theater Chase Rainbow
15 Running Lights
16 Twinkle
17 Twinkle Random
18 Twinkle Fade
19 Twinkle Fade Random
20 Sparkle
21 Flash Sparkle
22 Hyper Sparkle
23 Strobe
24 Strobe Rainbow
25 Multi Strobe
26 Blink Rainbow
27 Chase White
28 Chase Color
29 Chase Random
30 Chase Rainbow
31 Chase Flash
32 Chase Flash Random
33 Chase Rainbow White
34 Chase Blackout
35 Chase Blackout Rainbow
36 Color Sweep Random
37 Running Color
38 Running Red Blue
39 Running Random
40 Larson Scanner
41 Comet
42 Fireworks
43 Fireworks Random
44 Merry Christmas
45 Fire Flicker
46 Fire Flicker (soft)

*/

Just a flicker on WS set single pixel command

I am not able to control single pixels with commands like !01FF00FF, although I do see a brief flicker. I have tried different modes although I would expect static to be the correct way to do this. Can anyone else verify that this isn't just me?

Memory leak in MQTT callback function

uint8_t * payload = (uint8_t *)malloc(length + 1);

The use of "malloc" without "free"ing up the result causes a memory leak - free heap space drops steadily with each received mqqt message, eventually resulting in heap overflow and chip reset. Suggest avoiding the use of malloc entirely. Just use "payload_in" instead of defining and copying the contents.

File Not Found

I am trying to get this working, but...
When I visit the webaddress the only thing I see is

File Not Found

URI: /
Method: GET
Arguments: 0

What am I missing?

Homebridge always 75%

I set, for example, 10% to my lightstrip w2812 and go to other app. Then I open home app again it shows 75%. Can I fix it or it is problem with HAP or homebridge?

Add called command in Websocket response?

First off, thank you for a WS2812 controller with an dedicated API!

It would be nice to have the issued command in the response of the websocket message. Something like #ok or color:ok.

Right now it kind of difficult to distinguish between an answer to a command or if you just polled for the current status. Or did I miss something?

Cheers,
Patrik

void configModeCallback (WiFiManager *myWiFiManager) {

Hi, n1 Idea.
But I cant Test it,

McLighting:117: error: variable or field 'configModeCallback' declared void

void configModeCallback (WiFiManager *myWiFiManager) {

                     ^

McLighting:117: error: 'WiFiManager' was not declared in this scope

McLighting:117: error: 'myWiFiManager' was not declared in this scope

My Hardwares

MCU 1.2
Nano with esp
Wemos1 R2

IDE Testet all from 1.8.1 - 1.8.5

Lib all the Newest

McLighting Artnet Branch

Hello, i just realized that there's a ArtNet Branch of your good work! It is working but i got a problem when switching back from ArtNet to another Preset.

This Problem does not occur when i first close the ArtNet Connection and then switch the preset.

Does anyone have this problem, too? Do i first have to end the ArtNet Session before switching the presets?

Forgot to mention what happens: when i forgot closing the artnet connection and then switch to another preset the esp8266 crashes and does not respond to pings and commands, when i reboot it everything is fine ok.

by the way, is there any way to get the other presets to work on startup? I want to choose between the ws2812fx effects, is that possible?

MCLighting in "accesspoint"

Hello,
I have a small question, is it possible to use MCLighting without going through the wifi of my network? (In access point)
If so, how?
thank you in advance.

And congratulations for your code and thank you for sharing.

Homebridge/Home Assistant Switch & get_switch parameter

HI Tobias,

Thanks for all your work! Great update.

I am having a small issue with the http:///get_switch. Basically it always returns a 1, whether the LEDs are on or off. Is this because the /off command just changes the colour to RGB 0 0 0 ?

I have tried turning the brightness to 0, RGB to 0 and mode to 0 and the return is still 1. The issue here is that I have added it to home bridge and the status always shows on. I also use Home Assistant and have added a command line switch, again the status is always on so I have had to remove the status line.Below is a snippet from my Homebridge code:

            {
                    "accessory": "HTTP-RGB",
                    "name": "strip",

                    "switch": {
                            "status": "http://IP/get_switch",
                            "powerOn": "http://IP/all?r=255&g=255&b=255",
                            "powerOff": "http://IP/off"
                    },

                    "brightness": {
                            "status": "http://IP/get_brightness",
                            "url": "http://IP/set_brightness?p=%s"
                    },

                    "color": {
                            "status": "http://IP/get_color",
                            "url": "http://IP/all?rgb=%s",
                            "brightness": true
                    }
            }

Here is my command line switch in Home Assistant:

- platform: command_line
    switches:
    light_strip:
      command_on: "/usr/bin/curl -X GET http://IP/all?r=255&g=255&b=255"
      command_off: "/usr/bin/curl -X GET http://IP/off"
      command_state: "/usr/bin/curl -X GET http://IP/get_switch"
      value_template: '{{ return_value == 1 }}'

Do you have any ideas on how I can report the status?

Thanks.

Enhancement Request: MQTT Control

Hello,

Thank you for this project, I have been trying to reliably control a NeoPixel with an ESP8266 and you made it very easy. Ultimately I would like to control this light via my home automation platform Home Assistant. MQTT control of the lights would make this integration very easy.

Thoughts?

MQTT Intopic always blank?

Hi,

I am getting this when it tried to connect to my MQTT server?

Attempting MQTT connection 1 / 4 ...
MQTT connected!
MQTT topic in:
MQTT topic out: 4MLED/out

it repeats this 4 times and ends with:

MQTT connection failed, giving up after 4 tries ...

I am using mosqiotto v3.1.1 - is anyone else experiencing this? I do not have any issues with any of my other MQTT clients.

Thanks
Mr Pasty

MQTT Setup

Hello, My esp auto connects to my wifi so an ap is never established to input my mqtt info. Is there a way to configure my mqtt host and port info in the ino files?

Instructions please.

Hi are there any tutorials on how to get this working? I did use this a few months ago but ive forgoten how to set it up,i remember trying last time and i think i had to use an older version as it was mutch easyer to set up,didnt have to coppy files to spiff.thanks

ESP not reachable after connecting to WIFI

Hi Tobi,

First of all, awesome project! Thanks a lot for sharing :)

Unfortunately, I cannot reach the ESP after it connected to the WIFI. The first start was flawless and I got redirected to the WIFI config page where I entered my SSID & PW.

*WM: AutoConnect
*WM: Connecting as wifi client...
*WM: Using last saved values, should be faster
*WM: Connection result:
*WM: 3
*WM: IP Address:
*WM: 192.168.2.126
connected...yeey :)
Open http://ESP8266_01.local/edit to see the file browser

After the ESP successfully connected to my WIFI network but from thereon is not reachable at all.
I can see it on my router as a connected device but can't reach the ESP8266_01.local page nor get even a ping back...
Any idea what might be the issue? I'm guessing it must be sth with the webserver but really don't know where or how to look :-/

Many thanks!
Alex

Boot error

Hi
I have been testing this project for a couple of days now but I cant get it working.
I got error message as soon I boot it up.
No problem to upload sketch but can´t run it.

The error is: ets Jan 8 2013,rst cause:2, boot mode:(2,7) "Even 2,6 and 3,0 sometimes"
I know that this normally i coursed by bad powersupply. But I can run every other sketch i try but not this one.
Arduino IDE 1.6.13 and 1.6.9
WifiManager 0.11.0 and 0.12.0
ESP8266 2.3.0

Thanks.

my setup doesn't work properly, static blinks

Hello! And thanks for listening me and i hope i did everything correctly.
I've managed to work it all, but i have this issue especially visible in static mode: the leds are lighting up like in "color wipe random" mode or similar, but they don't go static.
I have three 5m ws2812b connected to the same power supply and the data wire comes from the nodemcu, then it's connected in series from the first to the third strip.
The "scan" mode work properly i think.

Thanks in advice and sorry for my english, i'll try my best!

Does this work with a ESP8266-01?

I got the Software up and running on my ESP8266-01 but i don't know which pin to use as data pin for the ws2812 strip. I set PIN 1 in the config.

Couple of observations and a request

Firstly thanks! I'm planning halloween and christmas lights early! and wanted to have a nice setup.
I've got two rolls of WS2812 lights and have been testing compared to the standard controller.

I much prefer some of the light patterns from your collection but also I like that I can use the mobile device to set things up,
Its actually got me thinking about upgrading several existing light strings (currently WW only) and getting a super effect for the room. I digress!

Observations:
When I have static colour I notice a flicker. The flicker is random and when the light is dim. Also on a couple of sequences I noticed a random (as in not correct) sequence occuring occasionally. I am assuming this is a problem with noise on the data signal as opposed to the software, but wanted to flag it in case you are aware of a problem.

More worryingly, I occasionally have the lights turn on into a random pattern. During testing, I had the lights 'off' and within an hour they randomly turned on in some sequence. Not the odd few lights, it was actually running a sequence which I then had to connect back onto the web page to turn off.

Request:
Some controllers you can purchase have the ability to save a number of the sequences to create your custom show. ( see DIY settings in led2013-x )
Would be good to have this capability.

The other thing I would like to do is create a customer profile which I dont mind doing at compile time.
Basically rather than having the whole string static, I want to define the areas to turn on. This is because the string will run along the front of the house on the soffit board (roof line) and I want the light to shine down to the sides of the window and light the shutters not the windows or wall.
A simple string of ones and zeros representing each pixel would be easy to create. This could then be added to the list of profiles and you control colour and brightness as per normal.

Thanks

SK6812 compatibility

Would you add compatibility for SK6812 LED String to control the second LED (Warmwhite, Coldwhite)? At least the 4th bit is controlling the second LED.

Is this a mistake?

Hi Tobias,

I like v2. Thank you for this project.
I added homebridge. I use it via http without any problems.
But I have a problem via homebridge. I select color.
When I want to adjust the brightness, it flashing at every level (once).
and the current color is light color. not dimmed, the color is light color.
via http brightness setting decreases the light.
you can see the serial print output below.
I want to reduce the light via homebridge.
also will it be mqtt support?

img_0999

web page not found

Hi. I upload the code to esp8266 but when I open esp8266 IP with browser get error

File Not Found

URI: /
Method: GET
Arguments: 0

please help for fix this problem

Code

You used a niopixal circle i also want to use it. But you addred a code for niopixal strip of 60 led
where i have to change the code to use niopoxal circle which have only 12 led

HTTP REST API /set_switch

Thanks for the great Tutorial!

Is it possible that you add some more options to HTTP Rest API? I am using OpenHAB 2 and could run just the /set_brightness of the API.

Therefore /set_switch would be interesting to switch on and off. Its possible to bring the brightness to 0 but this is not possible by buttons.

handleSetSingleLED fails for certain values of LED

While working on a feature to enable ranges of LED's via MQTT, I found some weirdness with LED values over 79 passed to handleSetSingleLED() via MQTT.

At first I thought it was my code, so tried the same via existing +79ffffff and +80ffffff style notation (also via MQTT) and got the same error.

Details below.

A. Fails, my range code, calls handleSetSingleLED().

MQTT: Message arrived [R0199ff0000]
MQTT: Set RANGE of LEDS to single color: [R0199ff0000]
Setting RANGE from [1] to [99] as color [ff0000] 
WS: Set single led [1] to [255] [0] [0] (1ff0000)!
WS: Set single led [2] to [255] [0] [0] (2ff0000)!
.. removed for easy reading ..
WS: Set single led [45] to [255] [0] [0] (45ff0000)!
WS: Set single led [46] to [255] [0] [0] (46ff0000)!
WS: Set single led [47] to [255] [0] [0] (47ff0000)!
.. removed for easy reading ..
WS: Set single led [78] to [255] [0] [0] (78ff0000)!
WS: Set single led [79] to [255] [0] [0] (79ff0000)!
WS: Set single led [80] to [255] [255] [255] (80ff0000)!
WS: Set single led [81] to [255] [255] [255] (81ff0000)!
WS: Set single led [82] to [255] [255] [255] (82ff0000)!
WS: Set single led [83] to [255] [255] [255] (83ff0000)!
WS: Set single led [84] to [255] [255] [255] (84ff0000)!
WS: Set single led [85] to [255] [255] [255] (85ff0000)!
WS: Set single led [86] to [255] [255] [255] (86ff0000)!
WS: Set single led [87] to [255] [255] [255] (87ff0000)!
WS: Set single led [88] to [255] [255] [255] (88ff0000)!
WS: Set single led [89] to [255] [255] [255] (89ff0000)!
WS: Set single led [90] to [255] [255] [255] (90ff0000)!
WS: Set single led [91] to [255] [255] [255] (91ff0000)!
WS: Set single led [92] to [255] [255] [255] (92ff0000)!
WS: Set single led [93] to [255] [255] [255] (93ff0000)!
WS: Set single led [94] to [255] [255] [255] (94ff0000)!
WS: Set single led [95] to [255] [255] [255] (95ff0000)!
WS: Set single led [96] to [255] [255] [255] (96ff0000)!
WS: Set single led [97] to [255] [255] [255] (97ff0000)!
WS: Set single led [98] to [255] [255] [255] (98ff0000)!

As you can see, LED's after 80 ignore the RGB value provided in payload to the handleSetSingleLED() function.

B. Fails, Direct MQTT calls to handleSetSingleLED().

MQTT: Message arrived [!79ff0000]
WS: Set single led [79] to [255] [0] [0] (!79ff0000)!
MQTT: Set single LED in given color [!79ff0000]
MQTT: Message arrived [!80ff0000]
WS: Set single led [80] to [255] [255] [255] (!80ff0000)!
MQTT: Set single LED in given color [!80ff0000]

Also, I think potentially there's a memory corruption/leak going on somewhere (maybe a different problem); when exercising the handleSetSingleLED() function repeatedly for a number of LED's and values, some LED's get 'stuck' on a random color.

Setting those LED's to white FFFFFF seems to work, but other commands fail (ie, still sometimes 'stuck', just now white.)

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.