How to build a WS2812B LED strip with ESP8266 NodeMCU?

Correct. After manually sending this string
{“state”:“ON”,“color”:{“r”:255,“g”:255,“b”:255},“brightness”:150,“effect”:“solid”,“transistion”:0} through the MQTT fx, I can use the colour picker to choose a colour and turn on/off.

Again the LED.map file is a copy from above only with the name change.

LED.map:

1={"effect":"bpm"}
2={"effect":"noise"}
3={"effect":"fire"}
4={"effect":"rainbow"}
5={"effect":"twinkle"}
6={"effect":"glitter"}
7={"effect":"solid"}
8={"effect":"sinelon"}
9={"effect":"juggle"}
10={"effect":"confetti"}
11={"effect":"dots"}
12={"effect":"lightning"}
13={"effect":"candy cane"}
14={"effect":"cyclon rainbow"}
15={"effect":"ripple"}
16={"effect":"christmas alternate"}
17={"effect":"police all"}
18={"effect":"police one"}
19={"effect":"random stars"}
20={"effect":"sine hue"}
ON={"state":"ON"}
OFF={"state":"OFF"}

I wont get a chance to send through the messages from the MQTT until later.

Ahh, I see a problem now…your “Power” item has a hard-coded ON command in the definition, which isn’t a valid JSON string. Change it to:

Switch LEDStrip_Bedstrip_Power "Bedstrip Power"  [ "Switchable" ] {mqtt=">[mqtt:main/bedstrip/set:command:*:MAP(LED.map)]"}

(the two ON/OFF states are mapped to their proper “{state}” JSON format).

Ok, I will check when I get home. I may have changed that last night trying to diagnose the workings and non workings to see if could see any trends as to why. As I copied the code from Openhab this morning before I left for work. I may not have changed it back to the LED.map entry. If that is the case, it still won’t work. Fingers crossed :crossed_fingers: Thanks for your perseverance.

If that’s the case, then the next step in troubleshooting would be to take the exact JSON string from the MAP file and post it to your MQTT.fx (publish to the set topic)…if it doesn’t work there, we may need to start looking at your arduino code next.

Have access to the MQTT and system now.
I have updated the {mqtt=">[mqtt:main/bedstrip/set:command:*:MAP(LED.map)]"} path to be correct. I did fail to change it back last night.

The following is the message is published on the MQTT topic main/bedstrip/set when I switch the power switch to ON. MAP(LED.map)
When I tap the up arrow on Bedstrip color the MQTT topic main/bedstrip/set publishes
{“color”: {“r”: 21.202913280000000000,“g”: 100,“b”: 10.45785600}}

I think the next course of action is to reflash the NodeMCU and coy verbatim your Openhab files to see if that works, then I will try to modify to suit.

Update. I deleted my previous entries and reflashed the NodeMCU and copied item,sitemap,rules and map files in their entirety into my openhab.

Below is what was returned when I switched on the led strip power and selected JSON in MQTTfx.

*** PAYLOAD IS NOT VALID JSON DATA *** 

