forked from forkineye/ESPixelStick
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwshandler.h
770 lines (667 loc) · 24.7 KB
/
wshandler.h
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
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
/*
* wshandler.h
*
* Project: ESPixelStick - An ESP8266 and E1.31 based pixel driver
* Copyright (c) 2016 Shelby Merrick
* http://www.forkineye.com
*
* This program is provided free for you to use in any way that you wish,
* subject to the laws and regulations where you are using it. Due diligence
* is strongly suggested before using this code. Please give credit where due.
*
* The Author makes no warranty of any kind, express or implied, with regard
* to this program or the documentation contained in this document. The
* Author shall not be liable in any event for incidental or consequential
* damages in connection with, or arising out of, the furnishing, performance
* or use of these programs.
*
*/
#ifndef WSHANDLER_H_
#define WSHANDLER_H_
#if defined(ESPS_MODE_WNRF)
#include "WnrfDriver.h"
extern WnrfDriver out_driver; // Wnrf object
#endif
extern EffectEngine effects; // EffectEngine for test modes
extern char fw_name[40];
extern ESPAsyncE131 e131; // ESPAsyncE131 with X buffers
extern ESPAsyncDDP ddp; // ESPAsyncDDP with X buffers
extern config_t config; // Current configuration
extern uint32_t *seqError; // Sequence error tracking for each universe
extern uint16_t uniLast; // Last Universe to listen for
extern bool reboot; // Reboot flag
extern const char CONFIG_FILE[];
#if defined(ESPS_MODE_WNRF)
#define MAX_WS 5
AsyncWebSocketClient * connections[MAX_WS]={NULL,NULL,NULL,NULL,NULL};
AsyncWebSocketClient * ws_edit_client;
#endif
// Forward Declaration - code clean-up to fix
void cb_flash (tDevId id, void * context, int result);
void cb_startaddr(tDevId id, void * context, int result);
/*
Packet Commands
E1 - Get Elements
G1 - Get Config
G2 - Get Config Status
G3 - Get Current Effect and Effect Config Options
T0 - Disable Testing
T1 - Static Testing
T2 - Blink Test
T3 - Flash Test
T4 - Chase Test
T5 - Rainbow Test
T6 - Fire flicker
T7 - Lightning
T8 - Breathe
V1 - View Stream
NRF Device Editing/Auditing
D1 - List of NRF client devices
D2 - Update Channel Request
D3 - WS File Upload Return Code
Da/A - enable.disable Device Admin
S1 - Set Network Config
S2 - Set Device Config
S3 - Set Effect Startup Config
XJ - Get RSSI,heap,uptime, e131 stats in json
X6 - Reboot
*/
EFUpdate efupdate;
uint8_t * WSframetemp;
uint8_t * confuploadtemp;
void procX(uint8_t *data, AsyncWebSocketClient *client) {
switch (data[1]) {
case 'J': {
DynamicJsonDocument json(1024);
// system statistics
JsonObject system = json.createNestedObject("system");
system["rssi"] = (String)WiFi.RSSI();
system["freeheap"] = (String)ESP.getFreeHeap();
system["uptime"] = (String)millis();
// E131 statistics
JsonObject e131J = json.createNestedObject("e131");
uint32_t seqErrors = 0;
for (int i = 0; i < ((uniLast + 1) - config.universe); i++)
seqErrors =+ seqError[i];
e131J["universe"] = (String)config.universe;
e131J["uniLast"] = (String)uniLast;
e131J["num_packets"] = (String)e131.stats.num_packets;
e131J["seq_errors"] = (String)seqErrors;
e131J["packet_errors"] = (String)e131.stats.packet_errors;
e131J["last_clientIP"] = e131.stats.last_clientIP.toString();
JsonObject ddpJ = json.createNestedObject("ddp");
ddpJ["num_packets"] = (String)ddp.stats.packetsReceived;
ddpJ["seq_errors"] = (String)ddp.stats.errors;
ddpJ["num_bytes"] = (String)ddp.stats.bytesReceived;
ddpJ["max_channel"] = (String)ddp.stats.ddpMaxChannel;
ddpJ["min_channel"] = (String)ddp.stats.ddpMinChannel;
// WNRF stats
JsonObject nrf = json.createNestedObject("nrf");
if (config.nrf_chan==NrfChan::NRFCHAN_LEGACY) {
//nrf["chan"] = static_cast<uint8_t>(config.nrf_chan);
nrf["chan"] = "2.480 Mhz";
} else {
uint8_t tempChan = 70+((static_cast<uint8_t>(config.nrf_chan)-1)*2);
nrf["chan"] = "2.4"+String(tempChan)+" Mhz";
}
if (config.nrf_baud == NrfBaud::BAUD_2Mbps) {
nrf["baud"] = "2 Mbps";
} else {
nrf["baud"] = "1 Mbps";
}
if (ws_edit_client == NULL) {
nrf["mode"] = "BROADCAST";
} else {
nrf["mode"] = "ADMIN";
}
//
// To Do: add count after we start probing devices
//
String response;
serializeJson(json, response);
client->text("XJ" + response);
break;
}
case '6': // Init 6 baby, reboot!
reboot = true;
}
}
void procE(uint8_t *data, AsyncWebSocketClient *client) {
switch (data[1]) {
case '1':
// Create buffer and root object
DynamicJsonDocument json(1024);
#if defined (ESPS_MODE_WNRF)
JsonObject nrf_baud = json.createNestedObject("nrf_baud");
nrf_baud["1 Mbps"] = static_cast<uint8_t>(NrfBaud::BAUD_1Mbps);
nrf_baud["2 Mbps"] = static_cast<uint8_t>(NrfBaud::BAUD_2Mbps);
JsonObject nrf_chan = json.createNestedObject("nrf_chan");
nrf_chan["Legacy (2480)"] = static_cast<uint8_t>(NrfChan::NRFCHAN_LEGACY);
nrf_chan["2470"] = static_cast<uint8_t>(NrfChan::NRFCHAN_A);
nrf_chan["2472"] = static_cast<uint8_t>(NrfChan::NRFCHAN_B);
nrf_chan["2474"] = static_cast<uint8_t>(NrfChan::NRFCHAN_C);
nrf_chan["2476"] = static_cast<uint8_t>(NrfChan::NRFCHAN_D);
nrf_chan["2478"] = static_cast<uint8_t>(NrfChan::NRFCHAN_E);
nrf_chan["2480"] = static_cast<uint8_t>(NrfChan::NRFCHAN_F);
nrf_chan["2482"] = static_cast<uint8_t>(NrfChan::NRFCHAN_G);
#endif
String response;
serializeJson(json, response);
client->text("E1" + response);
break;
}
}
#ifdef ESPS_MODE_WNRF
// Helper Function to broadcast to all open
// ws connections
void broadcast(String message) {
for (int i=0;i<MAX_WS;i++){
if (connections[i]) {
connections[i]->text(message);
}
}// for each connection
}
//
// 'D1' = Device List Push to client
//
void cb_devlist(tDeviceInfo * dev_list, uint8_t count) {
// Count is the number of rows in the dev_list table
// Dont' want to generate the JSON more than once.. so should we be
// maintaining the context list here vs in the WnrfDriver??
if (count) {
DynamicJsonDocument json(1024);
JsonObject devList = json.createNestedObject("deviceList");
char tempid[8];
while (count--) {
tDeviceInfo *dev = &(dev_list[count]);
id2txt(tempid, dev->dev_id);
// Convert 3-byte address into a HEX string
/*char *bytes = (char *)&(dev->dev_id);
sprintf(tempid,"%2.2X%2.2X%2.2X",bytes[2],bytes[1],bytes[0]); */
JsonObject device = devList.createNestedObject(tempid);
device["dev_id"]= tempid; // Device Id
device["type"] = dev->type; // Device Type
device["blv"] = dev->blv; // Boot Loader Version
device["apm"] = dev->apm; // App Magic Number
device["apv"] = dev->apv; // Boot Loader Version
device["start"] = dev->start;// E1.31 start Address
} // While
// Prepare JSON for transmission
String message;
serializeJson(devList, message);
// Broadcast this to all web clients devices
broadcast("D1"+message);
} // if result>0
}
void sendDeviceStatus(AsyncWebSocketClient *client) {
DynamicJsonDocument json(1024);
JsonObject status = json.createNestedObject("status");
status["admin"] = (ws_edit_client!=NULL);
String message;
serializeJson(status, message);
broadcast("DS"+message);
}
void sendEditResponse(char cmd, bool result, AsyncWebSocketClient *client ) {
DynamicJsonDocument json(1024);
JsonObject admin = json.createNestedObject("admin");
admin["result"] = result;
String message;
serializeJson(admin, message);
if (cmd=='a') {
client->text("Da"+message);
} else {
client->text("DA"+message);
}
}
void cb_upload_reply (uint16_t retcode, char * fname) {
DynamicJsonDocument json(1024);
JsonObject wnrfu = json.createNestedObject("wnrfu");
wnrfu["retcode"] = retcode;
wnrfu["nrf_fw"] = fname;
String message;
serializeJson(wnrfu, message);
broadcast("D3"+message);
}
// Device Admin handler
void procD(uint8_t *data, AsyncWebSocketClient *client) {
DynamicJsonDocument json(1024);
DeserializationError error = deserializeJson(json, reinterpret_cast<char*>(data + 2));
JsonObject params = json.as<JsonObject>();
switch (data[1]) {
case 'A':
// Highlander: There can be only ONE ADMIN control UI
if (ws_edit_client==NULL) {
out_driver.enableAdmin();
ws_edit_client = client;
}
// Debugging - allow to gain control
ws_edit_client = client;
sendEditResponse(data[1],(ws_edit_client==client),client);
break; // Turn off the Streaming Output
case 'a':
// Only the ADMIN control UI can CANCEL it's own session
if (ws_edit_client==client) {
// This is permitted
out_driver.disableAdmin();
ws_edit_client = NULL;
sendEditResponse(data[1],true,client);
} else {
sendEditResponse(data[1],false,client);
}
break; // Turn on the Streaming Output
case '1':
LOG_PORT.println(F("(D1) Device Refresh Request**"));
break;
case '2': {
LOG_PORT.println(F("(D2) CHANNEL update request**"));
tDevId tempid=0;
int retcode = 0;
if (ws_edit_client == client) {
if (params.containsKey("devid")) {
tempid = txt2id(params["devid"].as<const char*>());
uint16_t newChan = params["chan"];
int retcode = out_driver.nrf_startaddr_update(tempid, newChan, client);
if (retcode) {
cb_startaddr(tempid, client, retcode);
}
} else {
LOG_PORT.println(F("(D2) No DEVID in request"));
}
} else {
LOG_PORT.println(F("(D2) Invalid EDIT OWNER"));
}
}
break;
case '4': {
tDevId tempid=0;
if (ws_edit_client==client) {
if (params.containsKey("devid")) {
// Parse the string to a device id
tempid = txt2id(params["devid"].as<const char*>());
int retcode = out_driver.nrf_flash(tempid, fw_name, client);
if (retcode)
cb_flash(tempid, client, retcode);
} else {
cb_flash(tempid,client, -21);
}
} else {
cb_flash(tempid,client, -11);
}
}
break;
default : // Do Nothing
break;
}
}
#endif
void procG(uint8_t *data, AsyncWebSocketClient *client) {
switch (data[1]) {
case '1': {
String response;
serializeConfig(response, false, true);
client->text("G1" + response);
break;
}
case '2': {
// Create buffer and root object
DynamicJsonDocument json(1024);
json["ssid"] = (String)WiFi.SSID();
if (WiFi.hostname().isEmpty()){
json["hostname"] = config.hostname.c_str();
} else {
json["hostname"] = (String)WiFi.hostname();
}
json["ip"] = WiFi.localIP().toString();
json["mac"] = WiFi.macAddress();
json["version"] = (String)VERSION;
json["built"] = (String)BUILD_DATE;
json["flashchipid"] = String(ESP.getFlashChipId(), HEX);
json["usedflashsize"] = (String)ESP.getFlashChipSize();
json["realflashsize"] = (String)ESP.getFlashChipRealSize();
json["freeheap"] = (String)ESP.getFreeHeap();
String response;
serializeJson(json, response);
client->text("G2" + response);
break;
}
case '3': {
String response;
DynamicJsonDocument json(2048);
// dump the current running effect options
JsonObject effect = json.createNestedObject("currentEffect");
if (config.ds == DataSource::E131) {
effect["name"] = "Disabled";
} else {
effect["name"] = (String)effects.getEffect() ? effects.getEffect() : "";
}
effect["brightness"] = effects.getBrightness();
effect["speed"] = effects.getSpeed();
effect["r"] = effects.getColor().r;
effect["g"] = effects.getColor().g;
effect["b"] = effects.getColor().b;
effect["reverse"] = effects.getReverse();
effect["mirror"] = effects.getMirror();
effect["allleds"] = effects.getAllLeds();
effect["startenabled"] = config.effect_startenabled;
effect["idleenabled"] = config.effect_idleenabled;
effect["idletimeout"] = config.effect_idletimeout;
// dump all the known effect and options
JsonObject effectList = json.createNestedObject("effectList");
for(int i=0; i < effects.getEffectCount(); i++){
JsonObject effect = effectList.createNestedObject( effects.getEffectInfo(i)->htmlid );
effect["name"] = effects.getEffectInfo(i)->name;
effect["htmlid"] = effects.getEffectInfo(i)->htmlid;
effect["hasColor"] = effects.getEffectInfo(i)->hasColor;
effect["hasMirror"] = effects.getEffectInfo(i)->hasMirror;
effect["hasReverse"] = effects.getEffectInfo(i)->hasReverse;
effect["hasAllLeds"] = effects.getEffectInfo(i)->hasAllLeds;
effect["wsTCode"] = effects.getEffectInfo(i)->wsTCode;
}
serializeJson(json, response);
client->text("G3" + response);
//LOG_PORT.print(response);
break;
}
}
}
void procS(uint8_t *data, AsyncWebSocketClient *client) {
DynamicJsonDocument json(1024);
DeserializationError error = deserializeJson(json, reinterpret_cast<char*>(data + 2));
if (error) {
LOG_PORT.println(F("*** procS(): Parse Error ***"));
LOG_PORT.println(reinterpret_cast<char*>(data));
return;
}
bool reboot = false;
switch (data[1]) {
case '1': // Set Network Config
dsNetworkConfig(json.as<JsonObject>());
saveConfig();
client->text("S1");
break;
case '2': // Set Device Config
#ifdef MQTT
// Reboot if MQTT changed
if (config.mqtt != json["mqtt"]["enabled"])
reboot = true;
#endif
dsDeviceConfig(json.as<JsonObject>());
saveConfig();
if (reboot)
client->text("S1");
else
client->text("S2");
break;
case '3': // Set Effect Startup Config
dsEffectConfig(json.as<JsonObject>());
saveConfig();
client->text("S3");
break;
}
}
void procT(uint8_t *data, AsyncWebSocketClient *client) {
if (data[1] == '0') {
//TODO: Store previous data source when effect is selected so we can switch back to it
config.ds = DataSource::E131;
effects.clearAll();
}
else if ( (data[1] >= '1') && (data[1] <= '8') ) {
String TCode;
TCode += (char)data[0];
TCode += (char)data[1];
const EffectDesc* effectInfo = effects.getEffectInfo(TCode);
if (effectInfo) {
DynamicJsonDocument j(1024);
DeserializationError error = deserializeJson(j, reinterpret_cast<char*>(data + 2));
// weird ... no error handling on json parsing
JsonObject json = j.as<JsonObject>();
config.ds = DataSource::WEB;
effects.setEffect( effectInfo->name );
if ( effectInfo->hasColor ) {
if (json.containsKey("r") && json.containsKey("g") && json.containsKey("b")) {
effects.setColor({json["r"], json["g"], json["b"]});
}
}
if ( effectInfo->hasMirror ) {
if (json.containsKey("mirror")) {
effects.setMirror(json["mirror"]);
}
}
if ( effectInfo->hasReverse ) {
if (json.containsKey("reverse")) {
effects.setReverse(json["reverse"]);
}
}
if ( effectInfo->hasAllLeds ) {
if (json.containsKey("allleds")) {
effects.setAllLeds(json["allleds"]);
}
}
if (json.containsKey("speed")) {
effects.setSpeed(json["speed"]);
}
if (json.containsKey("brightness")) {
effects.setBrightness(json["brightness"]);
}
}
}
#ifdef MQTT
if (config.mqtt)
publishState();
#endif
}
void procV(uint8_t *data, AsyncWebSocketClient *client) {
switch (data[1]) {
case '1': { // View stream
#if defined(ESPS_MODE_WNRF)
client->binary(out_driver.getData(), config.channel_count);
#endif
break;
}
#if defined(ESPS_MODE_WNRF)
case '2': { // View Frequency Histogram
client->binary(out_driver.getNrfHistogram(),84);
}
#endif
}
}
void handle_fw_upload(AsyncWebServerRequest *request, String filename,
size_t index, uint8_t *data, size_t len, bool final) {
if (!index) {
WiFiUDP::stopAll();
LOG_PORT.print(F("* Upload Started: "));
LOG_PORT.println(filename.c_str());
efupdate.begin();
}
if (!efupdate.process(data, len)) {
LOG_PORT.print(F("*** UPDATE ERROR: "));
LOG_PORT.println(String(efupdate.getError()));
}
if (efupdate.hasError())
request->send(200, "text/plain", "Update Error: " +
String(efupdate.getError()));
if (final) {
LOG_PORT.println(F("* Upload Finished."));
efupdate.end();
SPIFFS.begin();
saveConfig();
reboot = true;
}
}
void handle_config_upload(AsyncWebServerRequest *request, String filename,
size_t index, uint8_t *data, size_t len, bool final) {
static File file;
if (!index) {
WiFiUDP::stopAll();
LOG_PORT.print(F("* Config Upload Started: "));
LOG_PORT.println(filename.c_str());
if (confuploadtemp) {
free (confuploadtemp);
confuploadtemp = nullptr;
}
confuploadtemp = (uint8_t*) malloc(CONFIG_MAX_SIZE);
}
LOG_PORT.printf("index %d len %d\n", index, len);
memcpy(confuploadtemp + index, data, len);
confuploadtemp[index + len] = 0;
if (final) {
int filesize = index+len;
LOG_PORT.print(F("* Config Upload Finished:"));
LOG_PORT.printf(" %d bytes", filesize);
DynamicJsonDocument json(1024);
DeserializationError error = deserializeJson(json, reinterpret_cast<char*>(confuploadtemp));
if (error) {
LOG_PORT.println(F("*** Parse Error ***"));
LOG_PORT.println(reinterpret_cast<char*>(confuploadtemp));
request->send(500, "text/plain", "Config Update Error." );
} else {
dsNetworkConfig(json.as<JsonObject>());
dsDeviceConfig(json.as<JsonObject>());
dsEffectConfig(json.as<JsonObject>());
saveConfig();
request->send(200, "text/plain", "Config Update Finished: " );
// reboot = true;
}
if (confuploadtemp) {
free (confuploadtemp);
confuploadtemp = nullptr;
}
}
}
void wsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client,
AwsEventType type, void * arg, uint8_t *data, size_t len) {
switch (type) {
case WS_EVT_DATA: {
AwsFrameInfo *info = static_cast<AwsFrameInfo*>(arg);
if (info->opcode == WS_TEXT) {
switch (data[0]) {
case 'X':
procX(data, client);
break;
case 'E':
procE(data, client);
break;
case 'G':
procG(data, client);
break;
#ifdef ESPS_MODE_WNRF
case 'D':
procD(data, client);
break;
#endif
case 'S':
procS(data, client);
break;
case 'T':
procT(data, client);
break;
case 'V':
procV(data, client);
break;
}
} else {
LOG_PORT.println(F("-- binary message --"));
}
break;
}
case WS_EVT_CONNECT: {
int i;
LOG_PORT.print(F("* WS Connect - "));
LOG_PORT.println(client->id());
#if defined(ESPS_MODE_WNRF)
for (i=0;i<MAX_WS;i++) {
if (connections[i] == NULL) {
connections[i] = client;
break;
}
}
if (i==MAX_WS) {
LOG_PORT.println("Maximum number of concurrent clients exceeded");
} else {
LOG_PORT.print("Using connection: ");
LOG_PORT.println(i);
}
#endif
}
break;
case WS_EVT_DISCONNECT:{
int i;
LOG_PORT.print(F("* WS Disconnect - "));
LOG_PORT.println(client->id());
#if defined(ESPS_MODE_WNRF)
// LabRat - clearContext to be removed
out_driver.clearContext((void *) client);
for (i=0;i<MAX_WS;i++) {
if (connections[i] == client) {
connections[i] = NULL;
break;
}
}
if (ws_edit_client==client) {
// ADMIN EDITOR client has dropped
ws_edit_client = NULL;
out_driver.disableAdmin();
// LabRat Add a PUSH to remaining clients
}
#endif
}
break;
case WS_EVT_PONG:
LOG_PORT.println(F("* WS PONG *"));
break;
case WS_EVT_ERROR:
LOG_PORT.println(F("** WS ERROR **"));
break;
}
}
#ifdef ESPS_MODE_WNRF
// Async Callbacks from the WnrfDriver
// response to OTA FLASH request
void cb_flash (tDevId devid, void * context, int result) {
char tempid[8];
id2txt(tempid,devid);
DynamicJsonDocument json(1024);
JsonObject ota = json.createNestedObject("ota");
ota["result"] = result;
ota["dev_id"] = tempid;
String message;
serializeJson(ota, message);
if (context) {
((AsyncWebSocketClient *) context)->text("D4" + message);
}
}
// response to APP: Update RF channel request
void cb_rfchan (tDevId id, void * context, int result) {
// If result is ok..
// Convert context into a client and send "D4" result
}
// response to MTC: Update DeviceId request
void cb_devid (tDevId id, void * context, int result) {
// If result is ok..
// Convert context into a client and send "D5" result
}
// response to MTC: Update E1.31 Channel request
void cb_startaddr(tDevId id, void * context, int result) {
char tempid[8];
id2txt(tempid,id);
DynamicJsonDocument json(1024);
JsonObject updchan = json.createNestedObject("updchan");
updchan["result"] = result;
updchan["dev_id"] = tempid;
String message;
serializeJson(updchan, message);
if (context) {
((AsyncWebSocketClient *) context)->text("D2" + message);
} else {
LOG_PORT.println("** MISSING CONTEXT *** !!");
}
}
void register_nrf_callbacks () {
out_driver.nrf_async_otaflash = cb_flash;
out_driver.nrf_async_rfchan = cb_rfchan;
out_driver.nrf_async_devid = cb_devid;
out_driver.nrf_async_startaddr= cb_startaddr;
out_driver.nrf_async_devlist = cb_devlist;
}
#endif /*WNRF*/
#endif /* ESPIXELSTICK_H_ */