@@ -24,7 +24,7 @@ interface history {
24
24
values : number [ ] ;
25
25
}
26
26
27
- const client = new Paho . Client ( '192.168.1.2 ' , 9001 , '' , Date . now ( ) . toString ( ) ) ;
27
+ const client = new Paho . Client ( '10.0.0.101 ' , 9001 , '' , Date . now ( ) . toString ( ) ) ;
28
28
29
29
const App = ( ) => {
30
30
const [ latestData , setLatestData ] = useState ( [ { value : 0 } ] ) ;
@@ -139,6 +139,26 @@ const App = () => {
139
139
140
140
const unusableArea = 35 + 40 + 36 ;
141
141
142
+ const turnOnLed = ( ) => {
143
+ const buffer = new ArrayBuffer ( 3 ) ;
144
+ const charArray = new Uint8Array ( buffer ) ;
145
+ //charArray.set(0, 0x2);
146
+ charArray [ 0 ] = 0x06 ;
147
+ charArray [ 1 ] = 0x06 ;
148
+ charArray [ 2 ] = 0x06 ;
149
+ client . publish ( 'comand' , charArray , 2 , false ) ;
150
+ } ;
151
+
152
+ const turnOfLed = ( ) => {
153
+ const buffer = new ArrayBuffer ( 3 ) ;
154
+ const charArray = new Uint8Array ( buffer ) ;
155
+ //charArray.set(0, 0x2);
156
+ charArray [ 0 ] = 0x09 ;
157
+ charArray [ 1 ] = 0x09 ;
158
+ charArray [ 2 ] = 0x09 ;
159
+ client . publish ( 'comand' , charArray , 2 , false ) ;
160
+ } ;
161
+
142
162
return (
143
163
< ScrollView style = { [ styles . container , { backgroundColor : color } ] } >
144
164
< View style = { { padding : 20 , backgroundColor : 'red' } } >
@@ -475,46 +495,54 @@ const App = () => {
475
495
adjustToWidth = { true }
476
496
/>
477
497
</ View >
478
- < TouchableOpacity
479
- style = { styles . button }
480
- disabled = { client . isConnected ( ) }
481
- onPress = { ( ) => {
482
- if ( client . isConnected ( ) ) {
483
- Alert . alert ( 'Ja tá conectado' ) ;
484
- return ;
485
- }
486
- client . connect ( {
487
- userName : 'aluno' ,
488
- password : '@luno*123' ,
489
- onFailure : f => console . log ( 'Failure' , f ) ,
490
- onSuccess : ( ) => {
491
- console . log ( 'Sucesso' ) ;
492
- client . subscribe ( 'analogic/history' , {
493
- onSuccess : d => {
494
- console . log ( 'incrito em analogic/history' ) ;
495
- } ,
496
- } ) ;
497
- client . subscribe ( '5/history' , {
498
- onSuccess : d => {
499
- console . log ( 'incrito em 5/history' ) ;
500
- } ,
501
- } ) ;
502
- client . subscribe ( '16/history' , {
503
- onSuccess : d => {
504
- console . log ( 'incrito em 16/history' ) ;
505
- } ,
506
- } ) ;
507
- client . subscribe ( 'update_interval' , {
508
- onSuccess : d => {
509
- console . log ( 'incrito em update_interval' ) ;
510
- } ,
511
- } ) ;
512
- } ,
513
- reconnect : true ,
514
- } ) ;
515
- } } >
516
- < Text > { client . isConnected ( ) ? 'Conectado ✅' : 'Conectar 📡' } </ Text >
517
- </ TouchableOpacity >
498
+ < View style = { { flexDirection : 'row' } } >
499
+ < TouchableOpacity
500
+ style = { styles . block }
501
+ disabled = { client . isConnected ( ) }
502
+ onPress = { ( ) => {
503
+ if ( client . isConnected ( ) ) {
504
+ Alert . alert ( 'Ja tá conectado' ) ;
505
+ return ;
506
+ }
507
+ client . connect ( {
508
+ userName : 'aluno' ,
509
+ password : '@luno*123' ,
510
+ onFailure : f => console . log ( 'Failure' , f ) ,
511
+ onSuccess : ( ) => {
512
+ console . log ( 'Sucesso' ) ;
513
+ client . subscribe ( 'analogic/history' , {
514
+ onSuccess : ( ) => {
515
+ console . log ( 'incrito em analogic/history' ) ;
516
+ } ,
517
+ } ) ;
518
+ client . subscribe ( '5/history' , {
519
+ onSuccess : ( ) => {
520
+ console . log ( 'incrito em 5/history' ) ;
521
+ } ,
522
+ } ) ;
523
+ client . subscribe ( '16/history' , {
524
+ onSuccess : ( ) => {
525
+ console . log ( 'incrito em 16/history' ) ;
526
+ } ,
527
+ } ) ;
528
+ client . subscribe ( 'update_interval' , {
529
+ onSuccess : ( ) => {
530
+ console . log ( 'incrito em update_interval' ) ;
531
+ } ,
532
+ } ) ;
533
+ } ,
534
+ reconnect : true ,
535
+ } ) ;
536
+ } } >
537
+ < Text > { client . isConnected ( ) ? 'Conectado ✅' : 'Conectar 📡' } </ Text >
538
+ </ TouchableOpacity >
539
+ < TouchableOpacity onPress = { turnOnLed } style = { styles . block } >
540
+ < Text > Ligar o led</ Text >
541
+ </ TouchableOpacity >
542
+ < TouchableOpacity onPress = { turnOfLed } style = { styles . block } >
543
+ < Text > Desligar o led</ Text >
544
+ </ TouchableOpacity >
545
+ </ View >
518
546
{ /*}
519
547
<TouchableOpacity
520
548
disabled={!client.isConnected()}
@@ -546,6 +574,19 @@ const styles = StyleSheet.create({
546
574
title : {
547
575
fontSize : 40 ,
548
576
} ,
577
+ block : {
578
+ height : 150 ,
579
+ width : 150 ,
580
+ borderRadius : 10 ,
581
+ borderWidth : 1 ,
582
+ borderColor : 'rgba(0, 0, 0, 0.05)' ,
583
+ justifyContent : 'center' ,
584
+ alignContent : 'center' ,
585
+ display : 'flex' ,
586
+ backgroundColor : '#FFFFFF3F' ,
587
+ padding : 10 ,
588
+ marginHorizontal : 5 ,
589
+ } ,
549
590
} ) ;
550
591
551
592
export default App ;
0 commit comments