2019年7月2日 星期二

[OpenWRT] date 初始化

執行OpenWRT的裝置,主要像Router這一類或是一些MPU等級的開發板,

例如MTK7688,若裝置斷電重開後,要獲得正確的時間,可以透過NTP或是

額外加裝的RTC(Real-time Clock) Chip。

若是處於未連網及不具有RTC的情況下,系統會找尋/etc下最新一筆

檔案的變更時間,做為目前的時間。這段程式碼在/etc/init.d/sysfixtime


START=00
STOP=90
boot() {
 local maxtime="$(maxtime)"
 local curtime="$(date +%s)"
 [ $curtime -lt $maxtime ] && date -s @$maxtime
}

maxtime() {
 local file newest

 for file in $( find /etc -type f ) ; do
  [ -z "$newest" -o "$newest" -ot "$file" ] && newest=$file
 done
 [ "$newest" ] && date -r "$newest" +%s
}

2019年6月27日 星期四

「智語」沙士比亞名言


老實人就是傻瓜,雖然一片好心,結果還是自己吃了虧


我承認天底下再沒有比愛情的責罰更痛苦的,也沒有比服侍它更快樂的事了。


愛情不是花蔭下的甜言,不是桃花源中的密語,不是輕綿的眼淚,更不是死硬的強迫,愛情是建立在共同的基礎上的。


太完美的愛情,傷心又傷身,身為江湖兒女,沒那個閒工夫 .




參考來源:

https://mingyanjiaju.org/mr/7090.html

「Android] 重覆利用現有的Activity

有多個Activity時,若想避免重覆產生Activity,可以在Intent中加入以下這個Flag

 FLAG_ACTIVITY_REORDER_TO_FRONT
例如

Intent intent=new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
intent.setClass(nowAtvity.this,targetActivity.class);
startActivity(intent);


[Android]點擊畫面空白處Seekbar得到Focus問題

最近遇上一個UI的BUG,當點擊畫面空白處,

所有的Seekbar同時出現取得焦點的情況。

幾經測試發現是最外層的Constraintlayout有OnClick事件造成,

將OnClick由OnTouch替代即可解除這個問題。

2019年6月25日 星期二

「小技巧」取得網站的Root-CA


透過OpenSSl 可以方便取得指定網站的Root-CA 

openssl s_client -showcerts -connect japaneast.api.cognitive.microsoft.com:443

回應值如下
CONNECTED(00000005)
depth=2 C = IE, O = Baltimore, OU = CyberTrust, CN = Baltimore CyberTrust Root
verify return:1
depth=1 C = US, ST = Washington, L = Redmond, O = Microsoft Corporation, OU = Microsoft IT, CN = Microsoft IT TLS CA 2
verify return:1
depth=0 CN = *.cognitiveservices.azure.com
verify return:1
---
Certificate chain
 0 s:/CN=*.cognitiveservices.azure.com
   i:/C=US/ST=Washington/L=Redmond/O=Microsoft Corporation/OU=Microsoft IT/CN=Microsoft IT TLS CA 2
