-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsearch.xml
799 lines (771 loc) · 427 KB
/
search.xml
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
<?xml version="1.0" encoding="utf-8"?>
<search>
<entry>
<title>Ubuntu下配置Lineage OS编译环境</title>
<url>/2019/10/06/Android-envsetup/</url>
<content><![CDATA[<p>系统为Ubuntu18.04<br>物理内存至少8G起步,16G以上最好,建议SWAP+RAM>=20G,太小会爆内存。<br>硬盘空闲空间必须大于200G,因为光源码就70G左右了。</p>
<a id="more"></a>
<h1 id="安装依赖软件包"><a href="#安装依赖软件包" class="headerlink" title="安装依赖软件包"></a>安装依赖软件包</h1><figure class="highlight vim"><table><tr><td class="code"><pre><span class="line">sudo apt <span class="keyword">update</span> && sudo apt install -<span class="keyword">y</span> git curl <span class="keyword">python</span>-socks libncurses5-dev xclip && git clone http<span class="variable">s:</span>//github.<span class="keyword">com</span>/<span class="number">467815891</span><span class="keyword">a</span>/AndroidEnv_setup.git && <span class="keyword">cd</span> AndroidEnv_setup && sudo bash setup/android_build_env.<span class="keyword">sh</span> && <span class="keyword">cd</span> ..</span><br></pre></td></tr></table></figure>
<h1 id="设置-git用户名和邮箱"><a href="#设置-git用户名和邮箱" class="headerlink" title="设置 git用户名和邮箱"></a>设置 git用户名和邮箱</h1><p>这一步其实可以省略,git clone的时候告诉远程仓库的托管服务商(如github)你的个人信息,用于认证,可以减少你被ban的几率。<br>示例如下:</p>
<figure class="highlight routeros"><table><tr><td class="code"><pre><span class="line">git<span class="built_in"> config </span>--global user.email <span class="string">"[email protected]"</span></span><br></pre></td></tr></table></figure>
<figure class="highlight routeros"><table><tr><td class="code"><pre><span class="line">git<span class="built_in"> config </span>--global user.name <span class="string">"Your Name"</span></span><br></pre></td></tr></table></figure>
<p>双引号中的 <code>“[email protected]” </code>填写您的 github 所使用的邮箱。注意格式,不要把双引号去掉。<br>双引号中的 <code>“Your Name” </code>填写您的 github 用户名,不要把双引号去掉。</p>
<h1 id="生成-ssh-并添加到-github"><a href="#生成-ssh-并添加到-github" class="headerlink" title="生成 ssh 并添加到 github"></a>生成 ssh 并添加到 github</h1><figure class="highlight apache"><table><tr><td class="code"><pre><span class="line"><span class="attribute">ssh</span>-keygen -t ed<span class="number">25519</span> -C <span class="string">"[email protected]"</span></span><br></pre></td></tr></table></figure>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="built_in">eval</span> <span class="string">"$(ssh-agent -s)"</span></span><br><span class="line">ssh-add ~<span class="regexp">/.ssh/i</span>d_ed25519</span><br><span class="line">xclip -selection clipboard < ~<span class="regexp">/.ssh/i</span>d_ed25519.pub</span><br></pre></td></tr></table></figure>
<p>然后将剪切板的内容粘贴到Github网站的个人设置中,详见<a target="_blank" rel="noopener" href="https://docs.github.com/articles/generating-an-ssh-key/">Github官方指导</a></p>
<h1 id="自行repo-init项目-以lineageos为例"><a href="#自行repo-init项目-以lineageos为例" class="headerlink" title="自行repo init项目(以lineageos为例)"></a>自行repo init项目(以lineageos为例)</h1><figure class="highlight awk"><table><tr><td class="code"><pre><span class="line">mkdir lineageos && cd lineageos && repo init -u git:<span class="regexp">//gi</span>thub.com<span class="regexp">/LineageOS/</span>android.git -b lineage-<span class="number">17.0</span></span><br></pre></td></tr></table></figure>
<h1 id="新建local-manifests(或者手动同步device-tree,kernel-tree,vendor-tree)"><a href="#新建local-manifests(或者手动同步device-tree,kernel-tree,vendor-tree)" class="headerlink" title="新建local_manifests(或者手动同步device tree,kernel tree,vendor tree)"></a>新建local_manifests(或者手动同步device tree,kernel tree,vendor tree)</h1><figure class="highlight arduino"><table><tr><td class="code"><pre><span class="line"><span class="built_in">mkdir</span> .repo/local_manifests</span><br></pre></td></tr></table></figure>
<h1 id="同步项目"><a href="#同步项目" class="headerlink" title="同步项目"></a>同步项目</h1><p>因为网络环境不好,需要脚本自动化同步,失败不停重试。<br>在lineageos文件夹中新建<code>repo.sh</code>并写入脚本</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">cat > repo.sh << <span class="string">'EOF'</span></span><br><span class="line"><span class="meta">#!/bin/bash</span></span><br><span class="line"><span class="comment">#是否启用本地代理同步源码 (需要配合ss-local开启使用)</span></span><br><span class="line">ENABLE_PROXY=0</span><br><span class="line"><span class="comment">#SS的服务器地址</span></span><br><span class="line">SERVER=</span><br><span class="line"><span class="comment">#SS的远程端口</span></span><br><span class="line">PORT=</span><br><span class="line"><span class="comment">#SS的密码</span></span><br><span class="line">PASSWD=</span><br><span class="line"><span class="comment">#SS的加密方式</span></span><br><span class="line">METHOD=chacha20-ietf-poly1305</span><br><span class="line"><span class="comment">#SS的本地监听端口</span></span><br><span class="line">LOCAL=1080</span><br><span class="line">NAME=Shadowsocks-local</span><br><span class="line">PID_FILE=<span class="variable">$HOME</span>/shadowsocks-local.pid</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="title">check_running</span></span>() {</span><br><span class="line"> <span class="keyword">if</span> [ -r <span class="variable">$PID_FILE</span> ]; <span class="keyword">then</span></span><br><span class="line"> <span class="built_in">read</span> PID < <span class="variable">$PID_FILE</span></span><br><span class="line"> <span class="keyword">if</span> [ -d <span class="string">"/proc/<span class="variable">$PID</span>"</span> ]; <span class="keyword">then</span></span><br><span class="line"> <span class="built_in">return</span> 0</span><br><span class="line"> <span class="keyword">else</span></span><br><span class="line"> rm -f <span class="variable">$PID_FILE</span></span><br><span class="line"> <span class="built_in">return</span> 1</span><br><span class="line"> <span class="keyword">fi</span></span><br><span class="line"> <span class="keyword">else</span></span><br><span class="line"> <span class="built_in">return</span> 2</span><br><span class="line"> <span class="keyword">fi</span></span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="title">proxy_off</span></span>() {</span><br><span class="line"> <span class="keyword">if</span> check_running; <span class="keyword">then</span></span><br><span class="line"> <span class="built_in">kill</span> -9 <span class="variable">$PID</span></span><br><span class="line"> rm -f <span class="variable">$PID_FILE</span></span><br><span class="line"> <span class="built_in">echo</span> <span class="string">"Stopping <span class="variable">$NAME</span> success"</span></span><br><span class="line"> <span class="keyword">else</span></span><br><span class="line"> <span class="built_in">echo</span> <span class="string">"<span class="variable">$NAME</span> is stopped"</span></span><br><span class="line"> <span class="keyword">fi</span></span><br><span class="line"> <span class="built_in">return</span> 0</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="title">proxy_on</span></span>() {</span><br><span class="line"> check_running</span><br><span class="line"> <span class="keyword">case</span> $? <span class="keyword">in</span></span><br><span class="line"> 0)</span><br><span class="line"> <span class="built_in">echo</span> <span class="string">"<span class="variable">$NAME</span> (pid <span class="variable">$PID</span>) is running..., trying to restart"</span></span><br><span class="line"> proxy_off</span><br><span class="line"> ;;</span><br><span class="line"> 1|2)</span><br><span class="line"> <span class="built_in">command</span> -v ss-local >/dev/null 2>&1 || { <span class="built_in">echo</span> >&2 <span class="string">"你好像没有安装ss-local"</span>;<span class="built_in">exit</span> 1;}</span><br><span class="line"> ;;</span><br><span class="line"> <span class="keyword">esac</span></span><br><span class="line"> ss-local -b 127.0.0.1 -s <span class="variable">$SERVER</span> -p <span class="variable">$PORT</span> -l <span class="variable">$LOCAL</span> -m <span class="variable">$METHOD</span> -k <span class="variable">$PASSWD</span> -f <span class="variable">$PID_FILE</span></span><br><span class="line"> <span class="keyword">if</span> check_running; <span class="keyword">then</span></span><br><span class="line"> <span class="built_in">echo</span> <span class="string">"Starting <span class="variable">$NAME</span> success"</span></span><br><span class="line"> <span class="built_in">export</span> http_proxy=<span class="string">"socks5://127.0.0.1:<span class="variable">${LOCAL}</span>"</span></span><br><span class="line"> <span class="built_in">export</span> https_proxy=<span class="string">"socks5://127.0.0.1:<span class="variable">${LOCAL}</span>"</span></span><br><span class="line"> <span class="built_in">echo</span> <span class="string">"Setting Socks5 proxy for this shell success"</span></span><br><span class="line"> <span class="built_in">return</span> 0</span><br><span class="line"> <span class="keyword">else</span></span><br><span class="line"> <span class="built_in">echo</span> <span class="string">"Starting <span class="variable">$NAME</span> failed"</span></span><br><span class="line"> <span class="built_in">unset</span> https_proxy</span><br><span class="line"> <span class="built_in">unset</span> http_proxy</span><br><span class="line"> <span class="built_in">echo</span> <span class="string">"Unsetting Socks5 proxy for this shell success"</span></span><br><span class="line"> retrun 1</span><br><span class="line"> <span class="keyword">fi</span></span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="title">repo_sync</span></span>() {</span><br><span class="line"> <span class="keyword">if</span> [ <span class="variable">$ENABLE_PROXY</span> == <span class="string">'0'</span> ]; <span class="keyword">then</span></span><br><span class="line"> <span class="built_in">echo</span> <span class="string">"==========不使用代理同步源码========="</span></span><br><span class="line"> proxy_off</span><br><span class="line"> <span class="keyword">else</span></span><br><span class="line"> <span class="keyword">if</span> proxy_on; <span class="keyword">then</span> </span><br><span class="line"> <span class="built_in">echo</span> <span class="string">"=========开始使用代理同步源码========="</span></span><br><span class="line"> <span class="keyword">else</span></span><br><span class="line"> <span class="built_in">echo</span> <span class="string">"========开启代理失败,不使用代理同步源码========"</span></span><br><span class="line"> <span class="keyword">fi</span></span><br><span class="line"> <span class="keyword">fi</span></span><br><span class="line"> sleep 3</span><br><span class="line"> repo sync -j4 --no-clone-bundle --no-tags --force-sync</span><br><span class="line"> <span class="keyword">while</span> [ $? -ne 0 ]; <span class="keyword">do</span></span><br><span class="line"> <span class="built_in">echo</span> <span class="string">"======同步中断,重试中======"</span> </span><br><span class="line"> repo_sync</span><br><span class="line"> <span class="keyword">done</span></span><br><span class="line"> proxy_off</span><br><span class="line"> <span class="built_in">return</span> 0</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">case</span> <span class="string">"<span class="variable">$1</span>"</span> <span class="keyword">in</span></span><br><span class="line"> sync)</span><br><span class="line"> repo_sync</span><br><span class="line"> ;;</span><br><span class="line"> status)</span><br><span class="line"> <span class="keyword">if</span> [ ! -n <span class="string">"<span class="variable">$https_proxy</span>"</span> ]; <span class="keyword">then</span></span><br><span class="line"> <span class="built_in">echo</span> <span class="string">"当前终端代理设置为空"</span></span><br><span class="line"> <span class="keyword">else</span></span><br><span class="line"> <span class="built_in">echo</span> <span class="string">"当前终端代理设置为<span class="variable">${https_proxy}</span>"</span></span><br><span class="line"> <span class="keyword">fi</span></span><br><span class="line"> check_running</span><br><span class="line"> <span class="keyword">case</span> $? <span class="keyword">in</span></span><br><span class="line"> 0)</span><br><span class="line"> <span class="built_in">echo</span> <span class="string">"<span class="variable">$NAME</span> (pid <span class="variable">$PID</span>) is running..."</span></span><br><span class="line"> ;;</span><br><span class="line"> 1|2)</span><br><span class="line"> <span class="built_in">echo</span> <span class="string">"<span class="variable">$NAME</span> is stopped"</span></span><br><span class="line"> ;;</span><br><span class="line"> <span class="keyword">esac</span></span><br><span class="line"> ;;</span><br><span class="line"> proxy)</span><br><span class="line"> proxy_on</span><br><span class="line"> ;;</span><br><span class="line"> unproxy)</span><br><span class="line"> proxy_off</span><br><span class="line"> <span class="built_in">unset</span> http_proxy</span><br><span class="line"> <span class="built_in">unset</span> https_proxy</span><br><span class="line"> <span class="built_in">echo</span> <span class="string">"Unsetting Socks5 proxy for this shell success"</span></span><br><span class="line"> ;;</span><br><span class="line"> *)</span><br><span class="line"> repo_sync</span><br><span class="line"> ;;</span><br><span class="line"><span class="keyword">esac</span></span><br><span class="line">EOF</span><br></pre></td></tr></table></figure>
<p>赋予脚本执行权限并开始同步源码。</p>
<figure class="highlight css"><table><tr><td class="code"><pre><span class="line"><span class="selector-tag">chmod</span> <span class="selector-tag">a</span>+<span class="selector-tag">x</span> <span class="selector-tag">repo</span><span class="selector-class">.sh</span></span><br><span class="line"><span class="selector-tag">bash</span> <span class="selector-tag">repo</span><span class="selector-class">.sh</span></span><br></pre></td></tr></table></figure>
<h1 id="添加一些环境变量"><a href="#添加一些环境变量" class="headerlink" title="添加一些环境变量"></a>添加一些环境变量</h1><figure class="highlight jboss-cli"><table><tr><td class="code"><pre><span class="line"><span class="keyword">echo</span> 'export ALLOW_MISSING_DEPENDENCIES=<span class="literal">true</span>' >> ~<span class="string">/.bashrc</span></span><br><span class="line"><span class="keyword">echo</span> 'export USE_CCACHE=1' >> ~<span class="string">/.bashrc</span></span><br><span class="line"><span class="keyword">echo</span> 'export _JAVA_OPTIONS=<span class="string">"-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx8g"</span>' >> ~<span class="string">/.bashrc</span></span><br><span class="line">source ~<span class="string">/.bashrc</span> && export LANG=C</span><br></pre></td></tr></table></figure>
<h1 id="开始编译"><a href="#开始编译" class="headerlink" title="开始编译"></a>开始编译</h1><figure class="highlight vim"><table><tr><td class="code"><pre><span class="line"><span class="keyword">source</span> build/envsetup.<span class="keyword">sh</span></span><br><span class="line">lunch</span><br><span class="line"></span><br></pre></td></tr></table></figure>
]]></content>
<tags>
<tag>Android</tag>
</tags>
</entry>
<entry>
<title>中兴B760HV2电视盒子完美刷机</title>
<url>/2020/03/25/B760HV2/</url>
<content><![CDATA[<p>丈母娘想看电视,我就寻思着现在有线电视不划来,网络都这么发达了,找点直播源也很简单。但是给长辈用最重要的还是简单易用最重要。<br>先说成果,通电后自动播放直播电视,整个过程大概25秒。<br><img src= "/img/loading.gif" data-lazy-src="B760HV2_show.webp" alt="B760HV2_show"><br>通过利用手头安徽移动送的这个中兴B760HV2智能机顶盒,安装AlexELEC系统来实现播放电视直播源,记录一下这个曲折的过程。<br><img src= "/img/loading.gif" data-lazy-src="B760HV2_1.jpg" alt="B760HV2_1"><br><img src= "/img/loading.gif" data-lazy-src="B760HV2_2.jpg" alt="B760HV2_2"></p>
<a id="more"></a>
<p>丈母娘家有一个移动办宽带送的电视盒子——中兴 ZXV10 B760HV2智能机顶盒(WiFi版),我想大多数电视盒子都是晶晨的主控,刷机应该不难。但是翻遍了全网,没找到这个机子的刷机教程,只找到了救砖线刷包,也算是给我吃了一颗定心丸,不怕死了,综合其他机子的刷机教程就是干。<br>首先要确定硬件配置,找到硬件相似的机型的刷机教程或者刷机包。拆开机子一看,Realtek RTL8818ETV + 1G RAM 的组合不出我意料,但4G NAND + Amlogic S805的Soc就让我有些傻眼了,这配置简直丐中丐。CoreELEC已经放弃了S80x系列的Soc了。本来CoreELEC刷机包都下载好了,现在要重新查资料了。最终找到了支持S805的Kodi系统<a target="_blank" rel="noopener" href="https://github.com/AlexELEC/AE-AML/releases">AlexELEC</a>,看样子应该是LibreELEC和CoreELEC的魔改版,但是支持S805,Kodi版本同步到目前最新的18.6,也找到了相似的机型<a target="_blank" rel="noopener" href="https://www.rigacci.org/wiki/doku.php/doc/appunti/hardware/mxq_s805">MXQ (FW V2.0)</a> (代号m201c),NAND闪存差了4G,不过FLASH大小应该和内核没关系,启动后可以自己识别。</p>
<h1 id="进入Update模式(从TF卡启动)"><a href="#进入Update模式(从TF卡启动)" class="headerlink" title="进入Update模式(从TF卡启动)"></a>进入Update模式(从TF卡启动)</h1><p>按照帖子中的操作,将AlexELEC烧入TF卡(用<a target="_blank" rel="noopener" href="https://sourceforge.net/projects/win32diskimager/files/Archive/">Win32DiskImager</a>把img烧入TF卡),然后插入机器,上电。。。按照MXQ的刷机教程,此时已经可以从TF卡启动了,然而实际情况还是进入百视通自己的系统(从NAND启动的)。看来这个机子在软件上还是做了一些防刷机的屏蔽。仔细查看机子的裸板,没有复位键,没有短接点位,没有额外的SPI Flash做NAND里面系统的引导,网上说的那些捅菊花、短接进入升级模式方法都不好使了。不过发现了6根排针,不知道能不能找到TXD和RXD,通过串口控制台进入升级模式。<br>万用表测出GND,固定波特率115200,用USB TTL的RXD挨个碰其他针脚观察控制台的输出,注意只有启动前几秒才能观察到,启动完成之后串口不再向外输出。所以测试每根针脚时都要重新上电。最终测试出TXD和RXD,还好这个板子留出了TTL针脚,给我留了一条活路。<br><img src= "/img/loading.gif" data-lazy-src="B760HV2_TTL.jpg" alt="B760HV2_TTL"><br>登陆控制台之后发现这个机子的用户名也是m201,看来m201可能是Amlogic的公版代号。B760HV2的遥控器看起来跟MXQ的遥控器还是不一样,刷机之前首先保存遥控器的配置文件<code>remote.conf</code>(后面附具体内容),不然刷完机后,遥控器的按键编码我还要重新录制,重新设定按键响应。然后尝试重启进入刷机模式,在串口中输入</p>
<figure class="highlight ebnf"><table><tr><td class="code"><pre><span class="line"><span class="attribute">reboot update</span></span><br></pre></td></tr></table></figure>
<p>结果失败了,依然直接进入自带的系统,貌似在Uboot中禁用了update模式。我彻底怒了,串口定时每0.1秒发送enter,中断Uboot启动。修改Uboot的环境变量,将重启模式改为升级模式</p>
<figure class="highlight apache"><table><tr><td class="code"><pre><span class="line"><span class="attribute"><span class="nomarkup">setenv</span></span> reboot_mode update</span><br></pre></td></tr></table></figure>
<p>断电重启,这一次不用中断Uboot,等他自然进入系统,然后输入</p>
<figure class="highlight ebnf"><table><tr><td class="code"><pre><span class="line"><span class="attribute">reboot update</span></span><br></pre></td></tr></table></figure>
<p>串口输出变了,这一次终于可以从TF卡启动进入AlexELEC了,赶紧插上网线,然后尝试SSH登陆。。。哎呀,root密码不知道啊。接上键盘、显示器在AlexELEC设置中直接更改SSH的密码。(因为AlexELEC是毛子做的系统,默认语言是俄文,需要先改字体为Arial,再改语言为Chinese,别问我怎么看懂的,Kodi我玩的熟了,闭着眼都能改语言)</p>
<h1 id="安装AlexELEC系统到内置NAND"><a href="#安装AlexELEC系统到内置NAND" class="headerlink" title="安装AlexELEC系统到内置NAND"></a>安装AlexELEC系统到内置NAND</h1><p>简单测试一下,wifi正常,RAM、ROM容量识别正常,HDMI输出正常,声音正常,红外遥控器的大部分按键正常(数字键和方向键正常,但是也有些按键,比如确认键和音量键的映射不正常)。遥控器的问题不大,可以慢慢调整配置文件。总之,系统完全工作正常,把TF卡中的系统安装到NAND闪存中,SSH控制台中输入</p>
<figure class="highlight ebnf"><table><tr><td class="code"><pre><span class="line"><span class="attribute">installtointernal</span></span><br></pre></td></tr></table></figure>
<p>一路输入yes,完成安装。安装完成之后,关机</p>
<figure class="highlight ebnf"><table><tr><td class="code"><pre><span class="line"><span class="attribute">poweroff</span></span><br></pre></td></tr></table></figure>
<p>拔出TF卡,断电后再重新上电,成功进入AlexELEC,到此为止成功安装AlexELEC系统到内置NAND。</p>
<h1 id="Kodi中配置PVR直播电视"><a href="#Kodi中配置PVR直播电视" class="headerlink" title="Kodi中配置PVR直播电视"></a>Kodi中配置PVR直播电视</h1><p>启用IPTV Simple PVR Client插件(默认禁用)并配置IPTV Simple PVR Client。</p>
<ul>
<li>找到了一个<del>可靠的</del>有点慢的<a target="_blank" rel="noopener" href="https://github.com/BurningC4/Chinese-IPTV">直播源</a>(包含CCTV+地方卫视),(更新:<a target="_blank" rel="noopener" href="https://raw.githubusercontent.com/wuxiaoxiong1990/IPTVsource/master/ipv4.m3u">可靠的直播源</a>),可以直接填入IPTV Simple PVR Client的设置。</li>
<li>更改IPTV Simple PVR Client的设置,每次切换频道无需按确认键,还原老式电视的操作方式</li>
<li>Kodi的用户设置中,启动时自动打开PVR,再也不要担心妈妈不会调</li>
</ul>
<h1 id="调教红外遥控器"><a href="#调教红外遥控器" class="headerlink" title="调教红外遥控器"></a>调教红外遥控器</h1><p>真的是走了很多弯路,之前用过树莓派的红外线,以为是差不多的,犯了思维定势的错误。新版的LibreELEC已经支持amremote从系统底层接管红外了,AlexELEC当然也跟上了。忘记lirc和meson-ir吧,记录红外按键也不是用ir-keytable了,因为根本没有/dev/lirc0这个设备了,取而代之的是<code>/dev/amremote</code>。<br>amremote一听名字就知道是Amlogic平台的遥控器驱动,它的作用是将红外编码直接映射为键盘上的按键,所以不需要在Kodi中额外配置红外遥控器,更不需要通过keymap editor来重新设置键盘映射!amremote的工作流程是将遥控器的的红外编码(ircode)对应成key code,再触发key code代表的键盘按键。ircode与key code的对应关系在配置文件<code>/storage/.config/amremote/remote.conf</code>中(也就是我们之前在原厂固件中保存的那个),key code与键盘按键的对应关系在<code>/storage/.config/amremote/Config_key.sample</code>中(这个只是说明文件,不可更改,对应关系已经编译进驱动了)。下面记录一下如何完成一个遥控器的适配,或者说自定义。<br>首先停止kodi,不然kodi会产生许多我们不需要的内核调试信息,干扰我们调试</p>
<figure class="highlight arduino"><table><tr><td class="code"><pre><span class="line">systemctl <span class="built_in">stop</span> kodi</span><br></pre></td></tr></table></figure>
<p>在测试遥控器按键前,丢弃我们不想要的之前的内核日志</p>
<figure class="highlight ebnf"><table><tr><td class="code"><pre><span class="line"><span class="attribute">dmesg -c</span></span><br></pre></td></tr></table></figure>
<p>下面可以冲着盒子按下你想要更改的遥控器的按键,按一个按键一次,尽量手速加快,按一下就松手(不然就和我下面的图里一样,接收到多个红外编码),接着你就可以在内核日志中看到红外编码ircode</p>
<figure class="highlight ebnf"><table><tr><td class="code"><pre><span class="line"><span class="attribute">dmesg -c</span></span><br></pre></td></tr></table></figure>
<p>比如我按下遥控器上红色的按钮,输出了以下内核日志<br><img src= "/img/loading.gif" data-lazy-src="B760HV2_ircode.png" alt="B760HV2_ircode"><br>图中的0x0e就是ircode<br>下面就在<code>remote.conf</code>寻找ircode对应的key code,有两种情况,一种是配置文件里面已经有这个按键的ircode了,你需要更改后面的key code;另一种是没有对应的ircode,你需要自己添加。然后key code是你要去<code>Config_key.sample</code>查找你想要的按键。<br>以上面的例子ircode=0x0e为例,在<code>remote.conf</code>中寻找这个ircode<br><img src= "/img/loading.gif" data-lazy-src="B760HV2_keycode.png" alt="B760HV2_keycode"><br>可以看到在我这个配置文件中红外编码(ircode)0xe被映射成了key code为0x18e的按键,那么这个按键到底是什么呢?我们可以进<code>Config_key.sample</code>查找<br><img src= "/img/loading.gif" data-lazy-src="B760HV2_key.png" alt="B760HV2_key"><br>可以看到已经正确对应到红色按键了,所以这个按键不用修改。如果你想把这个红外按键对应到别的键盘按键,就需要在<code>Config_key.sample</code>查找对应的key code,替换掉<code>remote.conf</code>中的0x18e这个key code。<br>全部按键修改完成后用以下命令即时生效</p>
<figure class="highlight basic"><table><tr><td class="code"><pre><span class="line"><span class="comment">remotecfg /storage/.config/amremote/remote.conf</span></span><br></pre></td></tr></table></figure>
<p>然后可以在kodi里面测试</p>
<figure class="highlight crmsh"><table><tr><td class="code"><pre><span class="line">systemctl <span class="literal">start</span> kodi</span><br></pre></td></tr></table></figure>
<p>下面是我最终修改过的<code>remote.conf</code>,大部分按键我都按照按键上面的中文意思,对应了相近的实体按键。<br><a href="remote.conf">下载remote.conf</a></p>
<h1 id="曲线救国实现Autossh"><a href="#曲线救国实现Autossh" class="headerlink" title="曲线救国实现Autossh"></a>曲线救国实现Autossh</h1><p>万一哪天直播源失效了,丈母娘看不了电视,我的高大形象毁于一旦。所以给自己留个后门,便于远程维护。首先想到的就是AutoSSH维持远程反向连接通道,可惜AlexELEC没有AutoSSH,也没有软件包管理器,不能安装软件。但是可以用Systemd托管SSH呀。</p>
<ul>
<li>先配置公网远程服务器</li>
</ul>
<p>修改公网服务器的SSH配置文件<code>/etc/ssh/sshd_config</code> </p>
<figure class="highlight nginx"><table><tr><td class="code"><pre><span class="line"><span class="attribute">GatewayPorts</span> <span class="literal">yes</span></span><br></pre></td></tr></table></figure>
<p>这样可以把监听的端口绑定到任意IP 0.0.0.0上,否则只有本机127.0.0.1可以访问。<br>记得重启SSH服务器</p>
<figure class="highlight routeros"><table><tr><td class="code"><pre><span class="line">sudo<span class="built_in"> service </span>restart sshd</span><br></pre></td></tr></table></figure>
<ul>
<li>电视盒子上生成密钥</li>
</ul>
<figure class="highlight awk"><table><tr><td class="code"><pre><span class="line">ssh-keygen -t rsa -f <span class="regexp">/storage/</span>.ssh/id_rsa</span><br></pre></td></tr></table></figure>
<ul>
<li>将电视盒子密钥添加到公网远程服务器</li>
</ul>
<figure class="highlight awk"><table><tr><td class="code"><pre><span class="line">cat <span class="regexp">/storage/</span>.ssh<span class="regexp">/id_rsa.pub | ssh 远程用户名@远程服务器地址 'cat >> .ssh/</span>authorized_keys<span class="string">'</span></span><br></pre></td></tr></table></figure>
<ul>
<li>测试</li>
</ul>
<figure class="highlight css"><table><tr><td class="code"><pre><span class="line"><span class="selector-tag">ssh</span> <span class="selector-tag">-NTR</span> <span class="selector-attr">[远程映射端口]</span><span class="selector-pseudo">:localhost</span><span class="selector-pseudo">:22</span> 远程用户名@远程服务器地址 -o ExitOnForwardFailure=yes</span><br></pre></td></tr></table></figure>
<p>然后直接ssh连接远程服务器的远程映射端口就可以连上电视盒子了。</p>
<ul>
<li>编写serivce文件</li>
</ul>
<p>用你喜欢的文本编辑器,编辑<code>/storage/.config/system.d/autossh.service</code></p>
<figure class="highlight ini"><table><tr><td class="code"><pre><span class="line"><span class="section">[Unit]</span></span><br><span class="line"><span class="attr">Description</span>=SSH Tunnel</span><br><span class="line"><span class="attr">After</span>=network.target</span><br><span class="line"></span><br><span class="line"><span class="section">[Service]</span></span><br><span class="line"><span class="attr">Restart</span>=always</span><br><span class="line"><span class="attr">RestartSec</span>=<span class="number">5</span></span><br><span class="line"><span class="attr">User</span>=root</span><br><span class="line"><span class="attr">ExecStart</span>=/bin/ssh -NTR [远程映射端口]:localhost:<span class="number">22</span> 远程用户名@远程服务器地址 -o ExitOnForwardFailure=<span class="literal">yes</span></span><br><span class="line"></span><br><span class="line"><span class="section">[Install]</span></span><br><span class="line"><span class="attr">WantedBy</span>=multi-user.target</span><br></pre></td></tr></table></figure>
<p>启用这个服务,下次开机自动启动</p>
<figure class="highlight routeros"><table><tr><td class="code"><pre><span class="line">systemctl <span class="builtin-name">enable</span> autossh.service</span><br></pre></td></tr></table></figure>
<h1 id="加散热片和改内置WiFi天线"><a href="#加散热片和改内置WiFi天线" class="headerlink" title="加散热片和改内置WiFi天线"></a>加散热片和改内置WiFi天线</h1><p>图片丢了,就不贴了。焊了一个号称5DB的内置PCB天线效果,效果非常不好,后来还是改用了USB无线网卡。<br>到此功能全部实现,折腾结束</p>
]]></content>
</entry>
<entry>
<title>利用ESPHome自制万能遥控器</title>
<url>/2022/03/06/ESPHome-IRomte/</url>
<content><![CDATA[<p>最近捣鼓智能家居,用ESP32/ESP8266控制家里传统红外遥控的空调。其他红外的机顶盒、电视盒子也同理。</p>
<h1 id="硬件与软件准备工作"><a href="#硬件与软件准备工作" class="headerlink" title="硬件与软件准备工作"></a>硬件与软件准备工作</h1><table>
<thead>
<tr>
<th align="left">硬件</th>
<th align="right">软件</th>
</tr>
</thead>
<tbody><tr>
<td align="left">ESP32</td>
<td align="right">ESPHome v2022.2.1</td>
</tr>
<tr>
<td align="left">NAS/软路由</td>
<td align="right">Homeassistant 2021.11.4</td>
</tr>
<tr>
<td align="left">5mm红外发射头(940nm)</td>
<td align="right"></td>
</tr>
<tr>
<td align="left">红外接收头(型号随意)</td>
<td align="right"></td>
</tr>
</tbody></table>
<p><img src= "/img/loading.gif" data-lazy-src="IR-rx.png" alt="IR_RX"><br><img src= "/img/loading.gif" data-lazy-src="IR_tx.png" alt="IR_TX"><br>红外发射和接受按照上面电路连接,红外发射头由ESP32的GPIO27控制,红外接收头由GPIO14输入。</p>
<h1 id="红外接收与遥控器学习"><a href="#红外接收与遥控器学习" class="headerlink" title="红外接收与遥控器学习"></a>红外接收与遥控器学习</h1><p>详细参见<a target="_blank" rel="noopener" href="https://esphome.io/components/remote_receiver.html">ESPHome的Remote Receiver章节</a>,下面粘贴我的ESPHome的编译配置yaml。</p>
<figure class="highlight yaml"><table><tr><td class="code"><pre><span class="line"><span class="attr">esphome:</span></span><br><span class="line"> <span class="attr">name:</span> <span class="string">esp32</span></span><br><span class="line"></span><br><span class="line"><span class="attr">esp32:</span></span><br><span class="line"> <span class="attr">board:</span> <span class="string">esp32dev</span></span><br><span class="line"> <span class="attr">framework:</span></span><br><span class="line"> <span class="attr">type:</span> <span class="string">esp-idf</span></span><br><span class="line"> <span class="attr">version:</span> <span class="string">latest</span></span><br><span class="line"> <span class="comment"># Custom sdkconfig options</span></span><br><span class="line"> <span class="attr">sdkconfig_options:</span></span><br><span class="line"> <span class="attr">CONFIG_COMPILER_OPTIMIZATION_SIZE:</span> <span class="string">y</span></span><br><span class="line"> <span class="comment"># Advanced tweaking options</span></span><br><span class="line"> <span class="attr">advanced:</span></span><br><span class="line"> <span class="attr">ignore_efuse_mac_crc:</span> <span class="literal">false</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Enable logging</span></span><br><span class="line"><span class="attr">logger:</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Enable Home Assistant API</span></span><br><span class="line"><span class="attr">api:</span></span><br><span class="line"></span><br><span class="line"><span class="attr">ota:</span></span><br><span class="line"> <span class="attr">password:</span> <span class="string">""</span></span><br><span class="line"></span><br><span class="line"><span class="attr">wifi:</span></span><br><span class="line"> <span class="attr">ssid:</span> <span class="type">!secret</span> <span class="string">wifi_ssid</span></span><br><span class="line"> <span class="attr">password:</span> <span class="type">!secret</span> <span class="string">wifi_password</span></span><br><span class="line"></span><br><span class="line"><span class="attr">remote_receiver:</span></span><br><span class="line"> <span class="attr">pin:</span> </span><br><span class="line"> <span class="attr">number:</span> <span class="string">GPIO14</span></span><br><span class="line"> <span class="attr">inverted:</span> <span class="literal">True</span></span><br><span class="line"> <span class="attr">dump:</span> <span class="string">raw</span></span><br><span class="line"> <span class="attr">tolerance:</span> </span><br><span class="line"> <span class="attr">type:</span> <span class="string">percentage</span></span><br><span class="line"> <span class="attr">value:</span> <span class="number">70</span><span class="string">%</span></span><br><span class="line"> <span class="attr">idle:</span> <span class="string">50ms</span></span><br></pre></td></tr></table></figure>
<p>这里说明一下官方文档没有详细说明的地方:</p>
<ol>
<li>在<code>remote_receiver:</code>中<code>inverted: True</code>目的是设置电平反转,我一开始忽略了,获取的红外编码正好是反的,一堆乱七八糟。后来发现ESPHome在开机的logs中对我发出警告和建议,我才知道要设置这个。</li>
<li>在<code>remote_receiver:</code>中<code>dump: raw</code>的目的是接收到的所有红外编码一律不解析,按照raw格式记录。dump的可选类型很多,其中nec编码据说是使用类型最广泛的红外编码,兼容90%以上的电器。但是我觉得事实并不是这样,不然ESPHome就不会还有其他那么多其他类型可以选择了。千万不要选择<code>all</code>类型,这样一段红外编码可能会被错误得尝试解析成各种类型,非常糟糕。</li>
<li>在<code>remote_receiver:</code>中<code>idle: 50ms</code>非常重要,你可以理解为红外信号的超时等待时间。在一些私有协议的红外编码中(比如我家的格力空调),一条指令有可能里面的某段红外代码之间间隔比较长,会被ESPHome识别为两段甚至是多段单独的红外代码。将idle值设当设置偏大可以规避这个问题。<br>编译固件并上传到ESP32,打开logs,然后你就可以对准红外接收头,按下你想要学习的按键,比如以下是我抓取到的日志。<figure class="highlight angelscript"><table><tr><td class="code"><pre><span class="line">INFO Reading configuration /config/esp32.yaml...</span><br><span class="line">INFO Starting log output <span class="keyword">from</span> esp32.local using esphome API</span><br><span class="line">INFO Successfully connected to esp32.local</span><br><span class="line">[<span class="number">21</span>:<span class="number">03</span>:<span class="number">57</span>][I][app:<span class="number">102</span>]: ESPHome version <span class="number">2022.2</span><span class="number">.4</span> compiled on Mar <span class="number">5</span> <span class="number">2022</span>, <span class="number">20</span>:<span class="number">52</span>:<span class="number">27</span></span><br><span class="line">[<span class="number">21</span>:<span class="number">03</span>:<span class="number">58</span>][C][wifi:<span class="number">491</span>]: WiFi:</span><br><span class="line">[<span class="number">21</span>:<span class="number">03</span>:<span class="number">58</span>][C][wifi:<span class="number">353</span>]: Local MAC: <span class="number">78</span>:E3:<span class="number">6</span>D:<span class="number">19</span>:<span class="number">11</span>:C4</span><br><span class="line">[<span class="number">21</span>:<span class="number">03</span>:<span class="number">58</span>][C][wifi:<span class="number">354</span>]: SSID: <span class="string">'GECOOS'</span>[redacted]</span><br><span class="line">[<span class="number">21</span>:<span class="number">03</span>:<span class="number">58</span>][C][wifi:<span class="number">355</span>]: IP Address: <span class="number">192.168</span><span class="number">.0</span><span class="number">.178</span></span><br><span class="line">[<span class="number">21</span>:<span class="number">03</span>:<span class="number">58</span>][C][wifi:<span class="number">357</span>]: BSSID: <span class="number">1</span>C:<span class="number">88</span>:<span class="number">79</span>:<span class="number">5</span>F:E5:E2[redacted]</span><br><span class="line">[<span class="number">21</span>:<span class="number">03</span>:<span class="number">58</span>][C][wifi:<span class="number">358</span>]: Hostname: <span class="string">'esp32'</span></span><br><span class="line">[<span class="number">21</span>:<span class="number">03</span>:<span class="number">58</span>][C][wifi:<span class="number">360</span>]: Signal strength: <span class="number">-47</span> dB ▂▄▆█</span><br><span class="line">[<span class="number">21</span>:<span class="number">03</span>:<span class="number">58</span>][C][wifi:<span class="number">364</span>]: Channel: <span class="number">6</span></span><br><span class="line">[<span class="number">21</span>:<span class="number">03</span>:<span class="number">58</span>][C][wifi:<span class="number">365</span>]: Subnet: <span class="number">255.255</span><span class="number">.255</span><span class="number">.0</span></span><br><span class="line">[<span class="number">21</span>:<span class="number">03</span>:<span class="number">58</span>][C][wifi:<span class="number">366</span>]: Gateway: <span class="number">192.168</span><span class="number">.0</span><span class="number">.1</span></span><br><span class="line">[<span class="number">21</span>:<span class="number">03</span>:<span class="number">58</span>][C][wifi:<span class="number">367</span>]: DNS1: <span class="number">192.168</span><span class="number">.0</span><span class="number">.1</span></span><br><span class="line">[<span class="number">21</span>:<span class="number">03</span>:<span class="number">58</span>][C][wifi:<span class="number">368</span>]: DNS2: <span class="number">0.0</span><span class="number">.0</span><span class="number">.0</span></span><br><span class="line">[<span class="number">21</span>:<span class="number">03</span>:<span class="number">58</span>][C][logger:<span class="number">233</span>]: Logger:</span><br><span class="line">[<span class="number">21</span>:<span class="number">03</span>:<span class="number">58</span>][C][logger:<span class="number">234</span>]: Level: DEBUG</span><br><span class="line">[<span class="number">21</span>:<span class="number">03</span>:<span class="number">58</span>][C][logger:<span class="number">235</span>]: Log Baud Rate: <span class="number">115200</span></span><br><span class="line">[<span class="number">21</span>:<span class="number">03</span>:<span class="number">58</span>][C][logger:<span class="number">236</span>]: Hardware UART: UART0</span><br><span class="line">[<span class="number">21</span>:<span class="number">03</span>:<span class="number">58</span>][C][remote_receiver.esp32:<span class="number">054</span>]: Remote Receiver:</span><br><span class="line">[<span class="number">21</span>:<span class="number">03</span>:<span class="number">58</span>][C][remote_receiver.esp32:<span class="number">055</span>]: Pin: GPIO14</span><br><span class="line">[<span class="number">21</span>:<span class="number">03</span>:<span class="number">58</span>][C][remote_receiver.esp32:<span class="number">060</span>]: Channel: <span class="number">0</span></span><br><span class="line">[<span class="number">21</span>:<span class="number">03</span>:<span class="number">58</span>][C][remote_receiver.esp32:<span class="number">061</span>]: RMT memory blocks: <span class="number">3</span></span><br><span class="line">[<span class="number">21</span>:<span class="number">03</span>:<span class="number">58</span>][C][remote_receiver.esp32:<span class="number">062</span>]: Clock divider: <span class="number">80</span></span><br><span class="line">[<span class="number">21</span>:<span class="number">03</span>:<span class="number">58</span>][C][remote_receiver.esp32:<span class="number">063</span>]: Tolerance: <span class="number">25</span>%</span><br><span class="line">[<span class="number">21</span>:<span class="number">03</span>:<span class="number">58</span>][C][remote_receiver.esp32:<span class="number">064</span>]: Filter <span class="keyword">out</span> pulses shorter than: <span class="number">50</span> us</span><br><span class="line">[<span class="number">21</span>:<span class="number">03</span>:<span class="number">58</span>][C][remote_receiver.esp32:<span class="number">065</span>]: Signal <span class="keyword">is</span> done after <span class="number">40000</span> us of no changes</span><br><span class="line">[<span class="number">21</span>:<span class="number">03</span>:<span class="number">58</span>][C][mdns:<span class="number">084</span>]: mDNS:</span><br><span class="line">[<span class="number">21</span>:<span class="number">03</span>:<span class="number">58</span>][C][mdns:<span class="number">085</span>]: Hostname: esp32</span><br><span class="line">[<span class="number">21</span>:<span class="number">03</span>:<span class="number">58</span>][C][ota:<span class="number">085</span>]: Over-The-Air Updates:</span><br><span class="line">[<span class="number">21</span>:<span class="number">03</span>:<span class="number">58</span>][C][ota:<span class="number">086</span>]: Address: esp32.local:<span class="number">3232</span></span><br><span class="line">[<span class="number">21</span>:<span class="number">03</span>:<span class="number">58</span>][C][ota:<span class="number">089</span>]: Using Password.</span><br><span class="line">[<span class="number">21</span>:<span class="number">03</span>:<span class="number">58</span>][C][api:<span class="number">138</span>]: API Server:</span><br><span class="line">[<span class="number">21</span>:<span class="number">03</span>:<span class="number">58</span>][C][api:<span class="number">139</span>]: Address: esp32.local:<span class="number">6053</span></span><br><span class="line">[<span class="number">21</span>:<span class="number">03</span>:<span class="number">58</span>][C][api:<span class="number">143</span>]: Using noise encryption: NO</span><br><span class="line">[<span class="number">21</span>:<span class="number">04</span>:<span class="number">13</span>][D][remote.raw:<span class="number">028</span>]: Received Raw: <span class="number">9021</span>, <span class="number">-4476</span>, <span class="number">625</span>, <span class="number">-1666</span>, <span class="number">624</span>, <span class="number">-565</span>, <span class="number">624</span>, <span class="number">-567</span>, <span class="number">625</span>, <span class="number">-567</span>, <span class="number">621</span>, <span class="number">-567</span>, <span class="number">626</span>, <span class="number">-566</span>, <span class="number">622</span>, <span class="number">-1666</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">623</span>, <span class="number">-1666</span>, <span class="number">626</span>, <span class="number">-1691</span>, <span class="number">597</span>, <span class="number">-566</span>, <span class="number">626</span>, <span class="number">-1664</span>, <span class="number">625</span>, <span class="number">-593</span>, <span class="number">597</span>, <span class="number">-566</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">625</span>, <span class="number">-565</span>, <span class="number">624</span>, <span class="number">-565</span>, <span class="number">622</span>, <span class="number">-569</span>, <span class="number">624</span>, <span class="number">-565</span>, <span class="number">625</span>, <span class="number">-565</span>, <span class="number">625</span>, <span class="number">-592</span>, <span class="number">599</span>, <span class="number">-564</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">626</span>, <span class="number">-564</span>, <span class="number">626</span>, <span class="number">-565</span>, <span class="number">625</span>, <span class="number">-566</span>, <span class="number">623</span>, <span class="number">-565</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">624</span>, <span class="number">-1666</span>, <span class="number">625</span>, <span class="number">-565</span>, <span class="number">625</span>, <span class="number">-1665</span>, <span class="number">626</span>, <span class="number">-564</span>, <span class="number">623</span>, <span class="number">-567</span>, <span class="number">624</span>, <span class="number">-1666</span>, <span class="number">623</span>, <span class="number">-567</span>, <span class="number">626</span>, <span class="number">-19983</span>, <span class="number">625</span>, <span class="number">-1665</span>, <span class="number">624</span>, <span class="number">-567</span>, <span class="number">625</span>, <span class="number">-564</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">626</span>, <span class="number">-1664</span>, <span class="number">623</span>, <span class="number">-593</span>, <span class="number">599</span>, <span class="number">-565</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">624</span>, <span class="number">-594</span>, <span class="number">598</span>, <span class="number">-566</span>, <span class="number">622</span>, <span class="number">-567</span>, <span class="number">624</span>, <span class="number">-591</span>, <span class="number">598</span>, <span class="number">-1666</span>, <span class="number">625</span>, <span class="number">-565</span>, <span class="number">623</span>, <span class="number">-567</span>, <span class="number">624</span>, <span class="number">-569</span>, <span class="number">622</span>, <span class="number">-564</span>, <span class="number">625</span>, <span class="number">-568</span>, <span class="number">621</span>, <span class="number">-569</span>, <span class="number">624</span>, <span class="number">-564</span>, <span class="number">623</span>, <span class="number">-567</span>, <span class="number">625</span>, <span class="number">-564</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">623</span>, <span class="number">-568</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">623</span>, <span class="number">-566</span>, <span class="number">626</span>, <span class="number">-566</span>, <span class="number">622</span>, <span class="number">-1666</span>, <span class="number">623</span>, <span class="number">-568</span>, <span class="number">623</span>, <span class="number">-567</span>, <span class="number">624</span>, <span class="number">-1665</span>, <span class="number">624</span>, <span class="number">-7194</span>, <span class="number">9041</span>, <span class="number">-4481</span>, <span class="number">626</span>, <span class="number">-1665</span>, <span class="number">624</span>, <span class="number">-568</span>, <span class="number">621</span>, <span class="number">-566</span>, <span class="number">622</span>, <span class="number">-569</span>, <span class="number">625</span>, <span class="number">-567</span>, <span class="number">622</span>, <span class="number">-568</span>, <span class="number">621</span>, <span class="number">-1668</span>, <span class="number">622</span>, <span class="number">-566</span>, <span class="number">624</span>, <span class="number">-1666</span>, <span class="number">625</span>, <span class="number">-1666</span>, <span class="number">623</span>, <span class="number">-567</span>, <span class="number">625</span>, <span class="number">-1664</span>, <span class="number">623</span>, <span class="number">-594</span>, <span class="number">598</span>, <span class="number">-591</span>, <span class="number">599</span>, <span class="number">-566</span>, <span class="number">621</span>, <span class="number">-595</span>, <span class="number">599</span>, <span class="number">-565</span>, <span class="number">625</span>, <span class="number">-564</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">625</span>, <span class="number">-567</span>, <span class="number">622</span>, <span class="number">-569</span>, <span class="number">622</span>, <span class="number">-565</span>, <span class="number">623</span>, <span class="number">-569</span>, <span class="number">623</span>, <span class="number">-568</span>, <span class="number">622</span>, <span class="number">-567</span>, <span class="number">622</span>, <span class="number">-568</span>, <span class="number">621</span>, <span class="number">-567</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">623</span>, <span class="number">-1669</span>, <span class="number">623</span>, <span class="number">-1692</span>, <span class="number">597</span>, <span class="number">-1666</span>, <span class="number">624</span>, <span class="number">-565</span>, <span class="number">625</span>, <span class="number">-566</span>, <span class="number">624</span>, <span class="number">-1668</span>, <span class="number">622</span>, <span class="number">-565</span>, <span class="number">623</span>, <span class="number">-19985</span>, <span class="number">627</span>, <span class="number">-565</span>, <span class="number">626</span>, <span class="number">-564</span>, <span class="number">626</span>, <span class="number">-565</span>, <span class="number">623</span>, <span class="number">-566</span>, <span class="number">625</span>, <span class="number">-566</span>, <span class="number">623</span>, <span class="number">-593</span>, <span class="number">595</span>, <span class="number">-594</span>, <span class="number">600</span>, <span class="number">-565</span>, <span class="number">622</span>, <span class="number">-593</span>, <span class="number">597</span>, <span class="number">-567</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">623</span>, <span class="number">-567</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">625</span>, <span class="number">-565</span>, <span class="number">625</span>, <span class="number">-565</span>, <span class="number">626</span>, <span class="number">-564</span>, <span class="number">623</span>, <span class="number">-567</span>, <span class="number">623</span>, <span class="number">-567</span>, <span class="number">623</span>, <span class="number">-569</span>, <span class="number">622</span>, <span class="number">-566</span>, <span class="number">622</span>, <span class="number">-568</span>, <span class="number">622</span>, <span class="number">-569</span>, <span class="number">623</span>, <span class="number">-566</span>, <span class="number">623</span>, <span class="number">-567</span>, <span class="number">623</span>, <span class="number">-566</span>, <span class="number">624</span>, <span class="number">-567</span>, <span class="number">623</span>, <span class="number">-566</span>, <span class="number">624</span>, <span class="number">-568</span>, <span class="number">623</span>, <span class="number">-566</span>, <span class="number">622</span>, <span class="number">-1667</span>, <span class="number">625</span>, <span class="number">-1665</span>, <span class="number">623</span>, <span class="number">-594</span>, <span class="number">596</span></span><br><span class="line">[<span class="number">21</span>:<span class="number">04</span>:<span class="number">13</span>][D][remote.raw:<span class="number">041</span>]: Received Raw: <span class="number">81</span></span><br><span class="line">[<span class="number">21</span>:<span class="number">04</span>:<span class="number">13</span>][D][remote.raw:<span class="number">041</span>]: Received Raw: <span class="number">153</span></span><br><span class="line">[<span class="number">21</span>:<span class="number">04</span>:<span class="number">29</span>][D][remote.raw:<span class="number">041</span>]: Received Raw: <span class="number">178</span></span><br><span class="line">[<span class="number">21</span>:<span class="number">04</span>:<span class="number">29</span>][D][remote.raw:<span class="number">028</span>]: Received Raw: <span class="number">9048</span>, <span class="number">-4448</span>, <span class="number">653</span>, <span class="number">-1665</span>, <span class="number">623</span>, <span class="number">-539</span>, <span class="number">653</span>, <span class="number">-537</span>, <span class="number">650</span>, <span class="number">-1668</span>, <span class="number">625</span>, <span class="number">-537</span>, <span class="number">654</span>, <span class="number">-537</span>, <span class="number">650</span>, <span class="number">-1640</span>, <span class="number">650</span>, <span class="number">-539</span>, <span class="number">652</span>, <span class="number">-1639</span>, <span class="number">651</span>, <span class="number">-1638</span>, <span class="number">651</span>, <span class="number">-539</span>, <span class="number">652</span>, <span class="number">-1638</span>, <span class="number">653</span>, <span class="number">-538</span>, <span class="number">651</span>, <span class="number">-539</span>, <span class="number">650</span>, <span class="number">-540</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">650</span>, <span class="number">-539</span>, <span class="number">652</span>, <span class="number">-539</span>, <span class="number">651</span>, <span class="number">-537</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">652</span>, <span class="number">-1638</span>, <span class="number">651</span>, <span class="number">-540</span>, <span class="number">652</span>, <span class="number">-537</span>, <span class="number">653</span>, <span class="number">-538</span>, <span class="number">650</span>, <span class="number">-567</span>, <span class="number">623</span>, <span class="number">-539</span>, <span class="number">651</span>, <span class="number">-539</span>, <span class="number">651</span>, <span class="number">-1639</span>, <span class="number">652</span>, <span class="number">-566</span>, <span class="number">623</span>, <span class="number">-1639</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">653</span>, <span class="number">-537</span>, <span class="number">652</span>, <span class="number">-1638</span>, <span class="number">652</span>, <span class="number">-539</span>, <span class="number">651</span>, <span class="number">-19956</span>, <span class="number">653</span>, <span class="number">-1638</span>, <span class="number">653</span>, <span class="number">-539</span>, <span class="number">652</span>, <span class="number">-536</span>, <span class="number">650</span>, <span class="number">-541</span>, <span class="number">650</span>, <span class="number">-1666</span>, <span class="number">627</span>, <span class="number">-536</span>, <span class="number">654</span>, <span class="number">-536</span>, <span class="number">650</span>, <span class="number">-541</span>, <span class="number">653</span>, <span class="number">-537</span>, <span class="number">650</span>, <span class="number">-539</span>, <span class="number">653</span>, <span class="number">-565</span>, <span class="number">625</span>, <span class="number">-537</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">652</span>, <span class="number">-1638</span>, <span class="number">652</span>, <span class="number">-540</span>, <span class="number">650</span>, <span class="number">-541</span>, <span class="number">649</span>, <span class="number">-565</span>, <span class="number">625</span>, <span class="number">-566</span>, <span class="number">624</span>, <span class="number">-538</span>, <span class="number">651</span>, <span class="number">-539</span>, <span class="number">651</span>, <span class="number">-539</span>, <span class="number">653</span>, <span class="number">-537</span>, <span class="number">652</span>, <span class="number">-565</span>, <span class="number">624</span>, <span class="number">-539</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">652</span>, <span class="number">-539</span>, <span class="number">649</span>, <span class="number">-539</span>, <span class="number">653</span>, <span class="number">-564</span>, <span class="number">625</span>, <span class="number">-1639</span>, <span class="number">652</span>, <span class="number">-539</span>, <span class="number">650</span>, <span class="number">-539</span>, <span class="number">652</span>, <span class="number">-565</span>, <span class="number">625</span>, <span class="number">-7187</span>, <span class="number">9047</span>, <span class="number">-4453</span>, <span class="number">653</span>, <span class="number">-1640</span>, <span class="number">649</span>, <span class="number">-566</span>, <span class="number">625</span>, <span class="number">-540</span>, <span class="number">651</span>, <span class="number">-1637</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">651</span>, <span class="number">-539</span>, <span class="number">651</span>, <span class="number">-1638</span>, <span class="number">653</span>, <span class="number">-538</span>, <span class="number">650</span>, <span class="number">-1640</span>, <span class="number">651</span>, <span class="number">-1640</span>, <span class="number">652</span>, <span class="number">-537</span>, <span class="number">652</span>, <span class="number">-1637</span>, <span class="number">653</span>, <span class="number">-537</span>, <span class="number">652</span>, <span class="number">-541</span>, <span class="number">649</span>, <span class="number">-538</span>, <span class="number">653</span>, <span class="number">-538</span>, <span class="number">652</span>, <span class="number">-540</span>, <span class="number">649</span>, <span class="number">-565</span>, <span class="number">626</span>, <span class="number">-539</span>, <span class="number">651</span>, <span class="number">-539</span>, <span class="number">653</span>, <span class="number">-537</span>, <span class="number">652</span>, <span class="number">-1637</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">653</span>, <span class="number">-537</span>, <span class="number">652</span>, <span class="number">-565</span>, <span class="number">625</span>, <span class="number">-564</span>, <span class="number">627</span>, <span class="number">-537</span>, <span class="number">653</span>, <span class="number">-537</span>, <span class="number">652</span>, <span class="number">-1664</span>, <span class="number">627</span>, <span class="number">-1636</span>, <span class="number">653</span>, <span class="number">-1637</span>, <span class="number">654</span>, <span class="number">-563</span>, <span class="number">626</span>, <span class="number">-538</span>, <span class="number">653</span>, <span class="number">-1637</span>, <span class="number">653</span>, <span class="number">-537</span>, <span class="number">651</span>, <span class="number">-19956</span>, <span class="number">653</span>, <span class="number">-539</span>, <span class="number">654</span>, <span class="number">-537</span>, <span class="number">650</span>, <span class="number">-566</span>, <span class="number">625</span>, <span class="number">-538</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">654</span>, <span class="number">-536</span>, <span class="number">651</span>, <span class="number">-539</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">653</span>, <span class="number">-564</span>, <span class="number">624</span>, <span class="number">-539</span>, <span class="number">651</span>, <span class="number">-539</span>, <span class="number">651</span>, <span class="number">-539</span>, <span class="number">651</span>, <span class="number">-538</span>, <span class="number">651</span>, <span class="number">-540</span>, <span class="number">651</span>, <span class="number">-538</span>, <span class="number">653</span>, <span class="number">-538</span>, <span class="number">652</span>, <span class="number">-537</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">652</span>, <span class="number">-565</span>, <span class="number">624</span>, <span class="number">-567</span>, <span class="number">625</span>, <span class="number">-538</span>, <span class="number">653</span>, <span class="number">-562</span>, <span class="number">626</span>, <span class="number">-538</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">651</span>, <span class="number">-540</span>, <span class="number">651</span>, <span class="number">-538</span>, <span class="number">654</span>, <span class="number">-536</span>, <span class="number">653</span>, <span class="number">-537</span>, <span class="number">651</span>, <span class="number">-1665</span>, <span class="number">627</span>, <span class="number">-1637</span>, <span class="number">652</span>, <span class="number">-1638</span>, <span class="number">652</span></span><br><span class="line">[<span class="number">21</span>:<span class="number">04</span>:<span class="number">29</span>][D][remote.raw:<span class="number">041</span>]: Received Raw: <span class="number">132</span></span><br></pre></td></tr></table></figure>
我按了一个关闭空调和打开空调制冷的按钮,可以看到学习到了两段红外代码。要注意,有时候一段红外代码显示不完,ESPHome会把一段红外代码分成多条不同时间戳的log,大家不要以时间戳作为分开红外指令的标准,而是以一个<code>Received Raw:</code>字样到下一个<code>Received Raw:</code>之间的数字数组作为一条完整的红外代码。可以看到我的日志里面还有很多干扰的红外代码,这是由于我的供电不稳定导致的,可以忽略。</li>
</ol>
<h1 id="红外发射与Home-Assistant控制"><a href="#红外发射与Home-Assistant控制" class="headerlink" title="红外发射与Home Assistant控制"></a>红外发射与Home Assistant控制</h1><p>详细参见<a target="_blank" rel="noopener" href="https://esphome.io/components/remote_transmitter.html">ESPHome的Remote Transmitter章节</a><br>废话不说,直接上ESPHome的编译yaml文件。</p>
<figure class="highlight yaml"><table><tr><td class="code"><pre><span class="line"><span class="attr">esphome:</span></span><br><span class="line"> <span class="attr">name:</span> <span class="string">esp32</span></span><br><span class="line"></span><br><span class="line"><span class="attr">esp32:</span></span><br><span class="line"> <span class="attr">board:</span> <span class="string">esp32dev</span></span><br><span class="line"> <span class="attr">framework:</span></span><br><span class="line"> <span class="attr">type:</span> <span class="string">esp-idf</span></span><br><span class="line"> <span class="attr">version:</span> <span class="string">latest</span></span><br><span class="line"> <span class="comment"># Custom sdkconfig options</span></span><br><span class="line"> <span class="attr">sdkconfig_options:</span></span><br><span class="line"> <span class="attr">CONFIG_COMPILER_OPTIMIZATION_SIZE:</span> <span class="string">y</span></span><br><span class="line"> <span class="comment"># Advanced tweaking options</span></span><br><span class="line"> <span class="attr">advanced:</span></span><br><span class="line"> <span class="attr">ignore_efuse_mac_crc:</span> <span class="literal">false</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Enable logging</span></span><br><span class="line"><span class="attr">logger:</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Enable Home Assistant API</span></span><br><span class="line"><span class="attr">api:</span></span><br><span class="line"></span><br><span class="line"><span class="attr">ota:</span></span><br><span class="line"> <span class="attr">password:</span> <span class="string">""</span></span><br><span class="line"></span><br><span class="line"><span class="attr">wifi:</span></span><br><span class="line"> <span class="attr">ssid:</span> <span class="type">!secret</span> <span class="string">wifi_ssid</span></span><br><span class="line"> <span class="attr">password:</span> <span class="type">!secret</span> <span class="string">wifi_password</span></span><br><span class="line"></span><br><span class="line"><span class="attr">remote_receiver:</span></span><br><span class="line"> <span class="attr">pin:</span> </span><br><span class="line"> <span class="attr">number:</span> <span class="string">GPIO14</span></span><br><span class="line"> <span class="attr">inverted:</span> <span class="literal">True</span></span><br><span class="line"> <span class="attr">dump:</span> <span class="string">raw</span></span><br><span class="line"> <span class="attr">tolerance:</span> </span><br><span class="line"> <span class="attr">type:</span> <span class="string">percentage</span></span><br><span class="line"> <span class="attr">value:</span> <span class="number">70</span><span class="string">%</span></span><br><span class="line"> <span class="attr">idle:</span> <span class="string">50ms</span></span><br><span class="line"></span><br><span class="line"> <span class="attr">remote_transmitter:</span></span><br><span class="line"> <span class="attr">pin:</span> </span><br><span class="line"> <span class="attr">number:</span> <span class="string">GPIO27</span></span><br><span class="line"> <span class="attr">carrier_duty_percent:</span> <span class="number">50</span><span class="string">%</span></span><br><span class="line"></span><br><span class="line"> <span class="attr">switch:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">platform:</span> <span class="string">template</span></span><br><span class="line"> <span class="attr">name:</span> <span class="string">"BedRoom AC Switch"</span></span><br><span class="line"> <span class="attr">id:</span> <span class="string">esp32_ac_swi</span></span><br><span class="line"> <span class="attr">turn_on_action:</span></span><br><span class="line"> <span class="attr">then:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">switch.template.publish:</span></span><br><span class="line"> <span class="attr">id:</span> <span class="string">esp32_ac_swi</span></span><br><span class="line"> <span class="attr">state:</span> <span class="string">ON</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">remote_transmitter.transmit_raw:</span></span><br><span class="line"> <span class="attr">carrier_frequency:</span> <span class="string">38kHz</span></span><br><span class="line"> <span class="attr">code:</span> [<span class="number">9048</span>, <span class="number">-4448</span>, <span class="number">653</span>, <span class="number">-1665</span>, <span class="number">623</span>, <span class="number">-539</span>, <span class="number">653</span>, <span class="number">-537</span>, <span class="number">650</span>, <span class="number">-1668</span>, <span class="number">625</span>, <span class="number">-537</span>, <span class="number">654</span>, <span class="number">-537</span>, <span class="number">650</span>, <span class="number">-1640</span>, <span class="number">650</span>, <span class="number">-539</span>, <span class="number">652</span>, <span class="number">-1639</span>, <span class="number">651</span>, <span class="number">-1638</span>, <span class="number">651</span>, <span class="number">-539</span>, <span class="number">652</span>, <span class="number">-1638</span>, <span class="number">653</span>, <span class="number">-538</span>, <span class="number">651</span>, <span class="number">-539</span>, <span class="number">650</span>, <span class="number">-540</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">650</span>, <span class="number">-539</span>, <span class="number">652</span>, <span class="number">-539</span>, <span class="number">651</span>, <span class="number">-537</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">652</span>, <span class="number">-1638</span>, <span class="number">651</span>, <span class="number">-540</span>, <span class="number">652</span>, <span class="number">-537</span>, <span class="number">653</span>, <span class="number">-538</span>, <span class="number">650</span>, <span class="number">-567</span>, <span class="number">623</span>, <span class="number">-539</span>, <span class="number">651</span>, <span class="number">-539</span>, <span class="number">651</span>, <span class="number">-1639</span>, <span class="number">652</span>, <span class="number">-566</span>, <span class="number">623</span>, <span class="number">-1639</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">653</span>, <span class="number">-537</span>, <span class="number">652</span>, <span class="number">-1638</span>, <span class="number">652</span>, <span class="number">-539</span>, <span class="number">651</span>, <span class="number">-19956</span>, <span class="number">653</span>, <span class="number">-1638</span>, <span class="number">653</span>, <span class="number">-539</span>, <span class="number">652</span>, <span class="number">-536</span>, <span class="number">650</span>, <span class="number">-541</span>, <span class="number">650</span>, <span class="number">-1666</span>, <span class="number">627</span>, <span class="number">-536</span>, <span class="number">654</span>, <span class="number">-536</span>, <span class="number">650</span>, <span class="number">-541</span>, <span class="number">653</span>, <span class="number">-537</span>, <span class="number">650</span>, <span class="number">-539</span>, <span class="number">653</span>, <span class="number">-565</span>, <span class="number">625</span>, <span class="number">-537</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">652</span>, <span class="number">-1638</span>, <span class="number">652</span>, <span class="number">-540</span>, <span class="number">650</span>, <span class="number">-541</span>, <span class="number">649</span>, <span class="number">-565</span>, <span class="number">625</span>, <span class="number">-566</span>, <span class="number">624</span>, <span class="number">-538</span>, <span class="number">651</span>, <span class="number">-539</span>, <span class="number">651</span>, <span class="number">-539</span>, <span class="number">653</span>, <span class="number">-537</span>, <span class="number">652</span>, <span class="number">-565</span>, <span class="number">624</span>, <span class="number">-539</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">652</span>, <span class="number">-539</span>, <span class="number">649</span>, <span class="number">-539</span>, <span class="number">653</span>, <span class="number">-564</span>, <span class="number">625</span>, <span class="number">-1639</span>, <span class="number">652</span>, <span class="number">-539</span>, <span class="number">650</span>, <span class="number">-539</span>, <span class="number">652</span>, <span class="number">-565</span>, <span class="number">625</span>, <span class="number">-7187</span>, <span class="number">9047</span>, <span class="number">-4453</span>, <span class="number">653</span>, <span class="number">-1640</span>, <span class="number">649</span>, <span class="number">-566</span>, <span class="number">625</span>, <span class="number">-540</span>, <span class="number">651</span>, <span class="number">-1637</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">651</span>, <span class="number">-539</span>, <span class="number">651</span>, <span class="number">-1638</span>, <span class="number">653</span>, <span class="number">-538</span>, <span class="number">650</span>, <span class="number">-1640</span>, <span class="number">651</span>, <span class="number">-1640</span>, <span class="number">652</span>, <span class="number">-537</span>, <span class="number">652</span>, <span class="number">-1637</span>, <span class="number">653</span>, <span class="number">-537</span>, <span class="number">652</span>, <span class="number">-541</span>, <span class="number">649</span>, <span class="number">-538</span>, <span class="number">653</span>, <span class="number">-538</span>, <span class="number">652</span>, <span class="number">-540</span>, <span class="number">649</span>, <span class="number">-565</span>, <span class="number">626</span>, <span class="number">-539</span>, <span class="number">651</span>, <span class="number">-539</span>, <span class="number">653</span>, <span class="number">-537</span>, <span class="number">652</span>, <span class="number">-1637</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">653</span>, <span class="number">-537</span>, <span class="number">652</span>, <span class="number">-565</span>, <span class="number">625</span>, <span class="number">-564</span>, <span class="number">627</span>, <span class="number">-537</span>, <span class="number">653</span>, <span class="number">-537</span>, <span class="number">652</span>, <span class="number">-1664</span>, <span class="number">627</span>, <span class="number">-1636</span>, <span class="number">653</span>, <span class="number">-1637</span>, <span class="number">654</span>, <span class="number">-563</span>, <span class="number">626</span>, <span class="number">-538</span>, <span class="number">653</span>, <span class="number">-1637</span>, <span class="number">653</span>, <span class="number">-537</span>, <span class="number">651</span>, <span class="number">-19956</span>, <span class="number">653</span>, <span class="number">-539</span>, <span class="number">654</span>, <span class="number">-537</span>, <span class="number">650</span>, <span class="number">-566</span>, <span class="number">625</span>, <span class="number">-538</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">654</span>, <span class="number">-536</span>, <span class="number">651</span>, <span class="number">-539</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">653</span>, <span class="number">-564</span>, <span class="number">624</span>, <span class="number">-539</span>, <span class="number">651</span>, <span class="number">-539</span>, <span class="number">651</span>, <span class="number">-539</span>, <span class="number">651</span>, <span class="number">-538</span>, <span class="number">651</span>, <span class="number">-540</span>, <span class="number">651</span>, <span class="number">-538</span>, <span class="number">653</span>, <span class="number">-538</span>, <span class="number">652</span>, <span class="number">-537</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">652</span>, <span class="number">-565</span>, <span class="number">624</span>, <span class="number">-567</span>, <span class="number">625</span>, <span class="number">-538</span>, <span class="number">653</span>, <span class="number">-562</span>, <span class="number">626</span>, <span class="number">-538</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">651</span>, <span class="number">-540</span>, <span class="number">651</span>, <span class="number">-538</span>, <span class="number">654</span>, <span class="number">-536</span>, <span class="number">653</span>, <span class="number">-537</span>, <span class="number">651</span>, <span class="number">-1665</span>, <span class="number">627</span>, <span class="number">-1637</span>, <span class="number">652</span>, <span class="number">-1638</span>, <span class="number">652</span>]</span><br><span class="line"></span><br><span class="line"> <span class="attr">turn_off_action:</span></span><br><span class="line"> <span class="attr">then:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">switch.template.publish:</span></span><br><span class="line"> <span class="attr">id:</span> <span class="string">esp32_ac_swi</span></span><br><span class="line"> <span class="attr">state:</span> <span class="string">OFF</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">remote_transmitter.transmit_raw:</span></span><br><span class="line"> <span class="attr">carrier_frequency:</span> <span class="string">38kHz</span></span><br><span class="line"> <span class="attr">code:</span> [<span class="number">9021</span>, <span class="number">-4476</span>, <span class="number">625</span>, <span class="number">-1666</span>, <span class="number">624</span>, <span class="number">-565</span>, <span class="number">624</span>, <span class="number">-567</span>, <span class="number">625</span>, <span class="number">-567</span>, <span class="number">621</span>, <span class="number">-567</span>, <span class="number">626</span>, <span class="number">-566</span>, <span class="number">622</span>, <span class="number">-1666</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">623</span>, <span class="number">-1666</span>, <span class="number">626</span>, <span class="number">-1691</span>, <span class="number">597</span>, <span class="number">-566</span>, <span class="number">626</span>, <span class="number">-1664</span>, <span class="number">625</span>, <span class="number">-593</span>, <span class="number">597</span>, <span class="number">-566</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">625</span>, <span class="number">-565</span>, <span class="number">624</span>, <span class="number">-565</span>, <span class="number">622</span>, <span class="number">-569</span>, <span class="number">624</span>, <span class="number">-565</span>, <span class="number">625</span>, <span class="number">-565</span>, <span class="number">625</span>, <span class="number">-592</span>, <span class="number">599</span>, <span class="number">-564</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">626</span>, <span class="number">-564</span>, <span class="number">626</span>, <span class="number">-565</span>, <span class="number">625</span>, <span class="number">-566</span>, <span class="number">623</span>, <span class="number">-565</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">624</span>, <span class="number">-1666</span>, <span class="number">625</span>, <span class="number">-565</span>, <span class="number">625</span>, <span class="number">-1665</span>, <span class="number">626</span>, <span class="number">-564</span>, <span class="number">623</span>, <span class="number">-567</span>, <span class="number">624</span>, <span class="number">-1666</span>, <span class="number">623</span>, <span class="number">-567</span>, <span class="number">626</span>, <span class="number">-19983</span>, <span class="number">625</span>, <span class="number">-1665</span>, <span class="number">624</span>, <span class="number">-567</span>, <span class="number">625</span>, <span class="number">-564</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">626</span>, <span class="number">-1664</span>, <span class="number">623</span>, <span class="number">-593</span>, <span class="number">599</span>, <span class="number">-565</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">624</span>, <span class="number">-594</span>, <span class="number">598</span>, <span class="number">-566</span>, <span class="number">622</span>, <span class="number">-567</span>, <span class="number">624</span>, <span class="number">-591</span>, <span class="number">598</span>, <span class="number">-1666</span>, <span class="number">625</span>, <span class="number">-565</span>, <span class="number">623</span>, <span class="number">-567</span>, <span class="number">624</span>, <span class="number">-569</span>, <span class="number">622</span>, <span class="number">-564</span>, <span class="number">625</span>, <span class="number">-568</span>, <span class="number">621</span>, <span class="number">-569</span>, <span class="number">624</span>, <span class="number">-564</span>, <span class="number">623</span>, <span class="number">-567</span>, <span class="number">625</span>, <span class="number">-564</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">623</span>, <span class="number">-568</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">623</span>, <span class="number">-566</span>, <span class="number">626</span>, <span class="number">-566</span>, <span class="number">622</span>, <span class="number">-1666</span>, <span class="number">623</span>, <span class="number">-568</span>, <span class="number">623</span>, <span class="number">-567</span>, <span class="number">624</span>, <span class="number">-1665</span>, <span class="number">624</span>, <span class="number">-7194</span>, <span class="number">9041</span>, <span class="number">-4481</span>, <span class="number">626</span>, <span class="number">-1665</span>, <span class="number">624</span>, <span class="number">-568</span>, <span class="number">621</span>, <span class="number">-566</span>, <span class="number">622</span>, <span class="number">-569</span>, <span class="number">625</span>, <span class="number">-567</span>, <span class="number">622</span>, <span class="number">-568</span>, <span class="number">621</span>, <span class="number">-1668</span>, <span class="number">622</span>, <span class="number">-566</span>, <span class="number">624</span>, <span class="number">-1666</span>, <span class="number">625</span>, <span class="number">-1666</span>, <span class="number">623</span>, <span class="number">-567</span>, <span class="number">625</span>, <span class="number">-1664</span>, <span class="number">623</span>, <span class="number">-594</span>, <span class="number">598</span>, <span class="number">-591</span>, <span class="number">599</span>, <span class="number">-566</span>, <span class="number">621</span>, <span class="number">-595</span>, <span class="number">599</span>, <span class="number">-565</span>, <span class="number">625</span>, <span class="number">-564</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">625</span>, <span class="number">-567</span>, <span class="number">622</span>, <span class="number">-569</span>, <span class="number">622</span>, <span class="number">-565</span>, <span class="number">623</span>, <span class="number">-569</span>, <span class="number">623</span>, <span class="number">-568</span>, <span class="number">622</span>, <span class="number">-567</span>, <span class="number">622</span>, <span class="number">-568</span>, <span class="number">621</span>, <span class="number">-567</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">623</span>, <span class="number">-1669</span>, <span class="number">623</span>, <span class="number">-1692</span>, <span class="number">597</span>, <span class="number">-1666</span>, <span class="number">624</span>, <span class="number">-565</span>, <span class="number">625</span>, <span class="number">-566</span>, <span class="number">624</span>, <span class="number">-1668</span>, <span class="number">622</span>, <span class="number">-565</span>, <span class="number">623</span>, <span class="number">-19985</span>, <span class="number">627</span>, <span class="number">-565</span>, <span class="number">626</span>, <span class="number">-564</span>, <span class="number">626</span>, <span class="number">-565</span>, <span class="number">623</span>, <span class="number">-566</span>, <span class="number">625</span>, <span class="number">-566</span>, <span class="number">623</span>, <span class="number">-593</span>, <span class="number">595</span>, <span class="number">-594</span>, <span class="number">600</span>, <span class="number">-565</span>, <span class="number">622</span>, <span class="number">-593</span>, <span class="number">597</span>, <span class="number">-567</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">623</span>, <span class="number">-567</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">625</span>, <span class="number">-565</span>, <span class="number">625</span>, <span class="number">-565</span>, <span class="number">626</span>, <span class="number">-564</span>, <span class="number">623</span>, <span class="number">-567</span>, <span class="number">623</span>, <span class="number">-567</span>, <span class="number">623</span>, <span class="number">-569</span>, <span class="number">622</span>, <span class="number">-566</span>, <span class="number">622</span>, <span class="number">-568</span>, <span class="number">622</span>, <span class="number">-569</span>, <span class="number">623</span>, <span class="number">-566</span>, <span class="number">623</span>, <span class="number">-567</span>, <span class="number">623</span>, <span class="number">-566</span>, <span class="number">624</span>, <span class="number">-567</span>, <span class="number">623</span>, <span class="number">-566</span>, <span class="number">624</span>, <span class="number">-568</span>, <span class="number">623</span>, <span class="number">-566</span>, <span class="number">622</span>, <span class="number">-1667</span>, <span class="number">625</span>, <span class="number">-1665</span>, <span class="number">623</span>, <span class="number">-594</span>, <span class="number">596</span>]</span><br></pre></td></tr></table></figure>
<p>我创建了一个switch实体,这样在Home Assistant面板上就可以直接添加空调的开关。<br>这里注意一个细节<code>carrier_frequency: 38kHz</code>必须要有,貌似是红外的载波频率,如果没有也不能正常遥控。<br>现在编译上传固件,然后在你的HA面板中添加<code>BedRoom AC Switch</code>,然后尝试一下控制空调。</p>
<h1 id="后续改进"><a href="#后续改进" class="headerlink" title="后续改进"></a>后续改进</h1><p>录制开机制热和开机制冷两种红外代码,并且优化代码结构,并且根据外部气温,判断打开空调的时候让它制热还是制冷。</p>
<figure class="highlight yaml"><table><tr><td class="code"><pre><span class="line"><span class="attr">esphome:</span></span><br><span class="line"> <span class="attr">name:</span> <span class="string">esp32</span></span><br><span class="line"></span><br><span class="line"><span class="attr">esp32:</span></span><br><span class="line"> <span class="attr">board:</span> <span class="string">esp32dev</span></span><br><span class="line"> <span class="attr">framework:</span></span><br><span class="line"> <span class="attr">type:</span> <span class="string">esp-idf</span></span><br><span class="line"> <span class="attr">version:</span> <span class="string">latest</span></span><br><span class="line"> <span class="comment"># Custom sdkconfig options</span></span><br><span class="line"> <span class="attr">sdkconfig_options:</span></span><br><span class="line"> <span class="attr">CONFIG_COMPILER_OPTIMIZATION_SIZE:</span> <span class="string">y</span></span><br><span class="line"> <span class="comment"># Advanced tweaking options</span></span><br><span class="line"> <span class="attr">advanced:</span></span><br><span class="line"> <span class="attr">ignore_efuse_mac_crc:</span> <span class="literal">false</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Enable logging</span></span><br><span class="line"><span class="attr">logger:</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Enable Home Assistant API</span></span><br><span class="line"><span class="attr">api:</span></span><br><span class="line"></span><br><span class="line"><span class="attr">ota:</span></span><br><span class="line"> <span class="attr">password:</span> <span class="string">""</span></span><br><span class="line"></span><br><span class="line"><span class="attr">wifi:</span></span><br><span class="line"> <span class="attr">ssid:</span> <span class="type">!secret</span> <span class="string">wifi_ssid</span></span><br><span class="line"> <span class="attr">password:</span> <span class="type">!secret</span> <span class="string">wifi_password</span></span><br><span class="line"></span><br><span class="line"><span class="attr">remote_receiver:</span></span><br><span class="line"> <span class="attr">pin:</span> </span><br><span class="line"> <span class="attr">number:</span> <span class="string">GPIO14</span></span><br><span class="line"> <span class="attr">inverted:</span> <span class="literal">True</span></span><br><span class="line"> <span class="attr">dump:</span> <span class="string">raw</span></span><br><span class="line"> <span class="attr">tolerance:</span> </span><br><span class="line"> <span class="attr">type:</span> <span class="string">percentage</span></span><br><span class="line"> <span class="attr">value:</span> <span class="number">70</span><span class="string">%</span></span><br><span class="line"> <span class="attr">idle:</span> <span class="string">50ms</span></span><br><span class="line"></span><br><span class="line"> <span class="attr">remote_transmitter:</span></span><br><span class="line"> <span class="attr">pin:</span> </span><br><span class="line"> <span class="attr">number:</span> <span class="string">GPIO27</span></span><br><span class="line"> <span class="attr">carrier_duty_percent:</span> <span class="number">50</span><span class="string">%</span></span><br><span class="line"></span><br><span class="line"><span class="attr">sensor:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">platform:</span> <span class="string">homeassistant</span></span><br><span class="line"> <span class="attr">entity_id:</span> <span class="string">weather.wo_de_jia</span></span><br><span class="line"> <span class="attr">id:</span> <span class="string">temperature</span></span><br><span class="line"> <span class="attr">attribute:</span> <span class="string">temperature</span></span><br><span class="line"></span><br><span class="line"> <span class="attr">switch:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">platform:</span> <span class="string">template</span></span><br><span class="line"> <span class="attr">name:</span> <span class="string">"BedRoom AC Switch"</span></span><br><span class="line"> <span class="attr">id:</span> <span class="string">esp32_ac_swi</span></span><br><span class="line"> <span class="attr">turn_on_action:</span></span><br><span class="line"> <span class="attr">then:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">switch.template.publish:</span></span><br><span class="line"> <span class="attr">id:</span> <span class="string">esp32_ac_swi</span></span><br><span class="line"> <span class="attr">state:</span> <span class="string">ON</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">if:</span></span><br><span class="line"> <span class="attr">condition:</span></span><br><span class="line"> <span class="attr">lambda:</span> <span class="string">'return id(temperature).state < 20;'</span></span><br><span class="line"> <span class="attr">then:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">script.execute:</span> <span class="string">turn_ac_20c</span></span><br><span class="line"> <span class="attr">else:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">script.execute:</span> <span class="string">turn_ac_27c</span></span><br><span class="line"></span><br><span class="line"> <span class="attr">turn_off_action:</span></span><br><span class="line"> <span class="attr">then:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">switch.template.publish:</span></span><br><span class="line"> <span class="attr">id:</span> <span class="string">esp32_ac_swi</span></span><br><span class="line"> <span class="attr">state:</span> <span class="string">OFF</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">script.execute:</span> <span class="string">turn_ac_off</span></span><br><span class="line"></span><br><span class="line"><span class="attr">script:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">id:</span> <span class="string">turn_ac_20c</span></span><br><span class="line"> <span class="attr">then:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">remote_transmitter.transmit_raw:</span></span><br><span class="line"> <span class="attr">carrier_frequency:</span> <span class="string">38kHz</span></span><br><span class="line"> <span class="attr">code:</span> [<span class="number">9016</span>, <span class="number">-4481</span>, <span class="number">620</span>, <span class="number">-570</span>, <span class="number">620</span>, <span class="number">-570</span>, <span class="number">619</span>, <span class="number">-1670</span>, <span class="number">620</span>, <span class="number">-1671</span>, <span class="number">620</span>, <span class="number">-570</span>, <span class="number">621</span>, <span class="number">-569</span>, <span class="number">621</span>, <span class="number">-1668</span>, <span class="number">619</span>, <span class="number">-572</span>, <span class="number">620</span>, <span class="number">-569</span>, <span class="number">620</span>, <span class="number">-570</span>, <span class="number">621</span>, <span class="number">-1669</span>, <span class="number">621</span>, <span class="number">-570</span>, <span class="number">621</span>, <span class="number">-568</span>, <span class="number">620</span>, <span class="number">-570</span>, <span class="number">621</span>, <span class="number">-569</span>, <span class="number">621</span>, <span class="number">-569</span>, <span class="number">622</span>, <span class="number">-568</span>, <span class="number">619</span>, <span class="number">-572</span>, <span class="number">619</span>, <span class="number">-570</span>, <span class="number">621</span>, <span class="number">-569</span>, <span class="number">619</span>, <span class="number">-572</span>, <span class="number">619</span>, <span class="number">-1671</span>, <span class="number">618</span>, <span class="number">-571</span>, <span class="number">620</span>, <span class="number">-1670</span>, <span class="number">620</span>, <span class="number">-571</span>, <span class="number">619</span>, <span class="number">-571</span>, <span class="number">618</span>, <span class="number">-571</span>, <span class="number">619</span>, <span class="number">-570</span>, <span class="number">621</span>, <span class="number">-1670</span>, <span class="number">620</span>, <span class="number">-570</span>, <span class="number">646</span>, <span class="number">-1643</span>, <span class="number">621</span>, <span class="number">-569</span>, <span class="number">621</span>, <span class="number">-569</span>, <span class="number">621</span>, <span class="number">-1669</span>, <span class="number">620</span>, <span class="number">-571</span>, <span class="number">619</span>, <span class="number">-19990</span>, <span class="number">620</span>, <span class="number">-1670</span>, <span class="number">620</span>, <span class="number">-571</span>, <span class="number">620</span>, <span class="number">-568</span>, <span class="number">622</span>, <span class="number">-569</span>, <span class="number">621</span>, <span class="number">-1669</span>, <span class="number">621</span>, <span class="number">-569</span>, <span class="number">617</span>, <span class="number">-573</span>, <span class="number">617</span>, <span class="number">-573</span>, <span class="number">620</span>, <span class="number">-570</span>, <span class="number">645</span>, <span class="number">-545</span>, <span class="number">621</span>, <span class="number">-569</span>, <span class="number">620</span>, <span class="number">-570</span>, <span class="number">619</span>, <span class="number">-570</span>, <span class="number">621</span>, <span class="number">-1669</span>, <span class="number">618</span>, <span class="number">-572</span>, <span class="number">645</span>, <span class="number">-546</span>, <span class="number">619</span>, <span class="number">-571</span>, <span class="number">645</span>, <span class="number">-544</span>, <span class="number">620</span>, <span class="number">-571</span>, <span class="number">617</span>, <span class="number">-573</span>, <span class="number">643</span>, <span class="number">-547</span>, <span class="number">620</span>, <span class="number">-569</span>, <span class="number">620</span>, <span class="number">-571</span>, <span class="number">617</span>, <span class="number">-572</span>, <span class="number">644</span>, <span class="number">-546</span>, <span class="number">618</span>, <span class="number">-572</span>, <span class="number">612</span>, <span class="number">-578</span>, <span class="number">621</span>, <span class="number">-569</span>, <span class="number">619</span>, <span class="number">-1671</span>, <span class="number">617</span>, <span class="number">-573</span>, <span class="number">620</span>, <span class="number">-1670</span>, <span class="number">644</span>, <span class="number">-1646</span>, <span class="number">619</span>, <span class="number">-7223</span>, <span class="number">9010</span>, <span class="number">-4489</span>, <span class="number">617</span>, <span class="number">-573</span>, <span class="number">615</span>, <span class="number">-575</span>, <span class="number">643</span>, <span class="number">-1647</span>, <span class="number">620</span>, <span class="number">-1670</span>, <span class="number">643</span>, <span class="number">-546</span>, <span class="number">619</span>, <span class="number">-572</span>, <span class="number">616</span>, <span class="number">-1674</span>, <span class="number">617</span>, <span class="number">-573</span>, <span class="number">644</span>, <span class="number">-545</span>, <span class="number">618</span>, <span class="number">-573</span>, <span class="number">617</span>, <span class="number">-1673</span>, <span class="number">615</span>, <span class="number">-574</span>, <span class="number">642</span>, <span class="number">-549</span>, <span class="number">617</span>, <span class="number">-572</span>, <span class="number">618</span>, <span class="number">-572</span>, <span class="number">617</span>, <span class="number">-573</span>, <span class="number">643</span>, <span class="number">-547</span>, <span class="number">644</span>, <span class="number">-546</span>, <span class="number">614</span>, <span class="number">-576</span>, <span class="number">643</span>, <span class="number">-547</span>, <span class="number">593</span>, <span class="number">-598</span>, <span class="number">643</span>, <span class="number">-1646</span>, <span class="number">643</span>, <span class="number">-547</span>, <span class="number">616</span>, <span class="number">-1674</span>, <span class="number">639</span>, <span class="number">-551</span>, <span class="number">610</span>, <span class="number">-580</span>, <span class="number">616</span>, <span class="number">-574</span>, <span class="number">641</span>, <span class="number">-549</span>, <span class="number">617</span>, <span class="number">-1673</span>, <span class="number">592</span>, <span class="number">-1699</span>, <span class="number">617</span>, <span class="number">-1672</span>, <span class="number">639</span>, <span class="number">-551</span>, <span class="number">642</span>, <span class="number">-547</span>, <span class="number">593</span>, <span class="number">-1698</span>, <span class="number">592</span>, <span class="number">-598</span>, <span class="number">640</span>, <span class="number">-19969</span>, <span class="number">637</span>, <span class="number">-553</span>, <span class="number">593</span>, <span class="number">-597</span>, <span class="number">642</span>, <span class="number">-548</span>, <span class="number">642</span>, <span class="number">-548</span>, <span class="number">640</span>, <span class="number">-550</span>, <span class="number">592</span>, <span class="number">-598</span>, <span class="number">592</span>, <span class="number">-598</span>, <span class="number">593</span>, <span class="number">-597</span>, <span class="number">592</span>, <span class="number">-597</span>, <span class="number">642</span>, <span class="number">-549</span>, <span class="number">593</span>, <span class="number">-597</span>, <span class="number">594</span>, <span class="number">-596</span>, <span class="number">593</span>, <span class="number">-597</span>, <span class="number">592</span>, <span class="number">-598</span>, <span class="number">640</span>, <span class="number">-550</span>, <span class="number">593</span>, <span class="number">-597</span>, <span class="number">593</span>, <span class="number">-597</span>, <span class="number">593</span>, <span class="number">-597</span>, <span class="number">592</span>, <span class="number">-597</span>, <span class="number">593</span>, <span class="number">-598</span>, <span class="number">641</span>, <span class="number">-548</span>, <span class="number">640</span>, <span class="number">-551</span>, <span class="number">592</span>, <span class="number">-597</span>, <span class="number">642</span>, <span class="number">-549</span>, <span class="number">593</span>, <span class="number">-597</span>, <span class="number">593</span>, <span class="number">-596</span>, <span class="number">594</span>, <span class="number">-597</span>, <span class="number">593</span>, <span class="number">-596</span>, <span class="number">594</span>, <span class="number">-596</span>, <span class="number">593</span>, <span class="number">-1697</span>, <span class="number">594</span>, <span class="number">-596</span>, <span class="number">594</span>, <span class="number">-1696</span>, <span class="number">594</span>]</span><br><span class="line"> <span class="bullet">-</span> <span class="attr">id:</span> <span class="string">turn_ac_off</span></span><br><span class="line"> <span class="attr">then:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">remote_transmitter.transmit_raw:</span></span><br><span class="line"> <span class="attr">carrier_frequency:</span> <span class="string">38kHz</span></span><br><span class="line"> <span class="attr">code:</span> [<span class="number">9021</span>, <span class="number">-4476</span>, <span class="number">625</span>, <span class="number">-1666</span>, <span class="number">624</span>, <span class="number">-565</span>, <span class="number">624</span>, <span class="number">-567</span>, <span class="number">625</span>, <span class="number">-567</span>, <span class="number">621</span>, <span class="number">-567</span>, <span class="number">626</span>, <span class="number">-566</span>, <span class="number">622</span>, <span class="number">-1666</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">623</span>, <span class="number">-1666</span>, <span class="number">626</span>, <span class="number">-1691</span>, <span class="number">597</span>, <span class="number">-566</span>, <span class="number">626</span>, <span class="number">-1664</span>, <span class="number">625</span>, <span class="number">-593</span>, <span class="number">597</span>, <span class="number">-566</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">625</span>, <span class="number">-565</span>, <span class="number">624</span>, <span class="number">-565</span>, <span class="number">622</span>, <span class="number">-569</span>, <span class="number">624</span>, <span class="number">-565</span>, <span class="number">625</span>, <span class="number">-565</span>, <span class="number">625</span>, <span class="number">-592</span>, <span class="number">599</span>, <span class="number">-564</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">626</span>, <span class="number">-564</span>, <span class="number">626</span>, <span class="number">-565</span>, <span class="number">625</span>, <span class="number">-566</span>, <span class="number">623</span>, <span class="number">-565</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">624</span>, <span class="number">-1666</span>, <span class="number">625</span>, <span class="number">-565</span>, <span class="number">625</span>, <span class="number">-1665</span>, <span class="number">626</span>, <span class="number">-564</span>, <span class="number">623</span>, <span class="number">-567</span>, <span class="number">624</span>, <span class="number">-1666</span>, <span class="number">623</span>, <span class="number">-567</span>, <span class="number">626</span>, <span class="number">-19983</span>, <span class="number">625</span>, <span class="number">-1665</span>, <span class="number">624</span>, <span class="number">-567</span>, <span class="number">625</span>, <span class="number">-564</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">626</span>, <span class="number">-1664</span>, <span class="number">623</span>, <span class="number">-593</span>, <span class="number">599</span>, <span class="number">-565</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">624</span>, <span class="number">-594</span>, <span class="number">598</span>, <span class="number">-566</span>, <span class="number">622</span>, <span class="number">-567</span>, <span class="number">624</span>, <span class="number">-591</span>, <span class="number">598</span>, <span class="number">-1666</span>, <span class="number">625</span>, <span class="number">-565</span>, <span class="number">623</span>, <span class="number">-567</span>, <span class="number">624</span>, <span class="number">-569</span>, <span class="number">622</span>, <span class="number">-564</span>, <span class="number">625</span>, <span class="number">-568</span>, <span class="number">621</span>, <span class="number">-569</span>, <span class="number">624</span>, <span class="number">-564</span>, <span class="number">623</span>, <span class="number">-567</span>, <span class="number">625</span>, <span class="number">-564</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">623</span>, <span class="number">-568</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">623</span>, <span class="number">-566</span>, <span class="number">626</span>, <span class="number">-566</span>, <span class="number">622</span>, <span class="number">-1666</span>, <span class="number">623</span>, <span class="number">-568</span>, <span class="number">623</span>, <span class="number">-567</span>, <span class="number">624</span>, <span class="number">-1665</span>, <span class="number">624</span>, <span class="number">-7194</span>, <span class="number">9041</span>, <span class="number">-4481</span>, <span class="number">626</span>, <span class="number">-1665</span>, <span class="number">624</span>, <span class="number">-568</span>, <span class="number">621</span>, <span class="number">-566</span>, <span class="number">622</span>, <span class="number">-569</span>, <span class="number">625</span>, <span class="number">-567</span>, <span class="number">622</span>, <span class="number">-568</span>, <span class="number">621</span>, <span class="number">-1668</span>, <span class="number">622</span>, <span class="number">-566</span>, <span class="number">624</span>, <span class="number">-1666</span>, <span class="number">625</span>, <span class="number">-1666</span>, <span class="number">623</span>, <span class="number">-567</span>, <span class="number">625</span>, <span class="number">-1664</span>, <span class="number">623</span>, <span class="number">-594</span>, <span class="number">598</span>, <span class="number">-591</span>, <span class="number">599</span>, <span class="number">-566</span>, <span class="number">621</span>, <span class="number">-595</span>, <span class="number">599</span>, <span class="number">-565</span>, <span class="number">625</span>, <span class="number">-564</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">625</span>, <span class="number">-567</span>, <span class="number">622</span>, <span class="number">-569</span>, <span class="number">622</span>, <span class="number">-565</span>, <span class="number">623</span>, <span class="number">-569</span>, <span class="number">623</span>, <span class="number">-568</span>, <span class="number">622</span>, <span class="number">-567</span>, <span class="number">622</span>, <span class="number">-568</span>, <span class="number">621</span>, <span class="number">-567</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">623</span>, <span class="number">-1669</span>, <span class="number">623</span>, <span class="number">-1692</span>, <span class="number">597</span>, <span class="number">-1666</span>, <span class="number">624</span>, <span class="number">-565</span>, <span class="number">625</span>, <span class="number">-566</span>, <span class="number">624</span>, <span class="number">-1668</span>, <span class="number">622</span>, <span class="number">-565</span>, <span class="number">623</span>, <span class="number">-19985</span>, <span class="number">627</span>, <span class="number">-565</span>, <span class="number">626</span>, <span class="number">-564</span>, <span class="number">626</span>, <span class="number">-565</span>, <span class="number">623</span>, <span class="number">-566</span>, <span class="number">625</span>, <span class="number">-566</span>, <span class="number">623</span>, <span class="number">-593</span>, <span class="number">595</span>, <span class="number">-594</span>, <span class="number">600</span>, <span class="number">-565</span>, <span class="number">622</span>, <span class="number">-593</span>, <span class="number">597</span>, <span class="number">-567</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">623</span>, <span class="number">-567</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">625</span>, <span class="number">-565</span>, <span class="number">625</span>, <span class="number">-565</span>, <span class="number">626</span>, <span class="number">-564</span>, <span class="number">623</span>, <span class="number">-567</span>, <span class="number">623</span>, <span class="number">-567</span>, <span class="number">623</span>, <span class="number">-569</span>, <span class="number">622</span>, <span class="number">-566</span>, <span class="number">622</span>, <span class="number">-568</span>, <span class="number">622</span>, <span class="number">-569</span>, <span class="number">623</span>, <span class="number">-566</span>, <span class="number">623</span>, <span class="number">-567</span>, <span class="number">623</span>, <span class="number">-566</span>, <span class="number">624</span>, <span class="number">-567</span>, <span class="number">623</span>, <span class="number">-566</span>, <span class="number">624</span>, <span class="number">-568</span>, <span class="number">623</span>, <span class="number">-566</span>, <span class="number">622</span>, <span class="number">-1667</span>, <span class="number">625</span>, <span class="number">-1665</span>, <span class="number">623</span>, <span class="number">-594</span>, <span class="number">596</span>]</span><br><span class="line"> <span class="bullet">-</span> <span class="attr">id:</span> <span class="string">turn_ac_27c</span></span><br><span class="line"> <span class="attr">then:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">remote_transmitter.transmit_raw:</span></span><br><span class="line"> <span class="attr">carrier_frequency:</span> <span class="string">38kHz</span></span><br><span class="line"> <span class="attr">code:</span> [<span class="number">9048</span>, <span class="number">-4448</span>, <span class="number">653</span>, <span class="number">-1665</span>, <span class="number">623</span>, <span class="number">-539</span>, <span class="number">653</span>, <span class="number">-537</span>, <span class="number">650</span>, <span class="number">-1668</span>, <span class="number">625</span>, <span class="number">-537</span>, <span class="number">654</span>, <span class="number">-537</span>, <span class="number">650</span>, <span class="number">-1640</span>, <span class="number">650</span>, <span class="number">-539</span>, <span class="number">652</span>, <span class="number">-1639</span>, <span class="number">651</span>, <span class="number">-1638</span>, <span class="number">651</span>, <span class="number">-539</span>, <span class="number">652</span>, <span class="number">-1638</span>, <span class="number">653</span>, <span class="number">-538</span>, <span class="number">651</span>, <span class="number">-539</span>, <span class="number">650</span>, <span class="number">-540</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">650</span>, <span class="number">-539</span>, <span class="number">652</span>, <span class="number">-539</span>, <span class="number">651</span>, <span class="number">-537</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">652</span>, <span class="number">-1638</span>, <span class="number">651</span>, <span class="number">-540</span>, <span class="number">652</span>, <span class="number">-537</span>, <span class="number">653</span>, <span class="number">-538</span>, <span class="number">650</span>, <span class="number">-567</span>, <span class="number">623</span>, <span class="number">-539</span>, <span class="number">651</span>, <span class="number">-539</span>, <span class="number">651</span>, <span class="number">-1639</span>, <span class="number">652</span>, <span class="number">-566</span>, <span class="number">623</span>, <span class="number">-1639</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">653</span>, <span class="number">-537</span>, <span class="number">652</span>, <span class="number">-1638</span>, <span class="number">652</span>, <span class="number">-539</span>, <span class="number">651</span>, <span class="number">-19956</span>, <span class="number">653</span>, <span class="number">-1638</span>, <span class="number">653</span>, <span class="number">-539</span>, <span class="number">652</span>, <span class="number">-536</span>, <span class="number">650</span>, <span class="number">-541</span>, <span class="number">650</span>, <span class="number">-1666</span>, <span class="number">627</span>, <span class="number">-536</span>, <span class="number">654</span>, <span class="number">-536</span>, <span class="number">650</span>, <span class="number">-541</span>, <span class="number">653</span>, <span class="number">-537</span>, <span class="number">650</span>, <span class="number">-539</span>, <span class="number">653</span>, <span class="number">-565</span>, <span class="number">625</span>, <span class="number">-537</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">652</span>, <span class="number">-1638</span>, <span class="number">652</span>, <span class="number">-540</span>, <span class="number">650</span>, <span class="number">-541</span>, <span class="number">649</span>, <span class="number">-565</span>, <span class="number">625</span>, <span class="number">-566</span>, <span class="number">624</span>, <span class="number">-538</span>, <span class="number">651</span>, <span class="number">-539</span>, <span class="number">651</span>, <span class="number">-539</span>, <span class="number">653</span>, <span class="number">-537</span>, <span class="number">652</span>, <span class="number">-565</span>, <span class="number">624</span>, <span class="number">-539</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">652</span>, <span class="number">-539</span>, <span class="number">649</span>, <span class="number">-539</span>, <span class="number">653</span>, <span class="number">-564</span>, <span class="number">625</span>, <span class="number">-1639</span>, <span class="number">652</span>, <span class="number">-539</span>, <span class="number">650</span>, <span class="number">-539</span>, <span class="number">652</span>, <span class="number">-565</span>, <span class="number">625</span>, <span class="number">-7187</span>, <span class="number">9047</span>, <span class="number">-4453</span>, <span class="number">653</span>, <span class="number">-1640</span>, <span class="number">649</span>, <span class="number">-566</span>, <span class="number">625</span>, <span class="number">-540</span>, <span class="number">651</span>, <span class="number">-1637</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">651</span>, <span class="number">-539</span>, <span class="number">651</span>, <span class="number">-1638</span>, <span class="number">653</span>, <span class="number">-538</span>, <span class="number">650</span>, <span class="number">-1640</span>, <span class="number">651</span>, <span class="number">-1640</span>, <span class="number">652</span>, <span class="number">-537</span>, <span class="number">652</span>, <span class="number">-1637</span>, <span class="number">653</span>, <span class="number">-537</span>, <span class="number">652</span>, <span class="number">-541</span>, <span class="number">649</span>, <span class="number">-538</span>, <span class="number">653</span>, <span class="number">-538</span>, <span class="number">652</span>, <span class="number">-540</span>, <span class="number">649</span>, <span class="number">-565</span>, <span class="number">626</span>, <span class="number">-539</span>, <span class="number">651</span>, <span class="number">-539</span>, <span class="number">653</span>, <span class="number">-537</span>, <span class="number">652</span>, <span class="number">-1637</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">653</span>, <span class="number">-537</span>, <span class="number">652</span>, <span class="number">-565</span>, <span class="number">625</span>, <span class="number">-564</span>, <span class="number">627</span>, <span class="number">-537</span>, <span class="number">653</span>, <span class="number">-537</span>, <span class="number">652</span>, <span class="number">-1664</span>, <span class="number">627</span>, <span class="number">-1636</span>, <span class="number">653</span>, <span class="number">-1637</span>, <span class="number">654</span>, <span class="number">-563</span>, <span class="number">626</span>, <span class="number">-538</span>, <span class="number">653</span>, <span class="number">-1637</span>, <span class="number">653</span>, <span class="number">-537</span>, <span class="number">651</span>, <span class="number">-19956</span>, <span class="number">653</span>, <span class="number">-539</span>, <span class="number">654</span>, <span class="number">-537</span>, <span class="number">650</span>, <span class="number">-566</span>, <span class="number">625</span>, <span class="number">-538</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">654</span>, <span class="number">-536</span>, <span class="number">651</span>, <span class="number">-539</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">653</span>, <span class="number">-564</span>, <span class="number">624</span>, <span class="number">-539</span>, <span class="number">651</span>, <span class="number">-539</span>, <span class="number">651</span>, <span class="number">-539</span>, <span class="number">651</span>, <span class="number">-538</span>, <span class="number">651</span>, <span class="number">-540</span>, <span class="number">651</span>, <span class="number">-538</span>, <span class="number">653</span>, <span class="number">-538</span>, <span class="number">652</span>, <span class="number">-537</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">652</span>, <span class="number">-565</span>, <span class="number">624</span>, <span class="number">-567</span>, <span class="number">625</span>, <span class="number">-538</span>, <span class="number">653</span>, <span class="number">-562</span>, <span class="number">626</span>, <span class="number">-538</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">651</span>, <span class="number">-540</span>, <span class="number">651</span>, <span class="number">-538</span>, <span class="number">654</span>, <span class="number">-536</span>, <span class="number">653</span>, <span class="number">-537</span>, <span class="number">651</span>, <span class="number">-1665</span>, <span class="number">627</span>, <span class="number">-1637</span>, <span class="number">652</span>, <span class="number">-1638</span>, <span class="number">652</span>]</span><br><span class="line"> <span class="bullet">-</span> <span class="attr">id:</span> <span class="string">turn_ac_28c</span></span><br><span class="line"> <span class="attr">then:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">remote_transmitter.transmit_raw:</span></span><br><span class="line"> <span class="attr">carrier_frequency:</span> <span class="string">38kHz</span></span><br><span class="line"> <span class="attr">code:</span> [<span class="number">9081</span>, <span class="number">-4466</span>, <span class="number">657</span>, <span class="number">-1630</span>, <span class="number">656</span>, <span class="number">-553</span>, <span class="number">629</span>, <span class="number">-558</span>, <span class="number">652</span>, <span class="number">-1634</span>, <span class="number">654</span>, <span class="number">-1634</span>, <span class="number">594</span>, <span class="number">-588</span>, <span class="number">597</span>, <span class="number">-613</span>, <span class="number">596</span>, <span class="number">-588</span>, <span class="number">595</span>, <span class="number">-587</span>, <span class="number">626</span>, <span class="number">-589</span>, <span class="number">590</span>, <span class="number">-1695</span>, <span class="number">595</span>, <span class="number">-1696</span>, <span class="number">591</span>, <span class="number">-643</span>, <span class="number">566</span>, <span class="number">-617</span>, <span class="number">566</span>, <span class="number">-616</span>, <span class="number">568</span>, <span class="number">-642</span>, <span class="number">568</span>, <span class="number">-615</span>, <span class="number">569</span>, <span class="number">-615</span>, <span class="number">568</span>, <span class="number">-616</span>, <span class="number">593</span>, <span class="number">-591</span>, <span class="number">593</span>, <span class="number">-591</span>, <span class="number">592</span>, <span class="number">-617</span>, <span class="number">594</span>, <span class="number">-592</span>, <span class="number">591</span>, <span class="number">-591</span>, <span class="number">591</span>, <span class="number">-618</span>, <span class="number">593</span>, <span class="number">-614</span>, <span class="number">568</span>, <span class="number">-617</span>, <span class="number">567</span>, <span class="number">-615</span>, <span class="number">596</span>, <span class="number">-1693</span>, <span class="number">594</span>, <span class="number">-623</span>, <span class="number">559</span>, <span class="number">-1696</span>, <span class="number">594</span>, <span class="number">-645</span>, <span class="number">564</span>, <span class="number">-617</span>, <span class="number">567</span>, <span class="number">-1694</span>, <span class="number">593</span>, <span class="number">-646</span>, <span class="number">561</span>, <span class="number">-20029</span>, <span class="number">613</span>, <span class="number">-653</span>, <span class="number">559</span>, <span class="number">-1695</span>, <span class="number">593</span>, <span class="number">-625</span>, <span class="number">558</span>, <span class="number">-621</span>, <span class="number">565</span>, <span class="number">-641</span>, <span class="number">567</span>, <span class="number">-617</span>, <span class="number">565</span>, <span class="number">-618</span>, <span class="number">568</span>, <span class="number">-618</span>, <span class="number">591</span>, <span class="number">-615</span>, <span class="number">569</span>, <span class="number">-591</span>, <span class="number">591</span>, <span class="number">-617</span>, <span class="number">594</span>, <span class="number">-614</span>, <span class="number">643</span>, <span class="number">-544</span>, <span class="number">565</span>, <span class="number">-617</span>, <span class="number">596</span>, <span class="number">-1695</span>, <span class="number">590</span>, <span class="number">-620</span>, <span class="number">563</span>, <span class="number">-643</span>, <span class="number">567</span>, <span class="number">-616</span>, <span class="number">566</span>, <span class="number">-618</span>, <span class="number">567</span>, <span class="number">-618</span>, <span class="number">593</span>, <span class="number">-590</span>, <span class="number">593</span>, <span class="number">-614</span>, <span class="number">567</span>, <span class="number">-618</span>, <span class="number">594</span>, <span class="number">-592</span>, <span class="number">591</span>, <span class="number">-591</span>, <span class="number">591</span>, <span class="number">-620</span>, <span class="number">659</span>, <span class="number">-550</span>, <span class="number">566</span>, <span class="number">-590</span>, <span class="number">594</span>, <span class="number">-1720</span>, <span class="number">595</span>, <span class="number">-1692</span>, <span class="number">594</span>, <span class="number">-620</span>, <span class="number">563</span>, <span class="number">-618</span>, <span class="number">591</span>, <span class="number">-7252</span>, <span class="number">9095</span>, <span class="number">-4467</span>, <span class="number">661</span>, <span class="number">-1628</span>, <span class="number">658</span>, <span class="number">-527</span>, <span class="number">654</span>, <span class="number">-580</span>, <span class="number">627</span>, <span class="number">-1637</span>, <span class="number">653</span>, <span class="number">-1635</span>, <span class="number">593</span>, <span class="number">-616</span>, <span class="number">568</span>, <span class="number">-618</span>, <span class="number">591</span>, <span class="number">-591</span>, <span class="number">592</span>, <span class="number">-592</span>, <span class="number">591</span>, <span class="number">-617</span>, <span class="number">595</span>, <span class="number">-1694</span>, <span class="number">593</span>, <span class="number">-1695</span>, <span class="number">592</span>, <span class="number">-645</span>, <span class="number">565</span>, <span class="number">-617</span>, <span class="number">566</span>, <span class="number">-594</span>, <span class="number">590</span>, <span class="number">-617</span>, <span class="number">592</span>, <span class="number">-618</span>, <span class="number">567</span>, <span class="number">-615</span>, <span class="number">569</span>, <span class="number">-640</span>, <span class="number">567</span>, <span class="number">-594</span>, <span class="number">591</span>, <span class="number">-590</span>, <span class="number">595</span>, <span class="number">-614</span>, <span class="number">596</span>, <span class="number">-587</span>, <span class="number">596</span>, <span class="number">-614</span>, <span class="number">568</span>, <span class="number">-616</span>, <span class="number">596</span>, <span class="number">-614</span>, <span class="number">566</span>, <span class="number">-593</span>, <span class="number">591</span>, <span class="number">-617</span>, <span class="number">594</span>, <span class="number">-1694</span>, <span class="number">593</span>, <span class="number">-1696</span>, <span class="number">594</span>, <span class="number">-1693</span>, <span class="number">592</span>, <span class="number">-649</span>, <span class="number">565</span>, <span class="number">-618</span>, <span class="number">565</span>, <span class="number">-1713</span>, <span class="number">572</span>, <span class="number">-648</span>, <span class="number">564</span>, <span class="number">-20051</span>, <span class="number">592</span>, <span class="number">-555</span>, <span class="number">630</span>, <span class="number">-648</span>, <span class="number">563</span>, <span class="number">-619</span>, <span class="number">562</span>, <span class="number">-621</span>, <span class="number">565</span>, <span class="number">-642</span>, <span class="number">568</span>, <span class="number">-617</span>, <span class="number">566</span>, <span class="number">-617</span>, <span class="number">564</span>, <span class="number">-1724</span>, <span class="number">592</span>, <span class="number">-620</span>, <span class="number">565</span>, <span class="number">-616</span>, <span class="number">565</span>, <span class="number">-645</span>, <span class="number">566</span>, <span class="number">-618</span>, <span class="number">566</span>, <span class="number">-615</span>, <span class="number">566</span>, <span class="number">-618</span>, <span class="number">594</span>, <span class="number">-617</span>, <span class="number">564</span>, <span class="number">-593</span>, <span class="number">594</span>, <span class="number">-615</span>, <span class="number">596</span>, <span class="number">-613</span>, <span class="number">567</span>, <span class="number">-592</span>, <span class="number">595</span>, <span class="number">-614</span>, <span class="number">593</span>, <span class="number">-1694</span>, <span class="number">595</span>, <span class="number">-618</span>, <span class="number">565</span>, <span class="number">-641</span>, <span class="number">569</span>, <span class="number">-1694</span>, <span class="number">592</span>, <span class="number">-621</span>, <span class="number">565</span>, <span class="number">-616</span>, <span class="number">564</span>, <span class="number">-645</span>, <span class="number">567</span>, <span class="number">-617</span>, <span class="number">567</span>, <span class="number">-618</span>, <span class="number">567</span>, <span class="number">-616</span>, <span class="number">594</span>, <span class="number">-614</span>, <span class="number">567</span>, <span class="number">-591</span>, <span class="number">593</span>]</span><br></pre></td></tr></table></figure>
<p>户外温度是从Home Assistant的天气中读取的,其中<code>entity_id: weather.wo_de_jia</code>是HA中的实体,你可以在HA面板中的“开发者工具”中查看“现有实体”。</p>
]]></content>
</entry>
<entry>
<title>利用ESPHome进行蓝牙设备定位</title>
<url>/2022/03/06/ESPHome-ble-tracker/</url>
<content><![CDATA[<p>最近捣鼓智能家居,用ESP32进行蓝牙设备定位,追踪小米手环手环,根据信号强度判断人是否在房间或者家里。</p>
<h1 id="硬件与软件准备工作"><a href="#硬件与软件准备工作" class="headerlink" title="硬件与软件准备工作"></a>硬件与软件准备工作</h1><table>
<thead>
<tr>
<th align="left">硬件</th>
<th align="right">软件</th>
</tr>
</thead>
<tbody><tr>
<td align="left">ESP32</td>
<td align="right">ESPHome v2022.2.1</td>
</tr>
<tr>
<td align="left">NAS/软路由</td>
<td align="right">Homeassistant 2021.11.4</td>
</tr>
<tr>
<td align="left">小米手环</td>
<td align="right"></td>
</tr>
</tbody></table>
<p>首先要在“小米穿戴”APP中打开小米手环的“蓝牙广播”功能,重启小米手环并确定“蓝牙广播”处于开启状态。进入小米手环的设置,记录下小米手环的蓝牙地址,例如我的小米手环蓝牙地址<code>FA:4C:19:74:CF:20</code></p>
<h1 id="编译并上传固件"><a href="#编译并上传固件" class="headerlink" title="编译并上传固件"></a>编译并上传固件</h1><p>详细参见<a target="_blank" rel="noopener" href="https://esphome.io/components/esp32_ble_tracker.html">ESPHome的ESP32 Bluetooth Low Energy Tracker Hub章节</a>,下面粘贴我的ESPHome的编译配置yaml。</p>
<figure class="highlight yaml"><table><tr><td class="code"><pre><span class="line"><span class="attr">esphome:</span></span><br><span class="line"> <span class="attr">name:</span> <span class="string">esp32</span></span><br><span class="line"></span><br><span class="line"><span class="attr">esp32:</span></span><br><span class="line"> <span class="attr">board:</span> <span class="string">esp32dev</span></span><br><span class="line"> <span class="attr">framework:</span></span><br><span class="line"> <span class="attr">type:</span> <span class="string">esp-idf</span></span><br><span class="line"> <span class="attr">version:</span> <span class="string">latest</span></span><br><span class="line"> <span class="comment"># Custom sdkconfig options</span></span><br><span class="line"> <span class="attr">sdkconfig_options:</span></span><br><span class="line"> <span class="attr">CONFIG_COMPILER_OPTIMIZATION_SIZE:</span> <span class="string">y</span></span><br><span class="line"> <span class="comment"># Advanced tweaking options</span></span><br><span class="line"> <span class="attr">advanced:</span></span><br><span class="line"> <span class="attr">ignore_efuse_mac_crc:</span> <span class="literal">false</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Enable logging</span></span><br><span class="line"><span class="attr">logger:</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Enable Home Assistant API</span></span><br><span class="line"><span class="attr">api:</span></span><br><span class="line"></span><br><span class="line"><span class="attr">ota:</span></span><br><span class="line"> <span class="attr">password:</span> <span class="string">""</span></span><br><span class="line"></span><br><span class="line"><span class="attr">wifi:</span></span><br><span class="line"> <span class="attr">ssid:</span> <span class="type">!secret</span> <span class="string">wifi_ssid</span></span><br><span class="line"> <span class="attr">password:</span> <span class="type">!secret</span> <span class="string">wifi_password</span></span><br><span class="line"></span><br><span class="line"><span class="attr">esp32_ble_tracker:</span></span><br><span class="line"> <span class="attr">scan_parameters:</span></span><br><span class="line"> <span class="attr">interval:</span> <span class="string">1s</span></span><br><span class="line"> <span class="attr">window:</span> <span class="string">500ms</span></span><br><span class="line"> <span class="attr">active:</span> <span class="literal">false</span></span><br><span class="line"><span class="attr">sensor:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">platform:</span> <span class="string">ble_rssi</span></span><br><span class="line"> <span class="attr">mac_address:</span> <span class="string">FA:4C:19:74:CF:20</span></span><br><span class="line"> <span class="attr">name:</span> <span class="string">"MI Band RSSI value"</span></span><br></pre></td></tr></table></figure>
<p>其中<code>scan_parameters:</code>字键中的参数是重点,默认参数不能保证每次扫描都获得信号强度。</p>
]]></content>
</entry>
<entry>
<title>部署Hexo笔记</title>
<url>/2019/10/05/Hexo-install/</url>
<content><![CDATA[<p>个人Hexo博客搭建的记录,我不想让别人看到推送记录,所以都是强制推送。</p>
<a id="more"></a>
<ul>
<li>先克隆已经配置好的源码 <figure class="highlight awk"><table><tr><td class="code"><pre><span class="line">git clone https:<span class="regexp">//gi</span>tlab.com<span class="regexp">/weiyangbo/</span>weiyangbo.gitlab.io.git && cd weiyangbo.gitlab.io</span><br></pre></td></tr></table></figure></li>
<li>安装hexo <figure class="highlight sas"><table><tr><td class="code"><pre><span class="line">curl -sL https://deb.nodesource.com/setup_18.<span class="meta">x</span> | sudo -E bash - <span class="variable">&&</span> sudo apt install -y nodejs <span class="variable">&&</span> sudo npm install hexo-cli gulp -g <span class="variable">&&</span> npm install</span><br></pre></td></tr></table></figure></li>
<li>推送到Gitlab并自动构建网页 <figure class="highlight sas"><table><tr><td class="code"><pre><span class="line">rm -rf .git <span class="variable">&&</span> git init <span class="variable">&&</span> git <span class="meta">add</span> . <span class="variable">&&</span> git remote <span class="meta">add</span> origin [email protected]:weiyangbo/weiyangbo.gitlab.io.git <span class="variable">&&</span> git commit -a -m <span class="string">"Init Blog"</span> <span class="variable">&&</span> git push -f --<span class="meta">set</span>-upstream origin master</span><br></pre></td></tr></table></figure></li>
<li>推送静态网页到GitHub && Gitee (Github推送后自动部署,Gitee推送后需手动更新) <figure class="highlight sas"><table><tr><td class="code"><pre><span class="line">rm -rf .deploy_git/ <span class="variable">&&</span> hexo clean <span class="variable">&&</span> hexo g <span class="variable">&&</span> gulp <span class="variable">&&</span> hexo d</span><br></pre></td></tr></table></figure></li>
<li>不到万不得已,不使用cnpm <figure class="highlight jboss-cli"><table><tr><td class="code"><pre><span class="line"><span class="keyword">echo</span> '<span class="keyword">alias</span> cnpm=<span class="string">"npm --registry=https://registry.npm.taobao.org --cache=$HOME/.npm/.cache/cnpm --disturl=https://npm.taobao.org/dist --userconfig=$HOME/.cnpmrc"</span>' >> ~<span class="string">/.bashrc</span> && source ~<span class="string">/.bashrc</span></span><br></pre></td></tr></table></figure>
</li>
</ul>
]]></content>
</entry>
<entry>
<title>Homeassistant远程开关NAS</title>
<url>/2021/11/28/Homeassistant-wol/</url>
<content><![CDATA[<h1 id="安装环境"><a href="#安装环境" class="headerlink" title="安装环境"></a>安装环境</h1><p>首先按照官方指南<a target="_blank" rel="noopener" href="https://www.home-assistant.io/installation/linux#install-home-assistant-supervised">Install Home Assistant Supervised</a></p>
<h1 id="HA控制Linux开机与关机"><a href="#HA控制Linux开机与关机" class="headerlink" title="HA控制Linux开机与关机"></a>HA控制Linux开机与关机</h1><h2 id="将HA的ssh-key添加到nas"><a href="#将HA的ssh-key添加到nas" class="headerlink" title="将HA的ssh key添加到nas"></a>将HA的ssh key添加到nas</h2><p>众所周知ssh登录是要输入密码的,为了能让关机的ssh可以在没有交互的情况下完成,我们要将HA的ssh key添加到nas。注意不是将HA的宿主机的SSH key添加到nas。</p>
<figure class="highlight reasonml"><table><tr><td class="code"><pre><span class="line">docker exec -it <span class="constructor">$(<span class="params">docker</span> <span class="params">ps</span> -<span class="params">f</span> <span class="params">name</span>=<span class="params">homeassistant</span> -<span class="params">q</span>)</span> bash</span><br></pre></td></tr></table></figure>
<p>这样进入docker容器的shell,如果是第一次,下面开始生成ssh key</p>
<figure class="highlight awk"><table><tr><td class="code"><pre><span class="line">ssh-keygen -t rsa -f <span class="regexp">/root/</span>.ssh/id_rsa</span><br></pre></td></tr></table></figure>
<p>然后一路回车,直到生成密钥,然后执行<code>ssh-id-copy</code>将密钥复制到nas</p>
<figure class="highlight applescript"><table><tr><td class="code"><pre><span class="line">ssh-<span class="keyword">copy</span>-<span class="built_in">id</span> root@nas的ip地址</span><br></pre></td></tr></table></figure>
<p>接着按照提示输入nas的root密码,复制密钥完成,以后就可以免密登录nas了。<br>可以在docker容器的shell中直接测试<code>ssh root@nas的ip地址</code></p>
<h2 id="在HA中添加一个名为nas的switch实体"><a href="#在HA中添加一个名为nas的switch实体" class="headerlink" title="在HA中添加一个名为nas的switch实体"></a>在HA中添加一个名为nas的switch实体</h2><p>然后编辑HA的配置文件<code>/usr/share/hassio/homeassistant/configuration.yaml</code>,添加如下字段</p>
<figure class="highlight less"><table><tr><td class="code"><pre><span class="line"><span class="attribute">switch</span>:</span><br><span class="line"> - <span class="attribute">platform</span>: wake_on_lan</span><br><span class="line"> <span class="attribute">mac</span>: <span class="string">"nas的mac地址"</span></span><br><span class="line"> <span class="attribute">name</span>: <span class="string">"nas"</span></span><br><span class="line"> <span class="attribute">host</span>: <span class="string">"nas的ip地址"</span></span><br><span class="line"> <span class="attribute">turn_off</span>:</span><br><span class="line"> <span class="attribute">service</span>: shell_command.turn_off_nas</span><br><span class="line"></span><br><span class="line"><span class="attribute">shell_command</span>:</span><br><span class="line"> <span class="attribute">turn_off_nas</span>: <span class="string">"ssh -i /root/.ssh/id_rsa -o 'StrictHostKeyChecking=no' root@nas的ip地址 poweroff"</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h2 id="在HA面板中添加nas"><a href="#在HA面板中添加nas" class="headerlink" title="在HA面板中添加nas"></a>在HA面板中添加nas</h2><p>在HA的概览中编辑仪表盘,添加nas开关。然后看看能不能控制nas的开机和关机啦!</p>
<h1 id="HA控制Windows开机与关机"><a href="#HA控制Windows开机与关机" class="headerlink" title="HA控制Windows开机与关机"></a>HA控制Windows开机与关机</h1><h2 id="让Windows支持远程关机"><a href="#让Windows支持远程关机" class="headerlink" title="让Windows支持远程关机"></a>让Windows支持远程关机</h2><ul>
<li>关闭防火墙,禁用杀毒软件,排除相关干扰</li>
<li>必须要设置账户密码,因为要远程开机,所以最好还要设置自动登录(下面会说到)</li>
<li>开启RPC相关服务(下面会说到)</li>
</ul>
<p>首先管理员身份运行CMD,运行如下命令</p>
<figure class="highlight routeros"><table><tr><td class="code"><pre><span class="line">sc<span class="built_in"> config </span>RemoteRegistry start= auto</span><br><span class="line">sc start RemoteRegistry</span><br><span class="line">sc<span class="built_in"> config </span>RpcSs start= auto</span><br><span class="line">sc start RpcSs</span><br></pre></td></tr></table></figure>
<p>将下面的文字复制到文本文档,更改<code>DefaultUserName</code>和<code>DefaultPassword</code>更改为你的用户名和密码</p>
<figure class="highlight moonscript"><table><tr><td class="code"><pre><span class="line">Windows Registry Editor Version <span class="number">5.00</span></span><br><span class="line"></span><br><span class="line">[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System]</span><br><span class="line"><span class="string">"LocalAccountTokenFilterPolicy"</span>=<span class="name">dword</span>:<span class="number">00000001</span></span><br><span class="line"></span><br><span class="line">[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon]</span><br><span class="line"><span class="string">"AutoAdminLogon"</span>=<span class="string">"1"</span></span><br><span class="line"><span class="string">"DefaultUserName"</span>=<span class="string">"My"</span></span><br><span class="line"><span class="string">"DefaultPassword"</span>=<span class="string">"weiyangbo"</span></span><br></pre></td></tr></table></figure>
<p>最后将文本文档的后缀改为reg,合并入注册表</p>
<h2 id="简单的RPC-Shutdown大法(HA支持Adds-on的情况)"><a href="#简单的RPC-Shutdown大法(HA支持Adds-on的情况)" class="headerlink" title="简单的RPC Shutdown大法(HA支持Adds-on的情况)"></a>简单的RPC Shutdown大法(HA支持Adds-on的情况)</h2><h3 id="安装RPC-Shutdown并配置"><a href="#安装RPC-Shutdown并配置" class="headerlink" title="安装RPC Shutdown并配置"></a>安装RPC Shutdown并配置</h3><p>这步很简单,直接在Add-ons商店里面搜索<code>RPC Shutdown</code>并安装就可以了。不过前提是你的HA要支持Add-ons,至少要Supervisor方式安装才有可能支持安装Add-ons。<br>进入RPC Shutdown的“配置”选项卡,更改<code>address</code>为你的Windows电脑的IP地址(肯定要是固定的),更改<code>credentials</code>为<code>Windows用户名%Windows密码</code>(其中%是不可省略的分隔符),更改<code>alias</code>为自己好记的名字。</p>
<figure class="highlight yaml"><table><tr><td class="code"><pre><span class="line"><span class="attr">computers:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">address:</span> <span class="number">192.168</span><span class="number">.0</span><span class="number">.12</span></span><br><span class="line"> <span class="attr">alias:</span> <span class="string">my-pc</span></span><br><span class="line"> <span class="attr">credentials:</span> <span class="string">My%weiyangbo</span></span><br><span class="line"> <span class="attr">delay:</span> <span class="number">0</span></span><br><span class="line"> <span class="attr">message:</span> <span class="string">>-</span></span><br><span class="line"> <span class="string">Home</span> <span class="string">Assistant</span> <span class="string">is</span> <span class="string">shutting</span> <span class="string">down</span> <span class="string">this</span> <span class="string">PC.</span> <span class="string">This</span> <span class="string">cannot</span> <span class="string">be</span> <span class="string">canceled.</span> <span class="string">Please</span></span><br><span class="line"> <span class="string">save</span> <span class="string">your</span> <span class="string">work!</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>保存并重启RPC Shutdown</p>
<h3 id="在HA中添加一个名为PC的switch实体"><a href="#在HA中添加一个名为PC的switch实体" class="headerlink" title="在HA中添加一个名为PC的switch实体"></a>在HA中添加一个名为PC的switch实体</h3><p>然后编辑HA的配置文件<code>/usr/share/hassio/homeassistant/configuration.yaml</code>,在<code>switch</code>字段下添加如下字段</p>
<figure class="highlight less"><table><tr><td class="code"><pre><span class="line"><span class="attribute">switch</span>:</span><br><span class="line"> - <span class="attribute">platform</span>: wake_on_lan</span><br><span class="line"> <span class="attribute">mac</span>: <span class="string">"1c-1b-0d-18-63-0c"</span></span><br><span class="line"> <span class="attribute">name</span>: <span class="string">"PC"</span></span><br><span class="line"> <span class="attribute">host</span>: <span class="string">"192.168.0.12"</span></span><br><span class="line"> <span class="attribute">turn_off</span>:</span><br><span class="line"> <span class="attribute">service</span>: hassio.addon_stdin</span><br><span class="line"> <span class="attribute">data</span>:</span><br><span class="line"> <span class="attribute">addon</span>: core_rpc_shutdown</span><br><span class="line"> <span class="attribute">input</span>: my-pc</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h2 id="复杂的曲线救国(HA不支持Adds-on的情况)"><a href="#复杂的曲线救国(HA不支持Adds-on的情况)" class="headerlink" title="复杂的曲线救国(HA不支持Adds-on的情况)"></a>复杂的曲线救国(HA不支持Adds-on的情况)</h2><h3 id="安装php和samba-common-bin"><a href="#安装php和samba-common-bin" class="headerlink" title="安装php和samba-common-bin"></a>安装php和samba-common-bin</h3><figure class="highlight sql"><table><tr><td class="code"><pre><span class="line">sudo apt <span class="keyword">install</span> php samba-common-<span class="keyword">bin</span></span><br></pre></td></tr></table></figure>
<p>新建php文件接受GET请求来执行对应的指令</p>
<figure class="highlight php"><table><tr><td class="code"><pre><span class="line">cat > remote_excute.php << <span class="string">'EOF'</span></span><br><span class="line"><span class="meta"><?php</span></span><br><span class="line"><span class="keyword">if</span> (<span class="keyword">isset</span>($_GET[<span class="string">'shutdown_pc'</span>])) {</span><br><span class="line"> $output = shell_exec(<span class="string">'net rpc -S 192.168.0.12 -U My%weiyangbo shutdown -t 1 -f'</span>);</span><br><span class="line"> <span class="keyword">echo</span> <span class="string">"<pre><span class="subst">$output</span></pre>"</span>;</span><br><span class="line">}</span><br><span class="line"><span class="meta">?></span></span><br><span class="line">EOF</span><br></pre></td></tr></table></figure>
<p>php开机自启动,添加以下内容到<code>/etc/rc.local</code></p>
<figure class="highlight angelscript"><table><tr><td class="code"><pre><span class="line">nohup php -S <span class="number">0.0</span><span class="number">.0</span><span class="number">.0</span>:<span class="number">80</span> /root/remote_excute.php &</span><br></pre></td></tr></table></figure>
<h3 id="在HA中添加一个名为PC的switch实体-1"><a href="#在HA中添加一个名为PC的switch实体-1" class="headerlink" title="在HA中添加一个名为PC的switch实体"></a>在HA中添加一个名为PC的switch实体</h3><p>然后编辑HA的配置文件<code>/usr/share/hassio/homeassistant/configuration.yaml</code>,在<code>switch</code>字段下添加如下字段</p>
<figure class="highlight less"><table><tr><td class="code"><pre><span class="line"><span class="attribute">switch</span>:</span><br><span class="line"> - <span class="attribute">platform</span>: wake_on_lan</span><br><span class="line"> <span class="attribute">mac</span>: <span class="string">"4c-cc-6a-6b-0a-15"</span></span><br><span class="line"> <span class="attribute">name</span>: <span class="string">"PC"</span></span><br><span class="line"> <span class="attribute">host</span>: <span class="string">"192.168.0.12"</span></span><br><span class="line"> <span class="attribute">turn_off</span>:</span><br><span class="line"> <span class="attribute">service</span>: shell_command.turn_off_pc</span><br><span class="line"></span><br><span class="line"><span class="attribute">shell_command</span>:</span><br><span class="line"> <span class="attribute">turn_off_pc</span>: <span class="string">"curl http://127.0.0.1:80/?shutdown_pc"</span></span><br></pre></td></tr></table></figure>
<h2 id="在HA面板中添加nas-1"><a href="#在HA面板中添加nas-1" class="headerlink" title="在HA面板中添加nas"></a>在HA面板中添加nas</h2><p>在HA的概览中编辑仪表盘,添加PC开关。然后看看能不能控制Windows PC的开机和关机啦!</p>
]]></content>
</entry>
<entry>
<title>Jellyfin-HWAcceleration</title>
<url>/2022/03/10/Jellyfin-HWAcceleration/</url>
<content><![CDATA[<p>Debian上直接<a target="_blank" rel="noopener" href="https://jellyfin.org/docs/general/administration/installing.html#debian">安装Jellyfin</a>,成功<a target="_blank" rel="noopener" href="https://jellyfin.org/docs/general/administration/hardware-acceleration.html#intel-quicksync">开启QSV硬解</a><br>某次<code>apt upgrade</code> 后,Jellyfin在网页播放视频时报错,提示“视频与客户端不兼容”之类的字样。关闭硬件解码就可以播放,但是不论打开QSV硬解还是VAAPI硬解都报错。</p>
<h1 id="问题描述"><a href="#问题描述" class="headerlink" title="问题描述"></a>问题描述</h1><p>jellyfin.log(片段)</p>
<figure class="highlight yaml"><table><tr><td class="code"><pre><span class="line">[<span class="number">2022-03-10 06:54:50.378 -05:00</span>] [<span class="string">INF</span>] <span class="string">Current</span> <span class="string">HLS</span> <span class="string">implementation</span> <span class="string">doesn't</span> <span class="string">support</span> <span class="string">non-keyframe</span> <span class="string">breaks</span> <span class="string">but</span> <span class="string">one</span> <span class="string">is</span> <span class="string">requested,</span> <span class="string">ignoring</span> <span class="string">that</span> <span class="string">request</span></span><br><span class="line">[<span class="number">2022-03-10 06:54:50.379 -05:00</span>] [<span class="string">INF</span>] <span class="string">/usr/lib/jellyfin-ffmpeg/ffmpeg</span> <span class="string">-c:v</span> <span class="string">h264_qsv</span> <span class="string">-hwaccel</span> <span class="string">qsv</span> <span class="string">-i</span> <span class="string">file:"/home/wei/downloads/porn/VID_20220128_081427_101.mp4"</span> <span class="string">-map_metadata</span> <span class="number">-1</span> <span class="string">-map_chapters</span> <span class="number">-1</span> <span class="string">-threads</span> <span class="number">0</span> <span class="string">-map</span> <span class="number">0</span><span class="string">:0</span> <span class="string">-map</span> <span class="number">0</span><span class="string">:1</span> <span class="string">-map</span> <span class="number">-0</span><span class="string">:s</span> <span class="string">-codec:v:0</span> <span class="string">h264_qsv</span> <span class="string">-preset</span> <span class="number">7</span> <span class="string">-look_ahead</span> <span class="number">0</span> <span class="string">-b:v</span> <span class="number">4497036</span> <span class="string">-maxrate</span> <span class="number">4497036</span> <span class="string">-bufsize</span> <span class="number">8994072</span> <span class="string">-profile:v:0</span> <span class="string">high</span> <span class="string">-level</span> <span class="number">41</span> <span class="string">-g:v:0</span> <span class="number">45</span> <span class="string">-keyint_min:v:0</span> <span class="number">45</span> <span class="string">-sc_threshold:v:0</span> <span class="number">0</span> <span class="string">-vf</span> <span class="string">"vpp_qsv=format=nv12"</span> <span class="string">-start_at_zero</span> <span class="string">-vsync</span> <span class="number">-1</span> <span class="string">-codec:a:0</span> <span class="string">aac</span> <span class="string">-ac</span> <span class="number">2</span> <span class="string">-ab</span> <span class="number">128000</span> <span class="string">-copyts</span> <span class="string">-avoid_negative_ts</span> <span class="string">disabled</span> <span class="string">-max_muxing_queue_size</span> <span class="number">2048</span> <span class="string">-f</span> <span class="string">hls</span> <span class="string">-max_delay</span> <span class="number">5000000</span> <span class="string">-hls_time</span> <span class="number">3</span> <span class="string">-hls_segment_type</span> <span class="string">mpegts</span> <span class="string">-start_number</span> <span class="number">0</span> <span class="string">-hls_segment_filename</span> <span class="string">"/var/lib/jellyfin/transcodes/904f296c004933ba148e126a69df77e7%d.ts"</span> <span class="string">-hls_playlist_type</span> <span class="string">vod</span> <span class="string">-hls_list_size</span> <span class="number">0</span> <span class="string">-y</span> <span class="string">"/var/lib/jellyfin/transcodes/904f296c004933ba148e126a69df77e7.m3u8"</span></span><br><span class="line">[<span class="number">2022-03-10 06:54:50.401 -05:00</span>] [<span class="string">ERR</span>] <span class="string">FFmpeg</span> <span class="string">exited</span> <span class="string">with</span> <span class="string">code</span> <span class="number">1</span></span><br><span class="line">[<span class="number">2022-03-10 06:54:50.486 -05:00</span>] [<span class="string">WRN</span>] <span class="string">cannot</span> <span class="string">serve</span> <span class="string">"/var/lib/jellyfin/transcodes/904f296c004933ba148e126a69df77e70.ts"</span> <span class="string">as</span> <span class="string">transcoding</span> <span class="string">quit</span> <span class="string">before</span> <span class="string">we</span> <span class="string">got</span> <span class="string">there</span></span><br><span class="line">[<span class="number">2022-03-10 06:54:50.489 -05:00</span>] [<span class="string">ERR</span>] <span class="attr">Error processing request:</span> <span class="string">"Could not find file '/var/lib/jellyfin/transcodes/904f296c004933ba148e126a69df77e70.ts'"</span><span class="string">.</span> <span class="string">URL</span> <span class="string">"GET"</span> <span class="string">"/videos/7a24af2c-9df3-66d4-aac8-9d671e3a6507/hls1/main/0.ts"</span><span class="string">.</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>FFMPEG.Transcode.log(片段)</p>
<figure class="highlight angelscript"><table><tr><td class="code"><pre><span class="line">/usr/lib/jellyfin-ffmpeg/ffmpeg -c:v h264_qsv -hwaccel qsv -i file:<span class="string">"/home/wei/downloads/porn/VID_20220128_081427_101.mp4"</span> -map_metadata <span class="number">-1</span> -map_chapters <span class="number">-1</span> -threads <span class="number">0</span> -map <span class="number">0</span>:<span class="number">0</span> -map <span class="number">0</span>:<span class="number">1</span> -map <span class="number">-0</span>:s -codec:v:<span class="number">0</span> h264_qsv -preset <span class="number">7</span> -look_ahead <span class="number">0</span> -b:v <span class="number">4497036</span> -maxrate <span class="number">4497036</span> -bufsize <span class="number">8994072</span> -profile:v:<span class="number">0</span> high -level <span class="number">41</span> -g:v:<span class="number">0</span> <span class="number">45</span> -keyint_min:v:<span class="number">0</span> <span class="number">45</span> -sc_threshold:v:<span class="number">0</span> <span class="number">0</span> -vf <span class="string">"vpp_qsv=format=nv12"</span> -start_at_zero -vsync <span class="number">-1</span> -codec:a:<span class="number">0</span> aac -ac <span class="number">2</span> -ab <span class="number">128000</span> -copyts -avoid_negative_ts disabled -max_muxing_queue_size <span class="number">2048</span> -f hls -max_delay <span class="number">5000000</span> -hls_time <span class="number">3</span> -hls_segment_type mpegts -start_number <span class="number">0</span> -hls_segment_filename <span class="string">"/var/lib/jellyfin/transcodes/904f296c004933ba148e126a69df77e7%d.ts"</span> -hls_playlist_type vod -hls_list_size <span class="number">0</span> -y <span class="string">"/var/lib/jellyfin/transcodes/904f296c004933ba148e126a69df77e7.m3u8"</span></span><br><span class="line"></span><br><span class="line">ffmpeg version <span class="number">4.4</span><span class="number">.1</span>-Jellyfin Copyright (c) <span class="number">2000</span><span class="number">-2021</span> the FFmpeg developers</span><br><span class="line"> built with gcc <span class="number">10</span> (Debian <span class="number">10.2</span><span class="number">.1</span><span class="number">-6</span>)</span><br><span class="line"> configuration: --prefix=/usr/lib/jellyfin-ffmpeg --target-os=linux --extra-version=Jellyfin --disable-doc --disable-ffplay --disable-<span class="keyword">shared</span> --disable-libxcb --disable-sdl2 --disable-xlib --enable-lto --enable-gpl --enable-version3 --enable-static --enable-gmp --enable-gnutls --enable-libdrm --enable-libass --enable-libfreetype --enable-libfribidi --enable-libfontconfig --enable-libbluray --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libdav1d --enable-libwebp --enable-libvpx --enable-libx264 --enable-libx265 --enable-libzvbi --enable-libzimg --arch=amd64 --enable-opencl --enable-vaapi --enable-amf --enable-libmfx --enable-vdpau --enable-ffnvcodec --enable-cuda --enable-cuda-llvm --enable-cuvid --enable-nvdec --enable-nvenc</span><br><span class="line"> libavutil <span class="number">56.</span> <span class="number">70.100</span> / <span class="number">56.</span> <span class="number">70.100</span></span><br><span class="line"> libavcodec <span class="number">58.134</span><span class="number">.100</span> / <span class="number">58.134</span><span class="number">.100</span></span><br><span class="line"> libavformat <span class="number">58.</span> <span class="number">76.100</span> / <span class="number">58.</span> <span class="number">76.100</span></span><br><span class="line"> libavdevice <span class="number">58.</span> <span class="number">13.100</span> / <span class="number">58.</span> <span class="number">13.100</span></span><br><span class="line"> libavfilter <span class="number">7.110</span><span class="number">.100</span> / <span class="number">7.110</span><span class="number">.100</span></span><br><span class="line"> libswscale <span class="number">5.</span> <span class="number">9.100</span> / <span class="number">5.</span> <span class="number">9.100</span></span><br><span class="line"> libswresample <span class="number">3.</span> <span class="number">9.100</span> / <span class="number">3.</span> <span class="number">9.100</span></span><br><span class="line"> libpostproc <span class="number">55.</span> <span class="number">9.100</span> / <span class="number">55.</span> <span class="number">9.100</span></span><br><span class="line">WARNING: defaulting hwaccel_output_format to qsv <span class="keyword">for</span> compatibility with old commandlines. This behaviour <span class="keyword">is</span> DEPRECATED <span class="keyword">and</span> will be removed <span class="keyword">in</span> the future. Please explicitly <span class="keyword">set</span> <span class="string">"-hwaccel_output_format qsv"</span>.</span><br><span class="line">Input #<span class="number">0</span>, mov,mp4,m4a,<span class="number">3</span>gp,<span class="number">3</span>g2,mj2, <span class="keyword">from</span> <span class="string">'file:/home/wei/downloads/porn/VID_20220128_081427_101.mp4'</span>:</span><br><span class="line"> Metadata:</span><br><span class="line"> major_brand : isom</span><br><span class="line"> minor_version : <span class="number">512</span></span><br><span class="line"> compatible_brands: isomiso2avc1mp41</span><br><span class="line"> encoder : Lavf58<span class="number">.20</span><span class="number">.100</span></span><br><span class="line"> Duration: <span class="number">01</span>:<span class="number">23</span>:<span class="number">00.66</span>, start: <span class="number">0.000000</span>, bitrate: <span class="number">1031</span> kb/s</span><br><span class="line"> Stream #<span class="number">0</span>:<span class="number">0</span>(und): Video: h264 (Constrained Baseline) (avc1 / <span class="number">0x31637661</span>), yuv420p, <span class="number">960</span>x540, <span class="number">899</span> kb/s, SAR <span class="number">1</span>:<span class="number">1</span> DAR <span class="number">16</span>:<span class="number">9</span>, <span class="number">14.99</span> fps, <span class="number">15</span> tbr, <span class="number">15360</span> tbn, <span class="number">30720</span> tbc (<span class="keyword">default</span>)</span><br><span class="line"> Metadata:</span><br><span class="line"> handler_name : VideoHandler</span><br><span class="line"> vendor_id : [<span class="number">0</span>][<span class="number">0</span>][<span class="number">0</span>][<span class="number">0</span>]</span><br><span class="line"> Stream #<span class="number">0</span>:<span class="number">1</span>(und): Audio: mp3 (mp4a / <span class="number">0x6134706D</span>), <span class="number">44100</span> Hz, stereo, fltp, <span class="number">128</span> kb/s (<span class="keyword">default</span>)</span><br><span class="line"> Metadata:</span><br><span class="line"> handler_name : SoundHandler</span><br><span class="line"> vendor_id : [<span class="number">0</span>][<span class="number">0</span>][<span class="number">0</span>][<span class="number">0</span>]</span><br><span class="line">Device creation failed: <span class="number">-542398533.</span></span><br><span class="line">[h264_qsv @ <span class="number">0x5608e2e5de40</span>] No device available <span class="keyword">for</span> decoder: device type qsv needed <span class="keyword">for</span> codec h264_qsv.</span><br><span class="line">Stream mapping:</span><br><span class="line"> Stream #<span class="number">0</span>:<span class="number">0</span> -> #<span class="number">0</span>:<span class="number">0</span> (h264 (h264_qsv) -> h264 (h264_qsv))</span><br><span class="line"> Stream #<span class="number">0</span>:<span class="number">1</span> -> #<span class="number">0</span>:<span class="number">1</span> (mp3 (mp3float) -> aac (native))</span><br><span class="line">Device setup failed <span class="keyword">for</span> decoder on input stream #<span class="number">0</span>:<span class="number">0</span> : Generic error <span class="keyword">in</span> an <span class="keyword">external</span> library</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h1 id="解决方案"><a href="#解决方案" class="headerlink" title="解决方案"></a>解决方案</h1><p>原因是Jellyfin没有使用<code>/dev/dri/renderD128</code>的权限,不信的话可以用root用户执行FFMPEG的命令试试,如果没有报错的话,那肯定是权限问题。<br>首先确定Jellyfin的所属用户</p>
<figure class="highlight vim"><table><tr><td class="code"><pre><span class="line"><span class="keyword">ps</span> auxw | <span class="keyword">grep</span> jellyfin</span><br></pre></td></tr></table></figure>
<p>查看渲染设备所处的用户组</p>
<figure class="highlight awk"><table><tr><td class="code"><pre><span class="line">stat -c <span class="string">"%G"</span> <span class="regexp">/dev/</span>dri/render*</span><br></pre></td></tr></table></figure>
<p>查看Jellyfin用户所属的用户组</p>
<figure class="highlight coq"><table><tr><td class="code"><pre><span class="line">groups `ps auxw | <span class="type">grep</span> jelly | <span class="type">sed</span> -n <span class="string">"1, 1p"</span> | <span class="type">awk</span> '{print $<span class="number">1</span>}'`</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>可以看到两个不在一个组中,接下来把Jellyfin用户添加到<code>/dev/dri/render*</code>所属的组中 </p>
<figure class="highlight autohotkey"><table><tr><td class="code"><pre><span class="line">sudo gpasswd -a `ps auxw | grep jelly | sed -n <span class="string">"1, 1p"</span> | awk '{print $<span class="number">1</span>}'` `stat -c <span class="string">"%G"</span> /dev/dri/render*`</span><br><span class="line">newgrp render</span><br></pre></td></tr></table></figure>
<p>不用重启,马上点开视频看看是不是正常了。</p>
]]></content>
</entry>
<entry>
<title>Jellyfin解决ass中文汉字变方块</title>
<url>/2021/11/25/Jellyfin-support-Chineese/</url>
<content><![CDATA[<p>有两种情形:Jellyfin直接在软件源中安装,或者docker安装的</p>
<a id="more"></a>
<p>Jellyfin在字幕设置中可以选择烧录字幕,开启之后一旦发现字幕会强制转码视频并烧录字幕,实测在我的rk3399开发板上是软件编码,消耗太大。不到万不得已不要开启,但是万一真的碰到烧录的中文汉字变成方块的情况,清继续往下看。</p>
<h1 id="情形一:软件源安装Jellyfin"><a href="#情形一:软件源安装Jellyfin" class="headerlink" title="情形一:软件源安装Jellyfin"></a>情形一:软件源安装Jellyfin</h1><p>详见<a target="_blank" rel="noopener" href="https://jellyfin.org/docs/general/installation/linux#debuntu-debian-ubuntu-and-derivatives-using-apt">Jellyfin官方安装指导</a></p>
<h2 id="下载字体文件"><a href="#下载字体文件" class="headerlink" title="下载字体文件"></a>下载字体文件</h2><p>首先下载<a href="FZZY_GBK.woff2.zip">方正准圆的 woff2 版本</a></p>
<figure class="highlight crystal"><table><tr><td class="code"><pre><span class="line">mkdir /var/<span class="class"><span class="keyword">lib</span>/<span class="title">jellyfin</span>/<span class="title">data</span>/<span class="title">fonts</span></span></span><br></pre></td></tr></table></figure>
<p>然后将字体文件解压并复制进上面的文件夹</p>
<h2 id="Jellyfin设置备用字体"><a href="#Jellyfin设置备用字体" class="headerlink" title="Jellyfin设置备用字体"></a>Jellyfin设置备用字体</h2><p>进入Jellyfin的控制台->备用字体文件路径,填写<code>/var/lib/jellyfin/data/fonts</code>。<br>然后勾选“启用备用字体”</p>
<h1 id="情形二:Docker安装Jellyfin(安装前)"><a href="#情形二:Docker安装Jellyfin(安装前)" class="headerlink" title="情形二:Docker安装Jellyfin(安装前)"></a>情形二:Docker安装Jellyfin(安装前)</h1><p>参考<a target="_blank" rel="noopener" href="https://jellyfin.org/docs/general/installation/container">Jellyfin官方安装指导</a><br>提供我的docker-compose.yaml</p>
<figure class="highlight routeros"><table><tr><td class="code"><pre><span class="line">version: <span class="string">'3.5'</span></span><br><span class="line">services:</span><br><span class="line"> jellyfin:</span><br><span class="line"> image: jellyfin/jellyfin</span><br><span class="line"> container_name: jellyfin</span><br><span class="line"> network_mode: <span class="string">'host'</span></span><br><span class="line"> volumes:</span><br><span class="line"> - /path/<span class="keyword">to</span>/media:/media</span><br><span class="line"> - <span class="variable">${PWD}</span>/jellyfin-config:/config</span><br><span class="line"> restart: <span class="string">'unless-stopped'</span></span><br><span class="line"> environment:</span><br><span class="line"> - <span class="attribute">DOCKER_MODS</span>=linuxserver/mods:universal-package-install</span><br><span class="line"> - <span class="attribute">INSTALL_PACKAGES</span>=fonts-noto-cjk-extra</span><br><span class="line"> - <span class="attribute">TZ</span>=Asia/Shanghai</span><br><span class="line"> devices:</span><br><span class="line"> - /dev/dri:/dev/dri</span><br></pre></td></tr></table></figure>
<p><code>docker-compose up -d</code></p>
<h1 id="情形三:Docker安装Jellyfin(安装后补救)"><a href="#情形三:Docker安装Jellyfin(安装后补救)" class="headerlink" title="情形三:Docker安装Jellyfin(安装后补救)"></a>情形三:Docker安装Jellyfin(安装后补救)</h1><figure class="highlight reasonml"><table><tr><td class="code"><pre><span class="line">docker exec -it <span class="constructor">$(<span class="params">docker</span> <span class="params">ps</span> -<span class="params">f</span> <span class="params">name</span>=<span class="params">jellyfin</span> -<span class="params">q</span>)</span> bash</span><br><span class="line">apt update</span><br><span class="line">apt install fonts-noto-cjk</span><br></pre></td></tr></table></figure>
]]></content>
</entry>
<entry>
<title>在Ubuntu 18.04上设置MTU</title>
<url>/2019/11/14/MTU-reset/</url>
<content><![CDATA[<p>用SSH连接服务器经常无缘无故断掉,SSH/SS连接表现出非常不稳定。但是用别的方法测试(ping或者访问服务器网页)速度都非常快,也没有丢包。<br>一番搜索,发现是MTU值为1500设置太高了,表现为SSH客户端在认证时会卡在<code>debug1: SSH2_MSG_KEXINIT sent</code><br>下面分别给出在Ubuntu 18.04和Android下设置MTU的方法。</p>
<a id="more"></a>
<h1 id="Ubuntu下的设置方式"><a href="#Ubuntu下的设置方式" class="headerlink" title="Ubuntu下的设置方式"></a>Ubuntu下的设置方式</h1><p>这是没有桌面环境的Ubuntu的设置方法,如果有桌面环境,那么直接进入<code>network-manager</code>中修改就完事了。</p>
<figure class="highlight awk"><table><tr><td class="code"><pre><span class="line">vi <span class="regexp">/etc/</span>netplan/<span class="number">99</span>-netcfg.yaml</span><br></pre></td></tr></table></figure>
<p>以我的文件为例</p>
<figure class="highlight yaml"><table><tr><td class="code"><pre><span class="line"><span class="attr">network:</span></span><br><span class="line"> <span class="attr">version:</span> <span class="number">2</span></span><br><span class="line"> <span class="attr">renderer:</span> <span class="string">networkd</span></span><br><span class="line"> <span class="attr">ethernets:</span></span><br><span class="line"> <span class="attr">eth0:</span></span><br><span class="line"> <span class="attr">dhcp4:</span> <span class="literal">yes</span></span><br><span class="line"> <span class="attr">mtu:</span> <span class="number">1400</span></span><br><span class="line"> <span class="attr">dhcp6:</span> <span class="literal">no</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>重启后永久生效</p>
<h1 id="Android下的设置方式"><a href="#Android下的设置方式" class="headerlink" title="Android下的设置方式"></a>Android下的设置方式</h1><p>首先需要知道移动数据走的是哪一个网卡</p>
<figure class="highlight ebnf"><table><tr><td class="code"><pre><span class="line"><span class="attribute">ifconfig</span></span><br></pre></td></tr></table></figure>
<p>以我的手机为例</p>
<figure class="highlight angelscript"><table><tr><td class="code"><pre><span class="line">lo Link encap:Local Loopback </span><br><span class="line"> inet addr:<span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span> Mask:<span class="number">255.0</span><span class="number">.0</span><span class="number">.0</span> </span><br><span class="line"> inet6 addr: ::<span class="number">1</span>/<span class="number">128</span> Scope: Host</span><br><span class="line"> UP LOOPBACK RUNNING MTU:<span class="number">65536</span> Metric:<span class="number">1</span></span><br><span class="line"> RX packets:<span class="number">20080</span> errors:<span class="number">0</span> dropped:<span class="number">0</span> overruns:<span class="number">0</span> frame:<span class="number">0</span> </span><br><span class="line"> TX packets:<span class="number">20080</span> errors:<span class="number">0</span> dropped:<span class="number">0</span> overruns:<span class="number">0</span> carrier:<span class="number">0</span> </span><br><span class="line"> collisions:<span class="number">0</span> txqueuelen:<span class="number">1</span> </span><br><span class="line"> RX bytes:<span class="number">45435532</span> TX bytes:<span class="number">45435532</span> </span><br><span class="line"></span><br><span class="line">dummy0 Link encap:Ethernet HWaddr <span class="number">66</span>:e6:<span class="number">63</span>:<span class="number">4</span>b:<span class="number">93</span>:c8</span><br><span class="line"> inet6 addr: fe80::<span class="number">64e6</span>:<span class="number">63f</span>f:fe4b:<span class="number">93</span>c8/<span class="number">64</span> Scope: Link</span><br><span class="line"> UP BROADCAST RUNNING NOARP MTU:<span class="number">1500</span> Metric:<span class="number">1</span></span><br><span class="line"> RX packets:<span class="number">0</span> errors:<span class="number">0</span> dropped:<span class="number">0</span> overruns:<span class="number">0</span> frame:<span class="number">0</span> </span><br><span class="line"> TX packets:<span class="number">18</span> errors:<span class="number">0</span> dropped:<span class="number">0</span> overruns:<span class="number">0</span> carrier:<span class="number">0</span> </span><br><span class="line"> collisions:<span class="number">0</span> txqueuelen:<span class="number">1000</span> </span><br><span class="line"> RX bytes:<span class="number">0</span> TX bytes:<span class="number">1260</span> </span><br><span class="line"></span><br><span class="line">wlan0 Link encap:Ethernet HWaddr <span class="number">26</span>:<span class="number">1</span>e:<span class="number">1</span>b:ed:<span class="number">72</span>:f0 Driver icnss</span><br><span class="line"> inet addr:<span class="number">192.168</span><span class="number">.2</span><span class="number">.146</span> Bcast:<span class="number">192.168</span><span class="number">.2</span><span class="number">.255</span> Mask:<span class="number">255.255</span><span class="number">.255</span><span class="number">.0</span> </span><br><span class="line"> inet6 addr: fe80::<span class="number">241</span>e:<span class="number">1</span>bff:feed:<span class="number">72f</span>0/<span class="number">64</span> Scope: Link</span><br><span class="line"> UP BROADCAST RUNNING MULTICAST MTU:<span class="number">1500</span> Metric:<span class="number">1</span></span><br><span class="line"> RX packets:<span class="number">513977</span> errors:<span class="number">0</span> dropped:<span class="number">0</span> overruns:<span class="number">0</span> frame:<span class="number">0</span> </span><br><span class="line"> TX packets:<span class="number">479613</span> errors:<span class="number">0</span> dropped:<span class="number">0</span> overruns:<span class="number">0</span> carrier:<span class="number">0</span> </span><br><span class="line"> collisions:<span class="number">0</span> txqueuelen:<span class="number">3000</span> </span><br><span class="line"> RX bytes:<span class="number">367769689</span> TX bytes:<span class="number">87048137</span> </span><br><span class="line"></span><br><span class="line">rmnet_data0 Link encap:UNSPEC </span><br><span class="line"> inet6 addr: fe80::fa03:<span class="number">7</span>b88:<span class="number">43</span>a:a1e/<span class="number">64</span> Scope: Link</span><br><span class="line"> UP RUNNING MTU:<span class="number">2000</span> Metric:<span class="number">1</span></span><br><span class="line"> RX packets:<span class="number">34</span> errors:<span class="number">0</span> dropped:<span class="number">0</span> overruns:<span class="number">0</span> frame:<span class="number">0</span> </span><br><span class="line"> TX packets:<span class="number">17</span> errors:<span class="number">0</span> dropped:<span class="number">0</span> overruns:<span class="number">0</span> carrier:<span class="number">0</span> </span><br><span class="line"> collisions:<span class="number">0</span> txqueuelen:<span class="number">1000</span> </span><br><span class="line"> RX bytes:<span class="number">17154</span> TX bytes:<span class="number">1200</span> </span><br><span class="line"></span><br><span class="line">rmnet_ipa0 Link encap:UNSPEC </span><br><span class="line"> UP RUNNING MTU:<span class="number">2000</span> Metric:<span class="number">1</span></span><br><span class="line"> RX packets:<span class="number">116428</span> errors:<span class="number">0</span> dropped:<span class="number">0</span> overruns:<span class="number">0</span> frame:<span class="number">0</span> </span><br><span class="line"> TX packets:<span class="number">110877</span> errors:<span class="number">0</span> dropped:<span class="number">0</span> overruns:<span class="number">0</span> carrier:<span class="number">0</span> </span><br><span class="line"> collisions:<span class="number">0</span> txqueuelen:<span class="number">1000</span> </span><br><span class="line"> RX bytes:<span class="number">178292211</span> TX bytes:<span class="number">15220756</span> </span><br><span class="line"></span><br><span class="line">rmnet_data1 Link encap:UNSPEC </span><br><span class="line"> inet addr:<span class="number">172.24</span><span class="number">.3</span><span class="number">.137</span> Mask:<span class="number">255.255</span><span class="number">.255</span><span class="number">.252</span> </span><br><span class="line"> UP RUNNING MTU:<span class="number">1500</span> Metric:<span class="number">1</span></span><br><span class="line"> RX packets:<span class="number">175319</span> errors:<span class="number">0</span> dropped:<span class="number">0</span> overruns:<span class="number">0</span> frame:<span class="number">0</span> </span><br><span class="line"> TX packets:<span class="number">110860</span> errors:<span class="number">0</span> dropped:<span class="number">0</span> overruns:<span class="number">0</span> carrier:<span class="number">0</span> </span><br><span class="line"> collisions:<span class="number">0</span> txqueuelen:<span class="number">1000</span> </span><br><span class="line"> RX bytes:<span class="number">176170341</span> TX bytes:<span class="number">15219556</span> </span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>可以看到rmnet_data0是没有连接网络的,移动数据在rmnet_data1上,下面修改MTU</p>
<figure class="highlight routeros"><table><tr><td class="code"><pre><span class="line">su</span><br><span class="line">ip link <span class="builtin-name">set</span> dev rmnet_data1 mtu 1400</span><br></pre></td></tr></table></figure>
<p>或者</p>
<figure class="highlight angelscript"><table><tr><td class="code"><pre><span class="line">su</span><br><span class="line">echo <span class="number">1400</span> > /sys/<span class="keyword">class</span>/<span class="symbol">net</span>/<span class="symbol">rmnet_data1</span>/<span class="symbol">mtu</span></span><br></pre></td></tr></table></figure>
<p>立马生效,不过重启后恢复默认值。<br>嫌麻烦可以修改init.rc,添加一行,永久生效</p>
<figure class="highlight gradle"><table><tr><td class="code"><pre><span class="line"><span class="keyword">write</span> <span class="regexp">/sys/</span><span class="keyword">class</span><span class="regexp">/net/</span>rmnet_data1/mtu <span class="number">1400</span></span><br></pre></td></tr></table></figure>
<h1 id="后记"><a href="#后记" class="headerlink" title="后记"></a>后记</h1><p>后来发现服务端上也有报错<code>error: Could not load host key: /etc/ssh/ssh_host_ed25519_key</code></p>
<figure class="highlight apache"><table><tr><td class="code"><pre><span class="line"><span class="attribute">ssh</span>-keygen -t ed<span class="number">25519</span> -f /etc/ssh/ssh_host_ed<span class="number">25519</span>_key</span><br></pre></td></tr></table></figure>
<p>重新生成密钥之后,多用一段时间再看疗效。</p>
]]></content>
</entry>
<entry>
<title>编译安装Nginx+FancyIndex</title>
<url>/2019/10/26/Nginx-FancyIndex/</url>
<content><![CDATA[<p>如果光是满足文件目录的需求有许多方案,如小程序webd,Python的SimpleHTTPServer,NPM的http-server,开源的的FileBrowser,闭源的FileRun…<br>而我选择了一个不上不下的方案,也就是Nginx+FancyIndex模块。优点是可以轻松地实现防盗链和Https的支持。</p>
<a id="more"></a>
<h1 id="编译安装Nginx"><a href="#编译安装Nginx" class="headerlink" title="编译安装Nginx"></a>编译安装Nginx</h1><p>必须要编译时添加FancyIndex模块才可以使用,所以先编译Nginx<br>克隆FancyIndex模块的源码</p>
<figure class="highlight awk"><table><tr><td class="code"><pre><span class="line">git clone https:<span class="regexp">//gi</span>thub.com<span class="regexp">/aperezdc/</span>ngx-fancyindex.git ngx-fancyindex</span><br></pre></td></tr></table></figure>
<figure class="highlight q"><table><tr><td class="code"><pre><span class="line">apt <span class="keyword">update</span> && sudo apt-<span class="built_in">get</span> install build-essential libtool gcc automake autoconf make libpcre3 libpcre3-<span class="built_in">dev</span> zlib1g-<span class="built_in">dev</span> openssl-y</span><br></pre></td></tr></table></figure>
<p>去 <a target="_blank" rel="noopener" href="http://nginx.org/download/">http://nginx.org/download/</a> 下载最新的Nginx源码,后缀为*.tar.gz的才是Linux版本</p>
<figure class="highlight stylus"><table><tr><td class="code"><pre><span class="line">wget http:<span class="comment">//nginx.org/download/nginx-1.17.6.tar.gz</span></span><br><span class="line">tar xvzf nginx-*<span class="selector-class">.tar</span><span class="selector-class">.gz</span> && rm nginx-*<span class="selector-class">.tar</span>.gz</span><br><span class="line">cd nginx-*</span><br></pre></td></tr></table></figure>
<p>编译时记得连带将FancyIndex模块添加进去</p>
<figure class="highlight jboss-cli"><table><tr><td class="code"><pre><span class="line"><span class="string">./configure</span> <span class="params">--prefix=/usr</span> <span class="params">--sbin-path=/usr/sbin/nginx</span> <span class="params">--conf-path=/etc/nginx/nginx</span>.conf <span class="params">--error-log-path=/var/log/nginx_error</span>.log <span class="params">--http-log-path=/var/log/nginx_access</span>.log <span class="params">--pid-path=/var/run/nginx</span>.pid <span class="params">--lock-path=/var/lock/nginx</span>.lock <span class="params">--user=root</span> <span class="params">--group=root</span> <span class="params">--with-http_ssl_module</span> <span class="params">--without-http_ssi_module</span> <span class="params">--without-http_memcached_module</span> <span class="params">--without-http_browser_module</span> <span class="params">--without-http_geo_module</span> <span class="params">--without-http_scgi_module</span> <span class="params">--without-http_uwsgi_module</span> <span class="params">--without-select_module</span> <span class="params">--add-module=</span><span class="string">../ngx-fancyindex</span> <span class="params">--with-http_v2_module</span> <span class="params">--with-http_realip_module</span></span><br><span class="line">make</span><br><span class="line">sudo make install</span><br></pre></td></tr></table></figure>
<h1 id="将Nginx添加开机启动"><a href="#将Nginx添加开机启动" class="headerlink" title="将Nginx添加开机启动"></a>将Nginx添加开机启动</h1><figure class="highlight routeros"><table><tr><td class="code"><pre><span class="line">sudo tee /etc/systemd/system/nginx.service >/dev/<span class="literal">null</span> <<<span class="string">'EOF'</span></span><br><span class="line">[Unit]</span><br><span class="line"><span class="attribute">Description</span>=nginx</span><br><span class="line"><span class="attribute">After</span>=network.target</span><br><span class="line"></span><br><span class="line">[Service]</span><br><span class="line"><span class="attribute">User</span>=root</span><br><span class="line"><span class="attribute">Type</span>=forking</span><br><span class="line"><span class="attribute">PIDFile</span>=/var/run/nginx.pid</span><br><span class="line"><span class="attribute">ExecStart</span>=/usr/sbin/nginx</span><br><span class="line"><span class="attribute">ExecReload</span>=/usr/sbin/nginx -s reload</span><br><span class="line"><span class="attribute">ExecStop</span>=/usr/sbin/nginx -s stop</span><br><span class="line"><span class="attribute">PrivateTmp</span>=<span class="literal">true</span></span><br><span class="line"></span><br><span class="line">[Install]</span><br><span class="line"><span class="attribute">WantedBy</span>=multi-user.target</span><br><span class="line">EOF</span><br></pre></td></tr></table></figure>
<p>将Nginx交给Systemd托管,设置Nginx下次开机启动</p>
<figure class="highlight routeros"><table><tr><td class="code"><pre><span class="line">sudo systemctl daemon-reload && sudo systemctl <span class="builtin-name">enable</span> nginx.service</span><br></pre></td></tr></table></figure>
<h1 id="为FancyIndex更换默认主题"><a href="#为FancyIndex更换默认主题" class="headerlink" title="为FancyIndex更换默认主题"></a>为FancyIndex更换默认主题</h1><p>默认的橙色主题是在太丑了,换成一个并没有名字的FancyIndex Theme<br><code>cd</code>到你的站点根目录,如<code>/www/wwwroot</code>,然后克隆这个主题</p>
<figure class="highlight awk"><table><tr><td class="code"><pre><span class="line">git clone https:<span class="regexp">//gi</span>thub.com<span class="regexp">/467815891a/</span>nginx-fancyindex-theme.git fancyindex</span><br></pre></td></tr></table></figure>
<p>在Nginx站点配置文件的<code>location</code>域中配置FancyIndex,这里直接贴上我Nginx的整个配置文件,以此为例</p>
<figure class="highlight properties"><table><tr><td class="code"><pre><span class="line"></span><br><span class="line"><span class="attr">user</span> <span class="string">root;</span></span><br><span class="line"><span class="attr">worker_processes</span> <span class="string">2;</span></span><br><span class="line"></span><br><span class="line"><span class="attr">pid</span> <span class="string">/var/run/nginx.pid;</span></span><br><span class="line"><span class="attr">error_log</span> <span class="string">/var/log/nginx_error.log;</span></span><br><span class="line"></span><br><span class="line"><span class="attr">events</span> <span class="string">{</span></span><br><span class="line"> <span class="attr">use</span> <span class="string">epoll;</span></span><br><span class="line"> <span class="attr">worker_connections</span> <span class="string">1024;</span></span><br><span class="line"> <span class="attr">multi_accept</span> <span class="string">on;</span></span><br><span class="line"><span class="attr">}</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="attr">http</span> <span class="string">{</span></span><br><span class="line"> <span class="attr">include</span> <span class="string">mime.types;</span></span><br><span class="line"> <span class="attr">default_type</span> <span class="string">application/octet-stream;</span></span><br><span class="line"> <span class="attr">charset</span> <span class="string">utf-8;</span></span><br><span class="line"> <span class="attr">sendfile</span> <span class="string">on;</span></span><br><span class="line"> <span class="attr">tcp_nopush</span> <span class="string">on;</span></span><br><span class="line"> <span class="attr">tcp_nodelay</span> <span class="string">on;</span></span><br><span class="line"> <span class="attr">keepalive_timeout</span> <span class="string">60;</span></span><br><span class="line"> <span class="attr">client_header_buffer_size</span> <span class="string">4k;</span></span><br><span class="line"> <span class="attr">open_file_cache</span> <span class="string">max=102400 inactive=20s;</span></span><br><span class="line"> <span class="attr">open_file_cache_valid</span> <span class="string">30s;</span></span><br><span class="line"> <span class="attr">open_file_cache_min_uses</span> <span class="string">1;</span></span><br><span class="line"> <span class="attr">client_header_timeout</span> <span class="string">15;</span></span><br><span class="line"> <span class="attr">client_body_timeout</span> <span class="string">15;</span></span><br><span class="line"> <span class="attr">reset_timedout_connection</span> <span class="string">on;</span></span><br><span class="line"> <span class="attr">send_timeout</span> <span class="string">15;</span></span><br><span class="line"> <span class="attr">gzip</span> <span class="string">on;</span></span><br><span class="line"> <span class="attr">gzip_disable</span> <span class="string">"msie6";</span></span><br><span class="line"> <span class="attr">gzip_vary</span> <span class="string">on;</span></span><br><span class="line"> <span class="attr">gzip_proxied</span> <span class="string">any;</span></span><br><span class="line"> <span class="attr">gzip_comp_level</span> <span class="string">3;</span></span><br><span class="line"> <span class="attr">gzip_buffers</span> <span class="string">16 8k;</span></span><br><span class="line"> <span class="attr">gzip_http_version</span> <span class="string">1.1;</span></span><br><span class="line"> <span class="attr">gzip_types</span> <span class="string">text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;</span></span><br><span class="line"> <span class="attr">server_tokens</span> <span class="string">off;</span></span><br><span class="line"> <span class="attr">access_log</span> <span class="string">/var/log/nginx_access.log;</span></span><br><span class="line"></span><br><span class="line"> <span class="attr">server</span> <span class="string">{</span></span><br><span class="line"> <span class="attr">listen</span> <span class="string">443 ssl;</span></span><br><span class="line"> <span class="attr">server_name</span> <span class="string">weiyangbo.com www.weiyangbo.com; #此处填你网站的域名</span></span><br><span class="line"><span class="comment"> #下面两行是你的ssl证书的路径</span></span><br><span class="line"> <span class="attr">ssl_certificate</span> <span class="string">/etc/nginx/cert/xxxxxxx.pem;</span></span><br><span class="line"> <span class="attr">ssl_certificate_key</span> <span class="string">/etc/nginx/cert/xxxxxxx.key;</span></span><br><span class="line"> <span class="attr">ssl_protocols</span> <span class="string">TLSv1 TLSv1.1 TLSv1.2;</span></span><br><span class="line"> <span class="attr">ssl_prefer_server_ciphers</span> <span class="string">on;</span></span><br><span class="line"> <span class="attr">ssl_session_timeout</span> <span class="string">5m;</span></span><br><span class="line"> <span class="attr">ssl_ciphers</span> <span class="string">ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;</span></span><br><span class="line"> <span class="attr">root</span> <span class="string">/www; #此处填你的网站目录</span></span><br><span class="line"> <span class="attr">location</span> <span class="string">/ {</span></span><br><span class="line"> <span class="attr">expires</span> <span class="string">10h;</span></span><br><span class="line"> <span class="attr">fancyindex</span> <span class="string">on;</span></span><br><span class="line"> <span class="attr">fancyindex_exact_size</span> <span class="string">off;</span></span><br><span class="line"> <span class="attr">fancyindex_localtime</span> <span class="string">on;</span></span><br><span class="line"> <span class="attr">fancyindex_header</span> <span class="string">"/fancyindex/header.html";</span></span><br><span class="line"> <span class="attr">fancyindex_footer</span> <span class="string">"/fancyindex/footer.html";</span></span><br><span class="line"> <span class="attr">fancyindex_ignore</span> <span class="string">"fancyindex" "Download"; #可以自定义文件服务器中不显示的文件或文件夹</span></span><br><span class="line"> <span class="attr">fancyindex_name_length</span> <span class="string">500;</span></span><br><span class="line"> <span class="attr">}</span></span><br><span class="line"><span class="comment"> #这是防盗链设置</span></span><br><span class="line"> <span class="attr">location</span> <span class="string">~* ^.+\.(jpg|gif|png|img|apk|tar.gz|wmv|jpeg|mp3|mp4|zip|rar)$ {</span></span><br><span class="line"> <span class="attr">valid_referers</span> <span class="string">none blocked weiyangbo.com www.weiyangbo.com;</span></span><br><span class="line"> <span class="attr">if</span> <span class="string">($invalid_referer){</span></span><br><span class="line"> <span class="attr">return</span> <span class="string">403;</span></span><br><span class="line"> <span class="attr">break;</span></span><br><span class="line"> <span class="attr">}</span></span><br><span class="line"> <span class="attr">access_log</span> <span class="string">off;</span></span><br><span class="line"> <span class="attr">}</span></span><br><span class="line"> <span class="attr">}</span></span><br><span class="line"><span class="comment"> #重定向80端口的全部http请求去https</span></span><br><span class="line"> <span class="attr">server</span> <span class="string">{</span></span><br><span class="line"> <span class="attr">listen</span> <span class="string">80;</span></span><br><span class="line"> <span class="attr">server_name</span> <span class="string">weiyangbo.com www.weiyangbo.com; #网站域名,跟上面保持一致</span></span><br><span class="line"> <span class="attr">return</span> <span class="string">301 https://$server_name$request_uri;</span></span><br><span class="line"> <span class="attr">}</span></span><br><span class="line"><span class="attr">}</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h1 id="测试网站"><a href="#测试网站" class="headerlink" title="测试网站"></a>测试网站</h1><p>检测配置文件有无语法错误</p>
<figure class="highlight ebnf"><table><tr><td class="code"><pre><span class="line"><span class="attribute">nginx -t</span></span><br></pre></td></tr></table></figure>
<p>尝试启动Nginx,看看实际效果。</p>
<figure class="highlight ebnf"><table><tr><td class="code"><pre><span class="line"><span class="attribute">nginx</span></span><br></pre></td></tr></table></figure>
<h1 id="定时清理Nginx日志"><a href="#定时清理Nginx日志" class="headerlink" title="定时清理Nginx日志"></a>定时清理Nginx日志</h1><p>Nginx没有日志自动归档或者清除的功能,我们要借助logrotate来定时清理日志,不然如果网页访问量大,没几天日志大小就上GB了,磁盘都不知道怎么爆的</p>
<figure class="highlight gradle"><table><tr><td class="code"><pre><span class="line">sudo tee <span class="regexp">/etc/</span>logrotate.d<span class="regexp">/nginx >/</span>dev/<span class="keyword">null</span> <<<span class="string">'EOF'</span></span><br><span class="line"><span class="regexp">/var/</span>log/nginx_*.log {</span><br><span class="line">su root root</span><br><span class="line"><span class="keyword">size</span> <span class="number">10000</span></span><br><span class="line">daily</span><br><span class="line">rotate <span class="number">3</span></span><br><span class="line">missingok</span><br><span class="line">dateext</span><br><span class="line">compress</span><br><span class="line">delaycompress</span><br><span class="line">notifempty</span><br><span class="line">create <span class="number">640</span> root root</span><br><span class="line">sharedscripts</span><br><span class="line">postrotate</span><br><span class="line"> <span class="keyword">if</span> [ -f <span class="regexp">/var/</span>run/nginx.pid ]; then</span><br><span class="line"> l -USR1 `cat <span class="regexp">/var/</span>run/nginx.pid`</span><br><span class="line"> fi</span><br><span class="line">endscript</span><br><span class="line">}</span><br><span class="line">EOF</span><br></pre></td></tr></table></figure>
<p><code>sudo logrotate /etc/logrotate.d/nginx</code></p>
]]></content>
</entry>
<entry>
<title>OrangePi第一次配置</title>
<url>/2020/03/12/OrangePi-Setup/</url>
<content><![CDATA[<p>入手了OrangePi Zero玩玩,已经把他做成了智能音箱了,结果不知道怎么回事就突然出问题了。之前一直都是通过WiFi连接SSH服务器来控制OrangePi Zero,现在的情况是WiFi刚连上就死机了。<br>OrangePi Zero已经用胶粘在音箱里了,TF卡可以取出来,但是网口没有空间插网线了。突然想起来手上还有一个CH340(USB转TTL)可以用来连接OrangePi Zero,记录一下不用网线配置OrangePi。<br> <a id="more"></a></p>
<h1 id="烧入Armbian"><a href="#烧入Armbian" class="headerlink" title="烧入Armbian"></a>烧入Armbian</h1><p>官方的Linux镜像已经完全不更新了。还是Armbian好,一直在不断更新,内核也到了5.4<br>下载<a target="_blank" rel="noopener" href="https://www.armbian.com/orange-pi-zero/">OrangePi Zero的镜像</a>,需要注意的是,我强烈推荐Ubuntu版的Armbian,Debian版反应迟缓、经常死机,具体原因不清楚。<br>然后解压,校验镜像<br><code>7z e Armbian_*.7z && sha256sum --check Armbian_*.img.sha</code><br>接着将SD卡插入电脑,查看SD的分区,如sdX<br><code>lsblk -p</code><br>依次卸载SD卡的所有分区<br><code>sudo umount /dev/sdX*</code><br>等等<br>烧录镜像<br><code>sudo dd bs=4M if=[你解压出来的img文件] of=/dev/sdX conv=fsync</code></p>
<h1 id="TTL连接"><a href="#TTL连接" class="headerlink" title="TTL连接"></a>TTL连接</h1><p>将USB TTL的Tx和Rx分别与OrangePi Zero的Rx和Tx连接起来,插入电脑的USB口。<br>安装并以root身份开启putty<br><code>sudo apt-get install putty</code><br><code>sudo putty</code><br>串口设备选择ttyUSB0,波特率115200,打开串口,然后接通OrangPi Zero的电源,不出意外可以看到串口打印出内核启动的信息了。</p>
<h1 id="连接WiFi"><a href="#连接WiFi" class="headerlink" title="连接WiFi"></a>连接WiFi</h1><p>Armbian默认的root密码是1234,设置好新密码后我们就可以连接wifi了<br><code>nmcli radio wifi on</code><br><code>nmcli d wifi connect YOUR_SSID password YOUR_PASSWROD</code><br>然后我们就可以查看IP地址了<br><code>ifconfig</code><br>尝试SSH连接吧,记得运行<code>armbian-config</code>更换国内软件源</p>
<h1 id="断线重连"><a href="#断线重连" class="headerlink" title="断线重连"></a>断线重连</h1><p>为了防止由于WiFi不稳定造成的断线问题,我们可以利用Crontab每分钟检测WiFi连接情况,判断是否要重新连接。<br><code>sudo crontab -e</code><br>追加一行<br><code>* * * * * ping $(ip route show default | awk '/default/ {print $3}') -c3 || reboot</code></p>
<h1 id="设置音频输出"><a href="#设置音频输出" class="headerlink" title="设置音频输出"></a>设置音频输出</h1><p>不管是树莓派还是其他Pi,ALSA管理的音频输出一直是我头疼的问题。一方面ALSA的配置极其复杂,各种card,device,asound.conf,.asoundrc让人眼花缭乱;另一方面这些开发板音频口底噪都比较大,如果能在软件方面提高音量,那跟从功放端提高音量相比可以减少噪声输出。<br>对于OrangePi Zero,我赶紧把调好步骤记录下来</p>
<figure class="highlight angelscript"><table><tr><td class="code"><pre><span class="line">/usr/bin/amixer -c <span class="number">0</span> cset numid=<span class="number">3</span> <span class="number">31</span></span><br><span class="line">/usr/bin/amixer -c <span class="number">0</span> cset numid=<span class="number">4</span> on</span><br><span class="line">/usr/bin/amixer -c <span class="number">0</span> cset numid=<span class="number">1</span> <span class="number">63</span></span><br><span class="line">/usr/bin/amixer -c <span class="number">0</span> cset numid=<span class="number">10</span> on</span><br><span class="line">/usr/bin/amixer -c <span class="number">0</span> cset numid=<span class="number">7</span> <span class="number">7</span></span><br><span class="line">/usr/bin/amixer -c <span class="number">0</span> cset numid=<span class="number">18</span> on</span><br><span class="line">/usr/bin/amixer -c <span class="number">0</span> cset numid=<span class="number">8</span> <span class="number">1</span></span><br><span class="line">/usr/bin/amixer -c <span class="number">0</span> cset numid=<span class="number">13</span> off</span><br><span class="line">/usr/bin/amixer -c <span class="number">0</span> cset numid=<span class="number">5</span> <span class="number">7</span></span><br><span class="line">/usr/bin/amixer -c <span class="number">0</span> cset numid=<span class="number">19</span> on</span><br><span class="line">/usr/bin/amixer -c <span class="number">0</span> cset numid=<span class="number">6</span> <span class="number">1</span></span><br><span class="line">/usr/bin/amixer -c <span class="number">0</span> cset numid=<span class="number">14</span> off</span><br></pre></td></tr></table></figure>
<p>编辑/etc/asound.conf</p>
<figure class="highlight routeros"><table><tr><td class="code"><pre><span class="line">sudo tee /etc/asound.conf >/dev/<span class="literal">null</span> <<<span class="string">'EOF'</span></span><br><span class="line"><span class="comment"># the sound card</span></span><br><span class="line">pcm.real {</span><br><span class="line"> <span class="built_in"> type </span>hw</span><br><span class="line"> card 0</span><br><span class="line"> device 0</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="comment"># software volume</span></span><br><span class="line">pcm.softvol {</span><br><span class="line"> <span class="built_in"> type </span>softvol</span><br><span class="line"> slave.pcm <span class="string">"real"</span></span><br><span class="line"> control {</span><br><span class="line"> name <span class="string">"Software"</span></span><br><span class="line"> card 0</span><br><span class="line"> }</span><br><span class="line"> max_dB 40.0</span><br><span class="line"> min_dB -10.0</span><br><span class="line"> resolution 10</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">pcm.mic {</span><br><span class="line"> <span class="built_in"> type </span>plug</span><br><span class="line"> slave.pcm <span class="string">"hw:0,0"</span></span><br><span class="line"> slave.format S16_LE</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="comment"># default device</span></span><br><span class="line">pcm.!default {</span><br><span class="line"> <span class="built_in"> type </span>asym</span><br><span class="line"> playback.pcm <span class="string">"softvol"</span></span><br><span class="line"> capture.pcm <span class="string">"mic"</span></span><br><span class="line">}</span><br><span class="line">EOF</span><br></pre></td></tr></table></figure>
<p>接着重启即可,然后测试默认音频输出</p>
<figure class="highlight apache"><table><tr><td class="code"><pre><span class="line"><span class="attribute">speaker</span>-test -c<span class="number">2</span> -twav</span><br></pre></td></tr></table></figure>
<p>此时应该可以听到轻柔的女声,如果不行就放大招————重装alsa</p>
<figure class="highlight applescript"><table><tr><td class="code"><pre><span class="line">sudo apt-<span class="keyword">get</span> <span class="comment">--purge --reinstall install alsa-base alsa-utils</span></span><br></pre></td></tr></table></figure>
<h1 id="配置硬件看门狗"><a href="#配置硬件看门狗" class="headerlink" title="配置硬件看门狗"></a>配置硬件看门狗</h1><figure class="highlight cmake"><table><tr><td class="code"><pre><span class="line">apt <span class="keyword">install</span> watchdog</span><br></pre></td></tr></table></figure>
<p><code>/etc/watchdog.conf</code>参考如下</p>
<figure class="highlight ini"><table><tr><td class="code"><pre><span class="line"><span class="comment"># Defaults compiled into the binary</span></span><br><span class="line"><span class="attr">temperature-sensor</span> = /sys/class/thermal/thermal_zone0/temp</span><br><span class="line"><span class="attr">max-temperature</span> = <span class="number">85</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Defaults compiled into the binary</span></span><br><span class="line"><span class="attr">admin</span> = root</span><br><span class="line"><span class="comment">#Allwinner H2+默认的看门狗timeout是16秒,所以每隔15秒喂一次就可以了</span></span><br><span class="line"><span class="attr">interval</span> = <span class="number">15</span></span><br><span class="line"><span class="attr">logtick</span> = <span class="number">1</span></span><br><span class="line"><span class="attr">log-dir</span> = /var/log/watchdog</span><br><span class="line"></span><br><span class="line"><span class="comment"># This greatly decreases the chance that watchdog won't be scheduled before</span></span><br><span class="line"><span class="comment"># your machine is really loaded</span></span><br><span class="line"><span class="attr">realtime</span> = <span class="literal">yes</span></span><br><span class="line"><span class="attr">priority</span> = <span class="number">1</span></span><br></pre></td></tr></table></figure>
<p>接着启用watchdog</p>
<figure class="highlight routeros"><table><tr><td class="code"><pre><span class="line">service<span class="built_in"> watchdog </span>start && systemctl <span class="builtin-name">enable</span> watchdog</span><br></pre></td></tr></table></figure>
]]></content>
</entry>
<entry>
<title>用AutoSSH建立SSH反向隧道</title>
<url>/2019/10/10/SSH-reverse-tunnel/</url>
<content><![CDATA[<ul>
<li>公网服务器A 开放端口5678(转发ssh连接),开放端口5679(监听连接状态),开放端口22</li>
<li>内网机器B Ubuntu18.04 </li>
</ul>
<p>建立公网服务器A到内网机器B的SSH反向代理,将连接到公网服务器A 5678端口的SSH请求转发给内网机器B的22端口</p>
<a id="more"></a>
<h2 id="修改公网服务器A的SSH配置文件-etc-ssh-sshd-config"><a href="#修改公网服务器A的SSH配置文件-etc-ssh-sshd-config" class="headerlink" title="修改公网服务器A的SSH配置文件/etc/ssh/sshd_config"></a>修改公网服务器A的SSH配置文件<code>/etc/ssh/sshd_config</code></h2><figure class="highlight nginx"><table><tr><td class="code"><pre><span class="line"><span class="attribute">GatewayPorts</span> <span class="literal">yes</span></span><br></pre></td></tr></table></figure>
<p>这样可以把监听的端口绑定到任意IP 0.0.0.0上,否则只有本机127.0.0.1可以访问。<br>记得重启SSH服务器</p>
<figure class="highlight routeros"><table><tr><td class="code"><pre><span class="line">sudo<span class="built_in"> service </span>restart sshd</span><br></pre></td></tr></table></figure>
<h2 id="用内网B机器保存公网服务器A的密钥,以便免密连接"><a href="#用内网B机器保存公网服务器A的密钥,以便免密连接" class="headerlink" title="用内网B机器保存公网服务器A的密钥,以便免密连接"></a>用内网B机器保存公网服务器A的密钥,以便免密连接</h2><figure class="highlight applescript"><table><tr><td class="code"><pre><span class="line">ssh-<span class="keyword">copy</span>-<span class="built_in">id</span> [公网服务器A的用户名]@[公网服务器A的IP]</span><br></pre></td></tr></table></figure>
<h2 id="在内网B机器上尝试建立反向代理"><a href="#在内网B机器上尝试建立反向代理" class="headerlink" title="在内网B机器上尝试建立反向代理"></a>在内网B机器上尝试建立反向代理</h2><figure class="highlight angelscript"><table><tr><td class="code"><pre><span class="line">ssh -NR <span class="number">5678</span>:<span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span>:<span class="number">22</span> 公网服务器A的用户名@公网服务器A的IP</span><br></pre></td></tr></table></figure>
<p>正常情况下,不用输入密码,通道即建立成功。 </p>
<ul>
<li>-N:只建立连接,不打开shell </li>
<li>-R:指定端口映射 </li>
</ul>
<h1 id="AutoSSH-自动重连"><a href="#AutoSSH-自动重连" class="headerlink" title="AutoSSH 自动重连"></a>AutoSSH 自动重连</h1><p>使用SSH的方式不够稳定,使用AutoSSH可以自动在连接断开时自动重连,再把AutoSSH加入系统服务自动启动,则可以做到稳定的连接。</p>
<h2 id="安装AutoSSH"><a href="#安装AutoSSH" class="headerlink" title="安装AutoSSH"></a>安装AutoSSH</h2><figure class="highlight routeros"><table><tr><td class="code"><pre><span class="line">sudo apt-<span class="builtin-name">get</span> install -y autossh</span><br></pre></td></tr></table></figure>
<h2 id="将AutoSSH添加到开机自启"><a href="#将AutoSSH添加到开机自启" class="headerlink" title="将AutoSSH添加到开机自启"></a>将AutoSSH添加到开机自启</h2><p>需要创建一个 <code>/etc/systemd/system/autossh.service</code> 文件</p>
<figure class="highlight routeros"><table><tr><td class="code"><pre><span class="line">sudo tee /etc/systemd/system/autossh.service >/dev/<span class="literal">null</span> <<<span class="string">'EOF'</span></span><br><span class="line">[Unit]</span><br><span class="line"><span class="attribute">Description</span>=AutoSSH<span class="built_in"> service </span><span class="keyword">for</span> remote tunnel</span><br><span class="line"><span class="attribute">After</span>=network-online.target</span><br><span class="line"></span><br><span class="line">[Service]</span><br><span class="line"><span class="attribute">User</span>=内网机器B的用户名</span><br><span class="line"><span class="attribute">ExecStart</span>=/usr/bin/autossh -M 5679 -N -o <span class="string">"StrictHostKeyChecking=false"</span> -o <span class="string">"ServerAliveInterval 60"</span> -o <span class="string">"ServerAliveCountMax 3"</span> -R 5678:localhost:22 公网服务器A的用户名@公网服务A的IP</span><br><span class="line"><span class="attribute">Restart</span>=always</span><br><span class="line"><span class="attribute">RestartSec</span>=3</span><br><span class="line"></span><br><span class="line">[Install]</span><br><span class="line"><span class="attribute">WantedBy</span>=multi-user.target</span><br><span class="line">EOF</span><br></pre></td></tr></table></figure>
<p>将AutoSSH交给Systemd托管,设置立即启动并下次开机自启</p>
<figure class="highlight smali"><table><tr><td class="code"><pre><span class="line">sudo<span class="keyword"> system</span>ctl daemon-reload && sudo<span class="keyword"> system</span>ctl start autossh && sudo<span class="keyword"> system</span>ctl enable autossh.service</span><br></pre></td></tr></table></figure>
<p>autossh相关参数说明</p>
<ul>
<li>-M: 5679 选项指定中继服务器上的监视端口,用于交换监视 SSH 会话的测试数据,需要保证该端口在服务器上未被占用。 </li>
<li>-o: 用于设置 autossh 参数。 </li>
<li>-f:指定 autossh 在后台运行,并不会传给 ssh。和 ssh 的 -f 不一样,autossh 指定 -f 时将无法寻求密码。指定 -f 时,会将环境变量 AUTOSSH_GATETIME 覆盖为 0! </li>
<li>-N:只建立连接,不打开shell </li>
<li>-R:指定端口映射 </li>
</ul>
]]></content>
</entry>
<entry>
<title>OpenWrt上使用AutoSSH建立反向代理</title>
<url>/2020/03/21/SSH-reverse-tunnel-Openwrt/</url>
<content><![CDATA[<p>丈母娘想让我解决她们家Wifi信号弱的问题,我决定把家里原来唯一的无线路由器变成纯AP,弱电箱里放一个星际宝盒,另外在客厅放一台K2保证全家的Wifi覆盖。<br>本来路由器这种东西设置好了就不会再动了,可是我还需要解决他们家网络电视的问题,网络电视这种东西,直播源很容易失效,感觉以后会涉及到远程维护了。<br>我之前写过<a href="/2019/10/10/SSH-reverse-tunnel/" title="Ubuntu下用Autossh建立反向连接">Ubuntu下用Autossh建立反向连接</a>的博文,现在想照搬到OpenWrt上。但是OpenWrt上是用Dropbear作为SSH工具,与OpenSSH有些许不同,记录一下过程。</p>
<a id="more"></a>
<h1 id="前期准备"><a href="#前期准备" class="headerlink" title="前期准备"></a>前期准备</h1><ul>
<li>公网服务器A 开放端口5680(转发ssh连接),开放端口5681(监听连接状态),开放端口22,用OpenSSH做SSH服务器</li>
<li>内网机器B OpenWrt with Dropbear</li>
</ul>
<h1 id="修改公网服务器A的SSH配置文件-etc-ssh-sshd-config"><a href="#修改公网服务器A的SSH配置文件-etc-ssh-sshd-config" class="headerlink" title="修改公网服务器A的SSH配置文件/etc/ssh/sshd_config"></a>修改公网服务器A的SSH配置文件<code>/etc/ssh/sshd_config</code></h1><figure class="highlight properties"><table><tr><td class="code"><pre><span class="line"><span class="attr">GatewayPorts</span> <span class="string">yes</span></span><br><span class="line"><span class="attr">HostKeyAlgorithms</span> <span class="string">+ssh-rsa</span></span><br><span class="line"><span class="attr">PubkeyAcceptedAlgorithms</span> <span class="string">+ssh-rsa</span></span><br><span class="line"><span class="attr">PubkeyAuthentication</span> <span class="string">yes</span></span><br><span class="line"><span class="attr">AuthorizedKeysFile</span> <span class="string">.ssh/authorized_keys</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>这样可以把监听的端口绑定到任意IP 0.0.0.0上,否则只有本机127.0.0.1可以访问。<br>添加ssh-rsa算法兼容老板版本dropbear<br>记得重启SSH服务器</p>
<figure class="highlight routeros"><table><tr><td class="code"><pre><span class="line">sudo<span class="built_in"> service </span>restart sshd</span><br></pre></td></tr></table></figure>
<h1 id="用内网B机器保存公网服务器A的密钥,以便免密连接"><a href="#用内网B机器保存公网服务器A的密钥,以便免密连接" class="headerlink" title="用内网B机器保存公网服务器A的密钥,以便免密连接"></a>用内网B机器保存公网服务器A的密钥,以便免密连接</h1><p>这里就跟OpenSSH不一样了,因为Dropbear没有ssh-id-copy这个命令,而Dropbear的private key又不是以明文方式存储的。</p>
<figure class="highlight awk"><table><tr><td class="code"><pre><span class="line"><span class="comment">#You can get the key using</span></span><br><span class="line">dropbearkey -y -f <span class="regexp">/etc/</span>dropbear<span class="regexp">/dropbear_rsa_host_key | grep "^ssh-rsa " > /</span>etc<span class="regexp">/dropbear/</span>authorized_keys</span><br></pre></td></tr></table></figure>
<p>然后将key从authorized_keys复制添加到到公网服务器的~/.ssh/authorized_keys中</p>
<h1 id="在内网B机器上尝试建立反向代理"><a href="#在内网B机器上尝试建立反向代理" class="headerlink" title="在内网B机器上尝试建立反向代理"></a>在内网B机器上尝试建立反向代理</h1><figure class="highlight angelscript"><table><tr><td class="code"><pre><span class="line">#注意Dropbear在建立SSH连接时不会自己带着私钥,需要指定</span><br><span class="line">ssh -NR <span class="number">5678</span>:<span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span>:<span class="number">22</span> 公网服务器A的用户名@公网服务器A的IP -i /etc/dropbear/dropbear_rsa_host_key</span><br></pre></td></tr></table></figure>
<p>正常情况下,不用输入密码,通道即建立成功。 </p>
<ul>
<li>-N:只建立连接,不打开shell </li>
<li>-R:指定端口映射 </li>
</ul>
<h1 id="AutoSSH-自动重连"><a href="#AutoSSH-自动重连" class="headerlink" title="AutoSSH 自动重连"></a>AutoSSH 自动重连</h1><p>使用SSH的方式不够稳定,使用AutoSSH可以自动在连接断开时自动重连,再把AutoSSH加入系统服务自动启动,则可以做到稳定的连接。</p>
<h2 id="安装AutoSSH"><a href="#安装AutoSSH" class="headerlink" title="安装AutoSSH"></a>安装AutoSSH</h2><figure class="highlight angelscript"><table><tr><td class="code"><pre><span class="line">opkg install <span class="built_in">auto</span>ssh</span><br></pre></td></tr></table></figure>
<h2 id="将AutoSSH添加到开机自启"><a href="#将AutoSSH添加到开机自启" class="headerlink" title="将AutoSSH添加到开机自启"></a>将AutoSSH添加到开机自启</h2><p>注意在OpenWrt里,官方的autossh早就给你准备好了 <code>/etc/init.d/autossh</code> 文件,你只需要在<code>/etc/config/autossh</code>中修改参数即可,下面贴出我的配置</p>
<figure class="highlight vbnet"><table><tr><td class="code"><pre><span class="line">config autossh</span><br><span class="line"> <span class="keyword">option</span> ssh <span class="comment">'-i /etc/dropbear/dropbear_rsa_host_key -N -T -R 5678:localhost:22 公网服务器A的用户名@公网服务器A的IP'</span></span><br><span class="line"> <span class="keyword">option</span> gatetime <span class="comment">'0'</span></span><br><span class="line"> <span class="keyword">option</span> monitorport <span class="comment">'5679'</span></span><br><span class="line"> <span class="keyword">option</span> poll <span class="comment">'180'</span></span><br><span class="line"> <span class="keyword">option</span> enabled <span class="comment">'1'</span></span><br></pre></td></tr></table></figure>
<h2 id="修复Dropbear的一个小bug"><a href="#修复Dropbear的一个小bug" class="headerlink" title="修复Dropbear的一个小bug"></a>修复Dropbear的一个小bug</h2><p>必须要指定HOME目录,详见<a target="_blank" rel="noopener" href="https://github.com/openwrt/packages/issues/5559">Github</a><br>修改<code>/etc/init.d/autossh</code>,添加<code>HOME=/root</code>,全文见下</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="meta">#!/bin/sh /etc/rc.common</span></span><br><span class="line"><span class="comment"># Copyright (C) 2007-2011 OpenWrt.org</span></span><br><span class="line"></span><br><span class="line">START=80</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="title">start_instance</span></span>() {</span><br><span class="line"> <span class="built_in">local</span> section=<span class="string">"<span class="variable">$1</span>"</span></span><br><span class="line"></span><br><span class="line"> config_get ssh <span class="string">"<span class="variable">$section</span>"</span> <span class="string">'ssh'</span></span><br><span class="line"> config_get gatetime <span class="string">"<span class="variable">$section</span>"</span> <span class="string">'gatetime'</span></span><br><span class="line"> config_get monitorport <span class="string">"<span class="variable">$section</span>"</span> <span class="string">'monitorport'</span></span><br><span class="line"> config_get poll <span class="string">"<span class="variable">$section</span>"</span> <span class="string">'poll'</span></span><br><span class="line"> config_get_bool enabled <span class="string">"<span class="variable">$section</span>"</span> <span class="string">'enabled'</span> <span class="string">'1'</span></span><br><span class="line"></span><br><span class="line"> [ <span class="string">"<span class="variable">$enabled</span>"</span> = 1 ] || <span class="built_in">exit</span> 0</span><br><span class="line"></span><br><span class="line"> <span class="built_in">export</span> AUTOSSH_GATETIME=<span class="string">"<span class="variable">${gatetime:-30}</span>"</span></span><br><span class="line"> <span class="built_in">export</span> AUTOSSH_POLL=<span class="string">"<span class="variable">${poll:-600}</span>"</span></span><br><span class="line"> <span class="built_in">export</span> HOME=/root</span><br><span class="line"> service_start /usr/sbin/autossh -M <span class="variable">${monitorport:-20000}</span> -f <span class="variable">${ssh}</span></span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="title">boot</span></span>() {</span><br><span class="line"> <span class="built_in">return</span></span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="title">start</span></span>() {</span><br><span class="line"> config_load <span class="string">'autossh'</span></span><br><span class="line"> config_foreach start_instance <span class="string">'autossh'</span></span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="title">stop</span></span>() {</span><br><span class="line"> service_stop /usr/sbin/autossh</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<p>然后开机启动Autossh<br><code>/etc/init.d/autossh enable</code></p>
]]></content>
</entry>
<entry>
<title>Trojan+Nginx实现HTTP+TLS伪装代理</title>
<url>/2020/02/28/Trojan/</url>
<content><![CDATA[<p>我之前写过<a href="/2019/12/08/V2ray/" title="V2ray+Nginx实现WebSocket+TLS伪装代理">V2ray+Nginx实现WebSocket+TLS伪装代理</a>的博文,用了几个月,效果不错的。本来不准备更换方案,但是我发现MT7621主控的路由器跑V2ray最高就8Mbps左右的速度,电脑上可以跑到30Mbps。很明显路由器成为了瓶颈。相对于Golang写的V2ray,用C写的Trojan明显应该可以消耗更少的资源,于是有了更换Trojan的想法。</p>
<a id="more"></a>
<h1 id="安装Trojan和Nginx"><a href="#安装Trojan和Nginx" class="headerlink" title="安装Trojan和Nginx"></a>安装Trojan和Nginx</h1><p>参考以下两个链接分别安装Nginx和Trojan,其中Trojan是在客户端和在服务器上都要安装的,跟SS不同,Trojan服务端和客户端是一体的。Nginx只需服务器安装就可以了。<br> <a target="_blank" rel="noopener" href="https://github.com/trojan-gfw/trojan-quickstart">Trojan官方Linux下安装指南</a><br>我之前写过<a href="/2019/10/26/Nginx-FancyIndex/" title="编译安装和配置Nginx">编译安装和配置Nginx</a>的博文</p>
<h1 id="服务端设置"><a href="#服务端设置" class="headerlink" title="服务端设置"></a>服务端设置</h1><p>网上所有的方案就是让Trojan监听443端口,然后将识别出的正常网页流量转发到Nginx,这样无疑会降低访问正常网页的速度。但是想想我的网站也没多少访问量,而且这样应该会提升科学上网的速度,符合我的初衷,于是就开干了。<br>Nginx配置</p>
<figure class="highlight properties"><table><tr><td class="code"><pre><span class="line"></span><br><span class="line"><span class="attr">user</span> <span class="string">root;</span></span><br><span class="line"><span class="attr">worker_processes</span> <span class="string">2;</span></span><br><span class="line"></span><br><span class="line"><span class="attr">pid</span> <span class="string">/var/run/nginx.pid;</span></span><br><span class="line"><span class="attr">error_log</span> <span class="string">/var/log/nginx_error.log;</span></span><br><span class="line"></span><br><span class="line"><span class="attr">events</span> <span class="string">{</span></span><br><span class="line"> <span class="attr">use</span> <span class="string">epoll;</span></span><br><span class="line"> <span class="attr">worker_connections</span> <span class="string">1024;</span></span><br><span class="line"> <span class="attr">multi_accept</span> <span class="string">on;</span></span><br><span class="line"><span class="attr">}</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="attr">http</span> <span class="string">{</span></span><br><span class="line"> <span class="attr">include</span> <span class="string">mime.types;</span></span><br><span class="line"> <span class="attr">default_type</span> <span class="string">application/octet-stream;</span></span><br><span class="line"> <span class="attr">charset</span> <span class="string">utf-8;</span></span><br><span class="line"> <span class="attr">sendfile</span> <span class="string">on;</span></span><br><span class="line"> <span class="attr">tcp_nopush</span> <span class="string">on;</span></span><br><span class="line"> <span class="attr">tcp_nodelay</span> <span class="string">on;</span></span><br><span class="line"> <span class="attr">keepalive_timeout</span> <span class="string">60;</span></span><br><span class="line"> <span class="attr">client_header_buffer_size</span> <span class="string">4k;</span></span><br><span class="line"> <span class="attr">open_file_cache</span> <span class="string">max=102400 inactive=20s;</span></span><br><span class="line"> <span class="attr">open_file_cache_valid</span> <span class="string">30s;</span></span><br><span class="line"> <span class="attr">open_file_cache_min_uses</span> <span class="string">1;</span></span><br><span class="line"> <span class="attr">client_header_timeout</span> <span class="string">15;</span></span><br><span class="line"> <span class="attr">client_body_timeout</span> <span class="string">15;</span></span><br><span class="line"> <span class="attr">reset_timedout_connection</span> <span class="string">on;</span></span><br><span class="line"> <span class="attr">send_timeout</span> <span class="string">15;</span></span><br><span class="line"> <span class="attr">gzip</span> <span class="string">on;</span></span><br><span class="line"> <span class="attr">gzip_disable</span> <span class="string">"msie6";</span></span><br><span class="line"> <span class="attr">gzip_vary</span> <span class="string">on;</span></span><br><span class="line"> <span class="attr">gzip_proxied</span> <span class="string">any;</span></span><br><span class="line"> <span class="attr">gzip_comp_level</span> <span class="string">3;</span></span><br><span class="line"> <span class="attr">gzip_buffers</span> <span class="string">16 8k;</span></span><br><span class="line"> <span class="attr">gzip_http_version</span> <span class="string">1.1;</span></span><br><span class="line"> <span class="attr">gzip_types</span> <span class="string">text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;</span></span><br><span class="line"> <span class="attr">server_tokens</span> <span class="string">off;</span></span><br><span class="line"> <span class="attr">access_log</span> <span class="string">/var/log/nginx_access.log;</span></span><br><span class="line"></span><br><span class="line"> <span class="attr">server</span> <span class="string">{</span></span><br><span class="line"><span class="comment"># listen 443 ssl;</span></span><br><span class="line"> <span class="attr">listen</span> <span class="string">0.0.0.0:80;</span></span><br><span class="line"> <span class="attr">server_name</span> <span class="string">weiyangbo.com www.weiyangbo.com; #此处填你网站的域名</span></span><br><span class="line"><span class="comment"> #让Nginx让出443端口,只监听80,ssl设置也不需要了,一切交给Trojan</span></span><br><span class="line"><span class="comment"># ssl_certificate /etc/nginx/cert/xxxxxxx.pem;</span></span><br><span class="line"><span class="comment"># ssl_certificate_key /etc/nginx/cert/xxxxxxx.key;</span></span><br><span class="line"><span class="comment"># ssl_protocols TLSv1 TLSv1.1 TLSv1.2;</span></span><br><span class="line"><span class="comment"># ssl_prefer_server_ciphers on;</span></span><br><span class="line"><span class="comment"># ssl_session_timeout 5m;</span></span><br><span class="line"><span class="comment"># ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;</span></span><br><span class="line"> <span class="attr">root</span> <span class="string">/www; #此处填你的网站目录</span></span><br><span class="line"> <span class="attr">location</span> <span class="string">/ {</span></span><br><span class="line"> <span class="attr">expires</span> <span class="string">10h;</span></span><br><span class="line"> <span class="attr">fancyindex</span> <span class="string">on;</span></span><br><span class="line"> <span class="attr">fancyindex_exact_size</span> <span class="string">off;</span></span><br><span class="line"> <span class="attr">fancyindex_localtime</span> <span class="string">on;</span></span><br><span class="line"> <span class="attr">fancyindex_header</span> <span class="string">"/fancyindex/header.html";</span></span><br><span class="line"> <span class="attr">fancyindex_footer</span> <span class="string">"/fancyindex/footer.html";</span></span><br><span class="line"> <span class="attr">fancyindex_ignore</span> <span class="string">"fancyindex" "Download"; #可以自定义文件服务器中不显示的文件或文件夹</span></span><br><span class="line"> <span class="attr">fancyindex_name_length</span> <span class="string">500;</span></span><br><span class="line"> <span class="attr">}</span></span><br><span class="line"><span class="comment"> #这是防盗链设置</span></span><br><span class="line"> <span class="attr">location</span> <span class="string">~* ^.+\.(jpg|gif|png|img|apk|tar.gz|wmv|jpeg|mp3|mp4|zip|rar)$ {</span></span><br><span class="line"> <span class="attr">valid_referers</span> <span class="string">none blocked www.weiyangbo.com weiyangbo.com;</span></span><br><span class="line"> <span class="attr">if</span> <span class="string">($invalid_referer){</span></span><br><span class="line"> <span class="attr">return</span> <span class="string">403;</span></span><br><span class="line"> <span class="attr">break;</span></span><br><span class="line"> <span class="attr">}</span></span><br><span class="line"> <span class="attr">access_log</span> <span class="string">off;</span></span><br><span class="line"> <span class="attr">}</span></span><br><span class="line"> <span class="attr">}</span></span><br><span class="line"><span class="attr">}</span></span><br></pre></td></tr></table></figure>
<p>Nginx配置写完之后可以用<code>nginx -t</code>命令检查一下Nginx的配置文件有没有语法错误。然后<code>nginx -s reload</code>重启Nginx。</p>
<p>还有Trojan的服务端配置,默认在<code>/usr/local/etc/trojan/config.json</code></p>
<figure class="highlight json"><table><tr><td class="code"><pre><span class="line">{</span><br><span class="line"> <span class="attr">"run_type"</span>: <span class="string">"server"</span>,</span><br><span class="line"> <span class="attr">"local_addr"</span>: <span class="string">"0.0.0.0"</span>,</span><br><span class="line"> <span class="attr">"local_port"</span>: <span class="number">443</span>,</span><br><span class="line"> <span class="attr">"remote_addr"</span>: <span class="string">"127.0.0.1"</span>,</span><br><span class="line"> <span class="attr">"remote_port"</span>: <span class="number">80</span>,</span><br><span class="line"> <span class="attr">"password"</span>: [</span><br><span class="line"> <span class="string">"填你的密码"</span>,</span><br><span class="line"> <span class="string">"可以填多个"</span></span><br><span class="line"> ],</span><br><span class="line"> <span class="attr">"log_level"</span>: <span class="number">1</span>,</span><br><span class="line"> <span class="attr">"ssl"</span>: {</span><br><span class="line"> <span class="attr">"cert"</span>: <span class="string">"/etc/nginx/cert/xxxxxxx.pem"</span>,</span><br><span class="line"> <span class="attr">"key"</span>: <span class="string">"/etc/nginx/cert/xxxxxxx.key"</span>,</span><br><span class="line"> <span class="attr">"key_password"</span>: <span class="string">""</span>,</span><br><span class="line"> <span class="attr">"cipher"</span>: <span class="string">"ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305"</span>,</span><br><span class="line"> <span class="attr">"cipher_tls13"</span>: <span class="string">"TLS_AES_128_GCM_SHA256:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_256_GCM_SHA384"</span>,</span><br><span class="line"> <span class="attr">"prefer_server_cipher"</span>: <span class="literal">true</span>,</span><br><span class="line"> <span class="attr">"alpn"</span>: [</span><br><span class="line"> <span class="string">"http/1.1"</span></span><br><span class="line"> ],</span><br><span class="line"> <span class="attr">"reuse_session"</span>: <span class="literal">true</span>,</span><br><span class="line"> <span class="attr">"session_ticket"</span>: <span class="literal">false</span>,</span><br><span class="line"> <span class="attr">"session_timeout"</span>: <span class="number">600</span>,</span><br><span class="line"> <span class="attr">"plain_http_response"</span>: <span class="string">""</span>,</span><br><span class="line"> <span class="attr">"curves"</span>: <span class="string">""</span>,</span><br><span class="line"> <span class="attr">"dhparam"</span>: <span class="string">""</span></span><br><span class="line"> },</span><br><span class="line"> <span class="attr">"tcp"</span>: {</span><br><span class="line"> <span class="attr">"prefer_ipv4"</span>: <span class="literal">false</span>,</span><br><span class="line"> <span class="attr">"no_delay"</span>: <span class="literal">true</span>,</span><br><span class="line"> <span class="attr">"keep_alive"</span>: <span class="literal">true</span>,</span><br><span class="line"> <span class="attr">"reuse_port"</span>: <span class="literal">false</span>,</span><br><span class="line"> <span class="attr">"fast_open"</span>: <span class="literal">true</span>,</span><br><span class="line"> <span class="attr">"fast_open_qlen"</span>: <span class="number">20</span></span><br><span class="line"> },</span><br><span class="line"> <span class="attr">"mysql"</span>: {</span><br><span class="line"> <span class="attr">"enabled"</span>: <span class="literal">false</span>,</span><br><span class="line"> <span class="attr">"server_addr"</span>: <span class="string">"127.0.0.1"</span>,</span><br><span class="line"> <span class="attr">"server_port"</span>: <span class="number">3306</span>,</span><br><span class="line"> <span class="attr">"database"</span>: <span class="string">"trojan"</span>,</span><br><span class="line"> <span class="attr">"username"</span>: <span class="string">"trojan"</span>,</span><br><span class="line"> <span class="attr">"password"</span>: <span class="string">""</span></span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<p>确认配置文件填好之后,可以尝试启动Trojan<br><code>sudo systemctl start trojan</code><br>如果没有报错应该是启动成功了,也可以<code>sudo systemctl status trojan</code>检查一下。<br>测试没有问题就可以加入开机自启了<br><code>sudo systemctl enable trojan</code></p>
<h1 id="客户端配置"><a href="#客户端配置" class="headerlink" title="客户端配置"></a>客户端配置</h1><p>略</p>
<h1 id="总结与后记"><a href="#总结与后记" class="headerlink" title="总结与后记"></a>总结与后记</h1><p>测试下来非常失望,在路由器上科学上网的的速度仅仅比V2ray好上一点点,原来正常网页的访问速度却是明显降低了。<del>可能是我路由器真的该淘汰了。</del>后来进一步测试发现是由于路由器上开起了BBR拥塞算法导致的,取消之后立马可以跑到30Mbps(服务器上限)。</p>
]]></content>
</entry>
<entry>
<title>利用SU-03T和ESP32自制语音控制节点</title>
<url>/2022/03/06/Voice-control-node/</url>
<content><![CDATA[<p>传统智能音箱的缺点:</p>
<ul>
<li>成本高,严重依赖各家生态,各家生态互不兼容,用户一旦入坑就只能一条路走到黑。</li>
<li>执行一条语音命令需要先语音唤醒,效率低,影响使用心情。</li>
<li>智能音箱一直联网监听,隐私风险大。</li>
</ul>
<p>下面先来看看我制作的语音控制节点,不管是识别率,识别速度,识别距离都是令人满意的,而且不光可以控制接入Home Assistant的智能家电,还可以控制各种红外遥控的传统家电。</p>
<style type="text/css"> .aspect-ratio { position: relative; width: 100%; height: 0; padding-bottom: 75%; } .aspect-ratio iframe { position: absolute; width: 100%; height: 100%; left: 0; top: 0; } </style>
<div class="aspect-ratio" ><iframe src="//player.bilibili.com/player.html?aid=594535271&bvid=BV1rq4y147cQ&cid=543226313&page=1" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true"> </iframe></div>
<p>之所以叫做“语音控制节点”是因为目前这个手工焊接的版本实在是太过简陋,实在不像是一个“音箱”。另一方面这一个板子上不光有语音控制功能,还可以添加各种传感器,未来可以将自身数据与其他不同位置的设备共享,是我智能家居这个大工程当中的一个“节点”。</p>
<h1 id="硬件成本"><a href="#硬件成本" class="headerlink" title="硬件成本"></a>硬件成本</h1><table>
<thead>
<tr>
<th align="left">硬件</th>
<th align="right">成本</th>
</tr>
</thead>
<tbody><tr>
<td align="left">ESP32开发板</td>
<td align="right">16元</td>
</tr>
<tr>
<td align="left">SU-03T</td>
<td align="right">10.5元/片+6元运费</td>
</tr>
<tr>
<td align="left">喇叭 4欧3瓦</td>
<td align="right">2.8元</td>
</tr>
<tr>
<td align="left">咪头</td>
<td align="right">0.21元</td>
</tr>
<tr>
<td align="left">万用板5x7cm</td>
<td align="right">0.68元/片</td>
</tr>
<tr>
<td align="left">5mm红外发射头(940nm)</td>
<td align="right">1.9元/20只</td>
</tr>
<tr>
<td align="left">红外接收头(型号随意)</td>
<td align="right">0.23元/只</td>
</tr>
</tbody></table>
<p>另外还需要运行Debian系统的x86架构的设备(软路由、NAS等),用来安装Home Assistant平台。</p>
<h1 id="部署Home-Assistant并安装ESPHome"><a href="#部署Home-Assistant并安装ESPHome" class="headerlink" title="部署Home Assistant并安装ESPHome"></a>部署Home Assistant并安装ESPHome</h1><p>Home Assistant是是一个成熟完整的基于 Python 的开源智能家居系统,设备支持度高,支持自动化(Automation)、群组化(Group)、UI 客制化(Theme) 等等高度定制化设置。<br>ESPHome 是一个可以刷进ESP系列芯片的系统,可以通过简单但功能强大的配置文件来控制你的 ESP8266/ESP32,并通过Home Assistant对其进行远程控制。<br>Home Assistant就像是大脑,刷了ESPHome的ESP32就像是耳朵、眼睛、手。 Home Assistant根据ESPHome传感器传来的信息感知外界的环境变化,然后控制ESPHome或者其他设备执行设定好的指令。<br>大家可以看看目前我Home Assistant的界面<br><img src= "/img/loading.gif" data-lazy-src="HA.png" alt="HA主界面"></p>
<ul>
<li>开关控制NAS开关机,详见<a href="/2021/11/28/Homeassistant-wol/" title="Homeassistant远程开关NAS">Homeassistant远程开关NAS</a></li>
<li>WLED总开关,灯光效果切换,详见<a href="/2022/03/08/wled-HA/" title="用WLED控制流光灯带并接入Home Assistant">用WLED控制流光灯带并接入Home Assistant</a></li>
<li>控制空调的红外遥控开关,详见<a href="/2022/03/06/ESPHome-IRomte/" title="利用ESPHome自制万能遥控器">利用ESPHome自制万能遥控器</a></li>
<li>探测小米手环蓝牙信号强度的指示器,详见<a href="/2022/03/06/ESPHome-ble-tracker/" title="利用ESPHome进行蓝牙设备定位">利用ESPHome进行蓝牙设备定位</a></li>
<li>智能插座的控制开关(我买的BroadLink MP1-1K3S2U可以直接接入Home Assistant)</li>
<li>DLNA控制投影仪,天气……<br>安装<a target="_blank" rel="noopener" href="https://www.home-assistant.io/installation/">Home Assistant</a>需要有NAS、软路由或者树莓派之类的开发板。尽管Home Assistant支持Windows、macOS、Linux等平台安装,兼容x86、ARM、AArch64架构。但我强烈建议在x86架构并安装Debian的设备上部署Home Assistant,因为要在Home Assistant上安装ESPHome,而ESPHome的编译链对架构和平台有要求。要注意Home Assistant有多种安装方式,不同安装方式对设备的要求不同,提供的功能有差别,详情见下图:<br><img src= "/img/loading.gif" data-lazy-src="HA_Compare.png" alt="HA安装方式比较"><br>因为我们需要<code>Add-ons</code>功能来安装ESPHome,必须选Supervised或OS的安装方式。OS安装方式只适用于树莓派等开发板,大部分人只能Supervised方式安装。个人认为这一步需要一点Linux知识,篇幅有限大家自己按照<a target="_blank" rel="noopener" href="https://github.com/home-assistant/supervised-installer">官方教程安装Home Assistant</a>。<br>当然如果你有树莓派那当我前面都没说,直接选择32-bit版本的HA OS系统镜像刷进去就行。不选64位的原因是ESPHome的编译链不支持AArch64架构,ARM应该是可以的,但我没有测试过。<br>安装完Home Assistant,浏览器进入<code>http://你的服务器IP:8123</code>,进行一些初始化设置,就进入Home Assistant的主界面了。后面安装ESPHome就简单了,详见<a target="_blank" rel="noopener" href="https://esphome.io/guides/getting_started_hassio.html#installing-esphome-dashboard">ESPHome官方教程 Installing ESPHome Dashboard</a></li>
</ul>
<h1 id="焊接"><a href="#焊接" class="headerlink" title="焊接"></a>焊接</h1><p>SU-03T自带功放,所以喇叭和咪头都是直接接在SU-03T上,如下图所示。<br><img src= "/img/loading.gif" data-lazy-src="SU-03T.png" alt="SU-03T示意图"><br>红外发射头和红外接收头都接在ESP32上,焊接电路图见之前的帖子<a href="/2022/03/06/ESPHome-IRomte/" title="利用ESPHome自制万能遥控器">利用ESPHome自制万能遥控器</a>。<br>焊接其他部分其实很简单,主要是将SU-03T中可以输出脉冲的GPIO同ESP32中可以输入的GPIO连起来,VCC和GND都连起来。<br>我是按照下表连接的</p>
<table>
<thead>
<tr>
<th align="left">SU-03T的引脚</th>
<th align="right">ESP32的引脚</th>
</tr>
</thead>
<tbody><tr>
<td align="left">B2</td>
<td align="right">GPIO25</td>
</tr>
<tr>
<td align="left">B8</td>
<td align="right">GPIO26</td>
</tr>
<tr>
<td align="left">A27</td>
<td align="right">GPIO32</td>
</tr>
<tr>
<td align="left">B3</td>
<td align="right">GPIO33</td>
</tr>
<tr>
<td align="left">A25</td>
<td align="right">GPIO34</td>
</tr>
<tr>
<td align="left">A26</td>
<td align="right">GPIO35</td>
</tr>
<tr>
<td align="left">GND</td>
<td align="right">GND</td>
</tr>
<tr>
<td align="left">VCC</td>
<td align="right">VCC</td>
</tr>
</tbody></table>
<p>最后找ESP32的VCC时发现这个开发板没有引出来,无奈从PCB上找到了一个直接与VCC相连的芯片焊脚接了出来。<br>成品高清大图,这实在太丑,有空去打个板子:<br><img src= "/img/loading.gif" data-lazy-src="pcb1.jpg" alt="正面"><br><img src= "/img/loading.gif" data-lazy-src="pcb2.jpg" alt="反面"></p>
<h1 id="对SU-03T语音模块编程"><a href="#对SU-03T语音模块编程" class="headerlink" title="对SU-03T语音模块编程"></a>对SU-03T语音模块编程</h1><p>SU-03T有以下优点:</p>
<ul>
<li>价格便宜,识别率不错,可用GPIO口多</li>
<li>编程简单而且免费,而且普通USB-TTL就可以刷入</li>
<li>可以自定义唤醒词,而且支持免唤醒词就执行语音命令<br>SU-03T语音模块的固件完全在网页上编辑和生成,目前完全免费,访问<a target="_blank" rel="noopener" href="http://www.smartpi.cn/">智能公元</a>。<br>部分配置如图所示,B2、A25、A26、A27这四个GPIO依次对应开灯、关灯、开空调、关空调这四个指令,当其中一条语音命令被接受到,对应的GPIO就会发出一次周期为200ms的脉冲信号(引脚其余时间默认低电平)。<br><img src= "/img/loading.gif" data-lazy-src="smartpi.png" alt="智能公元"><br>编辑好了就在线生成SDK,等待10-30分钟就可以下载SDK了。烧录工具、固件、说明书等都在SDK压缩包中。<br>烧录固件很简单,先不要给模块上电,用USB-TTL的TX接连SU-03T的B6,用USB-TTL的RX接连SU-03T的B7,打开烧录软件并点击“烧录”,最后给模块上电并等待烧录结束。<br><img src= "/img/loading.gif" data-lazy-src="ttl.jpg" alt="烧录接线图"><br><img src= "/img/loading.gif" data-lazy-src="UniOne.png" alt="UniOne"></li>
</ul>
<h1 id="使用ESPHome编写和烧录ESP32的固件"><a href="#使用ESPHome编写和烧录ESP32的固件" class="headerlink" title="使用ESPHome编写和烧录ESP32的固件"></a>使用ESPHome编写和烧录ESP32的固件</h1><p>由于ESP32的Flash只有4MB,并不能将所有的功能都放下,所以ESPHome的思路是根据使用者需要的功能编译固件,需要什么功能就把什么功能编译进去。<br>在ESPHome界面,如图所示新建一个ESP32设备<br><img src= "/img/loading.gif" data-lazy-src="esphome1.png" alt="ESPHome新建设备"><br>按向导提示输入Wi-Fi的SSID和密码,向导的最后一步就是点击“install”,然后回弹出如下的提示框。<br><img src= "/img/loading.gif" data-lazy-src="esphome2.png" alt="ESPHome下载固件"><br>第一次往ESP32中烧录固件必须使用有线的方式。首先选择“Manual download”,等待固件编译完成后下载固件到本地电脑。然后返回,再刚刚新建的那个配置的右下角点击菜单,再次选择“install”,这次选择“Plug into this computer”,这个功能可以直接利用你的网页浏览器(仅限Chrome内核浏览器,如Edge)控制串口给ESP32刷机。刷机前先将ESP32的GPIO0和GND用一根杜邦线短接起来(开机前拉低GPIO0使ESP32进入下载模式),然后用一根USB数据线将ESP32连接电脑。网页端按照如图所示让浏览器连接USB-Serial(不同电脑上可以COM后的数字不一样,这是正常的)<br><img src= "/img/loading.gif" data-lazy-src="esphome3.png" alt="ESPHome连接串口"><br>然后上传固件,刷写固件,等待1-2分钟烧写完成,将ESP32的USB数据线拔掉,连接GPIO0的杜邦线拔掉,然后再插回USB数据线。<br>等待片刻,你的ESP32应该就自动连接上你家的Wi-Fi了,在ESPHome界面应该就能看到刚刚配置的ESP32配置文件右上角有个“ONLINE”<br><img src= "/img/loading.gif" data-lazy-src="esphome4.png" alt="ESPHome编辑配置"><br>下面我们就可以对ESP32的固件当中添加各种我们需要的功能了,点击“EDIT”,我就直接粘贴配置文件了</p>
<figure class="highlight yaml"><table><tr><td class="code"><pre><span class="line"><span class="attr">esphome:</span></span><br><span class="line"> <span class="attr">name:</span> <span class="string">esp32</span></span><br><span class="line"></span><br><span class="line"><span class="attr">esp32:</span></span><br><span class="line"> <span class="attr">board:</span> <span class="string">esp32dev</span></span><br><span class="line"> <span class="attr">framework:</span></span><br><span class="line"> <span class="attr">type:</span> <span class="string">esp-idf</span></span><br><span class="line"> <span class="attr">version:</span> <span class="string">latest</span></span><br><span class="line"> <span class="comment"># Custom sdkconfig options</span></span><br><span class="line"> <span class="attr">sdkconfig_options:</span></span><br><span class="line"> <span class="attr">CONFIG_COMPILER_OPTIMIZATION_SIZE:</span> <span class="string">y</span></span><br><span class="line"> <span class="comment"># Advanced tweaking options</span></span><br><span class="line"> <span class="attr">advanced:</span></span><br><span class="line"> <span class="attr">ignore_efuse_mac_crc:</span> <span class="literal">false</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Enable logging</span></span><br><span class="line"><span class="attr">logger:</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Enable Home Assistant API</span></span><br><span class="line"><span class="attr">api:</span></span><br><span class="line"></span><br><span class="line"><span class="attr">ota:</span></span><br><span class="line"> <span class="attr">password:</span> <span class="string">""</span></span><br><span class="line"></span><br><span class="line"><span class="attr">wifi:</span></span><br><span class="line"> <span class="attr">ssid:</span> <span class="type">!secret</span> <span class="string">wifi_ssid</span></span><br><span class="line"> <span class="attr">password:</span> <span class="type">!secret</span> <span class="string">wifi_password</span></span><br><span class="line"></span><br><span class="line"> <span class="comment"># Enable fallback hotspot (captive portal) in case wifi connection fails</span></span><br><span class="line"> <span class="attr">ap:</span></span><br><span class="line"> <span class="attr">ssid:</span> <span class="string">"Esp32 Fallback Hotspot"</span></span><br><span class="line"> <span class="attr">password:</span> <span class="string">"PMQ3aD1W8AVF"</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="attr">binary_sensor:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">platform:</span> <span class="string">gpio</span></span><br><span class="line"> <span class="attr">id:</span> <span class="string">wledon</span></span><br><span class="line"> <span class="attr">pin:</span> </span><br><span class="line"> <span class="attr">number:</span> <span class="string">GPIO25</span></span><br><span class="line"> <span class="attr">mode:</span> <span class="string">INPUT</span></span><br><span class="line"> <span class="attr">on_click:</span></span><br><span class="line"> <span class="attr">min_length:</span> <span class="string">50ms</span></span><br><span class="line"> <span class="attr">max_length:</span> <span class="string">300ms</span></span><br><span class="line"> <span class="attr">then:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">homeassistant.service:</span></span><br><span class="line"> <span class="attr">service:</span> <span class="string">light.turn_on</span></span><br><span class="line"> <span class="attr">data:</span></span><br><span class="line"> <span class="attr">entity_id:</span> <span class="string">light.wled</span></span><br><span class="line"> </span><br><span class="line"> <span class="bullet">-</span> <span class="attr">platform:</span> <span class="string">gpio</span></span><br><span class="line"> <span class="attr">id:</span> <span class="string">wledoff</span></span><br><span class="line"> <span class="attr">pin:</span> </span><br><span class="line"> <span class="attr">number:</span> <span class="string">GPIO34</span></span><br><span class="line"> <span class="attr">mode:</span> <span class="string">INPUT</span></span><br><span class="line"> <span class="attr">on_click:</span></span><br><span class="line"> <span class="attr">min_length:</span> <span class="string">50ms</span></span><br><span class="line"> <span class="attr">max_length:</span> <span class="string">300ms</span></span><br><span class="line"> <span class="attr">then:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">homeassistant.service:</span></span><br><span class="line"> <span class="attr">service:</span> <span class="string">light.turn_off</span></span><br><span class="line"> <span class="attr">data:</span></span><br><span class="line"> <span class="attr">entity_id:</span> <span class="string">light.wled</span></span><br><span class="line"> </span><br><span class="line"> <span class="bullet">-</span> <span class="attr">platform:</span> <span class="string">gpio</span></span><br><span class="line"> <span class="attr">id:</span> <span class="string">acoff</span></span><br><span class="line"> <span class="attr">pin:</span> </span><br><span class="line"> <span class="attr">number:</span> <span class="string">GPIO32</span></span><br><span class="line"> <span class="attr">mode:</span> <span class="string">INPUT</span></span><br><span class="line"> <span class="attr">on_click:</span></span><br><span class="line"> <span class="attr">min_length:</span> <span class="string">50ms</span></span><br><span class="line"> <span class="attr">max_length:</span> <span class="string">300ms</span></span><br><span class="line"> <span class="attr">then:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">homeassistant.service:</span></span><br><span class="line"> <span class="attr">service:</span> <span class="string">switch.turn_off</span></span><br><span class="line"> <span class="attr">data:</span></span><br><span class="line"> <span class="attr">entity_id:</span> <span class="string">switch.bedroom_ac_switch</span></span><br><span class="line"> </span><br><span class="line"> <span class="bullet">-</span> <span class="attr">platform:</span> <span class="string">gpio</span></span><br><span class="line"> <span class="attr">id:</span> <span class="string">acon</span></span><br><span class="line"> <span class="attr">pin:</span> </span><br><span class="line"> <span class="attr">number:</span> <span class="string">GPIO35</span></span><br><span class="line"> <span class="attr">mode:</span> <span class="string">INPUT</span></span><br><span class="line"> <span class="attr">on_click:</span></span><br><span class="line"> <span class="attr">min_length:</span> <span class="string">50ms</span></span><br><span class="line"> <span class="attr">max_length:</span> <span class="string">300ms</span></span><br><span class="line"> <span class="attr">then:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">homeassistant.service:</span></span><br><span class="line"> <span class="attr">service:</span> <span class="string">switch.turn_on</span></span><br><span class="line"> <span class="attr">data:</span></span><br><span class="line"> <span class="attr">entity_id:</span> <span class="string">switch.bedroom_ac_switch</span></span><br><span class="line"> </span><br><span class="line"><span class="attr">remote_receiver:</span></span><br><span class="line"> <span class="attr">pin:</span> </span><br><span class="line"> <span class="attr">number:</span> <span class="string">GPIO14</span></span><br><span class="line"> <span class="attr">inverted:</span> <span class="literal">True</span></span><br><span class="line"> <span class="attr">mode:</span> <span class="string">INPUT_PULLUP</span></span><br><span class="line"> <span class="attr">dump:</span> <span class="string">raw</span></span><br><span class="line"> <span class="attr">idle:</span> <span class="string">40ms</span></span><br><span class="line"></span><br><span class="line"><span class="attr">remote_transmitter:</span></span><br><span class="line"> <span class="attr">pin:</span> </span><br><span class="line"> <span class="attr">number:</span> <span class="string">GPIO27</span></span><br><span class="line"> <span class="attr">carrier_duty_percent:</span> <span class="number">50</span><span class="string">%</span></span><br><span class="line"></span><br><span class="line"><span class="attr">switch:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">platform:</span> <span class="string">template</span></span><br><span class="line"> <span class="attr">name:</span> <span class="string">"BedRoom AC Switch"</span></span><br><span class="line"> <span class="attr">id:</span> <span class="string">esp32_ac_swi</span></span><br><span class="line"> <span class="attr">turn_on_action:</span></span><br><span class="line"> <span class="attr">then:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">switch.template.publish:</span></span><br><span class="line"> <span class="attr">id:</span> <span class="string">esp32_ac_swi</span></span><br><span class="line"> <span class="attr">state:</span> <span class="string">ON</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">if:</span></span><br><span class="line"> <span class="attr">condition:</span></span><br><span class="line"> <span class="attr">lambda:</span> <span class="string">'return id(temperature).state < 20;'</span></span><br><span class="line"> <span class="attr">then:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">script.execute:</span> <span class="string">turn_ac_20c</span></span><br><span class="line"> <span class="attr">else:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">script.execute:</span> <span class="string">turn_ac_27c</span></span><br><span class="line"></span><br><span class="line"> <span class="attr">turn_off_action:</span></span><br><span class="line"> <span class="attr">then:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">switch.template.publish:</span></span><br><span class="line"> <span class="attr">id:</span> <span class="string">esp32_ac_swi</span></span><br><span class="line"> <span class="attr">state:</span> <span class="string">OFF</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">script.execute:</span> <span class="string">turn_ac_off</span></span><br><span class="line"></span><br><span class="line"><span class="attr">esp32_ble_tracker:</span></span><br><span class="line"> <span class="attr">scan_parameters:</span></span><br><span class="line"> <span class="attr">interval:</span> <span class="string">1s</span></span><br><span class="line"> <span class="attr">window:</span> <span class="string">500ms</span></span><br><span class="line"> <span class="attr">active:</span> <span class="literal">false</span></span><br><span class="line"><span class="attr">sensor:</span></span><br><span class="line"> <span class="comment"># RSSI based on MAC address</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">platform:</span> <span class="string">ble_rssi</span></span><br><span class="line"> <span class="attr">mac_address:</span> <span class="string">FA:4C:19:74:CF:31</span></span><br><span class="line"> <span class="attr">name:</span> <span class="string">"MI Band RSSI value"</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">platform:</span> <span class="string">homeassistant</span></span><br><span class="line"> <span class="attr">entity_id:</span> <span class="string">weather.wo_de_jia</span></span><br><span class="line"> <span class="attr">id:</span> <span class="string">temperature</span></span><br><span class="line"> <span class="attr">attribute:</span> <span class="string">temperature</span></span><br><span class="line"> </span><br><span class="line"><span class="attr">script:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">id:</span> <span class="string">turn_ac_20c</span></span><br><span class="line"> <span class="attr">then:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">remote_transmitter.transmit_raw:</span></span><br><span class="line"> <span class="attr">carrier_frequency:</span> <span class="string">38kHz</span></span><br><span class="line"> <span class="attr">code:</span> [<span class="number">9016</span>, <span class="number">-4481</span>, <span class="number">620</span>, <span class="number">-570</span>, <span class="number">620</span>, <span class="number">-570</span>, <span class="number">619</span>, <span class="number">-1670</span>, <span class="number">620</span>, <span class="number">-1671</span>, <span class="number">620</span>, <span class="number">-570</span>, <span class="number">621</span>, <span class="number">-569</span>, <span class="number">621</span>, <span class="number">-1668</span>, <span class="number">619</span>, <span class="number">-572</span>, <span class="number">620</span>, <span class="number">-569</span>, <span class="number">620</span>, <span class="number">-570</span>, <span class="number">621</span>, <span class="number">-1669</span>, <span class="number">621</span>, <span class="number">-570</span>, <span class="number">621</span>, <span class="number">-568</span>, <span class="number">620</span>, <span class="number">-570</span>, <span class="number">621</span>, <span class="number">-569</span>, <span class="number">621</span>, <span class="number">-569</span>, <span class="number">622</span>, <span class="number">-568</span>, <span class="number">619</span>, <span class="number">-572</span>, <span class="number">619</span>, <span class="number">-570</span>, <span class="number">621</span>, <span class="number">-569</span>, <span class="number">619</span>, <span class="number">-572</span>, <span class="number">619</span>, <span class="number">-1671</span>, <span class="number">618</span>, <span class="number">-571</span>, <span class="number">620</span>, <span class="number">-1670</span>, <span class="number">620</span>, <span class="number">-571</span>, <span class="number">619</span>, <span class="number">-571</span>, <span class="number">618</span>, <span class="number">-571</span>, <span class="number">619</span>, <span class="number">-570</span>, <span class="number">621</span>, <span class="number">-1670</span>, <span class="number">620</span>, <span class="number">-570</span>, <span class="number">646</span>, <span class="number">-1643</span>, <span class="number">621</span>, <span class="number">-569</span>, <span class="number">621</span>, <span class="number">-569</span>, <span class="number">621</span>, <span class="number">-1669</span>, <span class="number">620</span>, <span class="number">-571</span>, <span class="number">619</span>, <span class="number">-19990</span>, <span class="number">620</span>, <span class="number">-1670</span>, <span class="number">620</span>, <span class="number">-571</span>, <span class="number">620</span>, <span class="number">-568</span>, <span class="number">622</span>, <span class="number">-569</span>, <span class="number">621</span>, <span class="number">-1669</span>, <span class="number">621</span>, <span class="number">-569</span>, <span class="number">617</span>, <span class="number">-573</span>, <span class="number">617</span>, <span class="number">-573</span>, <span class="number">620</span>, <span class="number">-570</span>, <span class="number">645</span>, <span class="number">-545</span>, <span class="number">621</span>, <span class="number">-569</span>, <span class="number">620</span>, <span class="number">-570</span>, <span class="number">619</span>, <span class="number">-570</span>, <span class="number">621</span>, <span class="number">-1669</span>, <span class="number">618</span>, <span class="number">-572</span>, <span class="number">645</span>, <span class="number">-546</span>, <span class="number">619</span>, <span class="number">-571</span>, <span class="number">645</span>, <span class="number">-544</span>, <span class="number">620</span>, <span class="number">-571</span>, <span class="number">617</span>, <span class="number">-573</span>, <span class="number">643</span>, <span class="number">-547</span>, <span class="number">620</span>, <span class="number">-569</span>, <span class="number">620</span>, <span class="number">-571</span>, <span class="number">617</span>, <span class="number">-572</span>, <span class="number">644</span>, <span class="number">-546</span>, <span class="number">618</span>, <span class="number">-572</span>, <span class="number">612</span>, <span class="number">-578</span>, <span class="number">621</span>, <span class="number">-569</span>, <span class="number">619</span>, <span class="number">-1671</span>, <span class="number">617</span>, <span class="number">-573</span>, <span class="number">620</span>, <span class="number">-1670</span>, <span class="number">644</span>, <span class="number">-1646</span>, <span class="number">619</span>, <span class="number">-7223</span>, <span class="number">9010</span>, <span class="number">-4489</span>, <span class="number">617</span>, <span class="number">-573</span>, <span class="number">615</span>, <span class="number">-575</span>, <span class="number">643</span>, <span class="number">-1647</span>, <span class="number">620</span>, <span class="number">-1670</span>, <span class="number">643</span>, <span class="number">-546</span>, <span class="number">619</span>, <span class="number">-572</span>, <span class="number">616</span>, <span class="number">-1674</span>, <span class="number">617</span>, <span class="number">-573</span>, <span class="number">644</span>, <span class="number">-545</span>, <span class="number">618</span>, <span class="number">-573</span>, <span class="number">617</span>, <span class="number">-1673</span>, <span class="number">615</span>, <span class="number">-574</span>, <span class="number">642</span>, <span class="number">-549</span>, <span class="number">617</span>, <span class="number">-572</span>, <span class="number">618</span>, <span class="number">-572</span>, <span class="number">617</span>, <span class="number">-573</span>, <span class="number">643</span>, <span class="number">-547</span>, <span class="number">644</span>, <span class="number">-546</span>, <span class="number">614</span>, <span class="number">-576</span>, <span class="number">643</span>, <span class="number">-547</span>, <span class="number">593</span>, <span class="number">-598</span>, <span class="number">643</span>, <span class="number">-1646</span>, <span class="number">643</span>, <span class="number">-547</span>, <span class="number">616</span>, <span class="number">-1674</span>, <span class="number">639</span>, <span class="number">-551</span>, <span class="number">610</span>, <span class="number">-580</span>, <span class="number">616</span>, <span class="number">-574</span>, <span class="number">641</span>, <span class="number">-549</span>, <span class="number">617</span>, <span class="number">-1673</span>, <span class="number">592</span>, <span class="number">-1699</span>, <span class="number">617</span>, <span class="number">-1672</span>, <span class="number">639</span>, <span class="number">-551</span>, <span class="number">642</span>, <span class="number">-547</span>, <span class="number">593</span>, <span class="number">-1698</span>, <span class="number">592</span>, <span class="number">-598</span>, <span class="number">640</span>, <span class="number">-19969</span>, <span class="number">637</span>, <span class="number">-553</span>, <span class="number">593</span>, <span class="number">-597</span>, <span class="number">642</span>, <span class="number">-548</span>, <span class="number">642</span>, <span class="number">-548</span>, <span class="number">640</span>, <span class="number">-550</span>, <span class="number">592</span>, <span class="number">-598</span>, <span class="number">592</span>, <span class="number">-598</span>, <span class="number">593</span>, <span class="number">-597</span>, <span class="number">592</span>, <span class="number">-597</span>, <span class="number">642</span>, <span class="number">-549</span>, <span class="number">593</span>, <span class="number">-597</span>, <span class="number">594</span>, <span class="number">-596</span>, <span class="number">593</span>, <span class="number">-597</span>, <span class="number">592</span>, <span class="number">-598</span>, <span class="number">640</span>, <span class="number">-550</span>, <span class="number">593</span>, <span class="number">-597</span>, <span class="number">593</span>, <span class="number">-597</span>, <span class="number">593</span>, <span class="number">-597</span>, <span class="number">592</span>, <span class="number">-597</span>, <span class="number">593</span>, <span class="number">-598</span>, <span class="number">641</span>, <span class="number">-548</span>, <span class="number">640</span>, <span class="number">-551</span>, <span class="number">592</span>, <span class="number">-597</span>, <span class="number">642</span>, <span class="number">-549</span>, <span class="number">593</span>, <span class="number">-597</span>, <span class="number">593</span>, <span class="number">-596</span>, <span class="number">594</span>, <span class="number">-597</span>, <span class="number">593</span>, <span class="number">-596</span>, <span class="number">594</span>, <span class="number">-596</span>, <span class="number">593</span>, <span class="number">-1697</span>, <span class="number">594</span>, <span class="number">-596</span>, <span class="number">594</span>, <span class="number">-1696</span>, <span class="number">594</span>]</span><br><span class="line"> <span class="bullet">-</span> <span class="attr">id:</span> <span class="string">turn_ac_off</span></span><br><span class="line"> <span class="attr">then:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">remote_transmitter.transmit_raw:</span></span><br><span class="line"> <span class="attr">carrier_frequency:</span> <span class="string">38kHz</span></span><br><span class="line"> <span class="attr">code:</span> [<span class="number">9021</span>, <span class="number">-4476</span>, <span class="number">625</span>, <span class="number">-1666</span>, <span class="number">624</span>, <span class="number">-565</span>, <span class="number">624</span>, <span class="number">-567</span>, <span class="number">625</span>, <span class="number">-567</span>, <span class="number">621</span>, <span class="number">-567</span>, <span class="number">626</span>, <span class="number">-566</span>, <span class="number">622</span>, <span class="number">-1666</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">623</span>, <span class="number">-1666</span>, <span class="number">626</span>, <span class="number">-1691</span>, <span class="number">597</span>, <span class="number">-566</span>, <span class="number">626</span>, <span class="number">-1664</span>, <span class="number">625</span>, <span class="number">-593</span>, <span class="number">597</span>, <span class="number">-566</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">625</span>, <span class="number">-565</span>, <span class="number">624</span>, <span class="number">-565</span>, <span class="number">622</span>, <span class="number">-569</span>, <span class="number">624</span>, <span class="number">-565</span>, <span class="number">625</span>, <span class="number">-565</span>, <span class="number">625</span>, <span class="number">-592</span>, <span class="number">599</span>, <span class="number">-564</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">626</span>, <span class="number">-564</span>, <span class="number">626</span>, <span class="number">-565</span>, <span class="number">625</span>, <span class="number">-566</span>, <span class="number">623</span>, <span class="number">-565</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">624</span>, <span class="number">-1666</span>, <span class="number">625</span>, <span class="number">-565</span>, <span class="number">625</span>, <span class="number">-1665</span>, <span class="number">626</span>, <span class="number">-564</span>, <span class="number">623</span>, <span class="number">-567</span>, <span class="number">624</span>, <span class="number">-1666</span>, <span class="number">623</span>, <span class="number">-567</span>, <span class="number">626</span>, <span class="number">-19983</span>, <span class="number">625</span>, <span class="number">-1665</span>, <span class="number">624</span>, <span class="number">-567</span>, <span class="number">625</span>, <span class="number">-564</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">626</span>, <span class="number">-1664</span>, <span class="number">623</span>, <span class="number">-593</span>, <span class="number">599</span>, <span class="number">-565</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">624</span>, <span class="number">-594</span>, <span class="number">598</span>, <span class="number">-566</span>, <span class="number">622</span>, <span class="number">-567</span>, <span class="number">624</span>, <span class="number">-591</span>, <span class="number">598</span>, <span class="number">-1666</span>, <span class="number">625</span>, <span class="number">-565</span>, <span class="number">623</span>, <span class="number">-567</span>, <span class="number">624</span>, <span class="number">-569</span>, <span class="number">622</span>, <span class="number">-564</span>, <span class="number">625</span>, <span class="number">-568</span>, <span class="number">621</span>, <span class="number">-569</span>, <span class="number">624</span>, <span class="number">-564</span>, <span class="number">623</span>, <span class="number">-567</span>, <span class="number">625</span>, <span class="number">-564</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">623</span>, <span class="number">-568</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">623</span>, <span class="number">-566</span>, <span class="number">626</span>, <span class="number">-566</span>, <span class="number">622</span>, <span class="number">-1666</span>, <span class="number">623</span>, <span class="number">-568</span>, <span class="number">623</span>, <span class="number">-567</span>, <span class="number">624</span>, <span class="number">-1665</span>, <span class="number">624</span>, <span class="number">-7194</span>, <span class="number">9041</span>, <span class="number">-4481</span>, <span class="number">626</span>, <span class="number">-1665</span>, <span class="number">624</span>, <span class="number">-568</span>, <span class="number">621</span>, <span class="number">-566</span>, <span class="number">622</span>, <span class="number">-569</span>, <span class="number">625</span>, <span class="number">-567</span>, <span class="number">622</span>, <span class="number">-568</span>, <span class="number">621</span>, <span class="number">-1668</span>, <span class="number">622</span>, <span class="number">-566</span>, <span class="number">624</span>, <span class="number">-1666</span>, <span class="number">625</span>, <span class="number">-1666</span>, <span class="number">623</span>, <span class="number">-567</span>, <span class="number">625</span>, <span class="number">-1664</span>, <span class="number">623</span>, <span class="number">-594</span>, <span class="number">598</span>, <span class="number">-591</span>, <span class="number">599</span>, <span class="number">-566</span>, <span class="number">621</span>, <span class="number">-595</span>, <span class="number">599</span>, <span class="number">-565</span>, <span class="number">625</span>, <span class="number">-564</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">625</span>, <span class="number">-567</span>, <span class="number">622</span>, <span class="number">-569</span>, <span class="number">622</span>, <span class="number">-565</span>, <span class="number">623</span>, <span class="number">-569</span>, <span class="number">623</span>, <span class="number">-568</span>, <span class="number">622</span>, <span class="number">-567</span>, <span class="number">622</span>, <span class="number">-568</span>, <span class="number">621</span>, <span class="number">-567</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">623</span>, <span class="number">-1669</span>, <span class="number">623</span>, <span class="number">-1692</span>, <span class="number">597</span>, <span class="number">-1666</span>, <span class="number">624</span>, <span class="number">-565</span>, <span class="number">625</span>, <span class="number">-566</span>, <span class="number">624</span>, <span class="number">-1668</span>, <span class="number">622</span>, <span class="number">-565</span>, <span class="number">623</span>, <span class="number">-19985</span>, <span class="number">627</span>, <span class="number">-565</span>, <span class="number">626</span>, <span class="number">-564</span>, <span class="number">626</span>, <span class="number">-565</span>, <span class="number">623</span>, <span class="number">-566</span>, <span class="number">625</span>, <span class="number">-566</span>, <span class="number">623</span>, <span class="number">-593</span>, <span class="number">595</span>, <span class="number">-594</span>, <span class="number">600</span>, <span class="number">-565</span>, <span class="number">622</span>, <span class="number">-593</span>, <span class="number">597</span>, <span class="number">-567</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">623</span>, <span class="number">-567</span>, <span class="number">624</span>, <span class="number">-566</span>, <span class="number">625</span>, <span class="number">-565</span>, <span class="number">625</span>, <span class="number">-565</span>, <span class="number">626</span>, <span class="number">-564</span>, <span class="number">623</span>, <span class="number">-567</span>, <span class="number">623</span>, <span class="number">-567</span>, <span class="number">623</span>, <span class="number">-569</span>, <span class="number">622</span>, <span class="number">-566</span>, <span class="number">622</span>, <span class="number">-568</span>, <span class="number">622</span>, <span class="number">-569</span>, <span class="number">623</span>, <span class="number">-566</span>, <span class="number">623</span>, <span class="number">-567</span>, <span class="number">623</span>, <span class="number">-566</span>, <span class="number">624</span>, <span class="number">-567</span>, <span class="number">623</span>, <span class="number">-566</span>, <span class="number">624</span>, <span class="number">-568</span>, <span class="number">623</span>, <span class="number">-566</span>, <span class="number">622</span>, <span class="number">-1667</span>, <span class="number">625</span>, <span class="number">-1665</span>, <span class="number">623</span>, <span class="number">-594</span>, <span class="number">596</span>]</span><br><span class="line"> <span class="bullet">-</span> <span class="attr">id:</span> <span class="string">turn_ac_27c</span></span><br><span class="line"> <span class="attr">then:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">remote_transmitter.transmit_raw:</span></span><br><span class="line"> <span class="attr">carrier_frequency:</span> <span class="string">38kHz</span></span><br><span class="line"> <span class="attr">code:</span> [<span class="number">9048</span>, <span class="number">-4448</span>, <span class="number">653</span>, <span class="number">-1665</span>, <span class="number">623</span>, <span class="number">-539</span>, <span class="number">653</span>, <span class="number">-537</span>, <span class="number">650</span>, <span class="number">-1668</span>, <span class="number">625</span>, <span class="number">-537</span>, <span class="number">654</span>, <span class="number">-537</span>, <span class="number">650</span>, <span class="number">-1640</span>, <span class="number">650</span>, <span class="number">-539</span>, <span class="number">652</span>, <span class="number">-1639</span>, <span class="number">651</span>, <span class="number">-1638</span>, <span class="number">651</span>, <span class="number">-539</span>, <span class="number">652</span>, <span class="number">-1638</span>, <span class="number">653</span>, <span class="number">-538</span>, <span class="number">651</span>, <span class="number">-539</span>, <span class="number">650</span>, <span class="number">-540</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">650</span>, <span class="number">-539</span>, <span class="number">652</span>, <span class="number">-539</span>, <span class="number">651</span>, <span class="number">-537</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">652</span>, <span class="number">-1638</span>, <span class="number">651</span>, <span class="number">-540</span>, <span class="number">652</span>, <span class="number">-537</span>, <span class="number">653</span>, <span class="number">-538</span>, <span class="number">650</span>, <span class="number">-567</span>, <span class="number">623</span>, <span class="number">-539</span>, <span class="number">651</span>, <span class="number">-539</span>, <span class="number">651</span>, <span class="number">-1639</span>, <span class="number">652</span>, <span class="number">-566</span>, <span class="number">623</span>, <span class="number">-1639</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">653</span>, <span class="number">-537</span>, <span class="number">652</span>, <span class="number">-1638</span>, <span class="number">652</span>, <span class="number">-539</span>, <span class="number">651</span>, <span class="number">-19956</span>, <span class="number">653</span>, <span class="number">-1638</span>, <span class="number">653</span>, <span class="number">-539</span>, <span class="number">652</span>, <span class="number">-536</span>, <span class="number">650</span>, <span class="number">-541</span>, <span class="number">650</span>, <span class="number">-1666</span>, <span class="number">627</span>, <span class="number">-536</span>, <span class="number">654</span>, <span class="number">-536</span>, <span class="number">650</span>, <span class="number">-541</span>, <span class="number">653</span>, <span class="number">-537</span>, <span class="number">650</span>, <span class="number">-539</span>, <span class="number">653</span>, <span class="number">-565</span>, <span class="number">625</span>, <span class="number">-537</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">652</span>, <span class="number">-1638</span>, <span class="number">652</span>, <span class="number">-540</span>, <span class="number">650</span>, <span class="number">-541</span>, <span class="number">649</span>, <span class="number">-565</span>, <span class="number">625</span>, <span class="number">-566</span>, <span class="number">624</span>, <span class="number">-538</span>, <span class="number">651</span>, <span class="number">-539</span>, <span class="number">651</span>, <span class="number">-539</span>, <span class="number">653</span>, <span class="number">-537</span>, <span class="number">652</span>, <span class="number">-565</span>, <span class="number">624</span>, <span class="number">-539</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">652</span>, <span class="number">-539</span>, <span class="number">649</span>, <span class="number">-539</span>, <span class="number">653</span>, <span class="number">-564</span>, <span class="number">625</span>, <span class="number">-1639</span>, <span class="number">652</span>, <span class="number">-539</span>, <span class="number">650</span>, <span class="number">-539</span>, <span class="number">652</span>, <span class="number">-565</span>, <span class="number">625</span>, <span class="number">-7187</span>, <span class="number">9047</span>, <span class="number">-4453</span>, <span class="number">653</span>, <span class="number">-1640</span>, <span class="number">649</span>, <span class="number">-566</span>, <span class="number">625</span>, <span class="number">-540</span>, <span class="number">651</span>, <span class="number">-1637</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">651</span>, <span class="number">-539</span>, <span class="number">651</span>, <span class="number">-1638</span>, <span class="number">653</span>, <span class="number">-538</span>, <span class="number">650</span>, <span class="number">-1640</span>, <span class="number">651</span>, <span class="number">-1640</span>, <span class="number">652</span>, <span class="number">-537</span>, <span class="number">652</span>, <span class="number">-1637</span>, <span class="number">653</span>, <span class="number">-537</span>, <span class="number">652</span>, <span class="number">-541</span>, <span class="number">649</span>, <span class="number">-538</span>, <span class="number">653</span>, <span class="number">-538</span>, <span class="number">652</span>, <span class="number">-540</span>, <span class="number">649</span>, <span class="number">-565</span>, <span class="number">626</span>, <span class="number">-539</span>, <span class="number">651</span>, <span class="number">-539</span>, <span class="number">653</span>, <span class="number">-537</span>, <span class="number">652</span>, <span class="number">-1637</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">653</span>, <span class="number">-537</span>, <span class="number">652</span>, <span class="number">-565</span>, <span class="number">625</span>, <span class="number">-564</span>, <span class="number">627</span>, <span class="number">-537</span>, <span class="number">653</span>, <span class="number">-537</span>, <span class="number">652</span>, <span class="number">-1664</span>, <span class="number">627</span>, <span class="number">-1636</span>, <span class="number">653</span>, <span class="number">-1637</span>, <span class="number">654</span>, <span class="number">-563</span>, <span class="number">626</span>, <span class="number">-538</span>, <span class="number">653</span>, <span class="number">-1637</span>, <span class="number">653</span>, <span class="number">-537</span>, <span class="number">651</span>, <span class="number">-19956</span>, <span class="number">653</span>, <span class="number">-539</span>, <span class="number">654</span>, <span class="number">-537</span>, <span class="number">650</span>, <span class="number">-566</span>, <span class="number">625</span>, <span class="number">-538</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">654</span>, <span class="number">-536</span>, <span class="number">651</span>, <span class="number">-539</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">653</span>, <span class="number">-564</span>, <span class="number">624</span>, <span class="number">-539</span>, <span class="number">651</span>, <span class="number">-539</span>, <span class="number">651</span>, <span class="number">-539</span>, <span class="number">651</span>, <span class="number">-538</span>, <span class="number">651</span>, <span class="number">-540</span>, <span class="number">651</span>, <span class="number">-538</span>, <span class="number">653</span>, <span class="number">-538</span>, <span class="number">652</span>, <span class="number">-537</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">652</span>, <span class="number">-565</span>, <span class="number">624</span>, <span class="number">-567</span>, <span class="number">625</span>, <span class="number">-538</span>, <span class="number">653</span>, <span class="number">-562</span>, <span class="number">626</span>, <span class="number">-538</span>, <span class="number">652</span>, <span class="number">-538</span>, <span class="number">651</span>, <span class="number">-540</span>, <span class="number">651</span>, <span class="number">-538</span>, <span class="number">654</span>, <span class="number">-536</span>, <span class="number">653</span>, <span class="number">-537</span>, <span class="number">651</span>, <span class="number">-1665</span>, <span class="number">627</span>, <span class="number">-1637</span>, <span class="number">652</span>, <span class="number">-1638</span>, <span class="number">652</span>]</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>改好配置文件后,点击“install”,然后用“Wireless”模式,也就是OTA升级就可以把新固件烧写进ESP32了。<br>这里只详细讲述配置中的<code>binary_sensor:</code>字键,其余配置详见我的另外三篇文章<a href="/2022/03/06/ESPHome-IRomte/" title="利用ESPHome自制万能遥控器">利用ESPHome自制万能遥控器</a>和<a href="/2022/03/06/ESPHome-ble-tracker/" title="利用ESPHome进行蓝牙设备定位">利用ESPHome进行蓝牙设备定位</a>里面都有提到。 <code>binary_sensor:</code>里我创建了4个传感器去检测上文提到的4个GPIO的电平变化,其中<code>on_click:</code>就是在GPIO口从低电平到高电平再回落到低电平的这个过程被检测到后执行的动作。所以<code>min_length:</code>是高电平状态最小的保持时间,必须高于这个值才会被认为是一次“click”。而之前我们对SU-03T编程时,设置一次脉冲周期是200ms,高电平和低电平时间在一个周期内应该是一半一半,所以理论上触发一次动作高电平会保持100ms,<code>min_length:</code>应该低于这个值,但不能太低,不然供电一个不稳定也可能会引起误触。</p>
]]></content>
</entry>
<entry>
<title>Xray+Nginx实现Trojan+TLS伪装代理</title>
<url>/2021/12/03/Xray-trojan/</url>
<content><![CDATA[<p>记录一下Xray用Trojan协议(兼容Trojan)+ Nginx伪装代理</p>
<a id="more"></a>
<h1 id="安装Xray和Nginx"><a href="#安装Xray和Nginx" class="headerlink" title="安装Xray和Nginx"></a>安装Xray和Nginx</h1><p>参考以下两个链接分别在服务器上安装Xray和Nginx。</p>
<a href="/2019/10/26/Nginx-FancyIndex/" title="编译安装和配置Nginx">编译安装和配置Nginx</a>
<p> <a target="_blank" rel="noopener" href="https://github.com/XTLS/Xray-install">Xray官方Linux下安装指南</a></p>
<h1 id="Nginx配置"><a href="#Nginx配置" class="headerlink" title="Nginx配置"></a>Nginx配置</h1><p> 编辑<code>/etc/nginx/nginx.conf</code>, https的域名以weiyangbo.com为例</p>
<figure class="highlight properties"><table><tr><td class="code"><pre><span class="line"><span class="attr">user</span> <span class="string">root;</span></span><br><span class="line"><span class="attr">worker_processes</span> <span class="string">1;</span></span><br><span class="line"></span><br><span class="line"><span class="attr">pid</span> <span class="string">/var/run/nginx.pid;</span></span><br><span class="line"><span class="attr">error_log</span> <span class="string">/var/log/nginx_error.log;</span></span><br><span class="line"></span><br><span class="line"><span class="attr">events</span> <span class="string">{</span></span><br><span class="line"> <span class="attr">use</span> <span class="string">epoll;</span></span><br><span class="line"> <span class="attr">worker_connections</span> <span class="string">1024;</span></span><br><span class="line"> <span class="attr">multi_accept</span> <span class="string">on;</span></span><br><span class="line"><span class="attr">}</span></span><br><span class="line"></span><br><span class="line"><span class="attr">http</span> <span class="string">{</span></span><br><span class="line"> <span class="attr">include</span> <span class="string">/etc/nginx/mime.types;</span></span><br><span class="line"> <span class="attr">default_type</span> <span class="string">application/octet-stream;</span></span><br><span class="line"> <span class="attr">charset</span> <span class="string">ISO-88509-1;</span></span><br><span class="line"> <span class="attr">sendfile</span> <span class="string">on;</span></span><br><span class="line"> <span class="attr">tcp_nopush</span> <span class="string">on;</span></span><br><span class="line"> <span class="attr">tcp_nodelay</span> <span class="string">on;</span></span><br><span class="line"> <span class="attr">keepalive_timeout</span> <span class="string">60;</span></span><br><span class="line"> <span class="attr">client_header_buffer_size</span> <span class="string">4k;</span></span><br><span class="line"> <span class="attr">open_file_cache</span> <span class="string">max=102400 inactive=20s;</span></span><br><span class="line"> <span class="attr">open_file_cache_valid</span> <span class="string">30s;</span></span><br><span class="line"> <span class="attr">open_file_cache_min_uses</span> <span class="string">1;</span></span><br><span class="line"> <span class="attr">client_header_timeout</span> <span class="string">15;</span></span><br><span class="line"> <span class="attr">client_body_timeout</span> <span class="string">15;</span></span><br><span class="line"> <span class="attr">reset_timedout_connection</span> <span class="string">on;</span></span><br><span class="line"> <span class="attr">send_timeout</span> <span class="string">15;</span></span><br><span class="line"> <span class="attr">gzip</span> <span class="string">on;</span></span><br><span class="line"> <span class="attr">gzip_disable</span> <span class="string">"msie6";</span></span><br><span class="line"> <span class="attr">gzip_vary</span> <span class="string">on;</span></span><br><span class="line"> <span class="attr">gzip_proxied</span> <span class="string">any;</span></span><br><span class="line"> <span class="attr">gzip_comp_level</span> <span class="string">3;</span></span><br><span class="line"> <span class="attr">gzip_buffers</span> <span class="string">16 8k;</span></span><br><span class="line"> <span class="attr">gzip_http_version</span> <span class="string">1.1;</span></span><br><span class="line"> <span class="attr">gzip_types</span> <span class="string">text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;</span></span><br><span class="line"> <span class="attr">server_tokens</span> <span class="string">off;</span></span><br><span class="line"> <span class="attr">access_log</span> <span class="string">/var/log/nginx_access.log;</span></span><br><span class="line"></span><br><span class="line"> <span class="attr">server</span> <span class="string">{</span></span><br><span class="line"> <span class="attr">listen</span> <span class="string">80 default_server;</span></span><br><span class="line"> <span class="attr">server_name</span> <span class="string">weiyangbo.com www.weiyangbo.com;</span></span><br><span class="line"> <span class="attr">return</span> <span class="string">301 https://$server_name$request_uri;</span></span><br><span class="line"> <span class="attr">}</span></span><br><span class="line"></span><br><span class="line"> <span class="attr">server</span> <span class="string">{</span></span><br><span class="line"> <span class="attr">listen</span> <span class="string">unix:/dev/shm/default.sock proxy_protocol;</span></span><br><span class="line"> <span class="attr">listen</span> <span class="string">unix:/dev/shm/h2c.sock http2 proxy_protocol;</span></span><br><span class="line"> <span class="attr">charset</span> <span class="string">ISO-88509-1;</span></span><br><span class="line"> <span class="attr">server_name</span> <span class="string">weiyangbo.com www.weiyangbo.com;</span></span><br><span class="line"> <span class="attr">set_real_ip_from</span> <span class="string">127.0.0.1;</span></span><br><span class="line"> <span class="attr">add_header</span> <span class="string">Strict-Transport-Security "max-age=63072000" always;</span></span><br><span class="line"> <span class="attr">root</span> <span class="string">/root/mokee;</span></span><br><span class="line"> <span class="attr">location</span> <span class="string">/ {</span></span><br><span class="line"> <span class="attr">expires</span> <span class="string">10h;</span></span><br><span class="line"> <span class="attr">fancyindex</span> <span class="string">on;</span></span><br><span class="line"> <span class="attr">fancyindex_exact_size</span> <span class="string">off;</span></span><br><span class="line"> <span class="attr">fancyindex_localtime</span> <span class="string">on;</span></span><br><span class="line"> <span class="attr">fancyindex_header</span> <span class="string">"/fancyindex/header.html";</span></span><br><span class="line"> <span class="attr">fancyindex_footer</span> <span class="string">"/fancyindex/footer.html";</span></span><br><span class="line"> <span class="attr">fancyindex_ignore</span> <span class="string">"donate" "fancyindex" "Download";</span></span><br><span class="line"> <span class="attr">fancyindex_name_length</span> <span class="string">500;</span></span><br><span class="line"> <span class="attr">}</span></span><br><span class="line"> <span class="attr">location</span> <span class="string">~* ^.+\.(jpg|gif|png|img|apk|tar.gz|wmv|jpeg|mp3|mp4|zip|rar)$ {</span></span><br><span class="line"> <span class="attr">valid_referers</span> <span class="string">none blocked www.weiyangbo.com weiyangbo.com;</span></span><br><span class="line"> <span class="attr">if</span> <span class="string">($invalid_referer){</span></span><br><span class="line"> <span class="attr">return</span> <span class="string">403;</span></span><br><span class="line"> <span class="attr">break;</span></span><br><span class="line"> <span class="attr">}</span></span><br><span class="line"> <span class="attr">access_log</span> <span class="string">off;</span></span><br><span class="line"> <span class="attr">}</span></span><br><span class="line"> <span class="attr">}</span></span><br><span class="line"><span class="meta">}</span> <span class="string"></span></span><br></pre></td></tr></table></figure>
<p><code>sudo systemctl restart nginx</code></p>
<h1 id="Xray配置"><a href="#Xray配置" class="headerlink" title="Xray配置"></a>Xray配置</h1><p> 编辑<code>/usr/local/etc/xray/config.json</code></p>
<figure class="highlight json"><table><tr><td class="code"><pre><span class="line"> {</span><br><span class="line"> <span class="attr">"log"</span>: {</span><br><span class="line"> <span class="attr">"loglevel"</span>: <span class="string">"warning"</span></span><br><span class="line"> },</span><br><span class="line"> <span class="attr">"inbounds"</span>: [</span><br><span class="line"> {</span><br><span class="line"> <span class="attr">"port"</span>: <span class="number">443</span>,</span><br><span class="line"> <span class="attr">"protocol"</span>: <span class="string">"trojan"</span>,</span><br><span class="line"> <span class="attr">"settings"</span>: {</span><br><span class="line"> <span class="attr">"clients"</span>: [</span><br><span class="line"> {</span><br><span class="line"> <span class="attr">"password"</span>:<span class="string">"填你的密码"</span></span><br><span class="line"> }</span><br><span class="line"> ],</span><br><span class="line"> <span class="attr">"fallbacks"</span>: [</span><br><span class="line"> {</span><br><span class="line"> <span class="attr">"dest"</span>: <span class="string">"/dev/shm/default.sock"</span>,</span><br><span class="line"> <span class="attr">"xver"</span>: <span class="number">1</span></span><br><span class="line"> },</span><br><span class="line"> {</span><br><span class="line"> <span class="attr">"alpn"</span>: <span class="string">"h2"</span>,</span><br><span class="line"> <span class="attr">"dest"</span>: <span class="string">"/dev/shm/h2c.sock"</span>,</span><br><span class="line"> <span class="attr">"xver"</span>: <span class="number">1</span></span><br><span class="line"> }</span><br><span class="line"> ]</span><br><span class="line"> },</span><br><span class="line"> <span class="attr">"streamSettings"</span>: {</span><br><span class="line"> <span class="attr">"network"</span>: <span class="string">"tcp"</span>,</span><br><span class="line"> <span class="attr">"security"</span>: <span class="string">"tls"</span>,</span><br><span class="line"> <span class="attr">"tlsSettings"</span>: {</span><br><span class="line"> <span class="attr">"alpn"</span>:[<span class="string">"http/1.1"</span>,<span class="string">"h2"</span>],</span><br><span class="line"> <span class="attr">"certificates"</span>: [</span><br><span class="line"> {<span class="comment">//自己搞定域名和证书</span></span><br><span class="line"> <span class="attr">"certificateFile"</span>: <span class="string">"/etc/nginx/cert/2994039_weiyangbo.com.pem"</span>,</span><br><span class="line"> <span class="attr">"keyFile"</span>: <span class="string">"/etc/nginx/cert/2994039_weiyangbo.com.key"</span></span><br><span class="line"> }</span><br><span class="line"> ]</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> ],</span><br><span class="line"> <span class="attr">"outbounds"</span>: [</span><br><span class="line"> {</span><br><span class="line"> <span class="attr">"protocol"</span>: <span class="string">"freedom"</span></span><br><span class="line"> }</span><br><span class="line"> ]</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<p><code>sudo systemctl restart xray</code></p>
]]></content>
</entry>
<entry>
<title>Ubuntu优化指南</title>
<url>/2019/10/10/Ubuntu_optimization/</url>
<content><![CDATA[<p>记录一下Ubuntu系统安装完成后的一些自定义设置</p>
<a id="more"></a>
<h1 id="解决与Windows双系统时时区问题"><a href="#解决与Windows双系统时时区问题" class="headerlink" title="解决与Windows双系统时时区问题"></a>解决与Windows双系统时时区问题</h1><p>先保证Ubuntu下的时间是北京时间</p>
<figure class="highlight brainfuck"><table><tr><td class="code"><pre><span class="line"><span class="comment">sudo</span> <span class="comment">hwclock</span> --<span class="comment">localtime</span> --<span class="comment">systohc</span></span><br></pre></td></tr></table></figure>
<p>问题解决</p>
<h1 id="自定义Vi编辑器"><a href="#自定义Vi编辑器" class="headerlink" title="自定义Vi编辑器"></a>自定义Vi编辑器</h1><figure class="highlight awk"><table><tr><td class="code"><pre><span class="line">sudo nano <span class="regexp">/etc/</span>vim/vimrc</span><br></pre></td></tr></table></figure>
<p>添加如下</p>
<figure class="highlight vim"><table><tr><td class="code"><pre><span class="line"><span class="comment">"语法高亮</span></span><br><span class="line"><span class="comment">"syntax on</span></span><br><span class="line"><span class="comment">"显示行号</span></span><br><span class="line"><span class="keyword">set</span> <span class="keyword">nu</span></span><br><span class="line"><span class="comment">"修改默认注释颜色</span></span><br><span class="line"><span class="keyword">hi</span> Comment ctermfg=DarkCyan</span><br><span class="line"></span><br><span class="line"><span class="keyword">set</span> nocompatible</span><br><span class="line"><span class="comment">"允许退格键删除</span></span><br><span class="line"><span class="keyword">set</span> backspace=<span class="number">2</span></span><br><span class="line"><span class="comment">"启用鼠标</span></span><br><span class="line"><span class="comment">"set mouse=a</span></span><br><span class="line"><span class="comment">"set selection=exclusive</span></span><br><span class="line"><span class="comment">"set selectmode=mouse,key</span></span><br><span class="line"><span class="comment">"侦测文件类型</span></span><br><span class="line"><span class="keyword">filetype</span> <span class="keyword">on</span></span><br><span class="line"><span class="comment">"载入文件类型插件</span></span><br><span class="line"><span class="keyword">filetype</span> plugin <span class="keyword">on</span></span><br><span class="line"><span class="comment">"为特定文件类型载入相关缩进文件</span></span><br><span class="line"><span class="keyword">filetype</span> <span class="built_in">indent</span> <span class="keyword">on</span></span><br><span class="line"><span class="comment">"设置编码自动识别, 中文引号显示</span></span><br><span class="line"><span class="keyword">set</span> fileencodings=utf-<span class="number">8</span>,gbk</span><br><span class="line"><span class="comment">"set encoding=euc-cn</span></span><br><span class="line"><span class="keyword">set</span> ambiwidth=double</span><br><span class="line"><span class="comment">"设置高亮搜索</span></span><br><span class="line"><span class="keyword">set</span> hlsearch</span><br><span class="line"><span class="comment">"在搜索时,输入的词句的逐字符高亮</span></span><br><span class="line"><span class="keyword">set</span> incsearch</span><br><span class="line"><span class="comment">"按C语言格式缩进</span></span><br><span class="line"><span class="keyword">set</span> <span class="built_in">cindent</span></span><br><span class="line"><span class="comment">"设置Tab长度为4格</span></span><br><span class="line"><span class="keyword">set</span> tabstop=<span class="number">4</span></span><br><span class="line"><span class="comment">"设置自动缩进长度为4格</span></span><br><span class="line"><span class="keyword">set</span> <span class="built_in">shiftwidth</span>=<span class="number">4</span></span><br><span class="line"><span class="comment">"继承前一行的缩进方式,特别适用于多行注释</span></span><br><span class="line"><span class="comment">"set autoindent</span></span><br><span class="line"><span class="comment">"显示括号匹配</span></span><br><span class="line"><span class="keyword">set</span> showmatch</span><br><span class="line"><span class="comment">"括号匹配显示时间为1(单位是十分之一秒)</span></span><br><span class="line"><span class="keyword">set</span> matchtime=<span class="number">1</span></span><br><span class="line"><span class="comment">"增强模式中的命令行自动完成操作</span></span><br><span class="line"><span class="keyword">set</span> wildmenu</span><br><span class="line"><span class="comment">"不要生成swap文件,当buffer被丢弃的时候隐藏它</span></span><br><span class="line"><span class="keyword">setlocal</span> noswapfile</span><br><span class="line"><span class="keyword">set</span> bufhidden=<span class="keyword">hide</span></span><br></pre></td></tr></table></figure>
<h1 id="etc-sysctl-conf"><a href="#etc-sysctl-conf" class="headerlink" title="/etc/sysctl.conf"></a>/etc/sysctl.conf</h1><figure class="highlight awk"><table><tr><td class="code"><pre><span class="line">sudo vi <span class="regexp">/etc/</span>sysctl.conf</span><br></pre></td></tr></table></figure>
<p>按照如下方式修改</p>
<figure class="highlight ini"><table><tr><td class="code"><pre><span class="line"><span class="comment">#swappiness</span></span><br><span class="line"><span class="attr">vm.swappiness</span>=<span class="number">0</span></span><br><span class="line"><span class="comment"># max open files</span></span><br><span class="line"><span class="attr">fs.file-max</span> = <span class="number">51200</span></span><br><span class="line"><span class="comment"># max read buffer</span></span><br><span class="line"><span class="attr">net.core.rmem_max</span> = <span class="number">67108864</span></span><br><span class="line"><span class="comment"># max write buffer</span></span><br><span class="line"><span class="attr">net.core.wmem_max</span> = <span class="number">67108864</span></span><br><span class="line"><span class="comment"># default read buffer</span></span><br><span class="line"><span class="attr">net.core.rmem_default</span> = <span class="number">65536</span></span><br><span class="line"><span class="comment"># default write buffer</span></span><br><span class="line"><span class="attr">net.core.wmem_default</span> = <span class="number">65536</span></span><br><span class="line"><span class="comment"># max processor input queue</span></span><br><span class="line"><span class="attr">net.core.netdev_max_backlog</span> = <span class="number">4096</span></span><br><span class="line"><span class="comment"># max backlog</span></span><br><span class="line"><span class="attr">net.core.somaxconn</span> = <span class="number">4096</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># resist SYN flood attacks</span></span><br><span class="line"><span class="attr">net.ipv4.tcp_syncookies</span> = <span class="number">1</span></span><br><span class="line"><span class="comment"># reuse timewait sockets when safe</span></span><br><span class="line"><span class="attr">net.ipv4.tcp_tw_reuse</span> = <span class="number">1</span></span><br><span class="line"><span class="comment"># turn off fast timewait sockets recycling</span></span><br><span class="line"><span class="comment">#net.ipv4.tcp_tw_recycle = 0</span></span><br><span class="line"><span class="comment"># short FIN timeout</span></span><br><span class="line"><span class="attr">net.ipv4.tcp_fin_timeout</span> = <span class="number">30</span></span><br><span class="line"><span class="comment"># short keepalive time</span></span><br><span class="line"><span class="attr">net.ipv4.tcp_keepalive_time</span> = <span class="number">1200</span></span><br><span class="line"><span class="comment"># outbound port range</span></span><br><span class="line"><span class="attr">net.ipv4.ip_local_port_range</span> = <span class="number">10000</span> <span class="number">65000</span></span><br><span class="line"><span class="comment"># max SYN backlog</span></span><br><span class="line"><span class="attr">net.ipv4.tcp_max_syn_backlog</span> = <span class="number">4096</span></span><br><span class="line"><span class="comment"># max timewait sockets held by system simultaneously</span></span><br><span class="line"><span class="attr">net.ipv4.tcp_max_tw_buckets</span> = <span class="number">5000</span></span><br><span class="line"><span class="comment"># turn on TCP Fast Open on both client and server side</span></span><br><span class="line"><span class="attr">net.ipv4.tcp_fastopen</span> = <span class="number">3</span></span><br><span class="line"><span class="comment"># TCP receive buffer</span></span><br><span class="line"><span class="attr">net.ipv4.tcp_rmem</span> = <span class="number">4096</span> <span class="number">87380</span> <span class="number">67108864</span></span><br><span class="line"><span class="comment"># TCP write buffer</span></span><br><span class="line"><span class="attr">net.ipv4.tcp_wmem</span> = <span class="number">4096</span> <span class="number">65536</span> <span class="number">67108864</span></span><br><span class="line"><span class="comment"># turn on path MTU discovery</span></span><br><span class="line"><span class="attr">net.ipv4.tcp_mtu_probing</span> = <span class="number">1</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># for high-latency network</span></span><br><span class="line"><span class="comment">#net.ipv4.tcp_congestion_control = hybla</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># for low-latency network, use cubic instead</span></span><br><span class="line"><span class="comment"># net.ipv4.tcp_congestion_control = cubic</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#for kernel version >= 4.9</span></span><br><span class="line"><span class="attr">net.core.default_qdisc</span>=fq</span><br><span class="line"><span class="attr">net.ipv4.tcp_congestion_control</span>=bbr</span><br></pre></td></tr></table></figure>
<h1 id="开启rc-local支持"><a href="#开启rc-local支持" class="headerlink" title="开启rc.local支持"></a>开启rc.local支持</h1><h2 id="1-开启服务之前,要首先添加-Install-域"><a href="#1-开启服务之前,要首先添加-Install-域" class="headerlink" title="1.开启服务之前,要首先添加[Install]域"></a>1.开启服务之前,要首先添加[Install]域</h2><p>方法一(懒人法):</p>
<figure class="highlight awk"><table><tr><td class="code"><pre><span class="line">echo -e <span class="string">"\n\n[Install]\nWantedBy=multi-user.target\nAlias=rc-local.service"</span> | sudo tee -a <span class="regexp">/etc/</span>systemd<span class="regexp">/system/</span>rc-local.service</span><br></pre></td></tr></table></figure>
<p>方法二(手动添加):</p>
<figure class="highlight awk"><table><tr><td class="code"><pre><span class="line">sudo vi <span class="regexp">/etc/</span>systemd<span class="regexp">/system/</span>rc-local.service</span><br></pre></td></tr></table></figure>
<p>在末尾添加如下内容 </p>
<figure class="highlight ini"><table><tr><td class="code"><pre><span class="line"></span><br><span class="line"><span class="section">[Install]</span></span><br><span class="line"><span class="attr">WantedBy</span>=multi-user.target</span><br><span class="line"><span class="attr">Alias</span>=rc-local.service</span><br></pre></td></tr></table></figure>
<h2 id="2-设置rc-local服务开启"><a href="#2-设置rc-local服务开启" class="headerlink" title="2.设置rc.local服务开启"></a>2.设置rc.local服务开启</h2><figure class="highlight gauss"><table><tr><td class="code"><pre><span class="line">sudo systemctl <span class="keyword">enable</span> rc-<span class="keyword">local</span></span><br></pre></td></tr></table></figure>
<h2 id="3-接下来就创建属于我们的-etc-rc-local脚本吧"><a href="#3-接下来就创建属于我们的-etc-rc-local脚本吧" class="headerlink" title="3.接下来就创建属于我们的/etc/rc.local脚本吧"></a>3.接下来就创建属于我们的/etc/rc.local脚本吧</h2><figure class="highlight awk"><table><tr><td class="code"><pre><span class="line">sudo touch <span class="regexp">/etc/</span>rc.local</span><br><span class="line">chmod <span class="number">755</span> <span class="regexp">/etc/</span>rc.local</span><br><span class="line">sudo echo <span class="string">"#!/bin/bash"</span> > <span class="regexp">/etc/</span>rc.local</span><br><span class="line">sudo vi <span class="regexp">/etc/</span>rc.local</span><br></pre></td></tr></table></figure>
<h1 id="设置SWAP"><a href="#设置SWAP" class="headerlink" title="设置SWAP"></a>设置SWAP</h1><figure class="highlight properties"><table><tr><td class="code"><pre><span class="line"><span class="attr">sudo</span> <span class="string">fallocate -l 8G /swapfile</span></span><br><span class="line"><span class="attr">sudo</span> <span class="string">mkswap /swapfile</span></span><br><span class="line"><span class="attr">sudo</span> <span class="string">chmod 600 /swapfile</span></span><br><span class="line"><span class="attr">sudo</span> <span class="string">swapon /swapfile</span></span><br><span class="line"><span class="attr">swapon</span> <span class="string">-s</span></span><br></pre></td></tr></table></figure>
<p>加入fstab以便永久生效</p>
<figure class="highlight awk"><table><tr><td class="code"><pre><span class="line">echo -e <span class="string">"\n/swapfile swap swap defaults 0 0"</span> | sudo tee -a <span class="regexp">/etc/</span>fstab</span><br></pre></td></tr></table></figure>
]]></content>
</entry>
<entry>
<title>V2ray+Nginx实现WebSocket+TLS伪装代理</title>
<url>/2019/12/08/V2ray/</url>
<content><![CDATA[<p>相比于SS,V2ray设置太麻烦了,对于移动端来说太耗电,对于硬路由来说性能开销太大。但是现在要干扰SS实在太简单,所以不得不未雨绸缪了。花了很大的功夫才利用V2ray+Nginx配置好WebSocket+TLS,同时不影响原来的网站。将V2ray藏在Nginx后面,使用 TLS 加密流量,看起来更像HTTPS。<br> <a id="more"></a></p>
<h1 id="安装V2ray和Nginx"><a href="#安装V2ray和Nginx" class="headerlink" title="安装V2ray和Nginx"></a>安装V2ray和Nginx</h1><p>参考以下两个链接分别安装Nginx和V2ray,其中V2ray是在客户端和服务器上都要安装的,跟SS不同,V2ray不分服务端和客户端。Nginx只需服务器安装就可以了。<br> <a target="_blank" rel="noopener" href="https://toutyrater.github.io/prep/install.html">V2ray官方Linux下安装指南</a><br>我之前写过<a href="/2019/10/26/Nginx-FancyIndex/" title="编译安装和配置Nginx">编译安装和配置Nginx</a>的博文</p>
<h1 id="服务端设置"><a href="#服务端设置" class="headerlink" title="服务端设置"></a>服务端设置</h1><p>官方的教程说得已经很清楚了,Nginx的配置和V2ray的配置都提到了,可以先做个参考 <a target="_blank" rel="noopener" href="https://toutyrater.github.io/advanced/wss_and_web.html#websockettlsweb">V2ray官方白话文配置教程</a><br>服务器上的配置我跟官方差不多,直接贴出配置。<br>Nginx配置</p>
<figure class="highlight properties"><table><tr><td class="code"><pre><span class="line"></span><br><span class="line"><span class="attr">user</span> <span class="string">root;</span></span><br><span class="line"><span class="attr">worker_processes</span> <span class="string">2;</span></span><br><span class="line"></span><br><span class="line"><span class="attr">pid</span> <span class="string">/var/run/nginx.pid;</span></span><br><span class="line"><span class="attr">error_log</span> <span class="string">/var/log/nginx_error.log;</span></span><br><span class="line"></span><br><span class="line"><span class="attr">events</span> <span class="string">{</span></span><br><span class="line"> <span class="attr">use</span> <span class="string">epoll;</span></span><br><span class="line"> <span class="attr">worker_connections</span> <span class="string">1024;</span></span><br><span class="line"> <span class="attr">multi_accept</span> <span class="string">on;</span></span><br><span class="line"><span class="attr">}</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="attr">http</span> <span class="string">{</span></span><br><span class="line"> <span class="attr">include</span> <span class="string">mime.types;</span></span><br><span class="line"> <span class="attr">default_type</span> <span class="string">application/octet-stream;</span></span><br><span class="line"> <span class="attr">charset</span> <span class="string">utf-8;</span></span><br><span class="line"> <span class="attr">sendfile</span> <span class="string">on;</span></span><br><span class="line"> <span class="attr">tcp_nopush</span> <span class="string">on;</span></span><br><span class="line"> <span class="attr">tcp_nodelay</span> <span class="string">on;</span></span><br><span class="line"> <span class="attr">keepalive_timeout</span> <span class="string">60;</span></span><br><span class="line"> <span class="attr">client_header_buffer_size</span> <span class="string">4k;</span></span><br><span class="line"> <span class="attr">open_file_cache</span> <span class="string">max=102400 inactive=20s;</span></span><br><span class="line"> <span class="attr">open_file_cache_valid</span> <span class="string">30s;</span></span><br><span class="line"> <span class="attr">open_file_cache_min_uses</span> <span class="string">1;</span></span><br><span class="line"> <span class="attr">client_header_timeout</span> <span class="string">15;</span></span><br><span class="line"> <span class="attr">client_body_timeout</span> <span class="string">15;</span></span><br><span class="line"> <span class="attr">reset_timedout_connection</span> <span class="string">on;</span></span><br><span class="line"> <span class="attr">send_timeout</span> <span class="string">15;</span></span><br><span class="line"> <span class="attr">gzip</span> <span class="string">on;</span></span><br><span class="line"> <span class="attr">gzip_disable</span> <span class="string">"msie6";</span></span><br><span class="line"> <span class="attr">gzip_vary</span> <span class="string">on;</span></span><br><span class="line"> <span class="attr">gzip_proxied</span> <span class="string">any;</span></span><br><span class="line"> <span class="attr">gzip_comp_level</span> <span class="string">3;</span></span><br><span class="line"> <span class="attr">gzip_buffers</span> <span class="string">16 8k;</span></span><br><span class="line"> <span class="attr">gzip_http_version</span> <span class="string">1.1;</span></span><br><span class="line"> <span class="attr">gzip_types</span> <span class="string">text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;</span></span><br><span class="line"> <span class="attr">server_tokens</span> <span class="string">off;</span></span><br><span class="line"> <span class="attr">access_log</span> <span class="string">/var/log/nginx_access.log;</span></span><br><span class="line"></span><br><span class="line"> <span class="attr">server</span> <span class="string">{</span></span><br><span class="line"> <span class="attr">listen</span> <span class="string">443 ssl;</span></span><br><span class="line"> <span class="attr">server_name</span> <span class="string">weiyangbo.com www.weiyangbo.com; #此处填你网站的域名</span></span><br><span class="line"><span class="comment"> #下面两行是你的ssl证书的路径</span></span><br><span class="line"> <span class="attr">ssl_certificate</span> <span class="string">/etc/nginx/cert/xxxxxxx.pem;</span></span><br><span class="line"> <span class="attr">ssl_certificate_key</span> <span class="string">/etc/nginx/cert/xxxxxxx.key;</span></span><br><span class="line"> <span class="attr">ssl_protocols</span> <span class="string">TLSv1 TLSv1.1 TLSv1.2;</span></span><br><span class="line"> <span class="attr">ssl_prefer_server_ciphers</span> <span class="string">on;</span></span><br><span class="line"> <span class="attr">ssl_session_timeout</span> <span class="string">5m;</span></span><br><span class="line"> <span class="attr">ssl_ciphers</span> <span class="string">ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;</span></span><br><span class="line"> <span class="attr">root</span> <span class="string">/www; #此处填你的网站目录</span></span><br><span class="line"> <span class="attr">location</span> <span class="string">/ {</span></span><br><span class="line"> <span class="attr">expires</span> <span class="string">10h;</span></span><br><span class="line"> <span class="attr">fancyindex</span> <span class="string">on;</span></span><br><span class="line"> <span class="attr">fancyindex_exact_size</span> <span class="string">off;</span></span><br><span class="line"> <span class="attr">fancyindex_localtime</span> <span class="string">on;</span></span><br><span class="line"> <span class="attr">fancyindex_header</span> <span class="string">"/fancyindex/header.html";</span></span><br><span class="line"> <span class="attr">fancyindex_footer</span> <span class="string">"/fancyindex/footer.html";</span></span><br><span class="line"> <span class="attr">fancyindex_ignore</span> <span class="string">"fancyindex" "Download"; #可以自定义文件服务器中不显示的文件或文件夹</span></span><br><span class="line"> <span class="attr">fancyindex_name_length</span> <span class="string">500;</span></span><br><span class="line"> <span class="attr">}</span></span><br><span class="line"><span class="comment"> #这是防盗链设置</span></span><br><span class="line"> <span class="attr">location</span> <span class="string">~* ^.+\.(jpg|gif|png|img|apk|tar.gz|wmv|jpeg|mp3|mp4|zip|rar)$ {</span></span><br><span class="line"> <span class="attr">valid_referers</span> <span class="string">none blocked www.weiyangbo.com weiyangbo.com;</span></span><br><span class="line"> <span class="attr">if</span> <span class="string">($invalid_referer){</span></span><br><span class="line"> <span class="attr">return</span> <span class="string">403;</span></span><br><span class="line"> <span class="attr">break;</span></span><br><span class="line"> <span class="attr">}</span></span><br><span class="line"> <span class="attr">access_log</span> <span class="string">off;</span></span><br><span class="line"> <span class="attr">}</span></span><br><span class="line"> <span class="attr">location</span> <span class="string">/v2ray/ { #这一段就是用于V2ray的反向代理</span></span><br><span class="line"> <span class="attr">proxy_redirect</span> <span class="string">off;</span></span><br><span class="line"> <span class="attr">proxy_pass</span> <span class="string">http://127.0.0.1:10000;</span></span><br><span class="line"> <span class="attr">proxy_http_version</span> <span class="string">1.1;</span></span><br><span class="line"> <span class="attr">proxy_set_header</span> <span class="string">Upgrade $http_upgrade;</span></span><br><span class="line"> <span class="attr">proxy_set_header</span> <span class="string">Connection "upgrade";</span></span><br><span class="line"> <span class="attr">proxy_set_header</span> <span class="string">Host $http_host;</span></span><br><span class="line"> <span class="attr">}</span></span><br><span class="line"> <span class="attr">}</span></span><br><span class="line"><span class="comment"> #重定向80端口的全部http请求去https</span></span><br><span class="line"> <span class="attr">server</span> <span class="string">{</span></span><br><span class="line"> <span class="attr">listen</span> <span class="string">80;</span></span><br><span class="line"> <span class="attr">server_name</span> <span class="string">weiyangbo.com www.weiyangbo.com; #网站域名,跟上面保持一致</span></span><br><span class="line"> <span class="attr">return</span> <span class="string">301 https://$server_name$request_uri;</span></span><br><span class="line"> <span class="attr">}</span></span><br><span class="line"><span class="attr">}</span></span><br></pre></td></tr></table></figure>
<p>Nginx配置写完之后可以用<code>nginx -t</code>命令检查一下Nginx的配置文件有没有语法错误。然后<code>nginx -s reload</code>重启Nginx。<br>还有V2ray的服务端配置,默认在<code>/etc/v2ray/config.json</code></p>
<figure class="highlight json"><table><tr><td class="code"><pre><span class="line">{</span><br><span class="line"> <span class="attr">"log"</span> : {</span><br><span class="line"> <span class="attr">"access"</span>: <span class="string">"/var/log/v2ray/access.log"</span>,</span><br><span class="line"> <span class="attr">"error"</span>: <span class="string">"/var/log/v2ray/error.log"</span>,</span><br><span class="line"> <span class="attr">"loglevel"</span>: <span class="string">"warning"</span></span><br><span class="line"> },</span><br><span class="line"> <span class="attr">"inbound"</span>: {</span><br><span class="line"> <span class="attr">"port"</span>: <span class="number">10000</span>,</span><br><span class="line"> <span class="attr">"listen"</span>: <span class="string">"127.0.0.1"</span>,</span><br><span class="line"> <span class="attr">"protocol"</span>: <span class="string">"vmess"</span>,</span><br><span class="line"> <span class="attr">"settings"</span>: {</span><br><span class="line"> <span class="attr">"clients"</span>: [</span><br><span class="line"> {</span><br><span class="line"> <span class="attr">"id"</span>: <span class="string">"8335737e-124e-4935-818a-31501e43c819"</span>,</span><br><span class="line"> <span class="attr">"alterId"</span>: <span class="number">64</span></span><br><span class="line"> }</span><br><span class="line"> ]</span><br><span class="line"> },</span><br><span class="line"> <span class="attr">"streamSettings"</span>:</span><br><span class="line"> {</span><br><span class="line"> <span class="attr">"network"</span>: <span class="string">"ws"</span>,</span><br><span class="line"> <span class="attr">"wsSettings"</span>: {</span><br><span class="line"> <span class="attr">"path"</span>: <span class="string">"/v2ray/"</span></span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> },</span><br><span class="line"> <span class="attr">"outbound"</span>: {</span><br><span class="line"> <span class="attr">"protocol"</span>: <span class="string">"freedom"</span>,</span><br><span class="line"> <span class="attr">"settings"</span>: {}</span><br><span class="line"> },</span><br><span class="line"> <span class="attr">"outboundDetour"</span>: [</span><br><span class="line"> {</span><br><span class="line"> <span class="attr">"protocol"</span>: <span class="string">"blackhole"</span>,</span><br><span class="line"> <span class="attr">"settings"</span>: {</span><br><span class="line"> },</span><br><span class="line"> <span class="attr">"tag"</span>: <span class="string">"blocked"</span></span><br><span class="line"> }</span><br><span class="line"> ],</span><br><span class="line"> <span class="attr">"routing"</span>: {</span><br><span class="line"> <span class="attr">"strategy"</span>: <span class="string">"rules"</span>,</span><br><span class="line"> <span class="attr">"settings"</span>: {</span><br><span class="line"> <span class="attr">"rules"</span>: [</span><br><span class="line"> {</span><br><span class="line"> <span class="attr">"type"</span>: <span class="string">"field"</span>,</span><br><span class="line"> <span class="attr">"ip"</span>: [</span><br><span class="line"> <span class="string">"0.0.0.0/8"</span>,</span><br><span class="line"> <span class="string">"10.0.0.0/8"</span>,</span><br><span class="line"> <span class="string">"100.64.0.0/10"</span>,</span><br><span class="line"> <span class="string">"127.0.0.0/8"</span>,</span><br><span class="line"> <span class="string">"169.254.0.0/16"</span>,</span><br><span class="line"> <span class="string">"172.16.0.0/12"</span>,</span><br><span class="line"> <span class="string">"192.0.0.0/24"</span>,</span><br><span class="line"> <span class="string">"192.0.2.0/24"</span>,</span><br><span class="line"> <span class="string">"192.168.0.0/16"</span>,</span><br><span class="line"> <span class="string">"198.18.0.0/15"</span>,</span><br><span class="line"> <span class="string">"198.51.100.0/24"</span>,</span><br><span class="line"> <span class="string">"203.0.113.0/24"</span>,</span><br><span class="line"> <span class="string">"::1/128"</span>,</span><br><span class="line"> <span class="string">"fc00::/7"</span>,</span><br><span class="line"> <span class="string">"fe80::/10"</span></span><br><span class="line"> ],</span><br><span class="line"> <span class="attr">"outboundTag"</span>: <span class="string">"blocked"</span></span><br><span class="line"> }</span><br><span class="line"> ]</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<p>V2ray配置完之后可以用命令<code>/usr/bin/v2ray/v2ray -test /etc/v2ray/config.json</code>命令检查V2ray的配置文件是否有语法错误。接着用<code>systemctl start v2ray</code>来启动。<br>需要注意的是:<br>1、Nginx配置里面的<code>location</code>字段必须和V2ray中的<code>path</code>一模一样,连“/”也不可以省略。<br>2、Nginx配置里面的<code>proxy_pass</code>后面的端口,必须保持和V2ray中的<code>port</code>一致,同时注意SElinux是否允许Nginx做转发。</p>
<h1 id="客户端配置"><a href="#客户端配置" class="headerlink" title="客户端配置"></a>客户端配置</h1><p>我在官方的基础上做了较大改动,参考了Kitsunebi大神的<a target="_blank" rel="noopener" href="https://medium.com/@TachyonDevel/%E6%BC%AB%E8%B0%88%E5%90%84%E7%A7%8D%E9%BB%91%E7%A7%91%E6%8A%80%E5%BC%8F-dns-%E6%8A%80%E6%9C%AF%E5%9C%A8%E4%BB%A3%E7%90%86%E7%8E%AF%E5%A2%83%E4%B8%AD%E7%9A%84%E5%BA%94%E7%94%A8-62c50e58cbd0">这篇帖子</a>,在客户端实现了自动分流(绕过国内IP)和DNS防投毒。下面直接贴出我的配置</p>
<figure class="highlight json"><table><tr><td class="code"><pre><span class="line">{</span><br><span class="line"> <span class="attr">"inbounds"</span>: [</span><br><span class="line"> {</span><br><span class="line"> <span class="attr">"port"</span>: <span class="number">1080</span>,</span><br><span class="line"> <span class="attr">"listen"</span>: <span class="string">"127.0.0.1"</span>,</span><br><span class="line"> <span class="attr">"protocol"</span>: <span class="string">"socks"</span>,</span><br><span class="line"> <span class="attr">"sniffing"</span>: {</span><br><span class="line"> <span class="attr">"enabled"</span>: <span class="literal">true</span>,</span><br><span class="line"> <span class="attr">"destOverride"</span>: [</span><br><span class="line"> <span class="string">"http"</span>,</span><br><span class="line"> <span class="string">"tls"</span></span><br><span class="line"> ]</span><br><span class="line"> },</span><br><span class="line"> <span class="attr">"settings"</span>: {</span><br><span class="line"> <span class="attr">"auth"</span>: <span class="string">"noauth"</span>,</span><br><span class="line"> <span class="attr">"udp"</span>: <span class="literal">false</span></span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> ],</span><br><span class="line"> <span class="attr">"outbounds"</span>: [</span><br><span class="line"> {</span><br><span class="line"> <span class="attr">"protocol"</span>: <span class="string">"vmess"</span>,</span><br><span class="line"> <span class="attr">"settings"</span>: {</span><br><span class="line"> <span class="attr">"vnext"</span>: [</span><br><span class="line"> {</span><br><span class="line"> <span class="attr">"address"</span>: <span class="string">"weiyangbo.com"</span>,</span><br><span class="line"> <span class="attr">"port"</span>: <span class="number">443</span>,</span><br><span class="line"> <span class="attr">"users"</span>: [</span><br><span class="line"> {</span><br><span class="line"> <span class="attr">"id"</span>: <span class="string">"8335737e-124e-4935-818a-31501e43c819"</span>,</span><br><span class="line"> <span class="attr">"alterId"</span>: <span class="number">64</span>,</span><br><span class="line"> <span class="attr">"security"</span>: <span class="string">"auto"</span></span><br><span class="line"> }</span><br><span class="line"> ]</span><br><span class="line"> }</span><br><span class="line"> ]</span><br><span class="line"> },</span><br><span class="line"> <span class="attr">"streamSettings"</span>: {</span><br><span class="line"> <span class="attr">"network"</span>: <span class="string">"ws"</span>,</span><br><span class="line"> <span class="attr">"security"</span>: <span class="string">"tls"</span>,</span><br><span class="line"> <span class="attr">"tlsSettings"</span>: {</span><br><span class="line"> <span class="attr">"serverName"</span>: <span class="string">"weiyangbo.com"</span></span><br><span class="line"> },</span><br><span class="line"> <span class="attr">"wsSettings"</span>: {</span><br><span class="line"> <span class="attr">"path"</span>: <span class="string">"/v2ray/"</span></span><br><span class="line"> }</span><br><span class="line"> },</span><br><span class="line"> <span class="attr">"tag"</span>: <span class="string">"proxy"</span></span><br><span class="line"> },</span><br><span class="line"> {</span><br><span class="line"> <span class="attr">"protocol"</span>: <span class="string">"freedom"</span>,</span><br><span class="line"> <span class="attr">"settings"</span>: {</span><br><span class="line"> <span class="attr">"domainStrategy"</span>: <span class="string">"UseIP"</span></span><br><span class="line"> },</span><br><span class="line"> <span class="attr">"streamSettings"</span>: {},</span><br><span class="line"> <span class="attr">"tag"</span>: <span class="string">"direct"</span></span><br><span class="line"> },</span><br><span class="line"> {</span><br><span class="line"> <span class="attr">"protocol"</span>: <span class="string">"blackhole"</span>,</span><br><span class="line"> <span class="attr">"settings"</span>: {},</span><br><span class="line"> <span class="attr">"tag"</span>: <span class="string">"block"</span></span><br><span class="line"> },</span><br><span class="line"> {</span><br><span class="line"> <span class="attr">"protocol"</span>: <span class="string">"dns"</span>,</span><br><span class="line"> <span class="attr">"tag"</span>: <span class="string">"dns-out"</span></span><br><span class="line"> }</span><br><span class="line"> ],</span><br><span class="line"> <span class="attr">"dns"</span>: {</span><br><span class="line"> <span class="attr">"clientIp"</span>: <span class="string">"115.239.211.92"</span>,</span><br><span class="line"> <span class="attr">"hosts"</span>: {</span><br><span class="line"> <span class="attr">"localhost"</span>: <span class="string">"127.0.0.1"</span></span><br><span class="line"> },</span><br><span class="line"> <span class="attr">"servers"</span>: [</span><br><span class="line"> <span class="string">"114.114.114.114"</span>,</span><br><span class="line"> {</span><br><span class="line"> <span class="attr">"address"</span>: <span class="string">"8.8.8.8"</span>,</span><br><span class="line"> <span class="attr">"domains"</span>: [</span><br><span class="line"> <span class="string">"google"</span>,</span><br><span class="line"> <span class="string">"android"</span>,</span><br><span class="line"> <span class="string">"fbcdn"</span>,</span><br><span class="line"> <span class="string">"facebook"</span>,</span><br><span class="line"> <span class="string">"domain:fb.com"</span>,</span><br><span class="line"> <span class="string">"instagram"</span>,</span><br><span class="line"> <span class="string">"whatsapp"</span>,</span><br><span class="line"> <span class="string">"akamai"</span>,</span><br><span class="line"> <span class="string">"domain:line-scdn.net"</span>,</span><br><span class="line"> <span class="string">"domain:line.me"</span>,</span><br><span class="line"> <span class="string">"domain:naver.jp"</span></span><br><span class="line"> ],</span><br><span class="line"> <span class="attr">"port"</span>: <span class="number">53</span></span><br><span class="line"> }</span><br><span class="line"> ]</span><br><span class="line"> },</span><br><span class="line"> <span class="attr">"log"</span>: {</span><br><span class="line"> <span class="attr">"loglevel"</span>: <span class="string">"warning"</span></span><br><span class="line"> },</span><br><span class="line"> <span class="attr">"policy"</span>: {</span><br><span class="line"> <span class="attr">"levels"</span>: {</span><br><span class="line"> <span class="attr">"0"</span>: {</span><br><span class="line"> <span class="attr">"bufferSize"</span>: <span class="number">4096</span>,</span><br><span class="line"> <span class="attr">"connIdle"</span>: <span class="number">30</span>,</span><br><span class="line"> <span class="attr">"downlinkOnly"</span>: <span class="number">0</span>,</span><br><span class="line"> <span class="attr">"handshake"</span>: <span class="number">4</span>,</span><br><span class="line"> <span class="attr">"uplinkOnly"</span>: <span class="number">0</span></span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> },</span><br><span class="line"> <span class="attr">"routing"</span>: {</span><br><span class="line"> <span class="attr">"domainStrategy"</span>: <span class="string">"IPIfNonMatch"</span>,</span><br><span class="line"> <span class="attr">"rules"</span>: [</span><br><span class="line"> {</span><br><span class="line"> <span class="attr">"inboundTag"</span>: [</span><br><span class="line"> <span class="string">"tun2socks"</span></span><br><span class="line"> ],</span><br><span class="line"> <span class="attr">"network"</span>: <span class="string">"udp"</span>,</span><br><span class="line"> <span class="attr">"port"</span>: <span class="number">53</span>,</span><br><span class="line"> <span class="attr">"outboundTag"</span>: <span class="string">"dns-out"</span>,</span><br><span class="line"> <span class="attr">"type"</span>: <span class="string">"field"</span></span><br><span class="line"> },</span><br><span class="line"> {</span><br><span class="line"> <span class="attr">"domain"</span>: [</span><br><span class="line"> <span class="string">"domain:setup.icloud.com"</span></span><br><span class="line"> ],</span><br><span class="line"> <span class="attr">"outboundTag"</span>: <span class="string">"proxy"</span>,</span><br><span class="line"> <span class="attr">"type"</span>: <span class="string">"field"</span></span><br><span class="line"> },</span><br><span class="line"> {</span><br><span class="line"> <span class="attr">"ip"</span>: [</span><br><span class="line"> <span class="string">"8.8.8.8/32"</span>,</span><br><span class="line"> <span class="string">"8.8.4.4/32"</span>,</span><br><span class="line"> <span class="string">"1.1.1.1/32"</span>,</span><br><span class="line"> <span class="string">"1.0.0.1/32"</span>,</span><br><span class="line"> <span class="string">"9.9.9.9/32"</span>,</span><br><span class="line"> <span class="string">"149.112.112.112/32"</span>,</span><br><span class="line"> <span class="string">"208.67.222.222/32"</span>,</span><br><span class="line"> <span class="string">"208.67.220.220/32"</span></span><br><span class="line"> ],</span><br><span class="line"> <span class="attr">"outboundTag"</span>: <span class="string">"proxy"</span>,</span><br><span class="line"> <span class="attr">"type"</span>: <span class="string">"field"</span></span><br><span class="line"> },</span><br><span class="line"> {</span><br><span class="line"> <span class="attr">"ip"</span>: [</span><br><span class="line"> <span class="string">"geoip:cn"</span>,</span><br><span class="line"> <span class="string">"geoip:private"</span></span><br><span class="line"> ],</span><br><span class="line"> <span class="attr">"outboundTag"</span>: <span class="string">"direct"</span>,</span><br><span class="line"> <span class="attr">"type"</span>: <span class="string">"field"</span></span><br><span class="line"> },</span><br><span class="line"> {</span><br><span class="line"> <span class="attr">"outboundTag"</span>: <span class="string">"direct"</span>,</span><br><span class="line"> <span class="attr">"port"</span>: <span class="string">"123"</span>,</span><br><span class="line"> <span class="attr">"type"</span>: <span class="string">"field"</span></span><br><span class="line"> },</span><br><span class="line"> {</span><br><span class="line"> <span class="attr">"domain"</span>: [</span><br><span class="line"> <span class="string">"domain:pstatp.com"</span>,</span><br><span class="line"> <span class="string">"domain:snssdk.com"</span>,</span><br><span class="line"> <span class="string">"domain:toutiao.com"</span>,</span><br><span class="line"> <span class="string">"domain:ixigua.com"</span>,</span><br><span class="line"> <span class="string">"domain:apple.com"</span>,</span><br><span class="line"> <span class="string">"domain:crashlytics.com"</span>,</span><br><span class="line"> <span class="string">"domain:icloud.com"</span>,</span><br><span class="line"> <span class="string">"cctv"</span>,</span><br><span class="line"> <span class="string">"umeng"</span>,</span><br><span class="line"> <span class="string">"domain:weico.cc"</span>,</span><br><span class="line"> <span class="string">"domain:jd.com"</span>,</span><br><span class="line"> <span class="string">"domain:360buy.com"</span>,</span><br><span class="line"> <span class="string">"domain:360buyimg.com"</span>,</span><br><span class="line"> <span class="string">"domain:douyu.tv"</span>,</span><br><span class="line"> <span class="string">"domain:douyu.com"</span>,</span><br><span class="line"> <span class="string">"domain:douyucdn.cn"</span>,</span><br><span class="line"> <span class="string">"geosite:cn"</span></span><br><span class="line"> ],</span><br><span class="line"> <span class="attr">"outboundTag"</span>: <span class="string">"direct"</span>,</span><br><span class="line"> <span class="attr">"type"</span>: <span class="string">"field"</span></span><br><span class="line"> },</span><br><span class="line"> {</span><br><span class="line"> <span class="attr">"ip"</span>: [</span><br><span class="line"> <span class="string">"149.154.167.0/24"</span>,</span><br><span class="line"> <span class="string">"149.154.175.0/24"</span>,</span><br><span class="line"> <span class="string">"91.108.56.0/24"</span>,</span><br><span class="line"> <span class="string">"125.209.222.0/24"</span></span><br><span class="line"> ],</span><br><span class="line"> <span class="attr">"outboundTag"</span>: <span class="string">"proxy"</span>,</span><br><span class="line"> <span class="attr">"type"</span>: <span class="string">"field"</span></span><br><span class="line"> },</span><br><span class="line"> {</span><br><span class="line"> <span class="attr">"domain"</span>: [</span><br><span class="line"> <span class="string">"twitter"</span>,</span><br><span class="line"> <span class="string">"domain:twimg.com"</span>,</span><br><span class="line"> <span class="string">"domain:t.co"</span>,</span><br><span class="line"> <span class="string">"google"</span>,</span><br><span class="line"> <span class="string">"domain:ggpht.com"</span>,</span><br><span class="line"> <span class="string">"domain:gstatic.com"</span>,</span><br><span class="line"> <span class="string">"domain:youtube.com"</span>,</span><br><span class="line"> <span class="string">"domain:ytimg.com"</span>,</span><br><span class="line"> <span class="string">"pixiv"</span>,</span><br><span class="line"> <span class="string">"domain:pximg.net"</span>,</span><br><span class="line"> <span class="string">"tumblr"</span>,</span><br><span class="line"> <span class="string">"instagram"</span>,</span><br><span class="line"> <span class="string">"domain:line-scdn.net"</span>,</span><br><span class="line"> <span class="string">"domain:line.me"</span>,</span><br><span class="line"> <span class="string">"domain:naver.jp"</span>,</span><br><span class="line"> <span class="string">"domain:facebook.com"</span>,</span><br><span class="line"> <span class="string">"domain:fbcdn.net"</span>,</span><br><span class="line"> <span class="string">"pinterest"</span>,</span><br><span class="line"> <span class="string">"github"</span>,</span><br><span class="line"> <span class="string">"dropbox"</span>,</span><br><span class="line"> <span class="string">"netflix"</span>,</span><br><span class="line"> <span class="string">"domain:medium.com"</span>,</span><br><span class="line"> <span class="string">"domain:fivecdm.com"</span></span><br><span class="line"> ],</span><br><span class="line"> <span class="attr">"outboundTag"</span>: <span class="string">"proxy"</span>,</span><br><span class="line"> <span class="attr">"type"</span>: <span class="string">"field"</span></span><br><span class="line"> }</span><br><span class="line"> ],</span><br><span class="line"> <span class="attr">"strategy"</span>: <span class="string">"rules"</span></span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<p>需要注意的是:<br>客户端配置需要注意在<code>outbounds</code>里面的<code>protocol</code>、<code>settings</code>、 <code>streamSettings</code>三个字段下的所有值必须和服务器端一致,不然连不上。不过有一个例外,那就是<code>settings</code>下的<code>security</code>,因为v2ray的加密算法是客户端与服务器协商的,服务器没有强制,客户端可以随意,我这里填的是<code>auto</code>。<br>V2ray配置完之后可以用命令<code>/usr/bin/v2ray/v2ray -test /etc/v2ray/config.json</code>命令检查是否有语法错误。接着用<code>systemctl start v2ray</code>来启动。</p>
<h1 id="使用-amp-测试"><a href="#使用-amp-测试" class="headerlink" title="使用&测试"></a>使用&测试</h1><p>用<code>ps auxw | grep v2ray</code>分别检查服务器和客户端(本地)的v2ray是否正常运行。既可以在网络代理中设置系统代理,也可以在本地终端设置socksv5代理(仅在当前终端有效):</p>
<figure class="highlight routeros"><table><tr><td class="code"><pre><span class="line"><span class="builtin-name">export</span> <span class="attribute">http_proxy</span>=<span class="string">"socks5://127.0.0.1:1080"</span></span><br><span class="line"><span class="builtin-name">export</span> <span class="attribute">https_proxy</span>=<span class="string">"socks5://127.0.0.1:1080"</span></span><br></pre></td></tr></table></figure>
<p>可以用curl检测你当前的访问外网IP</p>
<figure class="highlight armasm"><table><tr><td class="code"><pre><span class="line"><span class="symbol">curl</span> <span class="built_in">ip</span>.sb</span><br></pre></td></tr></table></figure>
<p>根据curl返回的结果,可以判断代理是否设置正确。<br>1、如果返回的是本地计算机的外网IP,说明你的本地socksv5代理设置没有生效。<br>2、如果返回HTTP错误代码(404或者400之类的),检查Nginx与V2ray服务端的设置,也可以找找Nginx的日志找找线索。<br>3、当然返回服务器的外网IP是最好的情况。</p>
<h1 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h1><p>V2ray配置虽然麻烦,但是相较于SS优势明显<br>1、隐蔽性好。虽然道高一尺,魔高一丈,但是目前来说V2ray这种方法还是不容易被干扰的。<br>2、由于V2ray内建了DNS服务器和路由功能,不需要像SS那样配置路由表和安装额外的DNS服务器,算是一个一揽子解决方案。而且V2ray的socksv5代理支持转发DNS查询到内建的DNS服务器(明显SS并不支持转发DNS结果),可以直接将V2ray的socksv5代理设置为系统代理,上游DNS服务器不需要改动,国内域名还是国内DNS解析并且直连,国外域名用国外DNS服务器的解析结果并且走代理。</p>
]]></content>
</entry>
<entry>
<title>Docker使用Aria2容器</title>
<url>/2024/01/28/aria2-docker-1/</url>
<content><![CDATA[<h1 id="参考链接"><a href="#参考链接" class="headerlink" title="参考链接"></a>参考链接</h1><p>Github<br><a target="_blank" rel="noopener" href="https://github.com/P3TERX/Aria2-Pro-Docker">https://github.com/P3TERX/Aria2-Pro-Docker</a><br>进阶说明<br><a target="_blank" rel="noopener" href="https://p3terx.com/archives/docker-aria2-pro.html">Aria2 Pro - 更好用的 Aria2 Docker 容器镜像</a></p>
<h1 id="我的配置文件"><a href="#我的配置文件" class="headerlink" title="我的配置文件"></a>我的配置文件</h1><p>我的<code>docker-compose</code></p>
<figure class="highlight"><table><tr><td class="code"><pre><span class="line"><span class="attribute">version</span>: "3.8"</span><br><span class="line"></span><br><span class="line"><span class="attribute">services:</span></span><br><span class="line"><span class="attribute"></span></span><br><span class="line"> Aria2-Pro:</span><br><span class="line"> container_name: aria2-pro</span><br><span class="line"> image: p3terx/aria2-pro</span><br><span class="line"> environment:</span><br><span class="line"> - PUID=65534</span><br><span class="line"> - PGID=65534</span><br><span class="line"> - UMASK_SET=022</span><br><span class="line"> - RPC_SECRET=yourpassword</span><br><span class="line"> - RPC_PORT=6800</span><br><span class="line"> - LISTEN_PORT=6888</span><br><span class="line"> - DISK_CACHE=64M</span><br><span class="line"> - IPV6_MODE=true</span><br><span class="line"> - UPDATE_TRACKERS=true</span><br><span class="line"> - CUSTOM_TRACKER_URL=</span><br><span class="line"> - TZ=Asia/Shanghai</span><br><span class="line"> - SPECIAL_MODE=move</span><br><span class="line"> volumes:</span><br><span class="line"> - ${PWD}/aria2-config:/config</span><br><span class="line"> - /mnt/sata/.tmp:/downloads</span><br><span class="line"> - /mnt/sata:/completed</span><br><span class="line"></span><br><span class="line"> network_mode: host</span><br><span class="line"> restart: unless-stopped</span><br><span class="line"> logging:</span><br><span class="line"> driver: json-file</span><br><span class="line"> options:</span><br><span class="line"> max-size: 1m</span><br></pre></td></tr></table></figure>
<h1 id="修正一个小bug"><a href="#修正一个小bug" class="headerlink" title="修正一个小bug"></a>修正一个小bug</h1><p>修改<code>aria2-config/script.conf</code>第23行为<code>dest-dir=/completed</code></p>
]]></content>
</entry>
<entry>
<title>Armbian下配置成无线接入点</title>
<url>/2022/03/23/armbian-ap/</url>
<content><![CDATA[<p>捡了一个S912盒子,想要作为一个无线AP接入点。</p>
<h1 id="前期准备"><a href="#前期准备" class="headerlink" title="前期准备"></a>前期准备</h1><p>首先要解除NetworkManager对wlan0的占用,先<code>nmcli -s</code>记下wlan0的mac地址,比如<code>ff:ff:ff:ff:ff:ff</code>,编辑<code>/etc/NetworkManager/NetworkManager.conf</code>,改一下下面的字段,把你的wlan0划为<code>unmanageable-devices</code></p>
<figure class="highlight groovy"><table><tr><td class="code"><pre><span class="line">[keyfile]</span><br><span class="line">unmanaged-devices=<span class="attr">mac:</span><span class="attr">ff:</span><span class="attr">ff:</span><span class="attr">ff:</span><span class="attr">ff:</span><span class="attr">ff:</span>ff</span><br></pre></td></tr></table></figure>
<p>最后重启NetworkManager生效</p>
<figure class="highlight routeros"><table><tr><td class="code"><pre><span class="line">sudo<span class="built_in"> service </span>NetworkManager restart</span><br></pre></td></tr></table></figure>
<h1 id="配置WiFi"><a href="#配置WiFi" class="headerlink" title="配置WiFi"></a>配置WiFi</h1><p>然后我们安装hostapd、bridge-utils</p>
<figure class="highlight mipsasm"><table><tr><td class="code"><pre><span class="line">sudo apt-get <span class="keyword">install </span>hostapd <span class="keyword">bridge-utils </span>-y</span><br></pre></td></tr></table></figure>
<p>hostapd负责发射WiFi,先编辑他的配置文件<code>/etc/default/hostapd</code>,去掉下面这行注释并修改</p>
<figure class="highlight ini"><table><tr><td class="code"><pre><span class="line"><span class="attr">DAEMON_CONF</span>=<span class="string">"/etc/hostapd/hostapd.conf"</span></span><br></pre></td></tr></table></figure>
<p>再编辑他的配置文件<code>/etc/hostapd/hostapd.conf</code>,我把我的配置粘贴一下</p>
<figure class="highlight ini"><table><tr><td class="code"><pre><span class="line"><span class="attr">interface</span>=wlan0</span><br><span class="line"><span class="attr">bridge</span>=br0</span><br><span class="line"><span class="attr">driver</span>=nl80211</span><br><span class="line"><span class="attr">ssid</span>=Armbian</span><br><span class="line"><span class="attr">hw_mode</span>=g</span><br><span class="line"><span class="attr">channel</span>=<span class="number">7</span></span><br><span class="line"><span class="attr">wmm_enabled</span>=<span class="number">0</span></span><br><span class="line"><span class="attr">macaddr_acl</span>=<span class="number">0</span></span><br><span class="line"><span class="attr">auth_algs</span>=<span class="number">1</span></span><br><span class="line"><span class="attr">ignore_broadcast_ssid</span>=<span class="number">0</span></span><br><span class="line"><span class="attr">wpa</span>=<span class="number">2</span></span><br><span class="line"><span class="attr">wpa_passphrase</span>=<span class="number">1234567890</span></span><br><span class="line"><span class="attr">wpa_key_mgmt</span>=WPA-PSK</span><br><span class="line"><span class="attr">wpa_pairwise</span>=TKIP</span><br><span class="line"><span class="attr">rsn_pairwise</span>=CCMP</span><br></pre></td></tr></table></figure>
<p>最后启动hostapd</p>
<figure class="highlight css"><table><tr><td class="code"><pre><span class="line"><span class="selector-tag">sudo</span> <span class="selector-tag">systemctl</span> <span class="selector-tag">start</span> <span class="selector-tag">hostapd</span><span class="selector-class">.service</span> && <span class="selector-tag">sudo</span> <span class="selector-tag">systemctl</span> <span class="selector-tag">enable</span> <span class="selector-tag">hostapd</span><span class="selector-class">.service</span></span><br></pre></td></tr></table></figure>
<p>打开你的手机搜索WiFi试试,能不能搜到WiFi。搜到就行了,连不上的,因为wlan0啥都不是,下面要做桥接。</p>
<h1 id="配置eth0和wlan0桥接"><a href="#配置eth0和wlan0桥接" class="headerlink" title="配置eth0和wlan0桥接"></a>配置eth0和wlan0桥接</h1><p>编辑<code>/etc/network/interfaces</code>,我直接贴出我完整的配置</p>
<figure class="highlight apache"><table><tr><td class="code"><pre><span class="line"><span class="attribute">source</span> /etc/network/interfaces.d/*</span><br><span class="line"></span><br><span class="line"><span class="attribute">auto</span> lo br<span class="number">0</span></span><br><span class="line"><span class="attribute">iface</span> lo inet loopback</span><br><span class="line"></span><br><span class="line"><span class="attribute"><span class="nomarkup">allow</span></span>-hotplug wlan<span class="number">0</span></span><br><span class="line"><span class="attribute">iface</span> wlan<span class="number">0</span> inet manual</span><br><span class="line"></span><br><span class="line"><span class="comment"># eth0 connected to the ISP router</span></span><br><span class="line"><span class="attribute"><span class="nomarkup">allow</span></span>-hotplug eth<span class="number">0</span></span><br><span class="line"><span class="attribute">iface</span> eth<span class="number">0</span> inet manual</span><br><span class="line"></span><br><span class="line"><span class="comment"># Setup bridge</span></span><br><span class="line"><span class="attribute">auto</span> br<span class="number">0</span></span><br><span class="line"><span class="attribute">iface</span> br<span class="number">0</span> inet dhcp</span><br><span class="line"> <span class="attribute">bridge_ports</span> eth<span class="number">0</span> wlan<span class="number">0</span></span><br><span class="line"> <span class="attribute">bridge_stp</span> <span class="literal">off</span></span><br><span class="line"> <span class="attribute">bridge_maxwait</span> <span class="number">0</span></span><br></pre></td></tr></table></figure>
<h1 id="重启生效"><a href="#重启生效" class="headerlink" title="重启生效"></a>重启生效</h1><figure class="highlight ebnf"><table><tr><td class="code"><pre><span class="line"><span class="attribute">reboot</span></span><br></pre></td></tr></table></figure>
<p>到此结束~</p>
]]></content>
</entry>
<entry>
<title>定位Docker占用过多磁盘空间的问题</title>
<url>/2024/02/01/docker-clean/</url>
<content><![CDATA[<h1 id="定位爆闪存问题"><a href="#定位爆闪存问题" class="headerlink" title="定位爆闪存问题"></a>定位爆闪存问题</h1><p>从根目录开始使用<code>du -h --max-depth=1</code>一级一级往下找,最终定位到<code>/var/lib/docker/overlay2</code>占用了过多空间<br><code>docker system df -v</code>列出所有images、containers、volumes所占用的大小,发现是有一个volume占用了过多,而且并不属于任何一个container</p>
<h1 id="问题解决"><a href="#问题解决" class="headerlink" title="问题解决"></a>问题解决</h1><figure class="highlight routeros"><table><tr><td class="code"><pre><span class="line">docker<span class="built_in"> system </span>prune</span><br><span class="line">docker<span class="built_in"> system </span>prune -a</span><br><span class="line">docker<span class="built_in"> system </span>prune --volumes</span><br></pre></td></tr></table></figure>
]]></content>
</entry>
<entry>
<title>Armbian下配置成无线路由器</title>
<url>/2022/03/23/armbian-router/</url>
<content><![CDATA[<p>捡了一个S912盒子,想要作为一个无线网关,用作智能家居的网关。有线网口接路由器,通过无线网卡发射WiFi等待其他物联网设备连接。其实说白了就是无线路由器。</p>
<h1 id="前期准备"><a href="#前期准备" class="headerlink" title="前期准备"></a>前期准备</h1><p>首先我们改一下systemd-resolved,解除53端口占用。</p>
<figure class="highlight arcade"><table><tr><td class="code"><pre><span class="line">echo <span class="string">"DNS=114.114.114.114"</span>>><span class="regexp">/etc/</span>systemd/resolved.conf</span><br><span class="line">echo <span class="string">"DNSStubListener=no"</span>>><span class="regexp">/etc/</span>systemd/resolved.conf</span><br><span class="line">sudo systemctl restart systemd-resolved</span><br></pre></td></tr></table></figure>
<p>然后要解除NetworkManager对wlan0的占用,先<code>nmcli -s</code>记下wlan0的mac地址,比如<code>ff:ff:ff:ff:ff:ff</code>,编辑<code>/etc/NetworkManager/NetworkManager.conf</code>,改一下下面的字段,把你的wlan0划为<code>unmanageable-devices</code></p>
<figure class="highlight groovy"><table><tr><td class="code"><pre><span class="line">[keyfile]</span><br><span class="line">unmanaged-devices=<span class="attr">mac:</span><span class="attr">ff:</span><span class="attr">ff:</span><span class="attr">ff:</span><span class="attr">ff:</span><span class="attr">ff:</span>ff</span><br></pre></td></tr></table></figure>
<p>最后重启NetworkManager生效</p>
<figure class="highlight routeros"><table><tr><td class="code"><pre><span class="line">sudo<span class="built_in"> service </span>NetworkManager restart</span><br></pre></td></tr></table></figure>
<h1 id="配置WiFi"><a href="#配置WiFi" class="headerlink" title="配置WiFi"></a>配置WiFi</h1><p>然后我们安装hostapd、dnsmasq</p>
<figure class="highlight routeros"><table><tr><td class="code"><pre><span class="line">sudo apt-<span class="builtin-name">get</span> install hostapd dnsmasq -y</span><br></pre></td></tr></table></figure>
<p>hostapd负责发射WiFi,先编辑他的配置文件<code>/etc/default/hostapd</code>,去掉下面这行注释并修改</p>
<figure class="highlight ini"><table><tr><td class="code"><pre><span class="line"><span class="attr">DAEMON_CONF</span>=<span class="string">"/etc/hostapd/hostapd.conf"</span></span><br></pre></td></tr></table></figure>
<p>再编辑他的配置文件<code>/etc/hostapd/hostapd.conf</code>,我把我的配置粘贴一下</p>
<figure class="highlight ini"><table><tr><td class="code"><pre><span class="line"><span class="attr">interface</span>=wlan0</span><br><span class="line"><span class="attr">driver</span>=nl80211</span><br><span class="line"><span class="attr">ssid</span>=Armbian</span><br><span class="line"><span class="attr">hw_mode</span>=g</span><br><span class="line"><span class="attr">channel</span>=<span class="number">7</span></span><br><span class="line"><span class="attr">wmm_enabled</span>=<span class="number">0</span></span><br><span class="line"><span class="attr">macaddr_acl</span>=<span class="number">0</span></span><br><span class="line"><span class="attr">auth_algs</span>=<span class="number">1</span></span><br><span class="line"><span class="attr">ignore_broadcast_ssid</span>=<span class="number">0</span></span><br><span class="line"><span class="attr">wpa</span>=<span class="number">2</span></span><br><span class="line"><span class="attr">wpa_passphrase</span>=<span class="number">1234567890</span></span><br><span class="line"><span class="attr">wpa_key_mgmt</span>=WPA-PSK</span><br><span class="line"><span class="attr">wpa_pairwise</span>=TKIP</span><br><span class="line"><span class="attr">rsn_pairwise</span>=CCMP</span><br></pre></td></tr></table></figure>
<p>最后启动hostapd</p>
<figure class="highlight css"><table><tr><td class="code"><pre><span class="line"><span class="selector-tag">sudo</span> <span class="selector-tag">systemctl</span> <span class="selector-tag">start</span> <span class="selector-tag">hostapd</span><span class="selector-class">.service</span> && <span class="selector-tag">sudo</span> <span class="selector-tag">systemctl</span> <span class="selector-tag">enable</span> <span class="selector-tag">hostapd</span><span class="selector-class">.service</span></span><br></pre></td></tr></table></figure>
<p>打开你的手机搜索WiFi试试,能不能搜到WiFi。搜到就行了,连不上的,因为接下来才开始配置dhcp和dns呢。</p>
<h1 id="配置DHCP和DNS"><a href="#配置DHCP和DNS" class="headerlink" title="配置DHCP和DNS"></a>配置DHCP和DNS</h1><p>首先固定wlan0的IP地址,编辑<code>/etc/network/interfaces</code></p>
<figure class="highlight routeros"><table><tr><td class="code"><pre><span class="line">auto wlan0</span><br><span class="line">iface wlan0 inet static</span><br><span class="line">address 192.168.99.1</span><br><span class="line">netmask 255.255.255.0</span><br></pre></td></tr></table></figure>
<p>Dnsmasq是集DHCP和DNS服务器于一体的程序,我们编辑它的配置文件<code>/etc/dnsmasq.conf</code><br>我把我的<code>/etc/dnsmasq.conf</code>配置粘贴上,每个项字段在<code>dnsmasq.conf</code>里面都有解释,我就不做解释了。</p>
<figure class="highlight lsl"><table><tr><td class="code"><pre><span class="line">interface=wlan0</span><br><span class="line">dhcp-range=<span class="number">192.168</span><span class="number">.99</span><span class="number">.2</span>,<span class="number">192.168</span><span class="number">.99</span><span class="number">.254</span>,<span class="number">255.255</span><span class="number">.255</span><span class="number">.0</span>,<span class="number">12</span>h</span><br><span class="line">no-hosts</span><br><span class="line">addn-hosts=/etc/hosts.dnsmasq</span><br></pre></td></tr></table></figure>
<p>我把我的<code>/etc/hosts.dnsmasq</code>配置粘贴上,其实就一行</p>
<figure class="highlight accesslog"><table><tr><td class="code"><pre><span class="line"><span class="number">192.168.99.1</span> armbian.lan</span><br></pre></td></tr></table></figure>
<p>最后我们启动dnsmasq</p>
<figure class="highlight css"><table><tr><td class="code"><pre><span class="line"><span class="selector-tag">sudo</span> <span class="selector-tag">systemctl</span> <span class="selector-tag">start</span> <span class="selector-tag">dnsmasq</span><span class="selector-class">.service</span> && <span class="selector-tag">sudo</span> <span class="selector-tag">systemctl</span> <span class="selector-tag">enable</span> <span class="selector-tag">dnsmasq</span><span class="selector-class">.service</span></span><br></pre></td></tr></table></figure>
<p>打开你的手机连接WiFi试试,这回可以连上,但是不能连接互联网,因为eth0和wlan0之间没有配置网络转发。</p>
<h1 id="配置iptables"><a href="#配置iptables" class="headerlink" title="配置iptables"></a>配置iptables</h1><p>首先我们要允许内核进行网络转发,在<code>/etc/sysctl.conf</code>中注意修改以下内容</p>
<figure class="highlight apache"><table><tr><td class="code"><pre><span class="line"><span class="attribute">net</span>.ipv<span class="number">4</span>.ip_forward = <span class="number">1</span></span><br></pre></td></tr></table></figure>
<p>然后让内核参数即时生效</p>
<figure class="highlight ebnf"><table><tr><td class="code"><pre><span class="line"><span class="attribute">sysctl -p</span></span><br></pre></td></tr></table></figure>
<p>配置路由表,开启转发</p>
<figure class="highlight routeros"><table><tr><td class="code"><pre><span class="line">iptables -t<span class="built_in"> nat </span>-A POSTROUTING -o eth0 -j MASQUERADE </span><br><span class="line">iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT </span><br><span class="line">iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT</span><br></pre></td></tr></table></figure>
<p>如果一切正常现在应该可以通过WiFi热点连接互联网了,但是iptables配置是重启不会保存的,我们需要先保存iptables</p>
<figure class="highlight arcade"><table><tr><td class="code"><pre><span class="line">iptables-save > <span class="regexp">/etc/i</span>ptables.rules</span><br></pre></td></tr></table></figure>
<p>然后每次ifup时恢复,编辑<code>/etc/network/interfaces</code>,在wlan0那一段添加<code>up iptables-restore < /etc/iptables.rules</code>,下面贴上我完整的<code>/etc/network/interfaces</code>。</p>
<figure class="highlight gradle"><table><tr><td class="code"><pre><span class="line"><span class="keyword">source</span> <span class="regexp">/etc/</span>network<span class="regexp">/interfaces.d/</span>*</span><br><span class="line"></span><br><span class="line">auto lo</span><br><span class="line">iface lo inet loopback</span><br><span class="line"></span><br><span class="line">auto wlan0</span><br><span class="line">iface wlan0 inet <span class="keyword">static</span></span><br><span class="line">address <span class="number">192.168</span>.<span class="number">99.1</span></span><br><span class="line">netmask <span class="number">255.255</span>.<span class="number">255.0</span></span><br><span class="line">up iptables-restore < <span class="regexp">/etc/i</span>ptables.rules</span><br></pre></td></tr></table></figure>
<p>到此结束~</p>
]]></content>
</entry>
<entry>
<title>推送代码报错kex_exchange_identification</title>
<url>/2024/01/24/git-push-error/</url>
<content><![CDATA[<p>最近通过<a href="https://weiyangbo.gitee.io/2019/10/06/Android-envsetup/#%E7%94%9F%E6%88%90-ssh-%E5%B9%B6%E6%B7%BB%E5%8A%A0%E5%88%B0-github">sshkey的方式</a>推送GitHub代码报错:<code>kex_exchange_identification: Connection closed by remote host</code></p>
<h1 id="解决方案"><a href="#解决方案" class="headerlink" title="解决方案"></a>解决方案</h1><h2 id="1、关掉梯子"><a href="#1、关掉梯子" class="headerlink" title="1、关掉梯子"></a>1、关掉梯子</h2><h2 id="2、-将-Github-的连接端口从-22-改为-443-即可"><a href="#2、-将-Github-的连接端口从-22-改为-443-即可" class="headerlink" title="2、 将 Github 的连接端口从 22 改为 443 即可"></a>2、 将 Github 的连接端口从 22 改为 443 即可</h2><p>编辑<code> ~/.ssh/config</code>文件(没有就新增),windows在用户目录下的.ssh目录,添加如下内容</p>
<figure class="highlight routeros"><table><tr><td class="code"><pre><span class="line">Host github.com</span><br><span class="line"> HostName ssh.github.com</span><br><span class="line"> <span class="built_in"> User </span>git</span><br><span class="line"> <span class="built_in"> Port </span>443</span><br><span class="line"> </span><br><span class="line">Host gitlab.com</span><br><span class="line"> HostName altssh.gitlab.com</span><br><span class="line"> <span class="built_in"> User </span>git</span><br><span class="line"> <span class="built_in"> Port </span>443</span><br></pre></td></tr></table></figure>
]]></content>
</entry>
<entry>
<title>移动dt741-csf改桥接</title>
<url>/2024/02/01/dt741-bridge/</url>
<content><![CDATA[<h1 id="无用功"><a href="#无用功" class="headerlink" title="无用功"></a>无用功</h1><p>1、网上流传的各种超级管理员密码是不管用的,因为没有通用密码,每台设备密码是绑定时随机生成的<br>2、进入控制台之后改网页源代码也是不行的,因为按钮是可以点击的,但是就是不生效<br>3、进入hidden_version_switch.html里面开启telnet也是不行的,或许联通版的可以吧,反正移动版没这个隐藏入口</p>
<h1 id="简单方法"><a href="#简单方法" class="headerlink" title="简单方法"></a>简单方法</h1><p>先按照光猫背后的普通用户和密码登陆<br>然后输入网址 <a target="_blank" rel="noopener" href="http://192.168.1.1/bridge_route.gch">http://192.168.1.1/bridge_route.gch</a><br>是的,没错,一键切换。<br>不过好像只有第一个网口是桥接的</p>
]]></content>
</entry>
<entry>
<title>利用nginx做Google镜像站</title>
<url>/2024/01/24/nginx-google-mirror/</url>
<content><![CDATA[<h1 id="参考资料"><a href="#参考资料" class="headerlink" title="参考资料"></a>参考资料</h1><p><a target="_blank" rel="noopener" href="https://github.com/cuber/ngx_http_google_filter_module">ngx_http_google_filter_module</a><br><a target="_blank" rel="noopener" href="https://github.com/cuber/ngx_http_google_filter_module/issues/152">高版本nginx兼容情况的issues</a></p>
<h1 id="先卸载已有的Nginx"><a href="#先卸载已有的Nginx" class="headerlink" title="先卸载已有的Nginx"></a>先卸载已有的Nginx</h1><figure class="highlight routeros"><table><tr><td class="code"><pre><span class="line">sudo apt <span class="builtin-name">remove</span> nginx -y</span><br></pre></td></tr></table></figure>
<h1 id="编译安装Nginx"><a href="#编译安装Nginx" class="headerlink" title="编译安装Nginx"></a>编译安装Nginx</h1><h2 id="下载源码"><a href="#下载源码" class="headerlink" title="下载源码"></a>下载源码</h2><figure class="highlight awk"><table><tr><td class="code"><pre><span class="line">git clone https:<span class="regexp">//gi</span>thub.com<span class="regexp">/aperezdc/</span>ngx-fancyindex.git ngx-fancyindex</span><br><span class="line">git clone https:<span class="regexp">//gi</span>thub.com<span class="regexp">/cuber/</span>ngx_http_google_filter_module</span><br><span class="line">git clone https:<span class="regexp">//gi</span>thub.com<span class="regexp">/yaoweibin/</span>ngx_http_substitutions_filter_module</span><br><span class="line">wget http:<span class="regexp">//</span>ftp.cs.stanford.edu<span class="regexp">/pub/</span>exim<span class="regexp">/pcre/</span>pcre-<span class="number">8.45</span>.zip</span><br><span class="line">wget https:<span class="regexp">//</span>www.openssl.org<span class="regexp">/source/</span>old<span class="regexp">/1.0.1/</span>openssl-<span class="number">1.0</span>.<span class="number">1</span>u.tar.gz</span><br><span class="line">wget http:<span class="regexp">//</span>zlib.net<span class="regexp">/fossils/</span>zlib-<span class="number">1.2</span>.<span class="number">11</span>.tar.gz</span><br><span class="line">wget http:<span class="regexp">//</span>nginx.org<span class="regexp">/download/</span>nginx-<span class="number">1.9</span>.<span class="number">15</span>.tar.gz</span><br><span class="line">wget http:<span class="regexp">//</span>ftp.cs.stanford.edu<span class="regexp">/pub/</span>exim<span class="regexp">/pcre/</span>pcre-<span class="number">8.45</span>.zip</span><br></pre></td></tr></table></figure>
<h2 id="解压源码"><a href="#解压源码" class="headerlink" title="解压源码"></a>解压源码</h2><figure class="highlight css"><table><tr><td class="code"><pre><span class="line"><span class="selector-tag">tar</span> <span class="selector-tag">xzvf</span> <span class="selector-tag">nginx-1</span><span class="selector-class">.9</span><span class="selector-class">.15</span><span class="selector-class">.tar</span><span class="selector-class">.gz</span></span><br><span class="line"><span class="selector-tag">unzip</span> <span class="selector-tag">pcre-8</span><span class="selector-class">.45</span><span class="selector-class">.zip</span> </span><br><span class="line"><span class="selector-tag">tar</span> <span class="selector-tag">xzvf</span> <span class="selector-tag">openssl-1</span><span class="selector-class">.0</span><span class="selector-class">.1u</span><span class="selector-class">.tar</span><span class="selector-class">.gz</span></span><br><span class="line"><span class="selector-tag">tar</span> <span class="selector-tag">xzvf</span> <span class="selector-tag">zlib-1</span><span class="selector-class">.2</span><span class="selector-class">.11</span><span class="selector-class">.tar</span><span class="selector-class">.gz</span> </span><br></pre></td></tr></table></figure>
<h2 id="编译与安装"><a href="#编译与安装" class="headerlink" title="编译与安装"></a>编译与安装</h2><figure class="highlight jboss-cli"><table><tr><td class="code"><pre><span class="line"><span class="keyword">cd</span> nginx-1.9.15/</span><br><span class="line"><span class="string">./configure</span> <span class="params">--prefix=/usr</span> <span class="params">--sbin-path=/usr/sbin/nginx</span> <span class="params">--conf-path=/etc/nginx/nginx</span>.conf <span class="params">--error-log-path=/var/log/nginx_error</span>.log <span class="params">--http-log-path=/var/log/nginx_access</span>.log <span class="params">--pid-path=/var/run/nginx</span>.pid <span class="params">--lock-path=/var/lock/nginx</span>.lock <span class="params">--user=root</span> <span class="params">--group=root</span> <span class="params">--with-http_ssl_module</span> <span class="params">--without-http_ssi_module</span> <span class="params">--without-http_memcached_module</span> <span class="params">--without-http_browser_module</span> <span class="params">--without-http_geo_module</span> <span class="params">--without-http_scgi_module</span> <span class="params">--without-http_uwsgi_module</span> <span class="params">--without-select_module</span> <span class="params">--add-module=</span><span class="string">../ngx-fancyindex</span> <span class="params">--add-dynamic-module=</span><span class="string">../ngx_http_google_filter_module</span> <span class="params">--add-module=</span><span class="string">../ngx_http_substitutions_filter_module</span> <span class="params">--with-pcre=</span><span class="string">../pcre-8.45</span> <span class="params">--with-openssl=</span><span class="string">../openssl-1.0.1u</span> <span class="params">--with-zlib=</span><span class="string">../zlib-1.2.11</span> <span class="params">--with-http_v2_module</span> <span class="params">--with-http_realip_module</span></span><br><span class="line">sed -i 's/-Werror <span class="string">//g</span>' objs/Makefile</span><br><span class="line">make</span><br><span class="line">make install</span><br></pre></td></tr></table></figure>
<h1 id="Nginx加入开机自启动"><a href="#Nginx加入开机自启动" class="headerlink" title="Nginx加入开机自启动"></a>Nginx加入开机自启动</h1><figure class="highlight routeros"><table><tr><td class="code"><pre><span class="line">sudo tee /etc/systemd/system/nginx.service >/dev/<span class="literal">null</span> <<<span class="string">'EOF'</span></span><br><span class="line">[Unit]</span><br><span class="line"><span class="attribute">Description</span>=nginx</span><br><span class="line"><span class="attribute">After</span>=network.target</span><br><span class="line"></span><br><span class="line">[Service]</span><br><span class="line"><span class="attribute">User</span>=root</span><br><span class="line"><span class="attribute">Type</span>=forking</span><br><span class="line"><span class="attribute">PIDFile</span>=/var/run/nginx.pid</span><br><span class="line"><span class="attribute">ExecStart</span>=/usr/sbin/nginx</span><br><span class="line"><span class="attribute">ExecReload</span>=/usr/sbin/nginx -s reload</span><br><span class="line"><span class="attribute">ExecStop</span>=/usr/sbin/nginx -s stop</span><br><span class="line"><span class="attribute">PrivateTmp</span>=<span class="literal">true</span></span><br><span class="line"></span><br><span class="line">[Install]</span><br><span class="line"><span class="attribute">WantedBy</span>=multi-user.target</span><br><span class="line">EOF</span><br></pre></td></tr></table></figure>
<p>将Nginx交给Systemd托管,设置Nginx下次开机启动</p>
<figure class="highlight routeros"><table><tr><td class="code"><pre><span class="line">sudo systemctl daemon-reload && sudo systemctl <span class="builtin-name">enable</span> nginx.service</span><br></pre></td></tr></table></figure>
<h1 id="修改Nginx配置"><a href="#修改Nginx配置" class="headerlink" title="修改Nginx配置"></a>修改Nginx配置</h1><p>1、配置文件中要加载动态模块ngx_http_google_filter_module,所以添加如下语句<code>load_module modules/ngx_http_google_filter_module.so;</code><br>2、在二级域名中添加ngx_http_google_filter_module相关配置,在我这里的二级域名是<code>go.kexie.party</code></p>
<figure class="highlight properties"><table><tr><td class="code"><pre><span class="line"><span class="attr">user</span> <span class="string">root;</span></span><br><span class="line"><span class="attr">worker_processes</span> <span class="string">1;</span></span><br><span class="line"><span class="attr">load_module</span> <span class="string">modules/ngx_http_google_filter_module.so;</span></span><br><span class="line"><span class="attr">pid</span> <span class="string">/var/run/nginx.pid;</span></span><br><span class="line"><span class="attr">error_log</span> <span class="string">/var/log/nginx_error.log;</span></span><br><span class="line"></span><br><span class="line"><span class="attr">events</span> <span class="string">{</span></span><br><span class="line"> <span class="attr">use</span> <span class="string">epoll;</span></span><br><span class="line"> <span class="attr">worker_connections</span> <span class="string">1024;</span></span><br><span class="line"> <span class="attr">multi_accept</span> <span class="string">on;</span></span><br><span class="line"><span class="attr">}</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="attr">http</span> <span class="string">{</span></span><br><span class="line"> <span class="attr">include</span> <span class="string">/etc/nginx/mime.types;</span></span><br><span class="line"> <span class="attr">default_type</span> <span class="string">application/octet-stream;</span></span><br><span class="line"> <span class="attr">charset</span> <span class="string">ISO-88509-1;</span></span><br><span class="line"> <span class="attr">sendfile</span> <span class="string">on;</span></span><br><span class="line"> <span class="attr">tcp_nopush</span> <span class="string">on;</span></span><br><span class="line"> <span class="attr">tcp_nodelay</span> <span class="string">on;</span></span><br><span class="line"> <span class="attr">keepalive_timeout</span> <span class="string">60;</span></span><br><span class="line"> <span class="attr">client_header_buffer_size</span> <span class="string">4k;</span></span><br><span class="line"> <span class="attr">open_file_cache</span> <span class="string">max=102400 inactive=20s;</span></span><br><span class="line"> <span class="attr">open_file_cache_valid</span> <span class="string">30s;</span></span><br><span class="line"> <span class="attr">open_file_cache_min_uses</span> <span class="string">1;</span></span><br><span class="line"> <span class="attr">client_header_timeout</span> <span class="string">15;</span></span><br><span class="line"> <span class="attr">client_body_timeout</span> <span class="string">15;</span></span><br><span class="line"> <span class="attr">reset_timedout_connection</span> <span class="string">on;</span></span><br><span class="line"> <span class="attr">send_timeout</span> <span class="string">15;</span></span><br><span class="line"> <span class="attr">gzip</span> <span class="string">on;</span></span><br><span class="line"> <span class="attr">gzip_disable</span> <span class="string">"msie6";</span></span><br><span class="line"> <span class="attr">gzip_vary</span> <span class="string">on;</span></span><br><span class="line"> <span class="attr">gzip_proxied</span> <span class="string">any;</span></span><br><span class="line"> <span class="attr">gzip_comp_level</span> <span class="string">3;</span></span><br><span class="line"> <span class="attr">gzip_buffers</span> <span class="string">16 8k;</span></span><br><span class="line"> <span class="attr">gzip_http_version</span> <span class="string">1.1;</span></span><br><span class="line"> <span class="attr">gzip_types</span> <span class="string">text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;</span></span><br><span class="line"> <span class="attr">server_tokens</span> <span class="string">off;</span></span><br><span class="line"> <span class="attr">access_log</span> <span class="string">/var/log/nginx_access.log;</span></span><br><span class="line"></span><br><span class="line"> <span class="attr">server</span> <span class="string">{</span></span><br><span class="line"> <span class="attr">if</span> <span class="string">($host = www.kexie.party) {</span></span><br><span class="line"> <span class="attr">return</span> <span class="string">301 https://$host$request_uri;</span></span><br><span class="line"> <span class="meta">}</span> <span class="string"># managed by Certbot</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"> <span class="attr">if</span> <span class="string">($host = kexie.party) {</span></span><br><span class="line"> <span class="attr">return</span> <span class="string">301 https://$host$request_uri;</span></span><br><span class="line"> <span class="meta">}</span> <span class="string"># managed by Certbot</span></span><br><span class="line"></span><br><span class="line"> <span class="attr">if</span> <span class="string">($host = go.kexie.party) {</span></span><br><span class="line"> <span class="attr">return</span> <span class="string">301 https://$host$request_uri;</span></span><br><span class="line"> <span class="meta">}</span> <span class="string"># managed by Certbot</span></span><br><span class="line"></span><br><span class="line"> <span class="attr">listen</span> <span class="string">80 default_server;</span></span><br><span class="line"> <span class="attr">return</span> <span class="string">301 https://$server_name$request_uri;</span></span><br><span class="line"></span><br><span class="line"><span class="attr">}</span></span><br><span class="line"></span><br><span class="line"> <span class="attr">server</span> <span class="string">{</span></span><br><span class="line"> <span class="attr">listen</span> <span class="string">443 ssl;</span></span><br><span class="line"></span><br><span class="line"><span class="comment"> # 把example.com换成你的域名</span></span><br><span class="line"> <span class="attr">server_name</span> <span class="string">www.kexie.party kexie.party;</span></span><br><span class="line"> <span class="attr">root</span> <span class="string">/root/mokee;</span></span><br><span class="line"> <span class="attr">location</span> <span class="string">/ {</span></span><br><span class="line"> <span class="attr">expires</span> <span class="string">10h;</span></span><br><span class="line"> <span class="attr">fancyindex</span> <span class="string">on;</span></span><br><span class="line"> <span class="attr">fancyindex_exact_size</span> <span class="string">off;</span></span><br><span class="line"> <span class="attr">fancyindex_localtime</span> <span class="string">on;</span></span><br><span class="line"> <span class="attr">fancyindex_header</span> <span class="string">"/fancyindex/header.html";</span></span><br><span class="line"> <span class="attr">fancyindex_footer</span> <span class="string">"/fancyindex/footer.html";</span></span><br><span class="line"> <span class="attr">fancyindex_ignore</span> <span class="string">"donate" "fancyindex" "Download";</span></span><br><span class="line"> <span class="attr">}</span></span><br><span class="line"> <span class="attr">location</span> <span class="string">~* ^.+\.(jpg|gif|png|img|apk|tar.gz|wmv|jpeg|mp3|mp4|zip|rar)$ {</span></span><br><span class="line"> <span class="attr">valid_referers</span> <span class="string">none blocked www.kexie.party kexie.party;</span></span><br><span class="line"> <span class="attr">if</span> <span class="string">($invalid_referer){</span></span><br><span class="line"> <span class="attr">return</span> <span class="string">403;</span></span><br><span class="line"> <span class="attr">break;</span></span><br><span class="line"> <span class="attr">}</span></span><br><span class="line"> <span class="attr">access_log</span> <span class="string">off;</span></span><br><span class="line"> <span class="attr">}</span></span><br><span class="line"> <span class="attr">}</span></span><br><span class="line"></span><br><span class="line"> <span class="attr">server</span> <span class="string">{</span></span><br><span class="line"> <span class="attr">listen</span> <span class="string">443 ssl;</span></span><br><span class="line"><span class="comment"> # 把example.com换成你的域名</span></span><br><span class="line"> <span class="attr">server_name</span> <span class="string">go.kexie.party;</span></span><br><span class="line"> <span class="attr">resolver</span> <span class="string">8.8.8.8;</span></span><br><span class="line"> <span class="attr">location</span> <span class="string">/ {</span></span><br><span class="line"> <span class="attr">google</span> <span class="string">on;</span></span><br><span class="line"> <span class="attr">google_scholar</span> <span class="string">on;</span></span><br><span class="line"> <span class="attr">}</span></span><br><span class="line"> <span class="attr">}</span></span><br><span class="line"><span class="attr">}</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h1 id="安装cerbot自动申请证书"><a href="#安装cerbot自动申请证书" class="headerlink" title="安装cerbot自动申请证书"></a>安装cerbot自动申请证书</h1><p>前提是为二级域名添加dns记录,一般半小时不到生效。</p>
<figure class="highlight properties"><table><tr><td class="code"><pre><span class="line"><span class="attr">apt</span> <span class="string">install python3-certbot-nginx</span></span><br><span class="line"><span class="attr">certbot</span> <span class="string">--nginx</span></span><br></pre></td></tr></table></figure>
<p>非常傻瓜,按照指引来就好了</p>
]]></content>
</entry>
<entry>
<title>记录一下Openwrt的ipv6相关设置</title>
<url>/2024/03/13/openwrt-ipv6/</url>
<content><![CDATA[<p>OpenWRT支持ipv6有两种情况,一种是有ipv6-PD地址的(一般对应光猫桥接,路由器拨号的情况),反之就是没有ipv6-PD地址(一般对应自动获取ip)</p>
<h1 id="有IPv6-PD地址的情况"><a href="#有IPv6-PD地址的情况" class="headerlink" title="有IPv6-PD地址的情况"></a>有IPv6-PD地址的情况</h1><p>luci界面配置要点:</p>
<ul>
<li>“网络”-“接口”-“LAN”-“DHCP服务器”-“IPv6设置”<br>“RA服务”和“DHCPv6服务”都是服务器模式,“NDP 代理”设置为“混合模式”,通告的IPv6 DNS服务器填两个“2400:3200::1”、“2400:3200:baba::1”。</li>
<li>“网络”-“接口”-“LAN”-“DHCP服务器”-“IPv6 RA 设置”<br>“启用 SLAAC”打钩,“RA标记”只选一个“其他配置”。</li>
<li>“网络”-“接口”-“全局网络选项”<br>“IPv6 ULA 前缀”全部删掉,留空。</li>
<li>“网络”-“接口”-“WAN”-“高级设置”<br>“获取ipv6地址”选择“自动”。<figure class="highlight routeros"><table><tr><td class="code"><pre><span class="line"><span class="comment">#/etc/config/network</span></span><br><span class="line"></span><br><span class="line">config<span class="built_in"> interface </span><span class="string">'loopback'</span></span><br><span class="line"> option device <span class="string">'lo'</span></span><br><span class="line"> option proto <span class="string">'static'</span></span><br><span class="line"> option ipaddr <span class="string">'127.0.0.1'</span></span><br><span class="line"> option netmask <span class="string">'255.0.0.0'</span></span><br><span class="line"></span><br><span class="line">config globals <span class="string">'globals'</span></span><br><span class="line"> option packet_steering <span class="string">'1'</span></span><br><span class="line"></span><br><span class="line">config device</span><br><span class="line"> option name <span class="string">'br-lan'</span></span><br><span class="line"> option<span class="built_in"> type </span><span class="string">'bridge'</span></span><br><span class="line"> list ports <span class="string">'eth1'</span></span><br><span class="line"> option promisc <span class="string">'1'</span></span><br><span class="line"></span><br><span class="line">config device</span><br><span class="line"> option name <span class="string">'eth1'</span></span><br><span class="line"> option macaddr <span class="string">'76:1d:0b:98:e3:55'</span></span><br><span class="line"></span><br><span class="line">config<span class="built_in"> interface </span><span class="string">'lan'</span></span><br><span class="line"> option device <span class="string">'br-lan'</span></span><br><span class="line"> option proto <span class="string">'static'</span></span><br><span class="line"> option ipaddr <span class="string">'192.168.0.1'</span></span><br><span class="line"> option netmask <span class="string">'255.255.255.0'</span></span><br><span class="line"> option ip6assign <span class="string">'64'</span></span><br><span class="line"></span><br><span class="line">config device</span><br><span class="line"> option name <span class="string">'eth0'</span></span><br><span class="line"> option macaddr <span class="string">'76:1d:0b:98:e3:54'</span></span><br><span class="line"></span><br><span class="line">config<span class="built_in"> interface </span><span class="string">'wan'</span></span><br><span class="line"> option device <span class="string">'eth0'</span></span><br><span class="line"> option proto <span class="string">'pppoe'</span></span><br><span class="line"> option username <span class="string">'your_username'</span></span><br><span class="line"> option password <span class="string">'your_password'</span></span><br></pre></td></tr></table></figure>
<figure class="highlight routeros"><table><tr><td class="code"><pre><span class="line"><span class="comment">#/etc/config/dhcp</span></span><br><span class="line">config dnsmasq</span><br><span class="line"> option domainneeded <span class="string">'1'</span></span><br><span class="line"> option boguspriv <span class="string">'1'</span></span><br><span class="line"> option filterwin2k <span class="string">'0'</span></span><br><span class="line"> option localise_queries <span class="string">'1'</span></span><br><span class="line"> option rebind_protection <span class="string">'0'</span></span><br><span class="line"> option rebind_localhost <span class="string">'1'</span></span><br><span class="line"> option local <span class="string">'/lan/'</span></span><br><span class="line"> option domain <span class="string">'lan'</span></span><br><span class="line"> option expandhosts <span class="string">'1'</span></span><br><span class="line"> option nonegcache <span class="string">'0'</span></span><br><span class="line"> option authoritative <span class="string">'1'</span></span><br><span class="line"> option readethers <span class="string">'1'</span></span><br><span class="line"> option leasefile <span class="string">'/tmp/dhcp.leases'</span></span><br><span class="line"> option nonwildcard <span class="string">'1'</span></span><br><span class="line"> option localservice <span class="string">'0'</span></span><br><span class="line"> option ednspacket_max <span class="string">'1232'</span></span><br><span class="line"> option filter_aaaa <span class="string">'0'</span></span><br><span class="line"> option filter_a <span class="string">'0'</span></span><br><span class="line"> option<span class="built_in"> port </span><span class="string">'53'</span></span><br><span class="line"> option dns_redirect <span class="string">'1'</span></span><br><span class="line"> option allservers <span class="string">'1'</span></span><br><span class="line"> option min_ttl <span class="string">'3600'</span></span><br><span class="line"> option dnsforwardmax <span class="string">'10000'</span></span><br><span class="line"> option localuse <span class="string">'1'</span></span><br><span class="line"> option noresolv <span class="string">'1'</span></span><br><span class="line"> list<span class="built_in"> server </span><span class="string">'127.0.0.1#7874'</span></span><br><span class="line"> option cachesize <span class="string">'0'</span></span><br><span class="line"></span><br><span class="line">config dhcp <span class="string">'lan'</span></span><br><span class="line"> option<span class="built_in"> interface </span><span class="string">'lan'</span></span><br><span class="line"> option start <span class="string">'100'</span></span><br><span class="line"> option limit <span class="string">'150'</span></span><br><span class="line"> option leasetime <span class="string">'12h'</span></span><br><span class="line"> option dhcpv4 <span class="string">'server'</span></span><br><span class="line"> option ra <span class="string">'server'</span></span><br><span class="line"> option force <span class="string">'1'</span></span><br><span class="line"> option ndp <span class="string">'hybrid'</span></span><br><span class="line"> list<span class="built_in"> dns </span><span class="string">'2400:3200::1'</span></span><br><span class="line"> list<span class="built_in"> dns </span><span class="string">'2400:3200:baba::1'</span></span><br><span class="line"> list ra_flags <span class="string">'other-config'</span></span><br><span class="line"> option dhcpv6 <span class="string">'server'</span></span><br><span class="line"></span><br><span class="line">config dhcp <span class="string">'wan'</span></span><br><span class="line"> option<span class="built_in"> interface </span><span class="string">'wan'</span></span><br><span class="line"> option ignore <span class="string">'1'</span></span><br><span class="line"></span><br><span class="line">config odhcpd <span class="string">'odhcpd'</span></span><br><span class="line"> option maindhcp <span class="string">'0'</span></span><br><span class="line"> option leasefile <span class="string">'/tmp/hosts/odhcpd'</span></span><br><span class="line"> option leasetrigger <span class="string">'/usr/sbin/odhcpd-update'</span></span><br><span class="line"> option loglevel <span class="string">'4'</span></span><br></pre></td></tr></table></figure>
</li>
</ul>
<h1 id="无IPv6-PD地址的情况"><a href="#无IPv6-PD地址的情况" class="headerlink" title="无IPv6-PD地址的情况"></a>无IPv6-PD地址的情况</h1><p>luci界面配置要点:</p>
<ul>
<li>“网络”-“接口”-“LAN”-“DHCP服务器”-“IPv6设置”<br>“RA服务”、“DHCPv6服务”和“NDP 代理”都是中继模式。</li>
<li>“网络”-“接口”-“全局网络选项”<br>“IPv6 ULA 前缀”全部删掉,留空。</li>
<li>“网络”-“接口”-“WAN”-“高级设置”<br>“获取ipv6地址”选择“自动”。</li>
<li>“网络”-“接口”-“WAN”-“DHCP服务器”-“IPv6设置”<br>“指定的主接口”打钩。</li>
</ul>
<h1 id="DDNS设置"><a href="#DDNS设置" class="headerlink" title="DDNS设置"></a>DDNS设置</h1><p>我想要ipv6主要是想要公网ip,这当然需要DDNS。设置的时候ip地址来源选择“网络”,ipv6地址对应一个虚拟动态接口,在我这里叫“wan_6”。</p>
]]></content>
</entry>
<entry>
<title>Windows下Samba的匿名访问</title>
<url>/2023/07/02/samba-anonymous/</url>
<content><![CDATA[<p>Windows下搞定samba匿名访问是件很困难的事情</p>
<h1 id="Windows客户端设置"><a href="#Windows客户端设置" class="headerlink" title="Windows客户端设置"></a>Windows客户端设置</h1><p>Win+S,输入 <code>cmd.exe</code>,以管理员身份运行命令提示符。</p>
<figure class="highlight gams"><table><tr><td class="code"><pre><span class="line">reg add HKLM\<span class="keyword">SYSTEM</span>\CurrentControlSet\Services\LanmanWorkstation\<span class="keyword">Parameters</span> /v AllowInsecureGuestAuth /t <span class="comment">reg_dword</span> /d <span class="number">00000001</span> /<span class="comment">f</span></span><br></pre></td></tr></table></figure>
<p>Win+S,输入 启用或关闭 Windows 功能<br>启用 SMBv1 协议</p>
<p>Win+S,输入 secpol.msc,以管理员身份启动本地安全策略管理控制台。<br>转到 “本地策略 -> 安全选项”,将 Microsoft 网络客户端:对通信进行数字签名(如果服务器允许) 和 Microsoft 网络客户端:对通信进行数字签名(始终) 的安全设置设为 已禁用。</p>
<h1 id="Windows服务端设置"><a href="#Windows服务端设置" class="headerlink" title="Windows服务端设置"></a>Windows服务端设置</h1><p>在计算机管理窗口中,依次打开,计算机管理(本地)-> 本地用户和组 -> 用户, 在guest属性弹窗中取消勾选“账户已禁用”,并点击“应用”、“确定”即可。</p>
<p>win+R调出运行,输入“gpedit.msc”,回车。在本地组策略编辑器中,依次展开:计算机配置 -> Windows设置 -> 安全设置 -> 本地策略 -> 用户权限分配 -> 拒绝从网络访问这台计算机,右击属性,在弹出的属性中删除guest账户(假如有的话,没有就不管),点击确定。</p>
<p>win+R调出运行,输入“gpedit.msc”,回车。在本地组策略编辑器中,依次展开:计算机配置 -> Windows设置 -> 安全设置 -> 本地策略 -> 安全选项 -> 将“网络访问:本地帐户的共享和安全模式”,修改为“仅来宾-本地帐户以来宾身份验证”将“帐户:使用空白密码的本地帐户只允许通过控制台登录”,设置为已禁用。 </p>
<p>在cmd窗口中输入“gpupdate /force”,回车,等待更新策略,完成。</p>
<p>当然肯定要在控制面板里面关闭密码共享,开启文件夹共享,如果权限里面没有GUEST的话你要添加GUEST账户。</p>
<h1 id="Linux服务端设置"><a href="#Linux服务端设置" class="headerlink" title="Linux服务端设置"></a>Linux服务端设置</h1><p><code>sudo apt install samba wsdd</code>,然后编辑文件<code>/etc/samba/smb.conf</code></p>
<figure class="highlight routeros"><table><tr><td class="code"><pre><span class="line">[global]</span><br><span class="line"> workgroup = WORKGROUP</span><br><span class="line"><span class="built_in"> server </span>string = %h server</span><br><span class="line"> log file = /var/log/samba/log.%m</span><br><span class="line"> max log size = 1000</span><br><span class="line"> syslog = 0</span><br><span class="line"> panic action = /usr/share/samba/panic-action %d</span><br><span class="line"> write cache size = 524288</span><br><span class="line"> getwd cache = <span class="literal">yes</span></span><br><span class="line"> socket options = TCP_NODELAY IPTOS_LOWDELAY</span><br><span class="line"> map <span class="keyword">to</span> guest = Bad User</span><br><span class="line"> <span class="built_in"> server </span>role = standalone server</span><br><span class="line"> usershare allow guests = <span class="literal">yes</span></span><br><span class="line"> wins support = <span class="literal">yes</span></span><br><span class="line"> local master = <span class="literal">yes</span></span><br><span class="line"> preferred master = <span class="literal">yes</span></span><br><span class="line"> <span class="built_in"> server </span>min protocol = NT1</span><br><span class="line"> lanman auth = <span class="literal">no</span></span><br><span class="line"> ntlm auth = <span class="literal">yes</span></span><br><span class="line"> <span class="built_in"> client </span>lanman auth = <span class="literal">no</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">[TN3399_Share]</span><br><span class="line"> comment = TN3399_SATA</span><br><span class="line"> path = /mnt/sata</span><br><span class="line"> writable = <span class="literal">yes</span></span><br><span class="line"> guest only = <span class="literal">yes</span></span><br><span class="line"> force create mode = 0777</span><br><span class="line"> public = <span class="literal">yes</span></span><br><span class="line"> browseable = <span class="literal">yes</span></span><br></pre></td></tr></table></figure>
<p><code>sudo systemctl restart smbd.service && sudo systemctl enable --now wsdd</code></p>
]]></content>
</entry>
<entry>
<title>vsftpd配置root用户登录</title>
<url>/2024/01/27/vsftpd-root/</url>
<content><![CDATA[<p><code>nano /etc/vsftpd.conf</code></p>
<figure class="highlight ini"><table><tr><td class="code"><pre><span class="line"><span class="attr">listen</span>=<span class="literal">yes</span></span><br><span class="line"><span class="attr">listen_ipv6</span>=<span class="literal">no</span></span><br><span class="line"><span class="attr">anonymous_enable</span>=<span class="literal">NO</span></span><br><span class="line"><span class="attr">local_enable</span>=<span class="literal">YES</span></span><br><span class="line"><span class="attr">write_enable</span>=<span class="literal">YES</span></span><br><span class="line"><span class="attr">local_umask</span>=<span class="number">022</span></span><br><span class="line"><span class="attr">dirmessage_enable</span>=<span class="literal">YES</span></span><br><span class="line"><span class="attr">use_localtime</span>=<span class="literal">YES</span></span><br><span class="line"><span class="attr">chown_uploads</span>=<span class="literal">YES</span></span><br><span class="line"><span class="attr">chown_username</span>=root</span><br><span class="line"><span class="attr">rsa_cert_file</span>=/etc/ssl/certs/ssl-cert-snakeoil.pem</span><br><span class="line"><span class="attr">rsa_private_key_file</span>=/etc/ssl/private/ssl-cert-snakeoil.key</span><br><span class="line"><span class="attr">ssl_enable</span>=<span class="literal">NO</span></span><br><span class="line"><span class="attr">utf8_filesystem</span>=<span class="literal">YES</span></span><br><span class="line"><span class="attr">pasv_enable</span>=<span class="literal">YES</span></span><br><span class="line"><span class="attr">pasv_min_port</span>=<span class="number">21</span></span><br><span class="line"><span class="attr">pasv_max_port</span>=<span class="number">21</span></span><br><span class="line"><span class="attr">local_root</span>=/mnt/sata</span><br></pre></td></tr></table></figure>
<p>注释掉<code>/etc/ftpusers</code>中的<code>root</code><br>最后<code>service restart vsftpd</code></p>
]]></content>
</entry>
<entry>
<title>用WLED控制流光灯带并接入Home Assistant</title>
<url>/2022/03/08/wled-HA/</url>
<content><![CDATA[<h1 id="引言"><a href="#引言" class="headerlink" title="引言"></a>引言</h1><p>视频中的LED灯条,是由许多5050型RGB灯组成,其中每个RGB灯集成了红色、绿色、蓝色的三色LED灯和非常紧凑的WS2812B LED驱动器IC。根据三个红色、绿色和蓝色LED的强度,我们可以模拟出我们想要的任何颜色和亮度。 把许多RGB的连在一起并单独控制,就可以形成动态的灯带。<br><img src= "/img/loading.gif" data-lazy-src="ws2812.webp" alt="ws2812"><br>WLED固件既可以方便无门槛刷入ESP系列芯片、接入Home Assistant控制,而且各种自定义设置直接拉满,你想怎么自定义都行。</p>
<h1 id="硬件准备"><a href="#硬件准备" class="headerlink" title="硬件准备"></a>硬件准备</h1><ul>
<li>ESP8266/ESP32开发板(推荐FLASH大于1MB的ESP开发板,否则不支持OTA升级)</li>
<li>WS2812B灯带</li>
<li>足功率的5V电源(具体咨询卖灯带的客服)</li>
<li>电脑一台和USB数据线(用于为ESP8266刷写固件)</li>
</ul>
<h1 id="刷写固件"><a href="#刷写固件" class="headerlink" title="刷写固件"></a>刷写固件</h1><p>如果你的ESP8266/ESP32的FLASH大小是4MB的,官方推荐<a target="_blank" rel="noopener" href="https://install.wled.me/">WLED web installer</a>网页方式刷入固件。<br>否则的话需要手动下载<a target="_blank" rel="noopener" href="https://github.com/Aircoookie/WLED/releases">最新的WLED固件</a>和<a target="_blank" rel="noopener" href="https://github.com/esphome/esphome-flasher/releases">ESP Home Flasher</a>,用ESP Home Flasher将最新固件刷入你的ESP开发板。<br>刷机过程略过,大家自行百度。只要第一次刷如WLED,后期升级可以使用OTA方式升级,无需接线。</p>
<h1 id="硬件连接"><a href="#硬件连接" class="headerlink" title="硬件连接"></a>硬件连接</h1><p><img src= "/img/loading.gif" data-lazy-src="wled_hw.png" alt="wled_hw"><br>其中的电源建议6V-5V的输入,电流一定要根据灯带中LED的数量选择足瓦的电源。电容是为了稳定性建议加的,不加也行。</p>
<h1 id="首次设置"><a href="#首次设置" class="headerlink" title="首次设置"></a>首次设置</h1><p>将整个灯带和开发板通电,用手机或者其他设备,打开wifi,连接<code>WLED-AP</code>,密码是<code>wled1234</code>。在浏览器中访问<a target="_blank" rel="noopener" href="http://4.3.2.1/">4.3.2.1</a>,选择”WIFI SETTINGS”<br><img src= "/img/loading.gif" data-lazy-src="welcome-to-wled.png" alt="welcome-to-wled"><br>输入你家WiFi的SSID和密码,其他的可以不设置,或者根据自己需要设置,拉到最下面点击”Save&Connect”,你的开发板会自动重启并连接上WiFi。<br>等待几秒钟重启完成后,可以访问wled从路由器自动获取的IP地址来进入WLED的管理页面。<br>也可以进入Home Assistant的面板,在通知中找找被自动发现的WLED设备并按照向导配置。如果没有自动发现,可以手动点击“添加集成”,然后搜索“WLED”添加即可。(图都是我从网上找的,懒得重新配置了)<br><img src= "/img/loading.gif" data-lazy-src="Home-Assistant-and-WLED-integration-scaled.png" alt="Home-Assistant-and-WLED-integration-scaled"></p>
]]></content>
</entry>
</search>