├── .gitignore
├── Commands.h
├── GradientPalettes.h
├── Inits.h
├── LICENSE
├── PatternLogics.h
├── README.md
├── Settings.h
├── esp8266-fastled-mqtt.ino
└── webapp.png
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
--------------------------------------------------------------------------------
/Commands.h:
--------------------------------------------------------------------------------
1 | /*
2 | * ESP8266 + FastLED + IR Remote + MSGEQ7: https://github.com/jasoncoon/esp8266-fastled-webserver
3 | * Copyright (C) 2015 Jason Coon
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | enum class InputCommand {
20 | None,
21 | Up,
22 | Down,
23 | Left,
24 | Right,
25 | Select,
26 | Brightness,
27 | PlayMode,
28 | Palette,
29 | Power,
30 | BrightnessUp,
31 | BrightnessDown,
32 |
33 | Pattern1,
34 | Pattern2,
35 | Pattern3,
36 | Pattern4,
37 | Pattern5,
38 | Pattern6,
39 | Pattern7,
40 | Pattern8,
41 | Pattern9,
42 | Pattern10,
43 | Pattern11,
44 | Pattern12,
45 |
46 | RedUp,
47 | RedDown,
48 | GreenUp,
49 | GreenDown,
50 | BlueUp,
51 | BlueDown,
52 |
53 | Red,
54 | RedOrange,
55 | Orange,
56 | YellowOrange,
57 | Yellow,
58 |
59 | Green,
60 | Lime,
61 | Aqua,
62 | Teal,
63 | Navy,
64 |
65 | Blue,
66 | RoyalBlue,
67 | Purple,
68 | Indigo,
69 | Magenta,
70 |
71 | White,
72 | Pink,
73 | LightPink,
74 | BabyBlue,
75 | LightBlue,
76 | };
77 |
78 | // IR Raw Key Codes for SparkFun remote
79 | #define IRCODE_SPARKFUN_POWER 0x10EFD827 // 284153895
80 | #define IRCODE_SPARKFUN_A 0x10EFF807 //
81 | #define IRCODE_SPARKFUN_B 0x10EF7887
82 | #define IRCODE_SPARKFUN_C 0x10EF58A7
83 | #define IRCODE_SPARKFUN_UP 0x10EFA05F // 284139615
84 | #define IRCODE_SPARKFUN_LEFT 0x10EF10EF
85 | #define IRCODE_SPARKFUN_SELECT 0x10EF20DF
86 | #define IRCODE_SPARKFUN_RIGHT 0x10EF807F
87 | #define IRCODE_SPARKFUN_DOWN 0x10EF00FF
88 | #define IRCODE_SPARKFUN_HELD 0xFFFFFFFF
89 |
90 | // IR Raw Key Codes for Adafruit remote
91 | #define IRCODE_ADAFRUIT_HELD 0x7FFFFFFF // 4294967295
92 | #define IRCODE_ADAFRUIT_VOLUME_UP 0x00FD40BF // 16597183
93 | #define IRCODE_ADAFRUIT_PLAY_PAUSE 0x00FD807F // 16613503
94 | #define IRCODE_ADAFRUIT_VOLUME_DOWN 0x00FD00FF // 16580863
95 | #define IRCODE_ADAFRUIT_SETUP 0x00FD20DF // 16589023
96 | #define IRCODE_ADAFRUIT_UP 0x00FDA05F // 16621663
97 | #define IRCODE_ADAFRUIT_STOP_MODE 0x00FD609F // 16605343
98 | #define IRCODE_ADAFRUIT_LEFT 0x00FD10EF // 16584943
99 | #define IRCODE_ADAFRUIT_ENTER_SAVE 0x00FD906F // 16617583
100 | #define IRCODE_ADAFRUIT_RIGHT 0x00FD50AF // 16601263
101 | #define IRCODE_ADAFRUIT_0_10_PLUS 0x00FD30CF // 16593103
102 | #define IRCODE_ADAFRUIT_DOWN 0x00FDB04F // 16625743
103 | #define IRCODE_ADAFRUIT_BACK 0x00FD708F // 16609423
104 | #define IRCODE_ADAFRUIT_1 0x00FD08F7 // 16582903
105 | #define IRCODE_ADAFRUIT_2 0x00FD8877 // 16615543
106 | #define IRCODE_ADAFRUIT_3 0x00FD48B7 // 16599223
107 | #define IRCODE_ADAFRUIT_4 0x00FD28D7 // 16591063
108 | #define IRCODE_ADAFRUIT_5 0x00FDA857 // 16623703
109 | #define IRCODE_ADAFRUIT_6 0x00FD6897 // 16607383
110 | #define IRCODE_ADAFRUIT_7 0x00FD18E7 // 16586983
111 | #define IRCODE_ADAFRUIT_8 0x00FD9867 // 16619623
112 | #define IRCODE_ADAFRUIT_9 0x00FD58A7 // 16603303
113 |
114 | // IR Raw Key Codes for eTopxizu 44Key IR Remote Controller for 5050 3528 RGB LED Light Strip
115 | #define IRCODE_ETOPXIZU_HELD 0x7FFFFFFF // 4294967295
116 | #define IRCODE_ETOPXIZU_POWER 16712445
117 | #define IRCODE_ETOPXIZU_PLAY_PAUSE 16745085
118 | #define IRCODE_ETOPXIZU_BRIGHTNESS_UP 16726725
119 | #define IRCODE_ETOPXIZU_BRIGHTNESS_DOWN 16759365
120 |
121 | #define IRCODE_ETOPXIZU_DIY1 16724175
122 | #define IRCODE_ETOPXIZU_DIY2 16756815
123 | #define IRCODE_ETOPXIZU_DIY3 16740495
124 | #define IRCODE_ETOPXIZU_DIY4 16716015
125 | #define IRCODE_ETOPXIZU_DIY5 16748655
126 | #define IRCODE_ETOPXIZU_DIY6 16732335
127 |
128 | #define IRCODE_ETOPXIZU_JUMP3 16720095
129 | #define IRCODE_ETOPXIZU_JUMP7 16752735
130 | #define IRCODE_ETOPXIZU_FADE3 16736415
131 | #define IRCODE_ETOPXIZU_FADE7 16769055
132 | #define IRCODE_ETOPXIZU_FLASH 16764975
133 | #define IRCODE_ETOPXIZU_AUTO 16773135
134 |
135 | #define IRCODE_ETOPXIZU_QUICK 16771095
136 | #define IRCODE_ETOPXIZU_SLOW 16762935
137 |
138 | #define IRCODE_ETOPXIZU_RED_UP 16722135
139 | #define IRCODE_ETOPXIZU_RED_DOWN 16713975
140 |
141 | #define IRCODE_ETOPXIZU_GREEN_UP 16754775
142 | #define IRCODE_ETOPXIZU_GREEN_DOWN 16746615
143 |
144 | #define IRCODE_ETOPXIZU_BLUE_UP 16738455
145 | #define IRCODE_ETOPXIZU_BLUE_DOWN 16730295
146 |
147 | #define IRCODE_ETOPXIZU_RED 16718565
148 | #define IRCODE_ETOPXIZU_RED_ORANGE 16722645
149 | #define IRCODE_ETOPXIZU_ORANGE 16714485
150 | #define IRCODE_ETOPXIZU_YELLOW_ORANGE 16726215
151 | #define IRCODE_ETOPXIZU_YELLOW 16718055
152 |
153 | #define IRCODE_ETOPXIZU_GREEN 16751205
154 | #define IRCODE_ETOPXIZU_LIME 16755285
155 | #define IRCODE_ETOPXIZU_AQUA 16747125
156 | #define IRCODE_ETOPXIZU_TEAL 16758855
157 | #define IRCODE_ETOPXIZU_NAVY 16750695
158 |
159 | #define IRCODE_ETOPXIZU_BLUE 16753245
160 | #define IRCODE_ETOPXIZU_ROYAL_BLUE 16749165
161 | #define IRCODE_ETOPXIZU_PURPLE 16757325
162 | #define IRCODE_ETOPXIZU_INDIGO 16742535
163 | #define IRCODE_ETOPXIZU_MAGENTA 16734375
164 |
165 | #define IRCODE_ETOPXIZU_WHITE 16720605
166 | #define IRCODE_ETOPXIZU_PINK 16716525
167 | #define IRCODE_ETOPXIZU_LIGHT_PINK 16724685
168 | #define IRCODE_ETOPXIZU_BABY_BLUE 16775175
169 | #define IRCODE_ETOPXIZU_LIGHT_BLUE 16767015
170 |
171 | bool sparkfunRemoteEnabled = true;
172 | bool adafruitRemoteEnabled = true;
173 | bool etopxizuRemoteEnabled = true;
174 |
175 | // Low level IR code reading function
176 | // Function will return 0 if no IR code available
177 | unsigned long decodeIRCode() {
178 |
179 | decode_results results;
180 |
181 | results.value = 0;
182 |
183 | // Attempt to read an IR code ?
184 | if (irReceiver.decode(&results)) {
185 | delay(20);
186 |
187 | if (results.value != 0)
188 | Serial.println(results.value);
189 |
190 | // Prepare to receive the next IR code
191 | irReceiver.resume();
192 | }
193 |
194 | return results.value;
195 | }
196 |
197 | // Read an IR code
198 | // Function will return 0 if no IR code available
199 | unsigned long readIRCode() {
200 |
201 | // Is there an IR code to read ?
202 | unsigned long code = decodeIRCode();
203 | if (code == 0) {
204 | // No code so return 0
205 | return 0;
206 | }
207 |
208 | // Keep reading until code changes
209 | while (decodeIRCode() == code) {
210 | ;
211 | }
212 | // Serial.println(code);
213 | return code;
214 | }
215 |
216 | unsigned long lastIrCode = 0;
217 |
218 | unsigned int holdStartTime = 0;
219 | unsigned int defaultHoldDelay = 500;
220 | bool isHolding = false;
221 |
222 | unsigned int zeroStartTime = 0;
223 | unsigned int zeroDelay = 120;
224 |
225 | unsigned long readIRCode(unsigned int holdDelay) {
226 | // read the raw code from the sensor
227 | unsigned long irCode = readIRCode();
228 |
229 | //Serial.print(millis());
230 | //Serial.print("\t");
231 | //Serial.println(irCode);
232 |
233 | // don't return a short click until we know it's not a long hold
234 | // we'll have to wait for holdDelay ms to pass before returning a non-zero IR code
235 | // then, after that delay, as long as the button is held, we can keep returning the code
236 | // every time until it's released
237 |
238 | // the ir remote only sends codes every 107 ms or so (avg 106.875, max 111, min 102),
239 | // so the ir sensor will return 0 even if a button is held
240 | // so we have to wait longer than that before returning a non-zero code
241 | // in order to detect that a button has been released and is no longer held
242 |
243 | // only reset after we've gotten 0 back for more than the ir remote send interval
244 | unsigned int zeroTime = 0;
245 |
246 | if (irCode == 0) {
247 | zeroTime = millis() - zeroStartTime;
248 | if (zeroTime >= zeroDelay && lastIrCode != 0) {
249 | //Serial.println(F("zero delay has elapsed, returning last ir code"));
250 | // the button has been released for longer than the zero delay
251 | // start over delays over and return the last code
252 | irCode = lastIrCode;
253 | lastIrCode = 0;
254 | return irCode;
255 | }
256 |
257 | return 0;
258 | }
259 |
260 | // reset the zero timer every time a non-zero code is read
261 | zeroStartTime = millis();
262 |
263 | unsigned int heldTime = 0;
264 |
265 | if (irCode == IRCODE_SPARKFUN_HELD || irCode == IRCODE_ADAFRUIT_HELD) {
266 | // has the hold delay passed?
267 | heldTime = millis() - holdStartTime;
268 | if (heldTime >= holdDelay) {
269 | isHolding = true;
270 | //Serial.println(F("hold delay has elapsed, returning last ir code"));
271 | return lastIrCode;
272 | }
273 | else if (holdStartTime == 0) {
274 | isHolding = false;
275 | holdStartTime = millis();
276 | }
277 | }
278 | else {
279 | // not zero, not IRCODE_SPARKFUN_HELD
280 | // store it for use later, until the hold and zero delays have elapsed
281 | holdStartTime = millis();
282 | isHolding = false;
283 | lastIrCode = irCode;
284 | return 0;
285 | }
286 |
287 | return 0;
288 | }
289 |
290 | void heldButtonHasBeenHandled() {
291 | lastIrCode = 0;
292 | isHolding = false;
293 | holdStartTime = 0;
294 | }
295 |
296 | unsigned long waitForIRCode() {
297 |
298 | unsigned long irCode = readIRCode();
299 | while ((irCode == 0) || (irCode == 0xFFFFFFFF)) {
300 | delay(200);
301 | irCode = readIRCode();
302 | }
303 | return irCode;
304 | }
305 |
306 | InputCommand getCommand(unsigned long input) {
307 | if (adafruitRemoteEnabled) {
308 | switch (input) {
309 | case IRCODE_ADAFRUIT_UP:
310 | return InputCommand::Up;
311 |
312 | case IRCODE_ADAFRUIT_DOWN:
313 | return InputCommand::Down;
314 |
315 | case IRCODE_ADAFRUIT_LEFT:
316 | return InputCommand::Left;
317 |
318 | case IRCODE_ADAFRUIT_RIGHT:
319 | return InputCommand::Right;
320 |
321 | case IRCODE_ADAFRUIT_ENTER_SAVE:
322 | return InputCommand::Select;
323 |
324 | case IRCODE_ADAFRUIT_STOP_MODE:
325 | case IRCODE_ADAFRUIT_1:
326 | return InputCommand::PlayMode;
327 |
328 | case IRCODE_ADAFRUIT_2:
329 | return InputCommand::Palette;
330 |
331 | case IRCODE_ADAFRUIT_PLAY_PAUSE:
332 | return InputCommand::Power;
333 |
334 | case IRCODE_ADAFRUIT_VOLUME_UP:
335 | return InputCommand::BrightnessUp;
336 |
337 | case IRCODE_ADAFRUIT_VOLUME_DOWN:
338 | return InputCommand::BrightnessDown;
339 | }
340 | }
341 |
342 | if (sparkfunRemoteEnabled) {
343 | switch (input) {
344 | case IRCODE_SPARKFUN_UP:
345 | return InputCommand::Up;
346 |
347 | case IRCODE_SPARKFUN_DOWN:
348 | return InputCommand::Down;
349 |
350 | case IRCODE_SPARKFUN_LEFT:
351 | return InputCommand::Left;
352 |
353 | case IRCODE_SPARKFUN_RIGHT:
354 | return InputCommand::Right;
355 |
356 | case IRCODE_SPARKFUN_SELECT:
357 | return InputCommand::Select;
358 |
359 | case IRCODE_SPARKFUN_POWER:
360 | return InputCommand::Brightness;
361 |
362 | case IRCODE_SPARKFUN_A:
363 | return InputCommand::PlayMode;
364 |
365 | case IRCODE_SPARKFUN_B:
366 | return InputCommand::Palette;
367 | }
368 | }
369 |
370 | if (etopxizuRemoteEnabled) {
371 | switch (input) {
372 | case IRCODE_ETOPXIZU_QUICK:
373 | return InputCommand::Up;
374 |
375 | case IRCODE_ETOPXIZU_SLOW:
376 | return InputCommand::Down;
377 |
378 | case IRCODE_ETOPXIZU_PLAY_PAUSE:
379 | return InputCommand::PlayMode;
380 |
381 | case IRCODE_ETOPXIZU_POWER:
382 | return InputCommand::Power;
383 |
384 | case IRCODE_ETOPXIZU_BRIGHTNESS_UP:
385 | return InputCommand::BrightnessUp;
386 | case IRCODE_ETOPXIZU_BRIGHTNESS_DOWN:
387 | return InputCommand::BrightnessDown;
388 |
389 | case IRCODE_ETOPXIZU_DIY1:
390 | return InputCommand::Pattern1;
391 | case IRCODE_ETOPXIZU_DIY2:
392 | return InputCommand::Pattern2;
393 | case IRCODE_ETOPXIZU_DIY3:
394 | return InputCommand::Pattern3;
395 | case IRCODE_ETOPXIZU_DIY4:
396 | return InputCommand::Pattern4;
397 | case IRCODE_ETOPXIZU_DIY5:
398 | return InputCommand::Pattern5;
399 | case IRCODE_ETOPXIZU_DIY6:
400 | return InputCommand::Pattern6;
401 | case IRCODE_ETOPXIZU_JUMP3:
402 | return InputCommand::Pattern7;
403 | case IRCODE_ETOPXIZU_JUMP7:
404 | return InputCommand::Pattern8;
405 | case IRCODE_ETOPXIZU_FADE3:
406 | return InputCommand::Pattern9;
407 | case IRCODE_ETOPXIZU_FADE7:
408 | return InputCommand::Pattern10;
409 | case IRCODE_ETOPXIZU_FLASH:
410 | return InputCommand::Pattern11;
411 | case IRCODE_ETOPXIZU_AUTO:
412 | return InputCommand::Pattern12;
413 |
414 | case IRCODE_ETOPXIZU_RED_UP:
415 | return InputCommand::RedUp;
416 | case IRCODE_ETOPXIZU_RED_DOWN:
417 | return InputCommand::RedDown;
418 |
419 | case IRCODE_ETOPXIZU_GREEN_UP:
420 | return InputCommand::GreenUp;
421 | case IRCODE_ETOPXIZU_GREEN_DOWN:
422 | return InputCommand::GreenDown;
423 |
424 | case IRCODE_ETOPXIZU_BLUE_UP:
425 | return InputCommand::BlueUp;
426 | case IRCODE_ETOPXIZU_BLUE_DOWN:
427 | return InputCommand::BlueDown;
428 |
429 | case IRCODE_ETOPXIZU_RED:
430 | return InputCommand::Red;
431 | case IRCODE_ETOPXIZU_RED_ORANGE:
432 | return InputCommand::RedOrange;
433 | case IRCODE_ETOPXIZU_ORANGE:
434 | return InputCommand::Orange;
435 | case IRCODE_ETOPXIZU_YELLOW_ORANGE:
436 | return InputCommand::YellowOrange;
437 | case IRCODE_ETOPXIZU_YELLOW:
438 | return InputCommand::Yellow;
439 |
440 | case IRCODE_ETOPXIZU_GREEN:
441 | return InputCommand::Green;
442 | case IRCODE_ETOPXIZU_LIME:
443 | return InputCommand::Lime;
444 | case IRCODE_ETOPXIZU_AQUA:
445 | return InputCommand::Aqua;
446 | case IRCODE_ETOPXIZU_TEAL:
447 | return InputCommand::Teal;
448 | case IRCODE_ETOPXIZU_NAVY:
449 | return InputCommand::Navy;
450 |
451 | case IRCODE_ETOPXIZU_BLUE:
452 | return InputCommand::Blue;
453 | case IRCODE_ETOPXIZU_ROYAL_BLUE:
454 | return InputCommand::RoyalBlue;
455 | case IRCODE_ETOPXIZU_PURPLE:
456 | return InputCommand::Purple;
457 | case IRCODE_ETOPXIZU_INDIGO:
458 | return InputCommand::Indigo;
459 | case IRCODE_ETOPXIZU_MAGENTA:
460 | return InputCommand::Magenta;
461 |
462 | case IRCODE_ETOPXIZU_WHITE:
463 | return InputCommand::White;
464 | case IRCODE_ETOPXIZU_PINK:
465 | return InputCommand::Pink;
466 | case IRCODE_ETOPXIZU_LIGHT_PINK:
467 | return InputCommand::LightPink;
468 | case IRCODE_ETOPXIZU_BABY_BLUE:
469 | return InputCommand::BabyBlue;
470 | case IRCODE_ETOPXIZU_LIGHT_BLUE:
471 | return InputCommand::LightBlue;
472 | }
473 | }
474 |
475 | return InputCommand::None;
476 | }
477 |
478 | InputCommand readCommand() {
479 | return getCommand(readIRCode());
480 | }
481 |
482 | InputCommand readCommand(unsigned int holdDelay) {
483 | return getCommand(readIRCode(holdDelay));
484 | }
485 |
--------------------------------------------------------------------------------
/GradientPalettes.h:
--------------------------------------------------------------------------------
1 | // From ColorWavesWithPalettes by Mark Kriegsman: https://gist.github.com/kriegsman/8281905786e8b2632aeb
2 |
3 | // Gradient Color Palette definitions for 33 different cpt-city color palettes.
4 | // 956 bytes of PROGMEM for all of the palettes together,
5 | // +618 bytes of PROGMEM for gradient palette code (AVR).
6 | // 1,494 bytes total for all 34 color palettes and associated code.
7 |
8 | // Gradient palette "ib_jul01_gp", originally from
9 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/ing/xmas/tn/ib_jul01.png.index.html
10 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
11 | // Size: 16 bytes of program space.
12 |
13 | DEFINE_GRADIENT_PALETTE( ib_jul01_gp ) {
14 | 0, 194, 1, 1,
15 | 94, 1, 29, 18,
16 | 132, 57, 131, 28,
17 | 255, 113, 1, 1
18 | };
19 |
20 | // Gradient palette "es_vintage_57_gp", originally from
21 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/es/vintage/tn/es_vintage_57.png.index.html
22 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
23 | // Size: 20 bytes of program space.
24 |
25 | DEFINE_GRADIENT_PALETTE( es_vintage_57_gp ) {
26 | 0, 2, 1, 1,
27 | 53, 18, 1, 0,
28 | 104, 69, 29, 1,
29 | 153, 167, 135, 10,
30 | 255, 46, 56, 4
31 | };
32 |
33 | // Gradient palette "es_vintage_01_gp", originally from
34 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/es/vintage/tn/es_vintage_01.png.index.html
35 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
36 | // Size: 32 bytes of program space.
37 |
38 | DEFINE_GRADIENT_PALETTE( es_vintage_01_gp ) {
39 | 0, 4, 1, 1,
40 | 51, 16, 0, 1,
41 | 76, 97, 104, 3,
42 | 101, 255, 131, 19,
43 | 127, 67, 9, 4,
44 | 153, 16, 0, 1,
45 | 229, 4, 1, 1,
46 | 255, 4, 1, 1
47 | };
48 |
49 | // Gradient palette "es_rivendell_15_gp", originally from
50 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/es/rivendell/tn/es_rivendell_15.png.index.html
51 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
52 | // Size: 20 bytes of program space.
53 |
54 | DEFINE_GRADIENT_PALETTE( es_rivendell_15_gp ) {
55 | 0, 1, 14, 5,
56 | 101, 16, 36, 14,
57 | 165, 56, 68, 30,
58 | 242, 150, 156, 99,
59 | 255, 150, 156, 99
60 | };
61 |
62 | // Gradient palette "rgi_15_gp", originally from
63 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/ds/rgi/tn/rgi_15.png.index.html
64 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
65 | // Size: 36 bytes of program space.
66 |
67 | DEFINE_GRADIENT_PALETTE( rgi_15_gp ) {
68 | 0, 4, 1, 31,
69 | 31, 55, 1, 16,
70 | 63, 197, 3, 7,
71 | 95, 59, 2, 17,
72 | 127, 6, 2, 34,
73 | 159, 39, 6, 33,
74 | 191, 112, 13, 32,
75 | 223, 56, 9, 35,
76 | 255, 22, 6, 38
77 | };
78 |
79 | // Gradient palette "retro2_16_gp", originally from
80 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/ma/retro2/tn/retro2_16.png.index.html
81 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
82 | // Size: 8 bytes of program space.
83 |
84 | DEFINE_GRADIENT_PALETTE( retro2_16_gp ) {
85 | 0, 188, 135, 1,
86 | 255, 46, 7, 1
87 | };
88 |
89 | // Gradient palette "Analogous_1_gp", originally from
90 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/nd/red/tn/Analogous_1.png.index.html
91 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
92 | // Size: 20 bytes of program space.
93 |
94 | DEFINE_GRADIENT_PALETTE( Analogous_1_gp ) {
95 | 0, 3, 0, 255,
96 | 63, 23, 0, 255,
97 | 127, 67, 0, 255,
98 | 191, 142, 0, 45,
99 | 255, 255, 0, 0
100 | };
101 |
102 | // Gradient palette "es_pinksplash_08_gp", originally from
103 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/es/pink_splash/tn/es_pinksplash_08.png.index.html
104 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
105 | // Size: 20 bytes of program space.
106 |
107 | DEFINE_GRADIENT_PALETTE( es_pinksplash_08_gp ) {
108 | 0, 126, 11, 255,
109 | 127, 197, 1, 22,
110 | 175, 210, 157, 172,
111 | 221, 157, 3, 112,
112 | 255, 157, 3, 112
113 | };
114 |
115 | // Gradient palette "es_pinksplash_07_gp", originally from
116 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/es/pink_splash/tn/es_pinksplash_07.png.index.html
117 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
118 | // Size: 28 bytes of program space.
119 |
120 | DEFINE_GRADIENT_PALETTE( es_pinksplash_07_gp ) {
121 | 0, 229, 1, 1,
122 | 61, 242, 4, 63,
123 | 101, 255, 12, 255,
124 | 127, 249, 81, 252,
125 | 153, 255, 11, 235,
126 | 193, 244, 5, 68,
127 | 255, 232, 1, 5
128 | };
129 |
130 | // Gradient palette "Coral_reef_gp", originally from
131 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/nd/other/tn/Coral_reef.png.index.html
132 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
133 | // Size: 24 bytes of program space.
134 |
135 | DEFINE_GRADIENT_PALETTE( Coral_reef_gp ) {
136 | 0, 40, 199, 197,
137 | 50, 10, 152, 155,
138 | 96, 1, 111, 120,
139 | 96, 43, 127, 162,
140 | 139, 10, 73, 111,
141 | 255, 1, 34, 71
142 | };
143 |
144 | // Gradient palette "es_ocean_breeze_068_gp", originally from
145 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/es/ocean_breeze/tn/es_ocean_breeze_068.png.index.html
146 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
147 | // Size: 24 bytes of program space.
148 |
149 | DEFINE_GRADIENT_PALETTE( es_ocean_breeze_068_gp ) {
150 | 0, 100, 156, 153,
151 | 51, 1, 99, 137,
152 | 101, 1, 68, 84,
153 | 104, 35, 142, 168,
154 | 178, 0, 63, 117,
155 | 255, 1, 10, 10
156 | };
157 |
158 | // Gradient palette "es_ocean_breeze_036_gp", originally from
159 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/es/ocean_breeze/tn/es_ocean_breeze_036.png.index.html
160 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
161 | // Size: 16 bytes of program space.
162 |
163 | DEFINE_GRADIENT_PALETTE( es_ocean_breeze_036_gp ) {
164 | 0, 1, 6, 7,
165 | 89, 1, 99, 111,
166 | 153, 144, 209, 255,
167 | 255, 0, 73, 82
168 | };
169 |
170 | // Gradient palette "departure_gp", originally from
171 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/mjf/tn/departure.png.index.html
172 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
173 | // Size: 88 bytes of program space.
174 |
175 | DEFINE_GRADIENT_PALETTE( departure_gp ) {
176 | 0, 8, 3, 0,
177 | 42, 23, 7, 0,
178 | 63, 75, 38, 6,
179 | 84, 169, 99, 38,
180 | 106, 213, 169, 119,
181 | 116, 255, 255, 255,
182 | 138, 135, 255, 138,
183 | 148, 22, 255, 24,
184 | 170, 0, 255, 0,
185 | 191, 0, 136, 0,
186 | 212, 0, 55, 0,
187 | 255, 0, 55, 0
188 | };
189 |
190 | // Gradient palette "es_landscape_64_gp", originally from
191 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/es/landscape/tn/es_landscape_64.png.index.html
192 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
193 | // Size: 36 bytes of program space.
194 |
195 | DEFINE_GRADIENT_PALETTE( es_landscape_64_gp ) {
196 | 0, 0, 0, 0,
197 | 37, 2, 25, 1,
198 | 76, 15, 115, 5,
199 | 127, 79, 213, 1,
200 | 128, 126, 211, 47,
201 | 130, 188, 209, 247,
202 | 153, 144, 182, 205,
203 | 204, 59, 117, 250,
204 | 255, 1, 37, 192
205 | };
206 |
207 | // Gradient palette "es_landscape_33_gp", originally from
208 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/es/landscape/tn/es_landscape_33.png.index.html
209 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
210 | // Size: 24 bytes of program space.
211 |
212 | DEFINE_GRADIENT_PALETTE( es_landscape_33_gp ) {
213 | 0, 1, 5, 0,
214 | 19, 32, 23, 1,
215 | 38, 161, 55, 1,
216 | 63, 229, 144, 1,
217 | 66, 39, 142, 74,
218 | 255, 1, 4, 1
219 | };
220 |
221 | // Gradient palette "rainbowsherbet_gp", originally from
222 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/ma/icecream/tn/rainbowsherbet.png.index.html
223 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
224 | // Size: 28 bytes of program space.
225 |
226 | DEFINE_GRADIENT_PALETTE( rainbowsherbet_gp ) {
227 | 0, 255, 33, 4,
228 | 43, 255, 68, 25,
229 | 86, 255, 7, 25,
230 | 127, 255, 82, 103,
231 | 170, 255, 255, 242,
232 | 209, 42, 255, 22,
233 | 255, 87, 255, 65
234 | };
235 |
236 | // Gradient palette "gr65_hult_gp", originally from
237 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/hult/tn/gr65_hult.png.index.html
238 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
239 | // Size: 24 bytes of program space.
240 |
241 | DEFINE_GRADIENT_PALETTE( gr65_hult_gp ) {
242 | 0, 247, 176, 247,
243 | 48, 255, 136, 255,
244 | 89, 220, 29, 226,
245 | 160, 7, 82, 178,
246 | 216, 1, 124, 109,
247 | 255, 1, 124, 109
248 | };
249 |
250 | // Gradient palette "gr64_hult_gp", originally from
251 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/hult/tn/gr64_hult.png.index.html
252 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
253 | // Size: 32 bytes of program space.
254 |
255 | DEFINE_GRADIENT_PALETTE( gr64_hult_gp ) {
256 | 0, 1, 124, 109,
257 | 66, 1, 93, 79,
258 | 104, 52, 65, 1,
259 | 130, 115, 127, 1,
260 | 150, 52, 65, 1,
261 | 201, 1, 86, 72,
262 | 239, 0, 55, 45,
263 | 255, 0, 55, 45
264 | };
265 |
266 | // Gradient palette "GMT_drywet_gp", originally from
267 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/gmt/tn/GMT_drywet.png.index.html
268 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
269 | // Size: 28 bytes of program space.
270 |
271 | DEFINE_GRADIENT_PALETTE( GMT_drywet_gp ) {
272 | 0, 47, 30, 2,
273 | 42, 213, 147, 24,
274 | 84, 103, 219, 52,
275 | 127, 3, 219, 207,
276 | 170, 1, 48, 214,
277 | 212, 1, 1, 111,
278 | 255, 1, 7, 33
279 | };
280 |
281 | // Gradient palette "ib15_gp", originally from
282 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/ing/general/tn/ib15.png.index.html
283 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
284 | // Size: 24 bytes of program space.
285 |
286 | DEFINE_GRADIENT_PALETTE( ib15_gp ) {
287 | 0, 113, 91, 147,
288 | 72, 157, 88, 78,
289 | 89, 208, 85, 33,
290 | 107, 255, 29, 11,
291 | 141, 137, 31, 39,
292 | 255, 59, 33, 89
293 | };
294 |
295 | // Gradient palette "Fuschia_7_gp", originally from
296 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/ds/fuschia/tn/Fuschia-7.png.index.html
297 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
298 | // Size: 20 bytes of program space.
299 |
300 | DEFINE_GRADIENT_PALETTE( Fuschia_7_gp ) {
301 | 0, 43, 3, 153,
302 | 63, 100, 4, 103,
303 | 127, 188, 5, 66,
304 | 191, 161, 11, 115,
305 | 255, 135, 20, 182
306 | };
307 |
308 | // Gradient palette "es_emerald_dragon_08_gp", originally from
309 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/es/emerald_dragon/tn/es_emerald_dragon_08.png.index.html
310 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
311 | // Size: 16 bytes of program space.
312 |
313 | DEFINE_GRADIENT_PALETTE( es_emerald_dragon_08_gp ) {
314 | 0, 97, 255, 1,
315 | 101, 47, 133, 1,
316 | 178, 13, 43, 1,
317 | 255, 2, 10, 1
318 | };
319 |
320 | // Gradient palette "lava_gp", originally from
321 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/neota/elem/tn/lava.png.index.html
322 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
323 | // Size: 52 bytes of program space.
324 |
325 | DEFINE_GRADIENT_PALETTE( lava_gp ) {
326 | 0, 0, 0, 0,
327 | 46, 18, 0, 0,
328 | 96, 113, 0, 0,
329 | 108, 142, 3, 1,
330 | 119, 175, 17, 1,
331 | 146, 213, 44, 2,
332 | 174, 255, 82, 4,
333 | 188, 255, 115, 4,
334 | 202, 255, 156, 4,
335 | 218, 255, 203, 4,
336 | 234, 255, 255, 4,
337 | 244, 255, 255, 71,
338 | 255, 255, 255, 255
339 | };
340 |
341 | // Gradient palette "fire_gp", originally from
342 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/neota/elem/tn/fire.png.index.html
343 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
344 | // Size: 28 bytes of program space.
345 |
346 | DEFINE_GRADIENT_PALETTE( fire_gp ) {
347 | 0, 1, 1, 0,
348 | 76, 32, 5, 0,
349 | 146, 192, 24, 0,
350 | 197, 220, 105, 5,
351 | 240, 252, 255, 31,
352 | 250, 252, 255, 111,
353 | 255, 255, 255, 255
354 | };
355 |
356 | // Gradient palette "Colorfull_gp", originally from
357 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/nd/atmospheric/tn/Colorfull.png.index.html
358 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
359 | // Size: 44 bytes of program space.
360 |
361 | DEFINE_GRADIENT_PALETTE( Colorfull_gp ) {
362 | 0, 10, 85, 5,
363 | 25, 29, 109, 18,
364 | 60, 59, 138, 42,
365 | 93, 83, 99, 52,
366 | 106, 110, 66, 64,
367 | 109, 123, 49, 65,
368 | 113, 139, 35, 66,
369 | 116, 192, 117, 98,
370 | 124, 255, 255, 137,
371 | 168, 100, 180, 155,
372 | 255, 22, 121, 174
373 | };
374 |
375 | // Gradient palette "Magenta_Evening_gp", originally from
376 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/nd/atmospheric/tn/Magenta_Evening.png.index.html
377 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
378 | // Size: 28 bytes of program space.
379 |
380 | DEFINE_GRADIENT_PALETTE( Magenta_Evening_gp ) {
381 | 0, 71, 27, 39,
382 | 31, 130, 11, 51,
383 | 63, 213, 2, 64,
384 | 70, 232, 1, 66,
385 | 76, 252, 1, 69,
386 | 108, 123, 2, 51,
387 | 255, 46, 9, 35
388 | };
389 |
390 | // Gradient palette "Pink_Purple_gp", originally from
391 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/nd/atmospheric/tn/Pink_Purple.png.index.html
392 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
393 | // Size: 44 bytes of program space.
394 |
395 | DEFINE_GRADIENT_PALETTE( Pink_Purple_gp ) {
396 | 0, 19, 2, 39,
397 | 25, 26, 4, 45,
398 | 51, 33, 6, 52,
399 | 76, 68, 62, 125,
400 | 102, 118, 187, 240,
401 | 109, 163, 215, 247,
402 | 114, 217, 244, 255,
403 | 122, 159, 149, 221,
404 | 149, 113, 78, 188,
405 | 183, 128, 57, 155,
406 | 255, 146, 40, 123
407 | };
408 |
409 | // Gradient palette "Sunset_Real_gp", originally from
410 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/nd/atmospheric/tn/Sunset_Real.png.index.html
411 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
412 | // Size: 28 bytes of program space.
413 |
414 | DEFINE_GRADIENT_PALETTE( Sunset_Real_gp ) {
415 | 0, 120, 0, 0,
416 | 22, 179, 22, 0,
417 | 51, 255, 104, 0,
418 | 85, 167, 22, 18,
419 | 135, 100, 0, 103,
420 | 198, 16, 0, 130,
421 | 255, 0, 0, 160
422 | };
423 |
424 | // Gradient palette "es_autumn_19_gp", originally from
425 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/es/autumn/tn/es_autumn_19.png.index.html
426 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
427 | // Size: 52 bytes of program space.
428 |
429 | DEFINE_GRADIENT_PALETTE( es_autumn_19_gp ) {
430 | 0, 26, 1, 1,
431 | 51, 67, 4, 1,
432 | 84, 118, 14, 1,
433 | 104, 137, 152, 52,
434 | 112, 113, 65, 1,
435 | 122, 133, 149, 59,
436 | 124, 137, 152, 52,
437 | 135, 113, 65, 1,
438 | 142, 139, 154, 46,
439 | 163, 113, 13, 1,
440 | 204, 55, 3, 1,
441 | 249, 17, 1, 1,
442 | 255, 17, 1, 1
443 | };
444 |
445 | // Gradient palette "BlacK_Blue_Magenta_White_gp", originally from
446 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/nd/basic/tn/BlacK_Blue_Magenta_White.png.index.html
447 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
448 | // Size: 28 bytes of program space.
449 |
450 | DEFINE_GRADIENT_PALETTE( BlacK_Blue_Magenta_White_gp ) {
451 | 0, 0, 0, 0,
452 | 42, 0, 0, 45,
453 | 84, 0, 0, 255,
454 | 127, 42, 0, 255,
455 | 170, 255, 0, 255,
456 | 212, 255, 55, 255,
457 | 255, 255, 255, 255
458 | };
459 |
460 | // Gradient palette "BlacK_Magenta_Red_gp", originally from
461 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/nd/basic/tn/BlacK_Magenta_Red.png.index.html
462 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
463 | // Size: 20 bytes of program space.
464 |
465 | DEFINE_GRADIENT_PALETTE( BlacK_Magenta_Red_gp ) {
466 | 0, 0, 0, 0,
467 | 63, 42, 0, 45,
468 | 127, 255, 0, 255,
469 | 191, 255, 0, 45,
470 | 255, 255, 0, 0
471 | };
472 |
473 | // Gradient palette "BlacK_Red_Magenta_Yellow_gp", originally from
474 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/nd/basic/tn/BlacK_Red_Magenta_Yellow.png.index.html
475 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
476 | // Size: 28 bytes of program space.
477 |
478 | DEFINE_GRADIENT_PALETTE( BlacK_Red_Magenta_Yellow_gp ) {
479 | 0, 0, 0, 0,
480 | 42, 42, 0, 0,
481 | 84, 255, 0, 0,
482 | 127, 255, 0, 45,
483 | 170, 255, 0, 255,
484 | 212, 255, 55, 45,
485 | 255, 255, 255, 0
486 | };
487 |
488 | // Gradient palette "Blue_Cyan_Yellow_gp", originally from
489 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/nd/basic/tn/Blue_Cyan_Yellow.png.index.html
490 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
491 | // Size: 20 bytes of program space.
492 |
493 | DEFINE_GRADIENT_PALETTE( Blue_Cyan_Yellow_gp ) {
494 | 0, 0, 0, 255,
495 | 63, 0, 55, 255,
496 | 127, 0, 255, 255,
497 | 191, 42, 255, 45,
498 | 255, 255, 255, 0
499 | };
500 |
501 | // Gradient palette "fire", originally from
502 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/neota/elem/tn/fire.png.index.html
503 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
504 | // Size: 28 bytes of program space.
505 | DEFINE_GRADIENT_PALETTE( gp_fire ) {
506 | 0, 1, 1, 0,
507 | 20, 32, 5, 0,
508 | 60, 192, 24, 0,
509 | 100, 220,105, 5,
510 | 240, 252,255, 31,
511 | 250, 252,255,111,
512 | 255, 255,255,255};
513 |
514 |
515 |
516 | // Single array of defined cpt-city color palettes.
517 | // This will let us programmatically choose one based on
518 | // a number, rather than having to activate each explicitly
519 | // by name every time.
520 | // Since it is const, this array could also be moved
521 | // into PROGMEM to save SRAM, but for simplicity of illustration
522 | // we'll keep it in a regular SRAM array.
523 | //
524 | // This list of color palettes acts as a "playlist"; you can
525 | // add or delete, or re-arrange as you wish.
526 | const TProgmemRGBGradientPalettePtr gGradientPalettes[] = {
527 | Sunset_Real_gp,
528 | es_rivendell_15_gp,
529 | es_ocean_breeze_036_gp,
530 | rgi_15_gp,
531 | retro2_16_gp,
532 | Analogous_1_gp,
533 | es_pinksplash_08_gp,
534 | Coral_reef_gp,
535 | es_ocean_breeze_068_gp,
536 | es_pinksplash_07_gp,
537 | es_vintage_01_gp,
538 | departure_gp,
539 | es_landscape_64_gp,
540 | es_landscape_33_gp,
541 | rainbowsherbet_gp,
542 | gr65_hult_gp,
543 | gr64_hult_gp,
544 | GMT_drywet_gp,
545 | ib_jul01_gp,
546 | es_vintage_57_gp,
547 | ib15_gp,
548 | Fuschia_7_gp,
549 | es_emerald_dragon_08_gp,
550 | lava_gp,
551 | fire_gp,
552 | Colorfull_gp,
553 | Magenta_Evening_gp,
554 | Pink_Purple_gp,
555 | es_autumn_19_gp,
556 | BlacK_Blue_Magenta_White_gp,
557 | BlacK_Magenta_Red_gp,
558 | BlacK_Red_Magenta_Yellow_gp,
559 | Blue_Cyan_Yellow_gp,
560 | gp_fire
561 | };
562 |
563 |
564 | // Count of how many cpt-city gradients are defined:
565 | const uint8_t gGradientPaletteCount =
566 | sizeof( gGradientPalettes) / sizeof( TProgmemRGBGradientPalettePtr );
567 |
568 |
--------------------------------------------------------------------------------
/Inits.h:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | void initFastLED(void) {
5 | FastLED.addLeds(leds, NUM_LEDS);// for WS2812 (Neopixel)
6 | //FastLED.addLeds(leds, NUM_LEDS); // for APA102 (Dotstar)
7 | FastLED.setCorrection(TypicalLEDStrip);
8 | FastLED.setBrightness(brightness);
9 | FastLED.setMaxPowerInVoltsAndMilliamps(5, MILLI_AMPS);
10 | //TODO on 160Hz the LED's are full white! Why?
11 | if(power == 1 && currentPatternIndex == patternCount - 1) {
12 | fill_solid(leds, NUM_LEDS, solidColor);
13 | }else {
14 | fill_solid(leds, NUM_LEDS, CRGB::Black);
15 | }
16 |
17 | FastLED.show();
18 | }
19 |
20 | void loadSettings()
21 | {
22 | brightness = EEPROM.read(0);
23 |
24 | currentPatternIndex = EEPROM.read(1);
25 | if (currentPatternIndex < 0)
26 | currentPatternIndex = 0;
27 | else if (currentPatternIndex >= patternCount)
28 | currentPatternIndex = patternCount - 1;
29 |
30 | byte r = EEPROM.read(2);
31 | byte g = EEPROM.read(3);
32 | byte b = EEPROM.read(4);
33 |
34 | if (r == 0 && g == 0 && b == 0)
35 | {
36 | }
37 | else
38 | {
39 | solidColor = CRGB(r, g, b);
40 | }
41 | power = EEPROM.read(5);
42 | }
43 |
44 | void logSys() {
45 | Serial.println();
46 | Serial.print( F("Heap: ") ); Serial.println(system_get_free_heap_size());
47 | Serial.print( F("Boot Vers: ") ); Serial.println(system_get_boot_version());
48 | Serial.print( F("CPU: ") ); Serial.println(system_get_cpu_freq());
49 | Serial.print( F("SDK: ") ); Serial.println(system_get_sdk_version());
50 | Serial.print( F("Chip ID: ") ); Serial.println(system_get_chip_id());
51 | Serial.print( F("Flash ID: ") ); Serial.println(spi_flash_get_id());
52 | Serial.print( F("Flash Size: ") ); Serial.println(ESP.getFlashChipRealSize());
53 | Serial.print( F("Vcc: ") ); Serial.println(ESP.getVcc());
54 | Serial.println();
55 | }
56 |
57 |
58 | void initWlan() {
59 | if (apMode)
60 | {
61 | WiFi.mode(WIFI_AP);
62 |
63 | // Do a little work to get a unique-ish name. Append the
64 | // last two bytes of the MAC (HEX'd) to "Thing-":
65 | uint8_t mac[WL_MAC_ADDR_LENGTH];
66 | WiFi.softAPmacAddress(mac);
67 | String macID = String(mac[WL_MAC_ADDR_LENGTH - 2], HEX) +
68 | String(mac[WL_MAC_ADDR_LENGTH - 1], HEX);
69 | macID.toUpperCase();
70 | String AP_NameString = "ESP8266 Two " + macID;
71 |
72 | char AP_NameChar[AP_NameString.length() + 1];
73 | memset(AP_NameChar, 0, AP_NameString.length() + 1);
74 |
75 | for (int i = 0; i < AP_NameString.length(); i++)
76 | AP_NameChar[i] = AP_NameString.charAt(i);
77 |
78 | WiFi.softAP(AP_NameChar, WiFiAPPSK);
79 |
80 | Serial.printf("Connect to Wi-Fi access point: %s\n", AP_NameChar);
81 | }
82 | else
83 | {
84 | WiFi.mode(WIFI_STA);
85 | Serial.printf("Connecting to %s\n", ssid);
86 | if (String(WiFi.SSID()) != String(ssid)) {
87 | WiFi.begin(ssid, password);
88 | }
89 |
90 | while (WiFi.status() != WL_CONNECTED) {
91 | delay(500);
92 | Serial.print(".");
93 | }
94 |
95 | Serial.print("Connected! With IP ");
96 | Serial.print(WiFi.localIP());
97 | Serial.println(" have FUN :) ");
98 | }
99 | }
100 |
101 | // Only to test if SSL cert is matching if u have connection problems ...
102 | void verifytls() {
103 | // Use WiFiClientSecure class to create TLS connection
104 | Serial.print(" verifytls ... connecting to ");
105 | Serial.println(mqtt_server);
106 | if (!espClient.connect(mqtt_server, 8883)) {
107 | Serial.println("connection failed");
108 | return;
109 | }
110 |
111 | Serial.println(" checking fingerprint ... ");
112 | if (espClient.verify(fingerprint, mqtt_server)) {
113 | Serial.println("certificate matches");
114 | } else {
115 | Serial.println("certificate doesn't match");
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 | {one line to give the program's name and a brief idea of what it does.}
635 | Copyright (C) {year} {name of author}
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | {project} Copyright (C) {year} {fullname}
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/PatternLogics.h:
--------------------------------------------------------------------------------
1 |
2 | void showSolidColor()
3 | {
4 | fill_solid(leds, NUM_LEDS, solidColor);
5 | }
6 |
7 | void rainbow()
8 | {
9 | // FastLED's built-in rainbow generator
10 | fill_rainbow( leds, NUM_LEDS, gHue, 10);
11 | }
12 |
13 | void addGlitter( fract8 chanceOfGlitter)
14 | {
15 | if ( random8() < chanceOfGlitter) {
16 | leds[ random16(NUM_LEDS) ] += CRGB::White;
17 | }
18 | }
19 |
20 | void rainbowWithGlitter()
21 | {
22 | // built-in FastLED rainbow, plus some random sparkly glitter
23 | rainbow();
24 | addGlitter(80);
25 | }
26 |
27 |
28 |
29 | void confetti()
30 | {
31 | // random colored speckles that blink in and fade smoothly
32 | fadeToBlackBy( leds, NUM_LEDS, 10);
33 | int pos = random16(NUM_LEDS);
34 | leds[pos] += CHSV( gHue + random8(64), 200, 255);
35 | }
36 |
37 | void sinelon()
38 | {
39 | // a colored dot sweeping back and forth, with fading trails
40 | fadeToBlackBy( leds, NUM_LEDS, 20);
41 | int pos = beatsin16(13, 0, NUM_LEDS - 1);
42 | leds[pos] += CHSV( gHue, 255, 192);
43 | }
44 |
45 | void bpm()
46 | {
47 | // colored stripes pulsing at a defined Beats-Per-Minute (BPM)
48 | uint8_t BeatsPerMinute = 62;
49 | CRGBPalette16 palette = PartyColors_p;
50 | uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
51 | for ( int i = 0; i < NUM_LEDS; i++) { //9948
52 | leds[i] = ColorFromPalette(palette, gHue + (i * 2), beat - gHue + (i * 10));
53 | }
54 | }
55 |
56 | void juggle()
57 | {
58 | // eight colored dots, weaving in and out of sync with each other
59 | fadeToBlackBy( leds, NUM_LEDS, 20);
60 | byte dothue = 0;
61 | for ( int i = 0; i < 8; i++)
62 | {
63 | leds[beatsin16(i + 7, 0, NUM_LEDS)] |= CHSV(dothue, 200, 255);
64 | dothue += 32;
65 | }
66 | }
67 |
68 | // Pride2015 by Mark Kriegsman: https://gist.github.com/kriegsman/964de772d64c502760e5
69 | // This function draws rainbows with an ever-changing,
70 | // widely-varying set of parameters.
71 | void pride() {
72 | static uint16_t sPseudotime = 0;
73 | static uint16_t sLastMillis = 0;
74 | static uint16_t sHue16 = 0;
75 |
76 | uint8_t sat8 = beatsin88( 87, 220, 250);
77 | uint8_t brightdepth = beatsin88( 341, 96, 224);
78 | uint16_t brightnessthetainc16 = beatsin88( 203, (25 * 256), (40 * 256));
79 | uint8_t msmultiplier = beatsin88(147, 23, 60);
80 |
81 | uint16_t hue16 = sHue16;//gHue * 256;
82 | uint16_t hueinc16 = beatsin88(113, 1, 3000);
83 |
84 | uint16_t ms = millis();
85 | uint16_t deltams = ms - sLastMillis ;
86 | sLastMillis = ms;
87 | sPseudotime += deltams * msmultiplier;
88 | sHue16 += deltams * beatsin88( 400, 5, 9);
89 | uint16_t brightnesstheta16 = sPseudotime;
90 |
91 | for ( uint16_t i = 0 ; i < NUM_LEDS; i++) {
92 | hue16 += hueinc16;
93 | uint8_t hue8 = hue16 / 256;
94 |
95 | brightnesstheta16 += brightnessthetainc16;
96 | uint16_t b16 = sin16( brightnesstheta16 ) + 32768;
97 |
98 | uint16_t bri16 = (uint32_t)((uint32_t)b16 * (uint32_t)b16) / 65536;
99 | uint8_t bri8 = (uint32_t)(((uint32_t)bri16) * brightdepth) / 65536;
100 | bri8 += (255 - brightdepth);
101 |
102 | CRGB newcolor = CHSV( hue8, sat8, bri8);
103 |
104 | nblend(leds[i], newcolor, 64);
105 | }
106 | }
107 |
108 |
109 | // ColorWavesWithPalettes by Mark Kriegsman: https://gist.github.com/kriegsman/8281905786e8b2632aeb
110 | // This function draws color waves with an ever-changing,
111 | // widely-varying set of parameters, using a color palette.
112 | void colorwaves()
113 | {
114 | static uint16_t sPseudotime = 0;
115 | static uint16_t sLastMillis = 0;
116 | static uint16_t sHue16 = 0;
117 |
118 | // uint8_t sat8 = beatsin88( 87, 220, 250);
119 | uint8_t brightdepth = beatsin88( 341, 96, 224);
120 | uint16_t brightnessthetainc16 = beatsin88( 203, (25 * 256), (40 * 256));
121 | uint8_t msmultiplier = beatsin88(147, 23, 60);
122 |
123 | uint16_t hue16 = sHue16;//gHue * 256;
124 | uint16_t hueinc16 = beatsin88(113, 300, 1500);
125 |
126 | uint16_t ms = millis();
127 | uint16_t deltams = ms - sLastMillis ;
128 | sLastMillis = ms;
129 | sPseudotime += deltams * msmultiplier;
130 | sHue16 += deltams * beatsin88( 400, 5, 9);
131 | uint16_t brightnesstheta16 = sPseudotime;
132 |
133 | for ( uint16_t i = 0 ; i < NUM_LEDS; i++) {
134 | hue16 += hueinc16;
135 | uint8_t hue8 = hue16 / 256;
136 | uint16_t h16_128 = hue16 >> 7;
137 | if ( h16_128 & 0x100) {
138 | hue8 = 255 - (h16_128 >> 1);
139 | } else {
140 | hue8 = h16_128 >> 1;
141 | }
142 |
143 | brightnesstheta16 += brightnessthetainc16;
144 | uint16_t b16 = sin16( brightnesstheta16 ) + 32768;
145 |
146 | uint16_t bri16 = (uint32_t)((uint32_t)b16 * (uint32_t)b16) / 65536;
147 | uint8_t bri8 = (uint32_t)(((uint32_t)bri16) * brightdepth) / 65536;
148 | bri8 += (255 - brightdepth);
149 |
150 | uint8_t index = hue8;
151 | //index = triwave8( index);
152 | index = scale8( index, 240);
153 |
154 | CRGB newcolor = ColorFromPalette(gCurrentPalette, index, bri8);
155 |
156 | nblend(leds[i], newcolor, 128);
157 | }
158 | }
159 |
160 |
161 | // adapted from ColorWavesWithPalettes by Mark Kriegsman: https://gist.github.com/kriegsman/8281905786e8b2632aeb
162 | // This function draws color waves with an ever-changing,
163 | // widely-varying set of parameters, using a color palette.
164 | void fire()
165 | {
166 | static uint16_t sPseudotime = 0;
167 | static uint16_t sLastMillis = 0;
168 | static uint16_t sHue16 = 0;
169 |
170 | // uint8_t sat8 = beatsin88( 87, 220, 250);
171 | uint8_t brightdepth = beatsin88( 341, 96, 224);
172 | uint16_t brightnessthetainc16 = beatsin88( 203, (25 * 256), (40 * 256));
173 | uint8_t msmultiplier = beatsin88(147, 23, 60);
174 |
175 | uint16_t hue16 = sHue16;//gHue * 256;
176 | uint16_t hueinc16 = beatsin88(113, 300, 1500);
177 |
178 | uint16_t ms = millis();
179 | uint16_t deltams = ms - sLastMillis ;
180 | sLastMillis = ms;
181 | sPseudotime += deltams * msmultiplier;
182 | sHue16 += deltams * beatsin88( 400, 5, 9);
183 | uint16_t brightnesstheta16 = sPseudotime;
184 |
185 | for ( uint16_t i = 0 ; i < NUM_LEDS; i++) {
186 | if (random(0,255) > 200) {
187 | hue16 += hueinc16;
188 | uint8_t hue8 = hue16 / 256;
189 | uint16_t h16_128 = hue16 >> 7;
190 | if ( h16_128 & 0x100) {
191 | hue8 = 255 - (h16_128 >> 1);
192 | } else {
193 | hue8 = h16_128 >> 1;
194 | }
195 |
196 | brightnesstheta16 += brightnessthetainc16;
197 | uint16_t b16 = sin16( brightnesstheta16 ) + 32768;
198 |
199 | uint16_t bri16 = (uint32_t)((uint32_t)b16 * (uint32_t)b16) / 65536;
200 | uint8_t bri8 = (uint32_t)(((uint32_t)bri16) * brightdepth) / 65536;
201 | bri8 += (255 - brightdepth);
202 |
203 | uint8_t index = random(0,255);
204 | //index = triwave8( index);
205 | index = scale8( index, 240);
206 | gCurrentPalette = gp_fire;
207 | CRGB newcolor = ColorFromPalette(gCurrentPalette, index, bri8);
208 | nblend(leds[i], newcolor, 128);
209 | }
210 | }
211 | }
212 |
213 | // Alternate rendering function just scrolls the current palette
214 | // across the defined LED strip.
215 | void palettetest()
216 | {
217 | static uint8_t startindex = 0;
218 | startindex--;
219 | fill_palette( leds, NUM_LEDS, startindex, (256 / NUM_LEDS) + 1,
220 | gCurrentPalette, 255, LINEARBLEND);
221 | }
222 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | FastLED + ESP8266 + MQTT
2 | =========
3 |
4 | Control an addressable LED strip with an ESP8266 via a MQTT Broker like mosquitto.
5 | In this case you need AUTH and SSL enabled (no own cert, you need a CA trusted i.e. www.letsencrypt.org)
6 | TLS v1.2 only will maybe cause some erros.
7 | It's also possible to use your own cert, but u have to upload it to the ESP8266 and register it in the init phase.
8 | When disable SSL you have to switch the port.
9 |
10 | Hardware
11 | --------
12 |
13 | An ESP8266 development board, such as the [Adafruit HUZZAH ESP8266 Breakout]:
14 |
15 | [](https://www.adafruit.com/products/2471)
16 |
17 | Addressable LED strip, such as the [Adafruit NeoPixel Ring]:
18 |
19 | [](https://www.adafruit.com/product/1586)
20 |
21 | Features
22 | --------
23 | * Turn the NeoPixel Ring on and off
24 | * Adjust the brightness
25 | * Change the display pattern
26 | * Adjust the color
27 | * Control it via MQTT
28 | * Combinable with Amazon Alexa Skill via https://github.com/awilhelmer/alexa-mqtt-skill
29 |
30 | MQTT Message Format
31 | --------
32 |
33 | Command | Description
34 | -------------------------- | ----------------------------------------------------
35 | rgb(r,g,b) | rbg(0,0,0) for black or rbg(255,255,255) white
36 | power:x | x=0 off x=1 on
37 | ``solidcolor:r:x:g:y:b:z`` | other RGB format x, y, z are the RGB values
38 | pattern:x | 1-9 for the animation patterns
39 | brightness:x | x is the value for brightness (0-255)
40 | brightnessAdjust:x | x=0 =\> up x=1 =\> down
41 | patternAdjust:x | x=0 =\> up x=1 =\> down
42 |
43 |
44 |
45 | Installing
46 | -----------
47 | These programs are installed via the Arduino IDE which can be [downloaded here](https://www.arduino.cc/en/main/software). The ESP8266 boards will need to be added to the Arduino IDE which is achieved as follows. Click File > Preferences and copy and paste the URL "http://arduino.esp8266.com/stable/package_esp8266com_index.json" into the Additional Boards Manager URLs field. Click OK. Click Tools > Boards: ... > Boards Manager. Find and click on ESP8266 (using the Search function may expedite this). Click on Install. After installation, click on Close and then select your ESP8266 board from the Tools > Board: ... menu.
48 |
49 | Download the programs from GitHub using the green Clone or Download button from [the GitHub project main page](https://github.com/jasoncoon/esp8266-fastled-webserver) and click Download ZIP. Decompress the ZIP file in your Arduino sketch folder.
50 |
51 | MQTT
52 | -----------
53 | You need to have one MQTT broker like mosquitto https://mosquitto.org/
54 |
--------------------------------------------------------------------------------
/Settings.h:
--------------------------------------------------------------------------------
1 | const bool apMode = false;
2 |
3 | // AP mode password
4 | const char WiFiAPPSK[] = "";
5 |
6 | // Wi-Fi network to connect to (if not in AP mode)
7 | const char* ssid = "";
8 | const char* password = "";
9 |
10 |
11 | #define DATA_PIN 5 // for Huzzah: Pins w/o special function: #4,#5, #12, #13, #14; // #16 does not work :(
12 | #define LED_TYPE WS2812
13 | #define COLOR_ORDER GRB
14 | #define NUM_LEDS 150
15 |
16 | #define MILLI_AMPS 500 // IMPORTANT: set here the maxmilli-Amps of your power supply 5V 2A = 2000
17 | #define FRAMES_PER_SECOND 120 // here you can control the speed. With the Access Point / Web Server the animations run a bit slower.
18 |
19 | // MQTT Broker settings
20 | const char* mqtt_server = "";
21 | const int mqtt_port = 8883; // Change this if u don't use a SSL connection
22 | const char* mqtt_user = "";
23 | const char* mqtt_password = "";
24 | const char* mqtt_topic = "";
25 | const char* mqtt_clientid = "";
26 |
27 | // openssl x509 -fingerprint -in mqttserver.crt - Only if you must verify your certs for connection issues with MQTT
28 | const char* fingerprint = "AF FD A4 F6 3B 74 FE EE A5 71 3A 08 7F 30 F8 CF DE 8D E6 7F";
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/esp8266-fastled-mqtt.ino:
--------------------------------------------------------------------------------
1 | /*
2 | ESP8266 + FastLED + MQTT: https://github.com/jasoncoon/esp8266-fastled-webserver
3 | Copyright (C) 2015 Jason Coon
4 |
5 | This program is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | This program is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with this program. If not, see .
17 | */
18 |
19 |
20 | // TODO Flickering LED's ... https://github.com/FastLED/FastLED/issues/394 or https://github.com/FastLED/FastLED/issues/306
21 | #define FASTLED_ALLOW_INTERRUPTS 0
22 | #define FASTLED_ESP8266_RAW_PIN_ORDER
23 | //#define FASTLED_INTERRUPT_RETRY_COUNT 0
24 | #include "FastLED.h"
25 | FASTLED_USING_NAMESPACE
26 |
27 | extern "C" {
28 | #include "user_interface.h"
29 | }
30 |
31 | #include
32 | #include // Only use it with SSL on MQTT Broker
33 | #include
34 | #include
35 | #include "GradientPalettes.h"
36 | #include "Settings.h"
37 |
38 | CRGB leds[NUM_LEDS];
39 |
40 | uint8_t patternIndex = 0;
41 |
42 | const uint8_t brightnessCount = 5;
43 | uint8_t brightnessMap[brightnessCount] = { 16, 32, 64, 128, 255 };
44 | int brightnessIndex = 0;
45 | uint8_t brightness = brightnessMap[brightnessIndex];
46 |
47 | #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
48 |
49 | // ten seconds per color palette makes a good demo
50 | // 20-120 is better for deployment
51 | #define SECONDS_PER_PALETTE 10
52 |
53 | ///////////////////////////////////////////////////////////////////////
54 |
55 | // Forward declarations of an array of cpt-city gradient palettes, and
56 | // a count of how many there are. The actual color palette definitions
57 | // are at the bottom of this file.
58 | extern const TProgmemRGBGradientPalettePtr gGradientPalettes[];
59 | extern const uint8_t gGradientPaletteCount;
60 |
61 | // Current palette number from the 'playlist' of color palettes
62 | uint8_t gCurrentPaletteNumber = 0;
63 |
64 | CRGBPalette16 gCurrentPalette( CRGB::Black);
65 | CRGBPalette16 gTargetPalette( gGradientPalettes[0] );
66 |
67 | uint8_t currentPatternIndex = 0; // Index number of which pattern is current
68 | bool autoplayEnabled = false;
69 |
70 | uint8_t autoPlayDurationSeconds = 10;
71 | unsigned int autoPlayTimeout = 0;
72 |
73 | uint8_t gHue = 0; // rotating "base color" used by many of the patterns
74 |
75 | CRGB solidColor = CRGB::Black;
76 |
77 | uint8_t power = 1;
78 |
79 | // Mqtt Vars
80 | WiFiClientSecure espClient;
81 | PubSubClient client(espClient);
82 |
83 |
84 | typedef void (*Pattern)();
85 | typedef Pattern PatternList[];
86 | typedef struct {
87 | Pattern pattern;
88 | String name;
89 | } PatternAndName;
90 | typedef PatternAndName PatternAndNameList[];
91 | // List of patterns to cycle through. Each is defined as a separate function below.
92 |
93 | #include "PatternLogics.h"
94 |
95 | PatternAndNameList patterns = {
96 | { colorwaves, "Color Waves" },
97 | { palettetest, "Palette Test" },
98 | { pride, "Pride" },
99 | { rainbow, "Rainbow" },
100 | { rainbowWithGlitter, "Rainbow With Glitter" },
101 | { confetti, "Confetti" },
102 | { sinelon, "Sinelon" },
103 | { juggle, "Juggle" },
104 | { bpm, "BPM" },
105 | { fire, "Fire" },
106 | { showSolidColor, "Solid Color" },
107 | };
108 | const uint8_t patternCount = ARRAY_SIZE(patterns);
109 |
110 | #include "Inits.h"
111 |
112 |
113 | void setup(void) {
114 | Serial.begin(115200);
115 | delay(100);
116 | //Serial.setDebugOutput(true);
117 | EEPROM.begin(512);
118 | loadSettings();
119 | initFastLED();
120 |
121 | logSys();
122 |
123 | initWlan();
124 |
125 | // Only to validate certs if u have problems ...
126 | // verifytls();
127 |
128 | //Mqtt Init
129 | client.setServer(mqtt_server, mqtt_port);
130 | client.setCallback(callback);
131 | autoPlayTimeout = millis() + (autoPlayDurationSeconds * 1000);
132 | }
133 |
134 | // Format is: command:value
135 | // value has to be a number, except rgb commands
136 | void callback(char* topic, byte* payload, unsigned int length) {
137 | // handle message arrived
138 | char tmp[length + 1];
139 | strncpy(tmp, (char*)payload, length);
140 | tmp[length] = '\0';
141 | String data(tmp);
142 |
143 |
144 | Serial.printf("Received Data from Topic: %s", data.c_str());
145 | Serial.println();
146 | if ( data.length() > 0) {
147 |
148 | if (data.startsWith("rgb(")) {
149 | data.replace("rgb(","");
150 | String r = getValue(data, ',', 0);
151 | String g = getValue(data, ',', 1);
152 |
153 | String b = getValue(data, ',', 2);
154 | b.replace("hallo","");
155 | Serial.printf("Received R: %s G: %s B: %s", r.c_str(), g.c_str(), b.c_str());
156 | Serial.println();
157 |
158 | if (r.length() > 0 && g.length() > 0 && b.length() > 0) {
159 | setSolidColor(r.toInt(), g.toInt(), b.toInt());
160 | }
161 | }else {
162 | String command = getValue(data, ':', 0);
163 | String value = getValue(data, ':', 1);
164 |
165 | if (command.length() > 0) {
166 |
167 | if (command.equals("power")) {
168 | if (isValidNumber(value)) {
169 | setPower(value.toInt());
170 | }
171 | } else if (command.equals("solidcolor")) {
172 | String r = getValue(data, ':', 2);
173 | String g = getValue(data, ':', 4);
174 | String b = getValue(data, ':', 6);
175 | Serial.printf("Received R: %s G: %s B: %s", r.c_str(), g.c_str(), b.c_str());
176 | Serial.println();
177 | if (r.length() > 0 && g.length() > 0 && b.length() > 0) {
178 | setSolidColor(r.toInt(), g.toInt(), b.toInt());
179 | }
180 | } else if (command.equals("pattern")) {
181 | if (isValidNumber(value)) {
182 | setPattern(value.toInt());
183 | }
184 | } else if (command.equals("brightness")) {
185 | if (isValidNumber(value)) {
186 | setBrightness(value.toInt());
187 | }
188 | } else if (command.equals("brightnessAdjust")) {
189 | if (isValidNumber(value)) {
190 | adjustBrightness(value.toInt() == 0 ? false : true);
191 | }
192 | } else if (command.equals("patternAdjust")) {
193 | if (isValidNumber(value)) {
194 | adjustPattern(value.toInt() == 0 ? false : true);
195 | }
196 | }
197 | }
198 | }
199 |
200 |
201 | }
202 | Serial.println("Finished Topic Data ...");
203 |
204 | }
205 |
206 |
207 |
208 | void loop(void) {
209 | yield(); // Avoid crashes on ESP8266
210 | // Add entropy to random number generator; we use a lot of it.
211 | random16_add_entropy(random(65535));
212 | if (!client.connected()) {
213 | reconnectMqtt();
214 | }
215 | client.loop();
216 |
217 | if (power == 0) {
218 | fill_solid(leds, NUM_LEDS, CRGB::Black);
219 | FastLED.show();
220 | delay(15);
221 | return;
222 | }
223 |
224 | // EVERY_N_SECONDS(10) {
225 | // Serial.print( F("Heap: ") ); Serial.println(system_get_free_heap_size());
226 | // }
227 |
228 | EVERY_N_MILLISECONDS( 20 ) {
229 | gHue++; // slowly cycle the "base color" through the rainbow
230 | }
231 |
232 | // change to a new cpt-city gradient palette
233 | EVERY_N_SECONDS( SECONDS_PER_PALETTE ) {
234 | gCurrentPaletteNumber = addmod8( gCurrentPaletteNumber, 1, gGradientPaletteCount);
235 | gTargetPalette = gGradientPalettes[ gCurrentPaletteNumber ];
236 | }
237 |
238 | // slowly blend the current cpt-city gradient palette to the next
239 | EVERY_N_MILLISECONDS(40) {
240 | nblendPaletteTowardPalette( gCurrentPalette, gTargetPalette, 16);
241 | }
242 |
243 | if (autoplayEnabled && millis() > autoPlayTimeout) {
244 | adjustPattern(true);
245 | autoPlayTimeout = millis() + (autoPlayDurationSeconds * 1000);
246 | }
247 |
248 | // Call the current pattern function once, updating the 'leds' array
249 | patterns[currentPatternIndex].pattern();
250 |
251 | FastLED.show();
252 |
253 | // insert a delay to keep the framerate modest
254 | delay(1000 / FRAMES_PER_SECOND);
255 | }
256 |
257 |
258 | void reconnectMqtt() {
259 | while (!client.connected()) {
260 | Serial.println("Attempting MQTT connection...");
261 | if (client.connect(mqtt_clientid, mqtt_user, mqtt_password)) {
262 | Serial.println("connected");
263 | client.subscribe(mqtt_topic);
264 | } else {
265 | Serial.print("failed, rc=");
266 | Serial.print(client.state());
267 | Serial.println(" try again in 5 seconds");
268 | // Wait 5 seconds before retrying
269 | delay(5000);
270 | }
271 | }
272 | }
273 |
274 |
275 | void setPower(uint8_t value)
276 | {
277 | power = value == 0 ? 0 : 1;
278 | EEPROM.write(5, power);
279 | EEPROM.commit();
280 |
281 | }
282 |
283 | void setSolidColor(CRGB color)
284 | {
285 | setSolidColor(color.r, color.g, color.b);
286 | }
287 |
288 | void setSolidColor(uint8_t r, uint8_t g, uint8_t b)
289 | {
290 | solidColor = CRGB(r, g, b);
291 |
292 | EEPROM.write(2, r);
293 | EEPROM.write(3, g);
294 | EEPROM.write(4, b);
295 |
296 | setPattern(patternCount - 1);
297 | }
298 |
299 | // increase or decrease the current pattern number, and wrap around at theends
300 | void adjustPattern(bool up)
301 | {
302 | if (up)
303 | currentPatternIndex++;
304 | else
305 | currentPatternIndex--;
306 |
307 | // wrap around at the ends
308 | if (currentPatternIndex < 0)
309 | currentPatternIndex = patternCount - 1;
310 | if (currentPatternIndex >= patternCount)
311 | currentPatternIndex = 0;
312 |
313 | EEPROM.write(1, currentPatternIndex);
314 | EEPROM.commit();
315 | }
316 |
317 | void setPattern(int value)
318 | {
319 | // don't wrap around at the ends
320 | if (value < 0)
321 | value = 0;
322 | else if (value >= patternCount)
323 | value = patternCount - 1;
324 |
325 | currentPatternIndex = value;
326 |
327 | EEPROM.write(1, currentPatternIndex);
328 | EEPROM.commit();
329 | }
330 |
331 | // adjust the brightness, and wrap around at the ends
332 | void adjustBrightness(bool up)
333 | {
334 | if (up)
335 | brightnessIndex++;
336 | else
337 | brightnessIndex--;
338 |
339 | // wrap around at the ends
340 | if (brightnessIndex < 0)
341 | brightnessIndex = brightnessCount - 1;
342 | else if (brightnessIndex >= brightnessCount)
343 | brightnessIndex = 0;
344 |
345 | brightness = brightnessMap[brightnessIndex];
346 |
347 | FastLED.setBrightness(brightness);
348 |
349 | EEPROM.write(0, brightness);
350 | EEPROM.commit();
351 | }
352 |
353 | void setBrightness(int value)
354 | {
355 | // don't wrap around at the ends
356 | if (value > 255)
357 | value = 255;
358 | else if (value < 0) value = 0;
359 |
360 | brightness = value;
361 |
362 | FastLED.setBrightness(brightness);
363 |
364 | EEPROM.write(0, brightness);
365 | EEPROM.commit();
366 | }
367 |
368 | String getValue(String data, char separator, int index)
369 | {
370 | int found = 0;
371 | int strIndex[] = { 0, -1 };
372 | int maxIndex = data.length() - 1;
373 |
374 | for (int i = 0; i <= maxIndex && found <= index; i++) {
375 | if (data.charAt(i) == separator || i == maxIndex) {
376 | found++;
377 | strIndex[0] = strIndex[1] + 1;
378 | strIndex[1] = (i == maxIndex) ? i + 1 : i;
379 | }
380 | }
381 | return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
382 | }
383 |
384 |
385 | boolean isValidNumber(String str) {
386 | // TODO replace with regex check
387 | bool result = false;
388 | for (byte i = 0; i < str.length(); i++)
389 | {
390 | if (isDigit(str.charAt(i))) {
391 | result = true;
392 | } else {
393 | result = false;
394 | break;
395 | }
396 | }
397 | return result;
398 | }
399 |
--------------------------------------------------------------------------------
/webapp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awilhelmer/esp8266-fastled-mqtt/3b9ec6bdd59b4415a7de588d436118e5324fbb61/webapp.png
--------------------------------------------------------------------------------