-----BEGIN CERTIFICATE-----
MIIIxzCCBq+gAwIBAgITIAAFRAs77OdnDzBu6AAAAAVECzANBgkqhkiG9w0BAQsF
ADCBizELMAkGA1UEBhMCVVMxEzARBgNVBAgTCldhc2hpbmd0b24xEDAOBgNVBAcT
B1JlZG1vbmQxHjAcBgNVBAoTFU1pY3Jvc29mdCBDb3Jwb3JhdGlvbjEVMBMGA1UE
CxMMTWljcm9zb2Z0IElUMR4wHAYDVQQDExVNaWNyb3NvZnQgSVQgVExTIENBIDIw
HhcNMTkwMTIzMDYwNTQ3WhcNMjEwMTIzMDYwNTQ3WjAoMSYwJAYDVQQDDB0qLmNv
Z25pdGl2ZXNlcnZpY2VzLmF6dXJlLmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEP
ADCCAQoCggEBAK2pLnlTsiv2lGiw9g/1OFdt4MBKw2vRuxnDLWyPUWw0i4bRlRcD
oNua0v2Q41MSK613TWU3k00t0GqYEm8RwxUkvCU9Yrxvb7cRrKix5kb9wQs1IKFM
0zBtRJUGPfx6+Zzw8AOP72b0/WbFHBSpmrVjIzoOXqSO3Xjhia05j4Xj4bkEx6cl
oweFzKXFlE2bT7GQZBaXoJ7zvH8nxjkf8OdVja++V7KBZ1lvnPyySD9c91iboojj
s8mugyk+aVdypnCT32cZfRMl88Vbm0eFRpAtsOfdN3AqDPt61iezd3N5A34ePDsg
HEOkuvIv7hBSvkY61wZZTMqfM/7b0tNvLOcCAwEAAaOCBIQwggSAMIIB9wYKKwYB
BAHWeQIEAgSCAecEggHjAeEAdgDuS723dc5gu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Nhf42D+ES8iA/vCm9KidS9
7SzH4EHYXDrylkaWu9rH6LeThlmIhhzyrbeL/y4GwFdMPjc80zKNSXK0hw==
-----END CERTIFICATE-----
 1 s:/C=US/ST=Washington/L=Redmond/O=Microsoft Corporation/OU=Microsoft IT/CN=Microsoft IT TLS CA 2
   i:/C=IE/O=Baltimore/OU=CyberTrust/CN=Baltimore CyberTrust Root