Unexpected character ('M' (code 77)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
 at [Source: java.io.StringReader@1511ecc0; line: 1, column: 2]

The frustrating part is that I am new to the Arduino world. But I’m learning fast.

Something is going on with your map transformation if you’re outputting a MQTT message with just “Map(Led.map)” in it as a string.

As a temporary workaround, you could write discrete rules for the fix and power items (matching the color rule).

Update. Finally stopped doing back flips and cart wheels.

Found the issue that dopey me didn’t have the map transformation installed. rebooted my openhab and what do you know… it works. thank you immensely @bartus for your perseverance. It is amazing what happens what the right words a poke in the right direction can do.

1 Like

Ha! It’s always the simplest thing, isn’t it? :smiley: I’ve done just the thing plenty of times, so don’t feel bad about it! Glad you got it sorted out!

I have the SK6812 with an 8266 board. However, only like 20 or so lights come one when i load the code.

The code I use is here: https://github.com/jasoncoon/esp8266-fastled-webserver

I do get this when i load:
/home/c/Arduino/libraries/FastLED/platforms/esp/8266/clockless_esp8266.h:11:21: note: #pragma message: Using RGBW controller as per FASTLED_RGBW define

pragma message “Using RGBW controller as per FASTLED_RGBW define”

It has something to do with my data i think. it is not loading it properly. i could not get the simplest of examples to work included with the Arduino IDE.

This is arduino related not openHAB. I would suggest you try the arduino forums.

vzorglub is right.

But I guess your problem is you did not define the count of your leds.

Default seems to be 24.

1 Like

thanks. i will post else where. i changed that 24 earlier with no result. the 20 or so that do light up are in no particular order, mainly toward one end of the screen. and stay white and occasionally switch to different shades of green.

If you’re using that code as is, you need to modify the WS2811 to WS2812…WS2811 is a 4-wire LED strip so the LEDs aren’t getting what they expect signal-wise. 6812 LEDs are similar in design to the WS2812, so FastLED supports them as that LED definition.

1 Like

Hi,

I’m reading this for a longer time now and tried to implement it for a testing.

Has anyone got this problem “‘StaticJsonBuffer’ was not declared in this scope” while compiling it as well?

greetings

Hey,

maybe anyone can help me? I dont get it where my mistake is:
.sitemap

    {
	Frame label="Leinwand" {
	Switch item=Leinwand_oben
				Selection item=Leinwand_oben_FX mappings=[1="BPM",2="Noise",3="Fire",4="Rainbow",5="Twinkle",6="Glitter",7="Solid",8="Sinelon",9="Juggle",10="Confetti",11="Dots",12="Lightning",13="Candy Cane",14="Cyclon Rainbow",15="Ripple",16="Christmas Alternate",17="Police All",18="Police One",19="Random Stars",20="Sine Hue"] 
				Colorpicker item=Leinwand_oben_Color
				Setpoint item=Leinwand_oben_Speed minValue=5 maxValue=240 step=5
				Setpoint item=Leinwand_oben_Intensity minValue=0 maxValue=255 step=16

.items

        String Leinwand_oben "Leinwand" {mqtt=">[broker:home/LeinwandUp/set:state:*:default]"}
    Switch Leinwand_oben_Power "Leinwand AN/AUS" (Status){mqtt=">[broker:home/LeinwandUp/set:command:*:MAP(LEDStripEffectJSON.map)]"}
    Number Leinwand_oben_FX "Leinwand Fx" (Status){mqtt=">[broker:home/LeinwandUp/set:command:*:MAP(LEDStripEffectJSON.map)]"}
    Color Leinwand_oben_Color "Leinwand Farbe"	<rgb>	(Status)
    Number Leinwand_oben_Speed "Leinwand Speed [%.0f]"		(Status)
    Number Leinwand_oben_Intensity "Leinwand Intensity [%d]" (Status)

.rules

rule "LED Strip Leinwand JSON Color"
when Item Leinwand_oben_Color received update
then Leinwand_oben.sendCommand("{\"color\": {" +
		"\"r\": " + (Leinwand_oben_Color.state as HSBType).red + "," +
		"\"g\": " + (Leinwand_oben_Color.state as HSBType).green + "," +
		"\"b\": " + (Leinwand_oben_Color.state as HSBType).blue + "}}") end
rule "LED Strip Leinwand JSON Speed"
when Item Leinwand_oben_Speed received update
then Leinwand_oben.sendCommand("{\"transition\": \"" + Leinwand_oben_Speed.state + "\"}") end
rule "LED Strip Leinwand JSON Intensity"
when Item Leinwand_oben_Intensity received update
then Leinwand_oben.sendCommand("{\"brightness\":" + Leinwand_oben_Intensity.state + "}") end

the mosquitto log:

1550419826: New connection from 192.168.178.77 on port 1883.
1550419826: New client connected from 192.168.178.77 as LeinwandUp (c1, k15, u'openhabian').
1550419826: Sending CONNACK to LeinwandUp (0, 0)
1550419826: Received SUBSCRIBE from LeinwandUp
1550419826:     home/LeinwandUp/set (QoS 0)
1550419826: LeinwandUp 0 home/LeinwandUp/set
1550419826: Sending SUBACK to LeinwandUp
1550419826: Received SUBSCRIBE from LeinwandUp
1550419826:     home/LEDStrip_Leinwand/set (QoS 0)
1550419826: LeinwandUp 0 home/LEDStrip_Leinwand/set
1550419826: Sending SUBACK to LeinwandUp
1550419826: Received PUBLISH from LeinwandUp (d0, q0, r1, m0, 'home/LeinwandUp', ... (97 bytes))
1550419826: Sending PUBLISH to 0567bfe1478248479f256b2b020ac5d4 (d0, q0, r0, m0, 'home/LeinwandUp', ... (97 bytes))
1550419841: Received PINGREQ from LeinwandUp
1550419841: Sending PINGRESP to LeinwandUp

so far everything seems to work fine. even if I listen with mqtt.fx i can see the esp8266 but it wont recognize anything from the openhab.

this is what the mqtt.cfg looks:

pid:org.openhab.mqtt
# Define your MQTT broker connections here for use in the MQTT Binding or MQTT
# Persistence bundles. Replace <broker> with an ID you choose.
#

# URL to the MQTT broker, e.g. tcp://localhost:1883 or ssl://localhost:8883
pinguinbau.url=tcp://localhost:1883


# Optional. Client id (max 23 chars) to use when connecting to the broker.
# If not provided a random default is generated.
#broker.clientId=openhab2.0

# Optional. True or false. If set to true, allows the use of clientId values
# up to 65535 characters long. Defaults to false.
# NOTE: clientId values longer than 23 characters may not be supported by all
# MQTT servers. Check the server documentation.
#<broker>.allowLongerClientIds=false

# Optional. User id to authenticate with the broker.
pinguinbau.user=openhabian

# Optional. Password to authenticate with the broker.
pinguinbau.pwd=secret

Any suggestions where the mistake is?

Thank you a lot and a nice rest weekend:)

Hi
I’m struggling with this and hit brick wall kind of immediately. I have successfully installed Mosquitto and can create items that publish/subscribe successfully to the broker service. However, my items don’t look like this:

Instead, to get it to work with the broker, I have to write like this in my items file:

{channel="mqtt:topic:MQTTgeneric:LEDStrip_XmasLights"}

If I write like this, I can’t get anything to work on the Arduino (D1 mini). It compiles allright (although I had to downgrade the ArduinoJson to ver 5), but nothing happens with the LED. I’m not sure I’ve got the part correct either with light_state_topic etc in the Arduino code either.

I’m not a very experienced programmer, so please be kind :slight_smile:
Sorry to bump this kind of dated thread, but any help would be appreciated.

OK, after some Googling it seems the thread sample is MQTT v1 and I’m using v2… If anyone can direct me how to translate or in other way get around this (preferably not downgrading the MQTT)…

What do you have in the things file? That’s where you define channels.

I don’t have a Things file. I have two Things created through paper ui, one for the broker and one generic where the channels are. If I create basic test channels through the ui it works well with the broker both ways. Maybe I just need to find a way to translate the v1 channel syntax to v2 in the items file used with the Arduino led strip… I’m not very familiar with openHAB syntax adding map transforms etc so I’m not sure where to start. I was so happy getting the MQTT working but since then I’m stuck… I haven’t been able to successfully get the Arduino code provided working with my broker either so I’m kind of stuck…

Some progress…
I was able to get the Arduino to speak with the broker, so I can now turn on/off my strip and change patterns etc through mqtt.fx. If I set the baud rate to 115200 in the Arduino serial monitor I was able to get the json string. I never understood how that was built up before. I’m also able to successfully send commands from Openhab through rules, like the color change rule.

However, there’s a magic to the v1 MQTT item transformation that I can’t understand or get to work in v2.

Switch LEDStrip_FF_Office_Window_Power "Office Power" (Status){mqtt=">[broker:home/FF_Office_Window/set:command:*:MAP(LEDStripEffectJSON.map)]"}

The string is actually looking like this:

{"state":"OFF","color":{"r":255,"g":0,"b":0},"brightness":64,"effect":"solid","transition":0}

So, how can I just change the ON/OFF part directly through the item MAP function without going through a rule? I’ve tried the transform function in the channel setting in paper ui, but I only get this error

2019-12-13 23:23:34.936 [WARN ] [rm.AbstractFileTransformationService] - Could not transform '{"state":"OFF","color":{"r":255,"g":0,"b":0},"brightness":64,"effect":"solid","transition":0}' with the file 'LEDStripEffectJSON.map' : Target value not found in map for '{"state":"OFF","color":{"r":255,"g":0,"b":0},"brightness":64,"effect":"solid","transition":0}'
2019-12-13 23:23:34.942 [WARN ] [eneric.internal.generic.ChannelState] - Command '' not supported by type 'OnOffValue': No enum constant org.eclipse.smarthome.core.library.types.OnOffType.