forked from Supernova4422/LimitlessLED-DevAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
July6_2017.html
3123 lines (2703 loc) · 149 KB
/
July6_2017.html
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
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<!--[if lt IE 7 ]><html class="ie ie6 no-js" dir="ltr" lang="en-US"> <![endif]-->
<!--[if IE 7 ]><html class="ie ie7 no-js" dir="ltr" lang="en-US"> <![endif]-->
<!--[if IE 8 ]><html class="ie ie8 no-js" dir="ltr" lang="en-US"> <![endif]-->
<!--[if IE 9 ]><html class="ie ie9 no-js" dir="ltr" lang="en-US"> <![endif]-->
<!--[if (gte IE 9)|!(IE)]><!--><html class="no-js" dir="ltr" lang="en-US"> <!--<![endif]-->
<head><base href="http://www.limitlessled.com/dev/" />
<style type="text/css">
<!--
#exaleadCached {
background: white;
border: 1px solid #ccc;
color: #000;
font-size: 13px;
font-family: arial, helvetica, sans-serif;
font-weight: normal;
margin-bottom: 20px;
padding: 10px;
position: relative;
text-align: left;
width: auto;
}
#exaleadCached .exaleadLogo {
position: relative;
float: left;
margin-right: 20px;
}
#exaleadCached .exaleadNavigation {
font-size: 11px;
font-family: arial, helvetica, sans-serif;
position: absolute;
top: 5px;
right: 15px;
}
#exaleadCached .exaleadNavigation a {
font-size: 11px;
font-family: arial, helvetica, sans-serif;
}
#exaleadCached .exaleadNavigation a:hover {
font-size: 11px;
font-family: arial, helvetica, sans-serif;
}
#exaleadCached a {
background: white;
border: none;
color: #3279BE;
font-size: 13px;
font-family: arial, helvetica, sans-serif;
font-weight: normal;
letter-spacing: normal;
line-height: 14px;
text-decoration: none;
}
#exaleadCached a:hover {
font-size: 13px;
font-family: arial, helvetica, sans-serif;
font-weight: normal;
text-decoration: underline;
}
#exaleadCached img {
color: white;
border: none;
}
#exaleadCached p {
margin: 20px 0px;
max-width: 100%;
width: 100%;
text-align: left;
}
#exaleadCached span {
background: white;
color: black;
display: inline;
font-size: 13px;
font-family: arial, helvetica, sans-serif;
font-weight: normal;
letter-spacing: normal;
line-height: 14px;
text-decoration: none;
}
#exaleadSelectedTerm {
border: 2px dashed black;
}
span.exalead_query {
color: black;
position: relative;
}
span.exalead_query .next {
display: none;
right: -1em;
}
span.exalead_query .previous {
display: none;
left: -1em;
}
span.exalead_query:hover .previous,
span.exalead_query:hover .next {
background: #DDD;
border: 1px solid black;
cursor: pointer;
height: 1em;
text-align: center;
width: 1em;
z-index: 100;
line-height: 1em;
position: absolute;
bottom: 0px;
display: block;
}
-->
</style>
<script type="text/javascript">
<!--
var exalead = new Object();
exalead.showNextTerm = function (element, direction)
{
var elements = exalead.getElementsByClassName(element.className);
var elementCount = elements.length;
var showNextElement = function(index) {
var currentElement = undefined
if (direction > 0)
{
if (index + 1 > elementCount - 1)
{
currentElement = elements[0];
}
else
{
currentElement = elements[index + 1];
}
}
else
{
if (index - 1 < 0)
{
currentElement = elements[elementCount - 1];
}
else
{
currentElement = elements[index - 1];
}
}
if (document.getElementById('exaleadSelectedTerm'))
{
document.getElementById('exaleadSelectedTerm').id = ''
}
var node = currentElement
while (node.parentNode)
{
var display = undefined;
if (window.getComputedStyle)
{
display = window.getComputedStyle(node, null).display;
}
else if (node.currentStyle)
{
display = node.currentStyle.display;
}
if (display.indexOf('none') >= 0)
{
node.style.display = 'inline-block';
}
node = node.parentNode
}
currentElement.id = 'exaleadSelectedTerm'
currentElement.scrollIntoView(true);
return;
}
for(var index = 0; index < elementCount; index++)
{
if (elements[index] == element)
{
showNextElement(index)
}
}
}
exalead.getElementsByClassName = function(string)
{
var result = [];
var spans = document.getElementsByTagName('span')
for(var index = 0; index < spans.length; index++)
{
if (spans[index].className.indexOf(string) >= 0)
{
result[result.length] = spans[index];
}
}
var selects = document.getElementsByTagName('selects')
for(var index = 0; index < selects.length; index++)
{
if (selects[index].className.indexOf(string) >= 0)
{
result[result.length] = selects[index];
}
}
return result;
}
-->
</script>
<meta charset="UTF-8" />
<title>LimitlessLED Technical Developer Opensource API | LimitlessLED</title>
<meta name="description" content="<p>WiFi Color E27 LED light bulbs for your iPhone or android</p>" /><p>WiFi Color E27 LED light bulbs for your iPhone or android</p>">
<meta name="keywords" content="<p>e27 e26 b22 lifx hue greenwave wifi led light bulbs iphone android</p>" /><p>e27 e26 b22 lifx hue greenwave wifi led light bulbs iphone android</p>">
<meta name="author" content="Limitless Designs" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<link rel="profile" href="http://gmpg.org/xfn/11" />
<link rel="pingback" href="http://www.limitlessled.com/xmlrpc.php" />
<link rel="alternate" type="application/rss+xml" title="LimitlessLED » Feed" href="http://www.limitlessled.com/feed/" />
<link rel="alternate" type="application/rss+xml" title="LimitlessLED » Comments Feed" href="http://www.limitlessled.com/comments/feed/" />
<link rel="stylesheet" id="woocommerce_frontend_styles-css" href="http://www.limitlessled.com/wp-content/plugins/woocommerce/assets/css/woocommerce.css?ver=3.4.2" type="text/css" media="all" />
<link rel="stylesheet" id="validate-engine-css-css" href="http://www.limitlessled.com/wp-content/plugins/wysija-newsletters/css/validationEngine.jquery.css?ver=2.7.2" type="text/css" media="all" />
<link rel="stylesheet" id="q-a-plus-css" href="http://www.limitlessled.com/wp-content/plugins/q-and-a/css/q-a-plus.css?ver=1.0.6.2" type="text/css" media="screen" />
<link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://www.limitlessled.com/xmlrpc.php?rsd" />
<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="http://www.limitlessled.com/wp-includes/wlwmanifest.xml" />
<link rel="prev" title="My Account" href="http://www.limitlessled.com/my-account/" />
<link rel="next" title="About LimitlessLED" href="http://www.limitlessled.com/about-limitlessled/" />
<meta name="generator" content="WordPress 3.4.2" />
<link rel="canonical" href="http://www.limitlessled.com/dev/" />
<!-- Q & A -->
<noscript><link rel="stylesheet" type="text/css" href="http://www.limitlessled.com/wp-content/plugins/q-and-a/css/q-a-plus-noscript.css?ver=1.0.6.2" /></noscript><!-- Q & A --><!-- Debug info: Spark - Responsive HTML5 WordPress Theme 1.3 -->
<!-- [Speed mode activated] - If you encounter problems loading the following URL, revert back to the Default mode in the Theme Options page. -->
<link rel="stylesheet" href="http://www.limitlessled.com/wp-content/themes/spark-v1.3/static-server/min-merge-cache.php?format=css&files=skeleton-v1.1.css,flexslider-v1.8.1.css,main-r8.css,media-queries-r7.css,theme-default-r6.css" />
<!-- WooCommerce Version -->
<meta name="generator" content="WooCommerce 1.6.6" />
<link href="http://fonts.googleapis.com/css?family=Open+Sans:400,600,400italic" rel="stylesheet" type="text/css" />
<style>
/* Custom CSS */
/* This is only an example */
.example-post-id-10 {
color: red;
font-size: 14px;
}
.logo {margin-left:300px; }
header {background: #ffffff;}
//.dark header {background: #111 url(/wp-content/themes/spark-v1.3/images/motifs/random_grey_variations1.png) repeat;}
body {background: #ffffff}
//body {background: #ffffff url("/wp-content/themes/spark-v1.3/images/motifs/grangray1.png") repeat;}
.smartbox {
color: #6B6B6B;
background-attachment: scroll;
background-clip: border-box;
background-color: transparent;
background-image: url("/wp-content/themes/spark-v1.3/images/motifs/gradient_bg.png");
background-origin: padding-box;
background-position-x: 0px;
background-position-y: 100%;
background-repeat: repeat-x;
background-size: auto;
border-bottom-color: #c4c4c4;
border-bottom-left-radius: 5px;
border-bottom-right-radius: 5px;
border-bottom-style: none;
border-bottom-width: 0px;
border-left-color: #c4c4c4;
border-left-style: none;
border-left-width: 0px;
border-right-color: #c4c4c4;
border-right-style: none;
border-right-width: 0px;
border-top-color: #c4c4c4;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
border-top-style: none;
border-top-width: 5px;
padding-bottom: 1px;
padding-left: 12px;
padding-right: 14px;
padding-top: 7px;
margin-bottom: 0px;
margin-left: 0px;
margin-right: 0px;
margin-top: 0px;
box-shadow: 0px 1px 2px rgba(0,0,0,0.5);
}
header, .dark header {
background: #0d0c0c url("");
background-repeat: ;
background-attachment: ;
background-position: ;
}
.dark,
.dark .container .column.box,
.dark .container .columns.box,
.dark .box,
.dark .box.dark,
.box.dark {
background: #6464f2 url("");
background-repeat: ;
background-attachment: ;
background-position: ;
}
</style>
<link rel="shortcut icon" href="http://www.limitlessled.com/wp-content/themes/spark-v1.3/images/favicon.ico" />
<link rel="apple-touch-icon" href="http://www.limitlessled.com/wp-content/themes/spark-v1.3/images/apple-touch-icon.png" />
<link rel="apple-touch-icon" sizes="72x72" href="http://www.limitlessled.com/wp-content/themes/spark-v1.3/images/apple-touch-icon-72x72.png" />
<link rel="apple-touch-icon" sizes="114x114" href="http://www.limitlessled.com/wp-content/themes/spark-v1.3/images/apple-touch-icon-114x114.png" />
<!-- Allow IE to render HTML5 -->
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body class="page page-id-560 page-template-default theme-spark-responsivehtml5wordpresstheme">
<div id="exaleadCached">
<div class="exaleadLogo">
<a href="http://www.exalead.com/search/web/" title="Go to Exalead homepage" style="float: left;">
<img src="http://www.exalead.com/content/img/logo.gif" alt=""/>
</a>
</div>
<div>
<p>
<span>
This is the Exalead cached version of <a href='http://www.limitlessled.com/dev/'>http://www.limitlessled.com/dev/</a> of July 6, 2017.
</span>
</p>
</div>
<div class="exaleadNavigation">
<a href="http://www.exalead.com/search/web/results/?q=&elements_per_page=&start_index=">Go back to the results page</a> | <a href="http://www.limitlessled.com/dev/">Show the current version</a>
</div>
<div style="clear: both;"></div>
</div>
<div style="position: relative;">
<div id="main" role="main">
<article>
<div class="container">
<div class="breadcrumb-list"><a href="http://www.limitlessled.com">Home</a> <span class="chevron">›</span> <span class="breadcrumb-current">LimitlessLED Technical Developer Opensource API</span></div>
<div id="post-560" class="post-560 page type-page status-publish hentry">
<h1>LimitlessLED Technical Developer Opensource API</h1>
<div class="post-entry">
<h3>LAST UPDATED: 29th January 2017</h3>
<p></p>
<h1>Domoticz wifi bridge v6 Code</h1>
<p><a href="https://github.com/domoticz/domoticz">https://github.com/domoticz/domoticz</a><br />
the sample code for wifi bridge v6 is here:<br />
<a href="https://github.com/domoticz/domoticz/blob/master/hardware/Limitless.cpp">https://github.com/domoticz/domoticz/blob/master/hardware/Limitless.cpp</a></p>
<h1>LimitlessLED Wifi Bridge v6.0 Sample Windows App</h1>
<p><a href="http://www.limitlessled.com/download/LimitlessLEDv6.zip">Download LimitlessLEDv6.zip Here</a></p>
<h1>LimitlessLED Wifi Bridge v6.0 VB.NET Sample code</h1>
<div class="container">
<div class="header"><span>VB.NET</span></div>
<div class="content">
<pre><code>
Imports System.Net
Imports System.Net.Sockets
Imports System.Text.Encoding
Private LimitlessLEDWifiBridgeSessionID1 As Byte = 0
Private LimitlessLEDWifiBridgeSessionID2 As Byte = 0
Private SequenceNumber As Byte = 0
'Usage: SendLightCommand(txtV6cmd01.Text, txtIP2.Text, txtCommandUDPPort.Text, txtZone.Text, "Waiting for response...", 500, "", 10, True)
Private Sub SendLightCommand(ByVal v6CommandString As String, ByVal sendIPAddress As String, ByVal sPortNumber As String, ByVal sZone As String, ByVal WaitText As String, ByVal ReceiveTimeout As Integer, ByVal ValidResponse As String, ByVal Retries As Integer, ByVal WaitForResponse As Boolean)
Dim iPortNum As Integer = CInt(sPortNumber)
If udpAdmin Is Nothing Then
udpAdmin = New UdpClient(iPortNum)
udpAdmin.EnableBroadcast = True
udpAdmin.DontFragment = True
Else
Throw New Exception("udpAdmin was already initialised")
End If
Dim sendEndPoint = New IPEndPoint(IPAddress.Parse(sendIPAddress), iPortNum)
Dim listenEndPoint = New IPEndPoint(IPAddress.Parse(sendIPAddress), iPortNum)
Dim StartSessionCommandString As String = "20 00 00 00 16 02 62 3A D5 ED A3 01 AE 08 2D 46 61 41 A7 F6 DC AF D3 E6 00 00 1E"
Dim b As Byte() = StringToBytes(StartSessionCommandString)
udpAdmin.Send(b, b.Length, sendEndPoint)
udpAdmin.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 1000)
Try
Do While iFoundWifiBridges < iLookForNumberOfWifiBridges
receiveBytes = udpAdmin.Receive(listenEndPoint) 'wait here until a UDP packet has been received. TIMEout if no response received.
If receiveBytes.Length > 0 AndAlso receiveBytes(0) = (b(0) + 8) AndAlso receiveBytes.Length = (receiveBytes(4) + 5) Then
'if the first byte sent on the command is 0x10 then expect response of 0x18 (+8)
'if the first byte sent on the command is 0x20 then expect response of 0x28 (+8)
UpdateCommandsResponseMessage("Received: " & ByteArrayToString(receiveBytes)) 'ByteArrayToHexString(receiveBytes))
' UpdateCommandsResponseMessage("Received bytes " & CUInt(receiveBytes(4)))
If Not chkFreezeSessionID.Checked Then
LimitlessLEDWifiBridgeSessionID1 = receiveBytes(19) '20th response byte
End If
UpdateCommandsResponseMessage("LimitlessLEDWifiBridgeSessionID1 is " & ByteToHexString(LimitlessLEDWifiBridgeSessionID1))
If Not chkFreezeSessionID.Checked Then
LimitlessLEDWifiBridgeSessionID2 = receiveBytes(20) '21st response byte
End If
UpdateCommandsResponseMessage("LimitlessLEDWifiBridgeSessionID2 is " & ByteToHexString(LimitlessLEDWifiBridgeSessionID2))
'could be broadcast, so we don't know how many bridges might respond
UpdateCommandsResponseMessage("IP Address is " & listenEndPoint.Address.ToString())
'The mac address is returned from the wifi bridge.
Dim macAddressFormatted As String = ByteToHexString(receiveBytes(8)) & ":" & ByteToHexString(receiveBytes(9)) & ":" & ByteToHexString(receiveBytes(10)) & ":" & ByteToHexString(receiveBytes(11)) & ":" & ByteToHexString(receiveBytes(12)) & ":" & ByteToHexString(receiveBytes(13))
Dim macAddressRaw As String = macAddressFormatted.Replace(":", "")
UpdateCommandsResponseMessage("MAC Address is " & macAddressFormatted)
SendCommand:
'80 00 00 00 11(length hex) (17 01)(WB1WB2) 00 SN 00 (31 00 00 08 04 01 00 00 00)(cmd) 01(zone) 00 3F(chksum) response: (88 00 00 00 03 00 SN 00)
Dim sendFullcommand As String = "80 00 00 00 04 05 06 00 08 00 " & v6CommandString & " 19 00 21"
Dim cmd As Byte() = StringToBytes(sendFullcommand)
cmd(4) = cmd.Length - 5 'set packet length (excluding 5 packet header bytes)
cmd(5) = LimitlessLEDWifiBridgeSessionID1 'session byte 1
cmd(6) = LimitlessLEDWifiBridgeSessionID2 'session byte 2
If Not chkFreezeSequenceNumber.Checked Then
If SequenceNumber = 255 Then
SequenceNumber = 0
Else
SequenceNumber = SequenceNumber + 1
End If
End If
cmd(8) = SequenceNumber
cmd(19) = CByte(sZone)
'Calculate Checksum:
Dim iChecksum As Integer
Dim bChecksum As Byte
For i As Integer = 10 To 20 '11 bytes
iChecksum += cmd(i)
Next
bChecksum = CByte(iChecksum And &HFF)
cmd(21) = bChecksum
UpdateCommandsResponseMessage("Sequence Number is " & ByteToHexString(SequenceNumber))
UpdateCommandsResponseMessage("Checksum is " & ByteToHexString(bChecksum))
udpAdmin.Send(cmd, cmd.Length, sendEndPoint)
'udpAdmin.Send(cmd, cmd.Length, broadcastEP)
UpdateCommandsResponseMessage("Sent: " & ByteArrayToString(cmd))
Do While iFoundWifiBridges < iLookForNumberOfWifiBridges
receiveBytes = udpAdmin.Receive(listenEndPoint) 'wait here until a UDP packet has been received. TIMEout if no response received.
If receiveBytes.Length > 0 AndAlso receiveBytes(0) = (cmd(0) + 8) AndAlso receiveBytes.Length = (receiveBytes(4) + 5) Then 'check header byte 0x88 and length byte 0x03 is correct (including the 5 packet header bytes that aren't counted)
UpdateCommandsResponseMessage("Command SUCCESSFUL.")
UpdateCommandsResponseMessage("Received: " & ByteArrayToString(receiveBytes))
'response should be: 88 00 00 00 03 00 SN 00
Exit Do
End If
Loop
Exit Do
End If
Loop
Catch ex As System.Net.Sockets.SocketException
Dim excp = ex.SocketErrorCode
If excp = SocketError.TimedOut Then
'TODO: retry if there is a timeout, chances are it will work the second time on UDP
UpdateCommandsResponseMessage("Timeout waiting for Wifi Bridge Response.")
Else
UpdateCommandsResponseMessage(ex.Message)
End If
Catch ex As Exception
UpdateCommandsResponseMessage(ex.Message)
Finally
Try
udpAdmin.Client.Shutdown(SocketShutdown.Receive)
Catch ex As Exception
'UpdateStatusMessage("udpAdmin.Client.Shutdown(SocketShutdown.Receive) exception." & ex.Message)
End Try
Try
udpAdmin.Client.Close()
Catch ex As Exception
'UpdateStatusMessage("udpAdmin.Client.Close() exception." & ex.Message)
End Try
Try
udpAdmin.Close()
Catch ex As Exception
'UpdateStatusMessage("udpAdmin.Close() exception." & ex.Message)
End Try
Try
udpAdmin = Nothing
Catch ex As Exception
' UpdateStatusMessage("udpAdmin = Nothing exception." & ex.Message)
End Try
End Try
End Sub
Public Shared Function StringToBytes(ByVal hex As String) As Byte()
hex = hex.Replace(" ", "")
If hex.Length Mod 2 = 1 Then
Throw New Exception("The hex string cannot have an odd number of digits")
End If
Dim arr As Byte() = New Byte((hex.Length >> 1) - 1) {}
For i As Integer = 0 To (hex.Length >> 1) - 1
arr(i) = CByte((GetHexVal(hex(i << 1)) << 4) + (GetHexVal(hex((i << 1) + 1))))
Next
Return arr
End Function
Public Shared Function GetHexVal(ByVal hex As Char) As Integer
Dim val As Integer = AscW(hex)
'For uppercase A-F letters:
'Return val - (If(val < 58, 48, 55))
'For lowercase a-f letters:
'Return val - (If(val < 58, 48, 87))
'Or the two combined, but a bit slower:
Return val - (If(val < 58, 48, (If(val < 97, 55, 87))))
End Function
Private Sub UpdateStatusMessage(ByVal message As String)
txtLog.Text &= message.Replace(vbCr, "\r").Replace(vbLf, "\n") & vbCrLf
'\r = Cr = decimal13 = 0x0D = Carriage Return
'\n = Lf = decimal10 = 0x0A = Linefeed
txtLog.SelectionStart = txtLog.Text.Length
txtLog.ScrollToCaret()
Application.DoEvents()
End Sub
</code></pre>
<p>
</p></div>
</div>
<h1>LimitlessLED Wifi Bridge v6.0 Sample code</h1>
<div class="container">
<div class="header"><span>NodeJS</span></div>
<div class="content">
<pre><code>
'use strict';
var dgram = require('dgram');
var debug=false;
var DEFAULT_HOST ;
var DEFAULT_PORT ;
var DEFAULT_REPEATS=3 ;
var PREAMPLE = [0x80,0x00,0x00,0x00,0x11]
var FILLER = 0x00
var CMDS={
ON: [0x31,0,0,0x08,0x04,0x01,0,0,0],
OFF: [0x31,0,0,0x08,0x04,0x02,0,0,0],
NIGHT: [0x31,0,0,0x08,0x04,0x05,0,0,0],
WHITEON: [0x31,0,0,0x08,0x05,0x64,0,0,0],
REG: [0x33,0,0,0,0,0,0,0,0,0],
BON: [0x31,0x00,0x00,0x00,0x03,0x03,0x00,0x00,0x00],
BOFF:[0x31,0x00,0x00,0x00,0x03,0x04,0x00,0x00,0x00],
BWHITE:[0x31 ,0x00 ,0x00 ,0x00 ,0x03 ,0x05 ,0x00 ,0x00 ,0x00],
};
var socket;
var zoneCtlRGBWFactory=function(zoneID){
var color=0x7A;
var brightness=0x32;
var saturation=0x32;
var colorTemp=0x4B;
var zone=zoneID;
if(zone > 4 || zone <0 ) console.log("invalid zone");
return {
on: function(){
return [0x31,0,0,0x08,0x04,0x01,0,0,0,zoneID];
},
off: function(){
return [0x31,0,0,0x08,0x04,0x02,0,0,0,zoneID];
},
nightMode: function() {
return [0x31,0,0,0x08,0x04,0x05,0,0,0,zoneID];
},
whiteMode:function() {
return [0x31,0,0,0x08,0x05,0x64,0,0,0,zoneID];
},
saturationUp:function(){
saturation=Math.min(saturation+5,0x64);
return [0x31,0x00,0x00,0x08,0x02,saturation,0x00,0x00,0x00,zoneID]
},
saturationDown:function(){
saturation=Math.max(saturation-5,0x00);
return [0x31,0x00,0x00,0x08,0x02,saturation,0x00,0x00,0x00,zoneID]
},
saturationSet:function(b){
saturation=Math.max(b,0x00);
saturation=Math.min(b,0x64);
return [0x31,0x00,0x00,0x08,0x02,saturation,0x00,0x00,0x00,zoneID]
},
brightnessUp:function(){
brightness=Math.min(brightness+5,0x64);
return [0x31,0x00,0x00,0x08,0x03,brightness,0x00,0x00,0x00,zoneID]
},
brightnessDown:function(){
brightness=Math.max(brightness-5,0x00);
return [0x31,0x00,0x00,0x08,0x03,brightness,0x00,0x00,0x00,zoneID]
},
brightnessSet:function(b){
brightness=Math.max(b,0x00);
brightness=Math.min(b,0x64);
return [0x31,0x00,0x00,0x08,0x03,brightness,0x00,0x00,0x00,zoneID]
},
colorUp:function(){
color=Math.min(color+5,0xFF);
return [0x31,0x00,0x00,0x08,0x01,color,color,color,color,zoneID]
},
colorDown:function(){
color=Math.max(color-5,0x00);
return [0x31,0x00,0x00,0x08,0x01,color,color,color,color,zoneID]
},
colorSet:function(c){
color=c;
return [0x31,0x00,0x00,0x08,0x01,color,color,color,color,zoneID]
},
colorRGB:function(rgb){
return rgbHandler(rgb,this);
},
colorTempUp:function(){
colorTemp=Math.min(colorTemp+5,0x64);
return [0x31,0x00,0x00,0x08,0x05,colorTemp,0,0,0,zoneID]
},
colorTempDown:function(){
colorTemp=Math.max(colorTemp-5,0x00);
return [0x31,0x00,0x00,0x08,0x05,colorTemp,0,0,0,zoneID]
},
colorTempSet:function(c){
colorTemp=c;
return [0x31,0x00,0x00,0x08,0x05,colorTemp,0,0,0,zoneID]
},
mode:function(mode){
return [0x31,0x00,0x00,0x08,0x06,mode,0,0,0,zoneID]
},
modeSpeedUp:function(){
return [0x31,0,0,0x08,0x04,0x03,0,0,0,zoneID]
},
modeSpeedDown:function(){
return [0x31,0,0,0x08,0x04,0x04,0,0,0,zoneID]
},
link:function(){
return [0x3D,0,0,0x08,0,0,0,0,0,zoneID]
},
unlink:function(){
return [0x3E,0,0,0x08,0,0,0,0,0,zoneID]
},
command(fnName,arg){
if (this[fnName]) {
var cmds=this[fnName](arg);
if (Array.isArray(cmds) && Array.isArray(cmds[0])){
cmds.forEach(function(elem){
sendCmd(elem)})
} else {
sendCmd(cmds);//single cmd`
}
}
}
}
}
var zoneCtlRGBWWFactory=function(zoneID){
var color=0x7A;
var brightness=0x32;
//var saturation=0x32;
//var colorTemp=0x4B;
var zone=zoneID;
if(zone > 4 || zone <0 ) console.log("invalid zone");
return {
on: function(){
return [0x31, 0x00, 0x00, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00, zoneID];
},
off: function(){
return [0x31, 0x00, 0x00, 0x07, 0x03, 0x02, 0x00, 0x00, 0x00, zoneID];
},
nightMode: function() {
return [0x31, 0x00, 0x00, 0x07, 0x03, 0x06, 0x00, 0x00, 0x00, zoneID];
},
whiteMode:function() {
return [0x31, 0x00, 0x00, 0x07, 0x03, 0x05, 0x00, 0x00, 0x00, zoneID];
},
brightnessUp:function(){
brightness=Math.min(brightness+5,0x64);
return [0x31, 0x00, 0x00, 0x07, 0x02, brightness, 0x00, 0x00, 0x00, zoneID]
},
brightnessDown:function(){
brightness=Math.max(brightness-5,0x00);
return [0x31, 0x00, 0x00, 0x07, 0x02, brightness, 0x00, 0x00, 0x00, zoneID]
},
brightnessSet:function(b){
brightness=Math.max(b,0x00);
brightness=Math.min(b,0xFF);
return [0x31, 0x00, 0x00, 0x07, 0x02, brightness, 0x00, 0x00, 0x00, zoneID]
},
colorUp:function(){
color=Math.min(color+5,0xFF);
return [0x31, 0x00, 0x00, 0x07, 0x01, color, color, color, color, zoneID]
},
colorDown:function(){
color=Math.max(color-5,0x00);
return [0x31, 0x00, 0x00, 0x07, 0x01, color, color, color, color, zoneID]
},
colorSet:function(c){
color=c;
return [0x31, 0x00, 0x00, 0x07, 0x01, color, color, color, color, zoneID]
},
colorRGB:function(rgb){
return rgbHandler(rgb,this);
},
mode:function(mode){
return [0x31, 0x00, 0x00, 0x07, 0x04, mode, 0x00, 0x00, 0x00, zoneID]
},
modeSpeedUp:function(){
return [0x31, 0x00, 0x00, 0x07, 0x03, 0x03, 0x00, 0x00, 0x00, zoneID]
},
modeSpeedDown:function(){
return [0x31, 0x00, 0x00, 0x07, 0x03, 0x04, 0x00, 0x00, 0x00, zoneID]
},
link:function(){
console.log("link not captured");
return [0x3D,0,0,0x07,0,0,0,0,0,zoneID]
},
unlink:function(){
console.log("link not captured");
return [0x3E,0,0,0x07,0,0,0,0,0,zoneID]
},
command(fnName,arg){
if (this[fnName]) {
var cmds=this[fnName](arg);
if (Array.isArray(cmds) && Array.isArray(cmds[0])){
cmds.forEach(function(elem){sendCmd(elem)})
} else {
sendCmd(cmds);//single cmd`
}
}
}
}
}
var baseCtlFactory=function(){
var color=0x7A;
var brightness=0x32;
var zoneID=0x01;
return {
on:function(){return [0x31,0x00,0x00,0x00,0x03,0x03,0x00,0x00,0x00,zoneID]},
off:function(){return [0x31,0x00,0x00,0x00,0x03,0x04,0x00,0x00,0x00,zoneID]},
whiteMode:function(){return [0x31 ,0x00 ,0x00 ,0x00 ,0x03 ,0x05 ,0x00 ,0x00 ,0x00,zoneID]},
brightnessUp:function(){
brightness=Math.min(brightness+5,0x64);
return [0x31,0x00,0x00,0x00,0x02,brightness,0x00,0x00,0x00,zoneID]
},
brightnessDown:function(){
brightness=Math.max(brightness-5,0x00);
return [0x31,0x00,0x00,0x00,0x02,brightness,0x00,0x00,0x00,zoneID]
},
brightnessSet:function(b){
brightness=Math.max(b,0x00);
brightness=Math.min(b,0xFF);
return [0x31,0x00,0x00,0x00,0x02,brightness,0x00,0x00,0x00,zoneID]
},
colorUp:function(){
color=Math.min(color+5,0xFF);
return [0x31,0x00,0x00,0x00,0x01,color,color,color,color,zoneID]
},
colorDown:function(){
color=Math.max(color-5,0x00);
return [0x31,0x00,0x00,0x00,0x01,color,color,color,color,zoneID]
},
colorSet:function(c){
color=c;
return [0x31,0x00,0x00,0x00,0x01,color,color,color,color,zoneID]
},
colorRGB:function(rgb){
return rgbHandler(rgb,this);
},
mode:function(mode){
return [0x31,0x00,0x00,0x00,0x04,mode,0,0,0,zoneID]
},
command(fnName,arg){
if (this[fnName]) {
var cmds=this[fnName](arg);
if (Array.isArray(cmds) && Array.isArray(cmds[0])){
cmds.forEach(function(elem){sendCmd(elem)})
} else {
sendCmd(cmds);//single cmd`
}
}
}
}
};
var bridgeID;
var bridgeID2;
var seqNum=0x02;
var sendCmd = function(CMD,repeats){
if (typeof repeats === 'undefined') { repeats = DEFAULT_REPEATS};
var out=[];
//console.log("#"+WB.toString('hex')+"-"+CMD.toString("hex"));
out=out.concat(PREAMPLE,bridgeID,bridgeID2,0x00,seqNum,FILLER,CMD)
var chkSum=calcCheckSum(out);
out = out.concat(chkSum);
//console.log(JSON.stringify(out));
if (debug) console.log("#"+out.toString('hex'));
out=new Buffer(out);
seqNum=(seqNum+1)%256;
if(debug) console.log("Sending: " + out.toString('hex'));
for (var i=0;i<repeats>< b ? 6 : 0); break;
case g: h = (b - r) / d + 2; break;
case b: h = (r - g) / d + 4; break;
}
h /= 6;
}
return [ Math.floor(h*0xFF), Math.floor(s*100), Math.floor(v*100) ];
}
var buildFrame = function(WB,WB2,CMD,ZONE){
var out=[];
//console.log("#"+WB.toString('hex')+"-"+CMD.toString("hex"));
if (debug) console.log("WB: "+ WB.toString("hex")+ " "+WB2.toString("hex") +" CMD: "+CMD.toString("hex"))
out=out.concat(PREAMPLE,WB,WB2,0x00,seqNum,FILLER,CMD,ZONE)
var chkSum=calcCheckSum(out);
out = out.concat(chkSum);
if (debug) console.log("out: "+ (new Buffer(out)).toString('hex'))
//console.log(JSON.stringify(out));
//console.log("#"+out.toString('hex'));
seqNum=(seqNum+1)%256;
return new Buffer(out);
}
var sendFrame=function(payload){
if(debug) console.log("Sending: " + payload.toString('hex'));
socket.send(payload,0,payload.length,DEFAULT_PORT,DEFAULT_HOST,function(){});
}
var sendKeepAlive=function(){
var out=new Buffer([0xD0,0x00,0x00,0x00,0x02,bridgeID,bridgeID2]);
sendFrame(out);
}
var calcCheckSum=function(aFrame){
var add=function(a,b){
return a+b;
};
var sub = aFrame.slice(Math.max(aFrame.length - 11, 0)) ;
var val=sub.reduce(add,0)
var val1=Math.floor(val / 0xff)
var val2=val % 0xff
return [val1, val2]
}
var _func={};
_func['2800000011']=function(msg){
//response to initiate
var unknown1=msg.slice(5,7);
var mac=msg.slice(7,13);
var fixed=msg.slice(13,15);
var unknown2=msg.slice(15,19);
var counter=msg.slice(19,20);
var counter2=msg.slice(20,21);
var padding=msg.slice(20);
if (debug) {
console.log("0:" +msg.toString('hex'));
console.log("1:" +unknown1.toString('hex'));
console.log("2:" +mac.toString('hex'));
console.log("2a:" +fixed.toString('hex'));
console.log("3:" +unknown2.toString('hex'));
console.log("4:" +counter.toString('hex'));
console.log("5:" +padding.toString('hex'));
}
bridgeID=new Uint8Array(counter);
bridgeID2=new Uint8Array(counter2);
//80:00:00:00:11:c1:01:00:0b:00:33:00:00:00:00:00:00:00:00:00:00:33
//complete initiation
if (debug) console.log("BridgeID: "+ bridgeID.toString("hex"))
if (debug) console.log("BridgeID2: "+ bridgeID2.toString("hex"))
var nFrame=buildFrame(bridgeID,bridgeID2,[0x33,0,0,0,0,0,0,0,0,0],0x00);
sendFrame(nFrame);
//start keepalive
setInterval(sendKeepAlive,10000);
};
_func['8800000003']=function(msg){
//ERROR - Confirmation?
var code= msg.slice(0,5);
var unknown1 = msg.slice(5,8);
if (debug) console.log("0:" +msg.toString('hex'));
if (debug) console.log("1:" +unknown1.toString('hex'));
if (debug) console.log("ID:"+bridgeID.toString('hex'));
}
_func['d800000007']=function(){
//keepalive response
}
var socket=dgram.createSocket({type:'udp4',reuseAddr:true});
socket.on("message", (msg, rinfo) => {
//console.log('Received %d bytes from %s:%d\n',
// msg.length, rinfo.address, rinfo.port);
var hmsg=msg.toString('hex');
var resp=(msg.toString('hex').substring(0,10));
if (_func[resp]) {
_func[resp](msg)
} else {
console.log("Unknown code");
console.log(hmsg);
}
});
var initiate=function(host,port){
//socket.send(payload,0,payload.length,DEFAULT_PORT,DEFAULT_HOST,function(a,b){});
DEFAULT_HOST=host;
DEFAULT_PORT=port;
//socket.bind();
//socket.bind(DEFAULT_PORT);