-----BEGIN CERTIFICATE-----
MIIFtDCCBJygAwIBAgIQDywQyVsGwJN/uNRJ+D6FaTANBgkqhkiG9w0BAQsFADBa
MQswCQYDVQQGEwJJRTESMBAGA1UEChMJQmFsdGltb3JlMRMwEQYDVQQLEwpDeWJl
clRydXN0MSIwIAYDVQQDExlCYWx0aW1vcmUgQ3liZXJUcnVzdCBSb290MB4XDTE2
MDUyMDEyNTE1N1oXDTI0MDUyMDEyNTE1N1owgYsxCzAJBgNVBAYTAlVTMRMwEQYD
VQQIEwpXYXNoaW5ndG9uMRAwDgYDVQQHEwdSZWRtb25kMR4wHAYDVQQKExVNaWNy
b3NvZnQgQ29ycG9yYXRpb24xFTATBgNVBAsTDE1pY3Jvc29mdCBJVDEeMBwGA1UE
AxMVTWljcm9zb2Z0IElUIFRMUyBDQSAyMIICIjANBgkqhkiG9w0BAQEFAAOCAg8A
MIICCgKCAgEAnqoVwRuhY1/mURjFFrsR3AtNm5EKukBJK9zWBgvFd1ksNEJFC06o
yRbwKPMflpW/HtOfzIeBliGk57MwZq18bgASr70sPUWuoD917HUgBfxBYoF8zA7Z
Ie5zAHODFboJL7Fg/apgbQs/GiZZNCi0QkQUWzw0nTUmVSNQ0mz6pCu95Dv1WMsL
GyPGfdN9zD3Q/QEDyJ695QgjRIxYA1DUE+54ti2k6r0ycKFQYkyWwZ25HD1h2kYt
3ovW85vF6y7tjTqUEcLbgKUCB81/955hdLLsbFd6f9o2PkU8xuOc3U+bUedvv6Sb
tvGjBEZeFyH8/CaQhzlsKMH0+OPOFv/bMqcLarPw1V1sOV1bl4W9vi2278niblzI
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zo0jDEq1at4zSeH4mV2PMM3LwIXBA2xo5sda1cnUWJo3Pq4uMgcL
e0t+fCut38NMkTl8F0arflspaqUVVUov
-----END CERTIFICATE-----
---
Server certificate
subject=/CN=*.cognitiveservices.azure.com
issuer=/C=US/ST=Washington/L=Redmond/O=Microsoft Corporation/OU=Microsoft IT/CN=Microsoft IT TLS CA 2
---
No client certificate CA names sent
Server Temp Key: ECDH, P-384, 384 bits
---
SSL handshake has read 4513 bytes and written 358 bytes
---
New, TLSv1/SSLv3, Cipher is ECDHE-RSA-AES256-GCM-SHA384
Server public key is 2048 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
    Protocol  : TLSv1.2
    Cipher    : ECDHE-RSA-AES256-GCM-SHA384
    Session-ID: 996FFFB3854CAC1205B783A59B76BDFAE38D24425C77C1C50A8B80832D606261
    Session-ID-ctx: 
    Master-Key: BCD00D7E1211EBD9A8755BC67584AEFEAE435E1F8842B9D13F90F6C2F8E4CE0AA646FE75377DACA2DDC40323C70B2910
    TLS session ticket lifetime hint: 36000 (seconds)
    TLS session ticket:
    0000 - 00 00 00 00 f1 09 a9 bd-e1 cc 12 43 b9 30 10 64   ...........C.0.d
    0010 - 28 4e 9f b9 d4 14 fb 68-92 1b ea 73 13 94 94 d5   (N.....h...s....
    0020 - d5 27 00 73 cc c6 2d d8-76 e3 36 bf 65 5b c9 e4   .'.s..-.v.6.e[..
    0030 - af 7f 09 39 18 fc 7d d4-1c 4c c0 8c 11 e5 a4 c8   ...9..}..L......
    0040 - d4 24 8c 68 4d 74 12 12-1f 86 c6 a3 1c d2 27 14   .$.hMt........'.
    0050 - 4d 1d 3b 03 ec e9 ac d2-f8 d3 d1 53 76 60 5a 31   M.;........Sv`Z1
    0060 - 91 76 92 67 ce ee 5e 68-73 9c 4c a7 9a 55 93 a2   .v.g..^hs.L..U..
    0070 - 17 00 05 25 1a 25 e9 cb-32 97 31 23 fc 15 5d a5   ...%.%..2.1#..].
    0080 - 84 ae 5b 90 2e 9c e9 0f-63 5f 76 2e 61 4b 90 d9   ..[.....c_v.aK..
    0090 - a6 ab ca ea df 36 23 cc-41 85 54 13 4f cc 7b d6   .....6#.A.T.O.{.
    00a0 - a5 73 88 c5 2a 9c e7 ad-01 b3 0b 47 76 02 df 3a   .s..*......Gv..:
    00b0 - b4 49 f0 0f a0 4f ba ac-a5 c5 be 35 29 53 66 44   .I...O.....5)SfD
    00c0 - ec 8d ad 1a 1c d4 e6 55-e6 ae eb 9e 3e 9f 9f d5   .......U....>...
    00d0 - f0 11 0d 68 de 66 94 7e-18 82 c9 03 a8 ee b7 b2   ...h.f.~........
    00e0 - c0 08 aa a8 b4 48 61 cb-1f a5 1f b1 63 93 de f1   .....Ha.....c...
    00f0 - 8a f8 f4 23 6b 02 76 7f-7b ad b1 94 f7 93 80 f9   ...#k.v.{.......
    0100 - ea 26 28 82                                       .&(.

    Start Time: 1561476387
    Timeout   : 7200 (sec)
    Verify return code: 0 (ok)
---

注意第二段 標示 CyberTrust Root 或是Root CA  即為所求
-----BEGIN CERTIFICATE-----
MIIFtDCCBJygAwIBAgIQDywQyVsGwJN/uNRJ+D6FaTANBgkqhkiG9w0BAQsFADBa
MQswCQYDVQQGEwJJRTESMBAGA1UEChMJQmFsdGltb3JlMRMwEQYDVQQLEwpDeWJl
clRydXN0MSIwIAYDVQQDExlCYWx0aW1vcmUgQ3liZXJUcnVzdCBSb290MB4XDTE2
MDUyMDEyNTE1N1oXDTI0MDUyMDEyNTE1N1owgYsxCzAJBgNVBAYTAlVTMRMwEQYD
VQQIEwpXYXNoaW5ndG9uMRAwDgYDVQQHEwdSZWRtb25kMR4wHAYDVQQKExVNaWNy
b3NvZnQgQ29ycG9yYXRpb24xFTATBgNVBAsTDE1pY3Jvc29mdCBJVDEeMBwGA1UE
AxMVTWljcm9zb2Z0IElUIFRMUyBDQSAyMIICIjANBgkqhkiG9w0BAQEFAAOCAg8A
MIICCgKCAgEAnqoVwRuhY1/mURjFFr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MCgGCCsG
AQUFBwIBFhxodHRwczovL3d3dy5kaWdpY2VydC5jb20vQ1BTMA0GCSqGSIb3DQEB
CwUAA4IBAQBsf+pqb89rW8E0rP/cDuB9ixMX4C9OWQ7EA7n0BSllR64ZmuhU9mTV
2L0G4HEiGXvOmt15i99wJ0ho2/dvMxm1ZeufkAfMuEc5fQ9RE5ENgNR2UCuFB2Bt
bVmaKUAWxscN4GpXS4AJv+/HS0VXs5Su19J0DA8Bg+lo8ekCl4dq2G1m1WsCvFBI
oLIjd4neCLlGoxT2jA43lj2JpQ/SMkLkLy9DXj/JHdsqJDR5ogcij4VIX8V+bVD0
NCw7kQa6Ulq9Zo0jDEq1at4zSeH4mV2PMM3LwIXBA2xo5sda1cnUWJo3Pq4uMgcL
e0t+fCut38NMkTl8F0arflspaqUVVUov
-----END CERTIFICATE-----


參考文章

http://www.iotsharing.com/2017/08/how-to-use-https-in-arduino-esp32.html

2019年4月24日 星期三

[IoT]Line Things 初體驗

Line Things是Line推出的IoT平台 ,簡單來說就是透過Line 去控制附近的藍芽裝置,

介面則是透過Line去載入LIFF App中所設定的EndPoint URL,開發商只需依照Line的

規範去實作硬體及韌體,無須自行再開發APP。

1.首先要申請一個Line Bot ,然候掃描Bot QR Code加入好友!!!


























2.Fork 這個Github到您的Github帳戶 (若有自己的網頁空間亦可以將liff-app下的內容複制到您的個人空間中)

https://github.com/line/line-things-starter

















3.到您帳號下Fork出來的專案中Settings頁面

將Source設為master branch,並且點擊Change theme後任選一個 ,就會出現您的網頁URL


















4.接下來回到Line Bot,申請一個LIFF App















把剛才的URL貼在Endpoint URL中,記得補上/liff_app , 記下LIFF URL 最後數字及英文,就是LIFF APP ID ,記得BLE Feature要開

EX: https://flowercatswets.github.io/line-things-starter/liff-app/



























5.回到Channel Setting 記一下Token ,如果沒有出現按一下最右邊的Issue,選個24 HR










6.最重要的過程是註冊取得Service UUID ,在mac 或Linux可以透過指令


curl -X POST https://api.line.me/things/v1/trial/products -H 'Authorization: Bearer 剛才的Token' -H 'Content-Type:application/json' -d '{"name": "LIFF APP 名字(例如我的是LIFF_BOYWHY","liffId": "LIFF URL最後面的數字及英文"}'

在Windows可以透過Restlet Client


如果成功會回應如下內容,重要的只有圈起來的部份,就是我們要的UUID。












7.點擊您Fork出來的專案下的liff-app中的liff.js

















點擊右方的筆圖示編輯它



















把USER_SERVICE_UUID改成剛才得到的UUID

接下來拉到最下方按Commit存檔

7.在此以ESP32示範,官方的範例中亦支援nrf52 / Micro:bit等開發版的範例程式。

開啟Arduino,點擊Preferences,加入額外的開發版網址
https://dl.espressif.com/dl/package_esp32_index.json


接下來到版子管理員,搜尋ESP32並安裝
裝官方的Sample Code 貼到一個Arduino IDE中 ,並修改USER_SERVICE_UUID






























我用的版子是這一塊 ESP32 Bit Kit , 版子上有LED及Button , 腳位和程式碼中相同。























選擇開發版為ESP32 Dev Module ,注意一下您的序列埠設定可能與我不同。



















沒問題的上請上傳程式碼到ESP32,大概要1~2分鐘。































8.用手機掃描這個QR Code 開啟Line Things ,第一次開啟要同意資料存取。















接下來你就可以看到畫面上有你的LIFF APP名字


允許配對藍芽(iphone)


連線裝置成功。
至於為什麼頁面只有半面呢?這是剛才的選項中選擇了Compact,選擇FULL的話會是整頁。

接下來點一下Switch LED  ON , 畫面呈現如下,此時ESP32上的LED也亮起來了




按幾下右邊的按鈕(左邊的是重置,不要按到),你會發現Click Count累進了。


當你按下ESP32上的按鍵不放時,Button State也會變成Pressed









































以上是初次玩Line Things心得,如果我們把LIFF APP Size改成Tall及Full, 則如下




Line Things目前還比較麻煩,取得UUID必須靠注冊,每次註冊取得的UUID會不同。
即使你使用同一組Token,這點要稍微注意一下。


參考資料:





2019年4月19日 星期五

[Android] TextView 中顯示不同字體大小

效果如下


這時就要透過Spannable 來做對應的處理

TextView textView=(TextView)findViewById(R.id.txt);

String str="您今天已經寫了100行書法";
//找到數字1的位置
int startIndex = str.indexOf('1');
//數字只有3個所以是startIndex+2
int endIndex = startIndex+2;
//初始化Spannable
Spannable textSpan = new SpannableStringBuilder(str);
//將數字1之前的字串,字體大小設為28 像素
textSpan.setSpan(new AbsoluteSizeSpan(28), 0, startIndex, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
//將數字100字體大小設為45 像素
textSpan.setSpan(new AbsoluteSizeSpan(45), startIndex, endIndex+1 , Spannable.SPAN_INCLUSIVE_INCLUSIVE);
//將100之後的內容字體大小設為28像素
textSpan.setSpan(new AbsoluteSizeSpan(28), endIndex+1 , str.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
//將Spannable設定給TextView
textView.setText(textSpan);

若要使用dip做為單位,則可以改成如下


TextView textView=(TextView)findViewById(R.id.txt);

String str="您今天已經寫了100行書法";
//找到數字1的位置
int startIndex = str.indexOf('1');
//數字只有3個所以是startIndex+2
 int endIndex = startIndex+2;
//初始化Spannable
Spannable textSpan = new SpannableStringBuilder(str);
//將數字1之前的字串,字體大小設為28
textSpan.setSpan(new AbsoluteSizeSpan(28,true), 0, startIndex, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
//將數字100字體大小設為45
textSpan.setSpan(new AbsoluteSizeSpan(45,true), startIndex, endIndex+1 , Spannable.SPAN_INCLUSIVE_INCLUSIVE);
//將100之後的內容字體大小設為28
textSpan.setSpan(new AbsoluteSizeSpan(28,true), endIndex+1 , str.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
//將Spannable設定給TextView
textView.setText(textSpan);



以下有針對幾個範圍的設定值做出解釋,但試起來還是有點怪怪的,多包函。

Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
不包含StartIndex及EndIndex
Spans of type SPAN_EXCLUSIVE_EXCLUSIVE do not expand to include text inserted at either their starting or ending point.

Spanned.SPAN_EXCLUSIVE_INCLUSIVE
不包含startIndex , 但包含endIndex
Non-0-length spans of type SPAN_EXCLUSIVE_INCLUSIVE expand to include text inserted at their ending point but not at their starting point.

Spanned.SPAN_INCLUSIVE_EXCLUSIVE
包含startIndex 但不包含endIndex
Non-0-length spans of type SPAN_INCLUSIVE_EXCLUSIVE expand to include text inserted at their starting point but not at their ending point.

Spanned.SPAN_INCLUSIVE_INCLUSIVE
包含startIndex及endIndex
Spans of type SPAN_INCLUSIVE_INCLUSIVE expand to include text inserted at either their starting or ending point.