-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathE131_PixelPusher.ino
534 lines (492 loc) · 26.1 KB
/
E131_PixelPusher.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
#ifdef ESP32
#include <WiFi.h>
#include <AsyncUDP.h>
#include <AsyncTCP.h> //https://github.com/me-no-dev/AsyncTCP
#include <ESPmDNS.h>
#include <Update.h>
// #include <WiFiManager.h> //https://github.com/tzapu/WiFiManager/tree/development
#elif defined(ESP8266)
#include <Hash.h>
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <ESPAsyncTCP.h> //https://github.com/me-no-dev/ESPAsyncTCP
#include <ESPAsyncUDP.h> //https://github.com/me-no-dev/ESPAsyncUDP
#if defined(ESP8266) and (defined(PIO_PLATFORM) or defined(USE_EADNS))
#include <ESPAsyncDNSServer.h> //https://github.com/devyte/ESPAsyncDNSServer
#else
#include <DNSServer.h>
#endif
#else
#error Platform not supported
#endif
#include <ESPAsyncE131.h> //https://github.com/forkineye/ESPAsyncE131
#include <ESPAsyncWebServer.h> //https://github.com/me-no-dev/ESPAsyncWebServer
#include <ESPAsyncWiFiManager.h> //https://github.com/alanswx/ESPAsyncWiFiManager
#include <EEPROM.h>
#include "version.h"
#define USE_NEOPIXELS 2 // Use any pin under 32
// #define USE_DOTSTAR //comment above line to use APA102
#ifdef USE_NEOPIXELS
#include <NeoPixelBus.h> //https://github.com/Makuna/NeoPixelBus
#elif defined(USE_DOTSTAR)
#include <Adafruit_DotStar.h> //https://github.com/debsahu/Adafruit_DotStar
#endif
#define WIFI_HTM_GZ_PROGMEM //comment to serve minimized html instead of gziped version
// #define SERIAL_DEBUG //uncomment to see if E1.31 data is received
//#define SHOW_FPS_SERIAL //uncomment to see Serial FPS
#define HOSTNAME "E131PixelPusher"
#define HTTP_PORT 80
uint8_t START_UNIVERSE = 1; // First DMX Universe to listen for
uint8_t END_UNIVERSE = 7; // Total number of Universes to listen for, starting at START_UNIVERSE max 7 for multicast and 12 for unicast
uint16_t ledCount = 12 * 170; // 170 LEDs per Universe
bool unicast_flag = false;
#if defined(USE_NEOPIXELS) and defined(USE_DOTSTAR)
#error "Choose only one type of LEDs"
#endif
#ifndef WIFI_HTM_GZ_PROGMEM
//size: 3195
static const char index_htm[] PROGMEM = R"=====(
<!DOCTYPE html><html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="viewport" content="width=device-width"><script>function LoadBody(){var e="/data";fetch(e,{method:"GET"}).then(function(e){if(e.ok)return e.json();throw new Error("Network response was not ok.")}).then(function(e){console.log("Success:",JSON.stringify(e)),document.getElementById("pixelct").innerHTML=170*(e.uct-e.su+1),document.getElementById("mode").value=e.mode,document.getElementById("su").value=e.su,document.getElementById("uct").value=e.uct}).catch(function(e){console.error("Error:",e)})}function validateVal(){var e=document.getElementById("su").value,t=document.getElementById("uct").value,n=1190;return"unicast"==document.frmmr.mode.value&&(n=2040),!(e>t||t-e+1<=0||170*(t-e+1)>n)||(e>t&&alert("Starting universe cant be higher than ending universe!"),t-e+1<=0&&alert("Number of Pixels cant be negative/zero!"),170*(t-e+1)>n&&alert("Cant access that many universes!"),!1)}function calcPixels(){document.getElementById("pixelct").innerHTML=170*(document.getElementById("uct").value-document.getElementById("su").value+1)}function checkUnicast(){"unicast"==document.frmmr.mode.value?(document.getElementById("su").max="12",document.getElementById("uct").max="12"):(document.getElementById("su").max="7",document.getElementById("uct").max="7")}</script><style>.subbt,body{text-align:center;color:#fff}.subbt,.title,a,body{color:#fff}.github a,.subbt,a{text-decoration:none}body{width:100%;height:100%;margin:auto;background-color:#c6b3d4;font-family:sans-serif;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}#wrapper{width:250px;height:270px;border:2px solid #8531C6;border-radius:8px;margin:25px auto auto;background-color:#580797}.subbt{margin:20px;background-color:#008CBA;border:none;padding:10px 30px;display:inline-block;font-size:20px;border-radius:8px}.title{line-height:24px;display:block;padding:2px 0}.form{width:100%;padding:10px;margin:8px 0;box-sizing:border-box}.github{margin-top:10px}.github a{color:#EF5989;font-weight:700;font-size:16px}</style></head><body onload="LoadBody()"><div id="wrapper"><h4 class="title">E1.31 Pixel Pusher</h4><form name="frmmr" class="form" method="POST" action="/updateparams" onsubmit="return validateVal()">Pixels: <span id="pixelct"></span><br>Mode:<select id="mode" name="mode" onblur="checkUnicast()"><option value="unicast">UNICAST</option><option value="multicast" selected>MULTICAST</option></select><br>Start Universe: <input id="su" name="su" type="number" placeholder="Starting universe" max="12" min="1" onkeyup="this.value=this.value.replace(/[^\d]/,"")" onblur="calcPixels()" onclick="calcPixels()"><br>End Universe : <input id="uct" name="uct" type="number" placeholder="Ending universe" max="12" min="1" onkeyup="this.value=this.value.replace(/[^\d]/,"")" onblur="calcPixels()" onclick="calcPixels()"><br><input class="subbt" type="submit" value="Update"></form></div><br><a href="/update">Update Firmware?</a><br><div class="github"><a href="https://github.com/debsahu/E131_PixelPusher">E131_PixelPusher by @debsahu</a></div><script></script></body></html>
)=====";
#else
//gziped: 1385 (~57% compression)
#define index_htm_gz_len 1385
static const uint8_t index_htm_gz[] PROGMEM = {
0x1f, 0x8b, 0x08, 0x00, 0xef, 0xa0, 0x4e, 0x5c, 0x00, 0x03, 0xc5, 0x57,
0x6d, 0x53, 0xe3, 0x36, 0x10, 0xfe, 0x2b, 0x42, 0x4c, 0x99, 0xa4, 0x17,
0xdb, 0x31, 0x2f, 0x07, 0x38, 0x71, 0xae, 0x77, 0x34, 0xd7, 0x5e, 0xe7,
0x8e, 0x63, 0x06, 0xe8, 0x4c, 0xa7, 0x6f, 0x23, 0xdb, 0x9b, 0x58, 0x8d,
0x2d, 0xb9, 0x92, 0x4c, 0xc8, 0x01, 0xff, 0xbd, 0x2b, 0xcb, 0x0e, 0x81,
0x3b, 0xae, 0xf4, 0x53, 0xbf, 0x10, 0x4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xf1, 0xc6, 0x9b, 0x8b, 0xae, 0x1b, 0x80, 0xeb, 0x49, 0x18,
0x58, 0x72, 0xb0, 0x4c, 0x61, 0xff, 0xd3, 0xf8, 0x07, 0xce, 0x1f, 0x2f,
0x41, 0x79, 0x0c, 0x00, 0x00};
#endif
//ESPAsyncE131 pointer
ESPAsyncE131 *e131;
AsyncWebServer server(HTTP_PORT);
NeoWs2813Method *dma; // Same as NeoEsp8266Dma800KbpsMethod -- uses RX/GPIO3 pin
// Same as NeoEsp32RmtWs2813Method -- any pin under 32
#ifdef ESP32
#if defined(USE_NEOPIXELS) and defined(ESP32)
#define PIN USE_NEOPIXELS //Use any pin under 32
// NeoEsp32I2s1800KbpsMethod *dma;
// NeoEsp32RmtWs2813Method *dma;
uint8_t *pixel = (uint8_t *)malloc(ledCount);
;
#endif
#if defined(USE_DOTSTAR) and defined(ESP32)
#define PIN_CLK SCK
#define PIN_DATA MOSI
Adafruit_DotStar *dma;
#endif
#elif defined(ESP8266)
#if defined(USE_NEOPIXELS) and defined(ESP8266)
// NeoEsp8266Dma800KbpsMethod *dma; //uses RX/GPIO3 pin
uint8_t *pixel;
#endif
#if defined(USE_DOTSTAR) and defined(ESP8266)
#define PIN_CLK SCK
#define PIN_DATA MOSI
Adafruit_DotStar *dma;
#endif
#endif
#if defined(ESP8266) and (defined(PIO_PLATFORM) or defined(USE_EADNS))
AsyncDNSServer dns;
#else
DNSServer dns;
#endif
struct
{
bool unicast = false;
uint16_t startUniverse = START_UNIVERSE;
uint16_t endUniverse = END_UNIVERSE;
} config;
int eeprom_addr = 0;
#ifdef SHOW_FPS_SERIAL
uint64_t frameCt = 0;
uint64_t PM = 0;
float interval = 10 * 1000.0; // 10s
#endif
bool shouldReboot = false;
bool updatedParams = false;
const char update_html[] PROGMEM = "<!DOCTYPE html><html lang=\"en\"><head><title>Firmware Update</title><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"><meta name=\"viewport\" content=\"width=device-width\"><link rel=\"shortcut icon\" type=\"image/x-icon\" href=\"favicon.ico\"></head><body><h3>Update Firmware</h3><br><form method=\"POST\" action=\"/update\" enctype=\"multipart/form-data\"><input type=\"file\" name=\"update\"> <input type=\"submit\" value=\"Update\"></form></body></html>";
void initDMA(void)
{
if (dma)
{
delete dma;
#if defined(USE_NEOPIXELS) and defined(ESP32)
delete pixel;
}
dma = new NeoWs2813Method(PIN, ledCount, 3);
//dma = new NeoEsp32RmtWs2813Method(PIN, ledCount, 3);
dma->Initialize();
pixel = (uint8_t *)malloc(ledCount);
memset(pixel, 0, sizeof(pixel));
#endif
#if defined(USE_NEOPIXELS) and defined(ESP8266)
delete pixel;
}
dma = new NeoWs2813Method(ledCount, 3);
dma->Initialize();
pixel = (uint8_t *)malloc(ledCount);
memset(pixel, 0, sizeof(pixel));
#endif
#ifdef USE_DOTSTAR
}
dma = new Adafruit_DotStar(ledCount, DOTSTAR_BRG);
dma->begin();
#endif
}
void initE131(void)
{
uint8_t TOTAL_UNIVERSES = (END_UNIVERSE - START_UNIVERSE + 1);
ledCount = TOTAL_UNIVERSES * 170;
if (e131)
delete e131;
initDMA();
e131 = new ESPAsyncE131(TOTAL_UNIVERSES);
if (e131->begin((unicast_flag) ? E131_UNICAST : E131_MULTICAST, START_UNIVERSE, TOTAL_UNIVERSES)) // Listen via Unicast/Multicast
Serial.println(F(">>> Listening for E1.31 data..."));
else
Serial.println(F(">>> e131.begin failed :("));
}
void readEEPROM(void)
{
char eeprominit = char(EEPROM.read(eeprom_addr));
if (eeprominit != 'w')
{
EEPROM.write(eeprom_addr, 'w');
writeEEPROM();
}
else
{
EEPROM.get(eeprom_addr + 1, config);
unicast_flag = config.unicast;
START_UNIVERSE = config.startUniverse;
END_UNIVERSE = config.endUniverse;
#ifdef SERIAL_DEBUG
Serial.printf("READ>> Mode: %s Start Universe: %d End Universe: %d\n", (unicast_flag) ? "unicast" : "multicast", START_UNIVERSE, END_UNIVERSE);
#endif
}
}
void writeEEPROM(void)
{
config.unicast = unicast_flag;
config.startUniverse = START_UNIVERSE;
config.endUniverse = END_UNIVERSE;
#ifdef SERIAL_DEBUG
Serial.printf("WRITE>> Mode: %s Start Universe: %d End Universe: %d\n", (unicast_flag) ? "unicast" : "multicast", START_UNIVERSE, END_UNIVERSE);
#endif
EEPROM.put(eeprom_addr + 1, config);
EEPROM.commit();
}
void setup()
{
EEPROM.begin(512);
Serial.begin(115200);
delay(10);
Serial.println();
readEEPROM();
char NameChipId[64] = {0}, chipId[9] = {0};
#ifdef USE_DOTSTAR
Serial.print("Hardware SPI //DATA PIN: ");
Serial.println(MOSI); //GPIO23:ESP32 GPIO13:ESP8266
Serial.print("Hardware SPI //CLOCK PIN: ");
Serial.println(SCK); //GPIO18:ESP32 GPIO14:ESP8266
#endif
#ifdef ESP32
snprintf(chipId, sizeof(chipId), "%08x", (uint32_t)ESP.getEfuseMac());
snprintf(NameChipId, sizeof(NameChipId), "%s_%08x", HOSTNAME, (uint32_t)ESP.getEfuseMac());
WiFi.mode(WIFI_STA); // Make sure you're in station mode
WiFi.setHostname(const_cast<char *>(NameChipId));
// WiFiManager wifiManager;
AsyncWiFiManager wifiManager(&server, &dns);
#else
snprintf(chipId, sizeof(chipId), "%06x", ESP.getChipId());
snprintf(NameChipId, sizeof(NameChipId), "%s_%06x", HOSTNAME, ESP.getChipId());
WiFi.mode(WIFI_STA); // Make sure you're in station mode
WiFi.hostname(const_cast<char *>(NameChipId));
AsyncWiFiManager wifiManager(&server, &dns); //Local intialization. Once its business is done, there is no need to keep it around
#endif
wifiManager.setConfigPortalTimeout(180); //sets timeout until configuration portal gets turned off, useful to make it all retry or go to sleep in seconds
if (!wifiManager.autoConnect(NameChipId))
{
Serial.println("Failed to connect and hit timeout");
ESP.restart();
}
Serial.println("");
Serial.print(F(">>> Connected with IP: "));
Serial.println(WiFi.localIP());
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
#ifdef WIFI_HTM_GZ_PROGMEM
AsyncWebServerResponse *response = request->beginResponse_P(200, "text/html", index_htm_gz, index_htm_gz_len);
response->addHeader("Content-Encoding", "gzip");
request->send(response);
#else
request->send_P(200, "text/html", index_htm);
#endif
});
server.on("/data", HTTP_GET, [](AsyncWebServerRequest *request) {
request->send(200, "application/json", "{\"ct\":" + String(ledCount) + ",\"mode\":\"" + String((unicast_flag) ? "unicast" : "multicast") + "\",\"su\":" + String(START_UNIVERSE) + ",\"uct\":" + String(END_UNIVERSE - START_UNIVERSE + 1) + "}");
});
server.on("/updateparams", HTTP_POST, [](AsyncWebServerRequest *request) {
if (request->hasParam("mode", true))
{
unicast_flag = (request->getParam("mode", true)->value() == "unicast") ? true : false;
updatedParams = true;
}
if (request->hasParam("su", true))
{
START_UNIVERSE = constrain(request->getParam("su", true)->value().toInt(), 1, (unicast_flag) ? 12 : 7);
updatedParams = true;
}
if (request->hasParam("uct", true))
{
END_UNIVERSE = constrain(request->getParam("uct", true)->value().toInt(), 1, (unicast_flag) ? 12 : 7);
updatedParams = true;
}
request->send(200, "text/html", "<META http-equiv='refresh' content='3;URL=/'><body align=center>LED Count: " + String((END_UNIVERSE - START_UNIVERSE + 1) * 170) + ", Mode: " + String((unicast_flag) ? "unicast" : "multicast") + ", Starting Universe: " + String(START_UNIVERSE) + ", Universe Count: " + String(END_UNIVERSE - START_UNIVERSE + 1) + "</body>");
});
server.on("/status", HTTP_GET, [](AsyncWebServerRequest *request) {
request->send(200, "text/plain", SKETCH_VERSION);
});
server.on("/update", HTTP_GET, [](AsyncWebServerRequest *request) {
AsyncWebServerResponse *response = request->beginResponse_P(200, "text/html", update_html);
request->send(response);
});
server.on("/update", HTTP_POST, [](AsyncWebServerRequest *request) {
shouldReboot = !Update.hasError();
AsyncWebServerResponse *response = request->beginResponse(200, "text/html", shouldReboot ? "<META http-equiv='refresh' content='15;URL=/'>Update Success, rebooting..." : "FAIL");
response->addHeader("Connection", "close");
request->send(response); }, [](AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final) {
if (!filename.endsWith(".bin")) {
return;
}
if(!index){
if(Serial) Serial.printf("Update Start: %s\n", filename.c_str());
#ifdef ESP32
uint32_t maxSketchSpace = len; // for ESP32 you just supply the length of file
#elif defined(ESP8266)
Update.runAsync(true); // There is no async for ESP32
uint32_t maxSketchSpace = ((ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000);
#endif
if(!Update.begin(maxSketchSpace)) {
if(Serial) Update.printError(Serial);
}
}
if(!Update.hasError()){
if(Update.write(data, len) != len) {
if(Serial) Update.printError(Serial);
}
}
if(final){
if(Update.end(true))
if(Serial) Serial.printf("Update Success: %uB\n", index+len);
else {
if(Serial) Update.printError(Serial);
}
} });
delay(10000);
if (MDNS.begin(NameChipId))
{
MDNS.addService("http", "tcp", HTTP_PORT);
MDNS.addService("e131", "udp", E131_DEFAULT_PORT);
#ifndef ARDUINO_ESP8266_RELEASE_2_4_2
MDNS.addServiceTxt("e131", "udp", "CID", String(chipId));
MDNS.addServiceTxt("e131", "udp", "Model", "E131_PixelPusher");
MDNS.addServiceTxt("e131", "udp", "Manuf", "debsahu");
#endif
//MDNS.setInstanceName("E1.31 PixelPusher"); //Adding this line decreases FPS by 4 times
Serial.printf(">>> MDNS Started: http://%s.local/\n", NameChipId);
}
else
{
Serial.println(F(">>> Error setting up mDNS responder <<<"));
}
DefaultHeaders::Instance().addHeader("Access-Control-Allow-Origin", "*");
server.begin();
#if !defined(SHOW_FPS_SERIAL) and !defined(SERIAL_DEBUG)
Serial.end();
#endif
initE131();
delay(1000);
}
void loop()
{
#ifdef ESP8266
MDNS.update();
#endif
if (updatedParams)
{
initE131();
writeEEPROM();
updatedParams = false;
}
if (!e131->isEmpty())
{
e131_packet_t packet;
e131->pull(&packet); // Pull packet from ring buffer
uint16_t CURRENT_UNIVERSE = htons(packet.universe);
uint8_t *data = packet.property_values + 1;
if (CURRENT_UNIVERSE < START_UNIVERSE || CURRENT_UNIVERSE > END_UNIVERSE)
return; //async will take care about filling the buffer
#ifdef SERIAL_DEBUG
Serial.printf("Universe %u / %u Channels | Packet#: %u / Errors: %u / CH1: %u\n",
htons(packet.universe), // The Universe for this packet
htons(packet.property_value_count) - 1, // Start code is ignored, we're interested in dimmer data
e131->stats.num_packets, // Packet counter
e131->stats.packet_errors, // Packet error counter
packet.property_values[1]); // Dimmer data for Channel 1
#endif
uint16_t multipacketOffset = (CURRENT_UNIVERSE - START_UNIVERSE) * 170; //if more than 170 LEDs (510 channels), client will send in next higher universe
if (ledCount <= multipacketOffset)
return;
uint16_t len = (170 + multipacketOffset > ledCount) ? (ledCount - multipacketOffset) * 3 : 510;
//memcpy(pixel + multipacketOffset * 3, data, len); // Burden on source to send in correct color order
//memcpy(dma->getPixels() + multipacketOffset * 3, data, len);
#ifdef USE_NEOPIXELS
memmove(&pixel[multipacketOffset * 3], data, len);
#elif defined(USE_DOTSTAR)
memmove(&dma->getPixels()[multipacketOffset * 3], data, len);
#endif
}
#ifdef USE_NEOPIXELS
if (dma->IsReadyToUpdate())
#endif
{
#ifdef USE_NEOPIXELS
memcpy(dma->getPixels(), pixel, dma->getPixelsSize());
dma->Update(true);
#elif defined(USE_DOTSTAR)
dma->show();
#endif
#ifdef SHOW_FPS_SERIAL
frameCt++;
#endif
}
#ifdef SHOW_FPS_SERIAL
if (millis() - PM >= interval)
{
PM = millis();
Serial.printf("FPS: %.2f\n", interval / frameCt);
frameCt = 0;
}
#endif
if (shouldReboot)
{
#ifdef SHOW_FPS_SERIAL
Serial.println("Rebooting...");
#endif
delay(100);
ESP.restart();
}
}