tag:blogger.com,1999:blog-29337551254315709312024-03-05T12:45:53.653+08:00金石微開好奇心是能量來源~恆心是我所追求—我的成長與您分享金石微開http://www.blogger.com/profile/13160756791496033950noreply@blogger.comBlogger663125tag:blogger.com,1999:blog-2933755125431570931.post-54361415575014459512022-07-16T23:48:00.003+08:002022-07-16T23:48:25.753+08:00Chrome 顯示不安全 - Lighthouse 幫大忙<p>公司的網站更換新的SSL 後依然在Chrome 網址列顯示不安全,也非自簽憑證。</p><p>用Chrome 開發人員工具內建的"Lighthouse" 進行檢查 ,總算發現問題。</p><p>原來是有部份CSS的來源並未使用HTTP<b>S</b> ,還一直延用HTTP 造成Chrome認為不安全。</p><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto;"><tbody><tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhiPd_gBwBYX4N9qCIVfXUWL7gAPyxQqNBRVCcAQu2VdMZLB93GtdELGFbjI3dIaA2GmML1N4Fxkcjqavnf_Uft7heFapzA5Mk4aPkK8cbqo9y_xwHjiz0hQqyFxMmP5CiiMhvKyXGM6KkOUYjJTFtcr1BbpAq0pry2QqVJVqRpGPDA70S-6txtHXqj2w/s1072/%E6%88%AA%E5%9C%96%202022-07-16%20%E4%B8%8B%E5%8D%8811.41.10.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" data-original-height="804" data-original-width="1072" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhiPd_gBwBYX4N9qCIVfXUWL7gAPyxQqNBRVCcAQu2VdMZLB93GtdELGFbjI3dIaA2GmML1N4Fxkcjqavnf_Uft7heFapzA5Mk4aPkK8cbqo9y_xwHjiz0hQqyFxMmP5CiiMhvKyXGM6KkOUYjJTFtcr1BbpAq0pry2QqVJVqRpGPDA70S-6txtHXqj2w/w640-h480/%E6%88%AA%E5%9C%96%202022-07-16%20%E4%B8%8B%E5%8D%8811.41.10.png" width="640" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;"></td></tr></tbody></table>順帶一提 "Lighthouse" 可以幫你掃描出目前使用的JavaScriptf函式庫是否有安全問題<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixniPYwN8ZyWVy0Te4ItUcgw3aR53oJHoIKBI4WZcsQ8y5X-n_PrMTaDl8w07hHnkQ7dmsc0wicelL88P_nPjBNq7DhED5WSC80UmGZ11LetqgKxDuPYQS741mVhAX0uz0xiVvtlhd6zmNHz9WAJ8X8crrKwvAVX2keGIuZVvbJXo7r6iqPOGOHhLB7g/s1072/%E6%88%AA%E5%9C%96%202022-07-16%20%E4%B8%8B%E5%8D%8811.46.44.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="468" data-original-width="1072" height="280" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixniPYwN8ZyWVy0Te4ItUcgw3aR53oJHoIKBI4WZcsQ8y5X-n_PrMTaDl8w07hHnkQ7dmsc0wicelL88P_nPjBNq7DhED5WSC80UmGZ11LetqgKxDuPYQS741mVhAX0uz0xiVvtlhd6zmNHz9WAJ8X8crrKwvAVX2keGIuZVvbJXo7r6iqPOGOHhLB7g/w640-h280/%E6%88%AA%E5%9C%96%202022-07-16%20%E4%B8%8B%E5%8D%8811.46.44.png" width="640" /></a></div><br /><div><br /><p><br /></p></div>金石微開http://www.blogger.com/profile/13160756791496033950noreply@blogger.com0tag:blogger.com,1999:blog-2933755125431570931.post-5234615306851165132022-07-16T23:20:00.003+08:002022-07-16T23:20:33.181+08:00學長傳授的戀愛觀<p><span style="font-size: medium;">男女交往沒必要迎合 ,那不會是你想要的。 </span></p><p><span style="font-size: medium;">不適合的話就早點結束, 改變對方是不可能的。</span></p>金石微開http://www.blogger.com/profile/13160756791496033950noreply@blogger.com0tag:blogger.com,1999:blog-2933755125431570931.post-49212701223179699292022-07-16T23:11:00.004+08:002022-07-16T23:11:19.339+08:00Default Gateway<p> Default Gateway (預設閘道) : 當網卡不知道道封包往那送時,就會送給Default Gateway.</p><p>最近遇到一個問題,公司的網路分為4個不同的網段 ,例如 192.168.1.x / 192.168.2.x / 192.168.3.x / 192.168.4.x 。</p><p>某一台電腦IP為192.168.2.234, 僅能與192.168.2.x 的其他電腦通訊,卻無法與其他網段電腦通訊,後來發現此電腦的Default Gateway 設定錯誤(IP打錯),因此無法將封包送到其他網段去,至於Default Gateway如何把封包送至其他網段,等我研究後再另外打一篇說明。</p>金石微開http://www.blogger.com/profile/13160756791496033950noreply@blogger.com0tag:blogger.com,1999:blog-2933755125431570931.post-48396984821057037172022-07-16T23:02:00.003+08:002022-07-16T23:02:43.398+08:00JavaScript 小陷阱<p> function demo(myType)</p><p>{</p><p> if (type=1)</p><p> {</p><p> console.log("Type is 1");</p><p> }</p><p> else</p><p> {</p><p> console.log("Type is 2");</p><p> }</p><p>}</p><p> </p><p>demo(2)</p><p><br /></p><p>上面這段程式碼乍看之下好像沒問題,但無論type多少,都會輸出type is 1. </p><p>原因出在 if (type=1) 永遠成立,注意是一個"=",也就是指定的意思.. </p><p>也就是你指定type 為1 這句話並沒有毛病,而且永遠成立,所有流程都會進這裡。</p><p>在幫朋友debug 時,一眼掃過去真的不容易發現。</p><p><br /></p><p><br /></p>金石微開http://www.blogger.com/profile/13160756791496033950noreply@blogger.com0tag:blogger.com,1999:blog-2933755125431570931.post-82374270475502754312019-07-02T22:57:00.001+08:002019-07-02T22:57:57.091+08:00[OpenWRT] date 初始化執行OpenWRT的裝置,主要像Router這一類或是一些MPU等級的開發板,<br />
<br />
例如MTK7688,若裝置斷電重開後,要獲得正確的時間,可以透過NTP或是<br />
<br />
額外加裝的RTC(<span style="font-size: 18px;">Real-time Clock) Chip。</span><br />
<span style="font-size: 18px;"><br /></span>
<span style="font-size: 18px;">若是處於未連網及不具有RTC的情況下,系統會找尋/etc下最新一筆</span><br />
<span style="font-size: 18px;"><br /></span>
<span style="font-size: 18px;">檔案的變更時間,做為目前的時間。這段程式碼在/etc/init.d/sysfixtime</span><br />
<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;">START=<span style="color: blue;">00</span>
STOP=<span style="color: blue;">90</span>
boot() {
local maxtime=<span style="color: blue;">"$(maxtime)"</span>
local curtime=<span style="color: blue;">"$(date +%s)"</span>
[ <span style="background-color: #e3d2d2; color: #a61717;">$</span>curtime -lt <span style="background-color: #e3d2d2; color: #a61717;">$</span>maxtime ] && date -s <span style="background-color: #e3d2d2; color: #a61717;">@$</span>maxtime
}
maxtime() {
local file newest
<span style="color: navy; font-weight: bold;">for</span> file in <span style="background-color: #e3d2d2; color: #a61717;">$</span>( find /etc -type f ) ; <span style="color: navy; font-weight: bold;">do</span>
[ -z <span style="color: blue;">"$newest"</span> -o <span style="color: blue;">"$newest"</span> -ot <span style="color: blue;">"$file"</span> ] && newest=<span style="background-color: #e3d2d2; color: #a61717;">$</span>file
done
[ <span style="color: blue;">"$newest"</span> ] && date -r <span style="color: blue;">"$newest"</span> +%s
}
</pre>
</div>
金石微開http://www.blogger.com/profile/13160756791496033950noreply@blogger.com1tag:blogger.com,1999:blog-2933755125431570931.post-88202929960967145592019-06-27T23:45:00.001+08:002019-06-27T23:45:08.829+08:00「智語」沙士比亞名言<span style="background-color: white; color: #333333; font-family: "Microsoft YaHei", MicrosoftJhengHei, STHeiti, MingLiu, sans-serif, Verdana; font-size: 16px;"><br /></span>
<span style="background-color: white; color: #333333; font-family: "Microsoft YaHei", MicrosoftJhengHei, STHeiti, MingLiu, sans-serif, Verdana; font-size: 16px;">老實人就是傻瓜,雖然一片好心,結果還是自己吃了虧</span><br />
<span style="background-color: white; color: #333333; font-family: "Microsoft YaHei", MicrosoftJhengHei, STHeiti, MingLiu, sans-serif, Verdana; font-size: 16px;"><br /></span>
<span style="background-color: white; color: #333333; font-family: "Microsoft YaHei", MicrosoftJhengHei, STHeiti, MingLiu, sans-serif, Verdana; font-size: 16px;"><br /></span>
<span style="background-color: white; color: #333333; font-family: "Microsoft YaHei", MicrosoftJhengHei, STHeiti, MingLiu, sans-serif, Verdana; font-size: 16px;">我承認天底下再沒有比愛情的責罰更痛苦的,也沒有比服侍它更快樂的事了。</span><br />
<span style="background-color: white; color: #333333; font-family: "Microsoft YaHei", MicrosoftJhengHei, STHeiti, MingLiu, sans-serif, Verdana; font-size: 16px;"><br /></span>
<span style="background-color: white; color: #333333; font-family: "Microsoft YaHei", MicrosoftJhengHei, STHeiti, MingLiu, sans-serif, Verdana; font-size: 16px;"><br /></span>
<span style="background-color: white; color: #333333; font-family: "Microsoft YaHei", MicrosoftJhengHei, STHeiti, MingLiu, sans-serif, Verdana; font-size: 16px;">愛情不是花蔭下的甜言,不是桃花源中的密語,不是輕綿的眼淚,更不是死硬的強迫,愛情是建立在共同的基礎上的。</span><br />
<span style="background-color: white; color: #333333; font-family: "Microsoft YaHei", MicrosoftJhengHei, STHeiti, MingLiu, sans-serif, Verdana; font-size: 16px;"><br /></span>
<span style="background-color: white; color: #333333; font-family: "Microsoft YaHei", MicrosoftJhengHei, STHeiti, MingLiu, sans-serif, Verdana; font-size: 16px;"><br /></span>
<span style="background-color: white; color: #333333; font-family: "Microsoft YaHei", MicrosoftJhengHei, STHeiti, MingLiu, sans-serif, Verdana; font-size: 16px;">太完美的愛情,傷心又傷身,身為江湖兒女,沒那個閒工夫 .</span><br />
<span style="background-color: white; color: #333333; font-family: "Microsoft YaHei", MicrosoftJhengHei, STHeiti, MingLiu, sans-serif, Verdana; font-size: 16px;"><br /></span>
<span style="background-color: white; color: #333333; font-family: "Microsoft YaHei", MicrosoftJhengHei, STHeiti, MingLiu, sans-serif, Verdana; font-size: 16px;"><br /></span>
<span style="background-color: white; color: #333333; font-family: "Microsoft YaHei", MicrosoftJhengHei, STHeiti, MingLiu, sans-serif, Verdana; font-size: 16px;"><br /></span>
<span style="background-color: white; color: #333333; font-family: "Microsoft YaHei", MicrosoftJhengHei, STHeiti, MingLiu, sans-serif, Verdana; font-size: 16px;"><br /></span>
<span style="background-color: white; color: #333333; font-family: "Microsoft YaHei", MicrosoftJhengHei, STHeiti, MingLiu, sans-serif, Verdana; font-size: 16px;">參考來源:</span><br />
<span style="background-color: white; color: #333333; font-family: "Microsoft YaHei", MicrosoftJhengHei, STHeiti, MingLiu, sans-serif, Verdana; font-size: 16px;"><br /></span>
<span style="background-color: white;"><span style="color: #333333; font-family: Microsoft YaHei, MicrosoftJhengHei, STHeiti, MingLiu, sans-serif, Verdana;"><a href="https://mingyanjiaju.org/mr/7090.html">https://mingyanjiaju.org/mr/7090.html</a></span></span>金石微開http://www.blogger.com/profile/13160756791496033950noreply@blogger.com0tag:blogger.com,1999:blog-2933755125431570931.post-57871123120353428652019-06-27T23:25:00.000+08:002019-06-27T23:25:04.241+08:00「Android] 重覆利用現有的Activity有多個Activity時,若想避免重覆產生Activity,可以在Intent中加入以下這個Flag<br />
<br />
<pre class="default prettyprint prettyprinted" style="background-color: #eff0f1; border-radius: 3px; border: 0px; box-sizing: inherit; color: #393318; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow-wrap: normal; overflow: auto; padding: 12px 8px; vertical-align: baseline; width: auto;"><code style="border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; white-space: inherit;"><span class="pln" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"> FLAG_ACTIVITY_REORDER_TO_FRONT</span></code></pre>
例如<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;">Intent intent<span style="color: #333333;">=</span><span style="color: #008800; font-weight: bold;">new</span> Intent<span style="color: #333333;">();</span>
intent<span style="color: #333333;">.</span><span style="color: #0000cc;">addFlags</span><span style="color: #333333;">(</span>Intent<span style="color: #333333;">.</span><span style="color: #0000cc;">FLAG_ACTIVITY_REORDER_TO_FRONT</span><span style="color: #333333;">);</span>
intent<span style="color: #333333;">.</span><span style="color: #0000cc;">setClass</span><span style="color: #333333;">(</span>nowAtvity<span style="color: #333333;">.</span><span style="color: #0000cc;">this</span><span style="color: #333333;">,</span>targetActivity<span style="color: #333333;">.</span><span style="color: #0000cc;">class</span><span style="color: #333333;">);</span>
startActivity<span style="color: #333333;">(</span>intent<span style="color: #333333;">);</span>
</pre>
</div>
<br />
<br />金石微開http://www.blogger.com/profile/13160756791496033950noreply@blogger.com0tag:blogger.com,1999:blog-2933755125431570931.post-73969916853419591672019-06-27T23:17:00.002+08:002019-06-27T23:17:28.735+08:00[Android]點擊畫面空白處Seekbar得到Focus問題最近遇上一個UI的BUG,當點擊畫面空白處,<br />
<br />
所有的Seekbar同時出現取得焦點的情況。<br />
<br />
幾經測試發現是最外層的Constraintlayout有OnClick事件造成,<br />
<br />
將OnClick由OnTouch替代即可解除這個問題。金石微開http://www.blogger.com/profile/13160756791496033950noreply@blogger.com0tag:blogger.com,1999:blog-2933755125431570931.post-69009819901579859042019-06-25T23:31:00.000+08:002019-06-25T23:31:16.288+08:00「小技巧」取得網站的Root-CA<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000}
span.s1 {font-variant-ligatures: no-common-ligatures}
</style>
<br />
<div class="p1">
<span style="font-variant-ligatures: no-common-ligatures;">透過OpenSSl 可以方便取得指定網站的Root-CA </span></div>
<div class="p1">
<span class="s1"><br /></span></div>
<div class="p1">
<span class="s1">openssl s_client -showcerts -connect japaneast.api.cognitive.microsoft.com:443</span></div>
<div class="p1">
<span class="s1"><br /></span></div>
<div class="p1">
<span class="s1">回應值如下</span></div>
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;">CONNECTED(<span style="color: #4400ee; font-weight: bold;">00000005</span>)
depth<span style="color: #333333;">=</span><span style="color: #0000dd; font-weight: bold;">2</span> C <span style="color: #333333;">=</span> IE, O <span style="color: #333333;">=</span> Baltimore, OU <span style="color: #333333;">=</span> CyberTrust, CN <span style="color: #333333;">=</span> Baltimore CyberTrust Root
verify <span style="color: #008800; font-weight: bold;">return</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">1</span>
depth<span style="color: #333333;">=</span><span style="color: #0000dd; font-weight: bold;">1</span> C <span style="color: #333333;">=</span> US, ST <span style="color: #333333;">=</span> Washington, L <span style="color: #333333;">=</span> Redmond, O <span style="color: #333333;">=</span> Microsoft Corporation, OU <span style="color: #333333;">=</span> Microsoft IT, CN <span style="color: #333333;">=</span> Microsoft IT TLS CA <span style="color: #0000dd; font-weight: bold;">2</span>
verify <span style="color: #008800; font-weight: bold;">return</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">1</span>
depth<span style="color: #333333;">=</span><span style="color: #0000dd; font-weight: bold;">0</span> CN <span style="color: #333333;">=</span> <span style="color: #333333;">*</span>.cognitiveservices.azure.com
verify <span style="color: #008800; font-weight: bold;">return</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">1</span>
<span style="color: #333333;">---</span>
Certificate chain
<span style="color: #0000dd; font-weight: bold;">0</span> s<span style="color: #333333;">:/</span>CN<span style="color: #333333;">=*</span>.cognitiveservices.azure.com
<span style="color: #997700; font-weight: bold;">i:</span><span style="color: #333333;">/</span>C<span style="color: #333333;">=</span>US<span style="color: #333333;">/</span>ST<span style="color: #333333;">=</span>Washington<span style="color: #333333;">/</span>L<span style="color: #333333;">=</span>Redmond<span style="color: #333333;">/</span>O<span style="color: #333333;">=</span>Microsoft Corporation<span style="color: #333333;">/</span>OU<span style="color: #333333;">=</span>Microsoft IT<span style="color: #333333;">/</span>CN<span style="color: #333333;">=</span>Microsoft IT TLS CA <span style="color: #0000dd; font-weight: bold;">2</span>
<span style="color: #333333;">-----</span>BEGIN CERTIFICATE<span style="color: #333333;">-----</span>
MIIIxzCCBq<span style="color: #333333;">+</span>gAwIBAgITIAAFRAs77OdnDzBu6AAAAAVECzANBgkqhkiG9w0BAQsF
ADCBizELMAkGA1UEBhMCVVMxEzARBgNVBAgTCldhc2hpbmd0b24xEDAOBgNVBAcT
B1JlZG1vbmQxHjAcBgNVBAoTFU1pY3Jvc29mdCBDb3Jwb3JhdGlvbjEVMBMGA1UE
CxMMTWljcm9zb2Z0IElUMR4wHAYDVQQDExVNaWNyb3NvZnQgSVQgVExTIENBIDIw
HhcNMTkwMTIzMDYwNTQ3WhcNMjEwMTIzMDYwNTQ3WjAoMSYwJAYDVQQDDB0qLmNv
Z25pdGl2ZXNlcnZpY2VzLmF6dXJlLmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEP
ADCCAQoCggEBAK2pLnlTsiv2lGiw9g<span style="color: #333333;">/</span><span style="color: #0000dd; font-weight: bold;">1</span>OFdt4MBKw2vRuxnDLWyPUWw0i4bRlRcD
oNua0v2Q41MSK613TWU3k00t0GqYEm8RwxUkvCU9Yrxvb7cRrKix5kb9wQs1IKFM
<span style="color: #0000dd; font-weight: bold;">0</span>zBtRJUGPfx6<span style="color: #333333;">+</span>Zzw8AOP72b0<span style="color: #333333;">/</span>WbFHBSpmrVjIzoOXqSO3Xjhia05j4Xj4bkEx6cl
oweFzKXFlE2bT7GQZBaXoJ7zvH8nxjkf8OdVja<span style="color: #333333;">++</span>V7KBZ1lvnPyySD9c91iboojj
s8mugyk<span style="color: #333333;">+</span>aVdypnCT32cZfRMl88Vbm0eFRpAtsOfdN3AqDPt61iezd3N5A34ePDsg
HEOkuvIv7hBSvkY61wZZTMqfM<span style="color: #333333;">/</span><span style="color: #0000dd; font-weight: bold;">7</span>b0tNvLOcCAwEAAaOCBIQwggSAMIIB9wYKKwYB
BAHWeQIEAgSCAecEggHjAeEAdgDuS723dc5guuFCaR<span style="color: #333333;">+</span>r4Z5mow9<span style="color: #333333;">+</span>X7By2IMAxHuJ
eqj9ywAAAWh5WbuoAAAEAwBHMEUCIQCpiobqLhY3FC4nMB6S6RdvVvHgI9wEDhSS
V7cJPYgB7wIgetEXIOZ4yqqZaKtlEcXGqQjd0CUFOJBXm4UPUI7QvFQAdwBVgdTC
FpA2AUrqC5tXPFPwwOQ4eHAlCBcvo6odBxPTDAAAAWh5Wbz9AAAEAwBIMEYCIQC5
sH1CnlDtZKLDj0FcLWKPBo1WpadkJ1lCxBB59zrYOgIhALxzYNrTjpzJERn3ff<span style="color: #333333;">/</span>U
XG4TeAtx3Usb9DRZ0i1mmOWFAHYAh3W<span style="color: #333333;">/</span><span style="color: #0000dd; font-weight: bold;">51l8</span><span style="color: #333333;">+</span>IxDmV<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">9827</span><span style="color: #333333;">/</span>Vo1HVjb<span style="color: #333333;">/</span>SrVgwbTq
<span style="color: #333333;">/</span><span style="color: #0000dd; font-weight: bold;">16</span>ggw8AAAFoeVm8twAABAMARzBFAiEA84pa6np0EEtH0PGTct8uqBobMTvz8S2l
Z9179Ua8PLUCIHHh7bM5lWS3QU<span style="color: #333333;">+</span>qPNhKBxq2Fjy<span style="color: #333333;">+</span>EzlGrQhYeNW58J5vAHYARJRl
LrDuzq<span style="color: #333333;">/</span>EQAfYqP4owNrmgr7YyzG1P9MzlrW2gagAAAFoeVm7sAAABAMARzBFAiBY
<span style="color: #0000dd; font-weight: bold;">3</span>QdvnGqCuVWbrhs9qbH1yAffQOCdnERU6exV<span style="color: #888888;">//9o/AIhAJX7WU19XamV5nXv/v6f</span>
CaufCaABHdW4jivgkM8I9RfXMCcGCSsGAQQBgjcVCgQaMBgwCgYIKwYBBQUHAwIw
CgYIKwYBBQUHAwEwPgYJKwYBBAGCNxUHBDEwLwYnKwYBBAGCNxUIh9qGdYPu2QGC
yYUbgbWeYYX062CBXYTS30KC55N6AgFkAgEdMIGFBggrBgEFBQcBAQR5MHcwUQYI
KwYBBQUHMAKGRWh0dHA6Ly93d3cubWljcm9zb2Z0LmNvbS9wa2kvbXNjb3JwL01p
Y3Jvc29mdCUyMElUJTIwVExTJTIwQ0ElMjAyLmNydDAiBggrBgEFBQcwAYYWaHR0
cDovL29jc3AubXNvY3NwLmNvbTAdBgNVHQ4EFgQUOajTQtEUdpIKprWd8liIwJoK
m0wwCwYDVR0PBAQDAgSwMCgGA1UdEQQhMB<span style="color: #333333;">+</span>CHSouY29nbml0aXZlc2VydmljZXMu
YXp1cmUuY29tMIGsBgNVHR8EgaQwgaEwgZ6ggZuggZiGS2h0dHA6Ly9tc2NybC5t
aWNyb3NvZnQuY29tL3BraS9tc2NvcnAvY3JsL01pY3Jvc29mdCUyMElUJTIwVExT
JTIwQ0ElMjAyLmNybIZJaHR0cDovL2NybC5taWNyb3NvZnQuY29tL3BraS9tc2Nv
cnAvY3JsL01pY3Jvc29mdCUyMElUJTIwVExTJTIwQ0ElMjAyLmNybDBNBgNVHSAE
RjBEMEIGCSsGAQQBgjcqATA1MDMGCCsGAQUFBwIBFidodHRwOi8vd3d3Lm1pY3Jv
c29mdC5jb20vcGtpL21zY29ycC9jcHMwHwYDVR0jBBgwFoAUkZ47RGw9V5xCdyo0
<span style="color: #0000dd; font-weight: bold;">10</span><span style="color: #333333;">/</span>RzEqXLNowHQYDVR0lBBYwFAYIKwYBBQUHAwIGCCsGAQUFBwMBMA0GCSqGSIb3
DQEBCwUAA4ICAQCCfSpc<span style="color: #333333;">+</span>ZzdzXIU8b4fW8jveZdME9QuaDGLC<span style="color: #333333;">/</span>OXZNyiJjo0nZSI
dAKgtEu0ME71<span style="color: #333333;">/</span>OiOoDAoY94<span style="color: #333333;">/</span>PfiGDWSOI3joWFrg20mbI18XYQHz8ukm5yqyOhtI
Lz7kKHpdx<span style="color: #333333;">/</span>O8cADUzpfsL7l8QKznZmhvoDY3XBX08V1ClHllqtwKBzyVB38wdruW
XznBrf0CkV5MrSL8Jugq7vYQAiVK7VbAkSvZ7M8h6dGXRvdwLl9trN0zIx5bjDIF
wdTnxAfVKeO8PD<span style="color: #333333;">+</span>FXvLw75jgiFTvJqBxvbfcig5XvfqaD4aQKOAQDOhV3thiStDm
<span style="color: #333333;">/</span><span style="color: #0000dd; font-weight: bold;">2</span>K8OPljtTd3evjX4yjyx<span style="color: #333333;">+</span>FoPoFiJZaMSE3j2jW1cmQt4eNSDB6OktmdjAcy2<span style="color: #333333;">+</span>gS
PM74zWRUd50mtEnhmCGsL0ef<span style="color: #333333;">/</span>jZLc7is4HVaUv2653GYBs7eCS454MZ1oCsDW6SC
HZXnfCJf00w80NdKSNpaiz58LvONLzuiuwXEFFU8qG2YeYAvgWnOPutAj5y3DEJR
xMrDvxVKQGcV7kaU4aDEp8ulwsS8IgMwQhuFgxbKFOEkrTPVPgyZDaNuSL02kefz
uykzE1BpG6gnuETzzPJrh94VZk7r31L29IYYLFcyY8Nhf42D<span style="color: #333333;">+</span>ES8iA<span style="color: #333333;">/</span>vCm9KidS9
<span style="color: #0000dd; font-weight: bold;">7</span>SzH4EHYXDrylkaWu9rH6LeThlmIhhzyrbeL<span style="color: #333333;">/</span>y4GwFdMPjc80zKNSXK0hw<span style="color: #333333;">==</span>
<span style="color: #333333;">-----</span>END CERTIFICATE<span style="color: #333333;">-----</span>
<span style="color: #0000dd; font-weight: bold;">1</span> s<span style="color: #333333;">:/</span>C<span style="color: #333333;">=</span>US<span style="color: #333333;">/</span>ST<span style="color: #333333;">=</span>Washington<span style="color: #333333;">/</span>L<span style="color: #333333;">=</span>Redmond<span style="color: #333333;">/</span>O<span style="color: #333333;">=</span>Microsoft Corporation<span style="color: #333333;">/</span>OU<span style="color: #333333;">=</span>Microsoft IT<span style="color: #333333;">/</span>CN<span style="color: #333333;">=</span>Microsoft IT TLS CA <span style="color: #0000dd; font-weight: bold;">2</span>
<span style="color: #997700; font-weight: bold;">i:</span><span style="color: #333333;">/</span>C<span style="color: #333333;">=</span>IE<span style="color: #333333;">/</span>O<span style="color: #333333;">=</span>Baltimore<span style="color: #333333;">/</span>OU<span style="color: #333333;">=</span>CyberTrust<span style="color: #333333;">/</span>CN<span style="color: #333333;">=</span>Baltimore CyberTrust Root
<span style="color: #333333;">-----</span>BEGIN CERTIFICATE<span style="color: #333333;">-----</span>
MIIFtDCCBJygAwIBAgIQDywQyVsGwJN<span style="color: #333333;">/</span>uNRJ<span style="color: #333333;">+</span>D6FaTANBgkqhkiG9w0BAQsFADBa
MQswCQYDVQQGEwJJRTESMBAGA1UEChMJQmFsdGltb3JlMRMwEQYDVQQLEwpDeWJl
clRydXN0MSIwIAYDVQQDExlCYWx0aW1vcmUgQ3liZXJUcnVzdCBSb290MB4XDTE2
MDUyMDEyNTE1N1oXDTI0MDUyMDEyNTE1N1owgYsxCzAJBgNVBAYTAlVTMRMwEQYD
VQQIEwpXYXNoaW5ndG9uMRAwDgYDVQQHEwdSZWRtb25kMR4wHAYDVQQKExVNaWNy
b3NvZnQgQ29ycG9yYXRpb24xFTATBgNVBAsTDE1pY3Jvc29mdCBJVDEeMBwGA1UE
AxMVTWljcm9zb2Z0IElUIFRMUyBDQSAyMIICIjANBgkqhkiG9w0BAQEFAAOCAg8A
MIICCgKCAgEAnqoVwRuhY1<span style="color: #333333;">/</span>mURjFFrsR3AtNm5EKukBJK9zWBgvFd1ksNEJFC06o
yRbwKPMflpW<span style="color: #333333;">/</span>HtOfzIeBliGk57MwZq18bgASr70sPUWuoD917HUgBfxBYoF8zA7Z
Ie5zAHODFboJL7Fg<span style="color: #333333;">/</span>apgbQs<span style="color: #333333;">/</span>GiZZNCi0QkQUWzw0nTUmVSNQ0mz6pCu95Dv1WMsL
GyPGfdN9zD3Q<span style="color: #333333;">/</span>QEDyJ695QgjRIxYA1DUE<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">54</span>ti2k6r0ycKFQYkyWwZ25HD1h2kYt
<span style="color: #0000dd; font-weight: bold;">3</span>ovW85vF6y7tjTqUEcLbgKUCB81<span style="color: #333333;">/</span><span style="color: #0000dd; font-weight: bold;">955</span>hdLLsbFd6f9o2PkU8xuOc3U<span style="color: #333333;">+</span>bUedvv6Sb
tvGjBEZeFyH8<span style="color: #333333;">/</span>CaQhzlsKMH0<span style="color: #333333;">+</span>OPOFv<span style="color: #333333;">/</span>bMqcLarPw1V1sOV1bl4W9vi2278niblzI
bEHt7nN888p4KNIwqCcXaGhbtS4tjn3NKI6v1d2XRyxIvCJDjgoZ09zF39Pyoe92
sSRikZh7xns4tQEQ8BCs4o5NBSx8UxEsgyzNSskWGEWqsIjt<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">7</span><span style="color: #333333;">+</span>A1skDDZv6k2o8
VCHNbTLFKS7d72wMI4ErpzVsBIicxaG2ezuMBBuqThxIiJ<span style="color: #333333;">+</span>G9zfoP9lxim<span style="color: #333333;">/</span><span style="color: #0000dd; font-weight: bold;">9</span>rvJA
xbh3nujA1VJfkOYTJIojEAYCxR3QjEoGdapJmBle97AfqEBnwoJsu2wav8h9v<span style="color: #333333;">+</span>po
DL4h6dRzRUxY1DHypcFlXGoHu<span style="color: #333333;">/</span>REQgFLq2IN30<span style="color: #333333;">/</span>AhQLN90Pj9TT2RQECAwEAAaOC
AUIwggE<span style="color: #333333;">+</span>MB0GA1UdDgQWBBSRnjtEbD1XnEJ3KjTXT9HMSpcs2jAfBgNVHSMEGDAW
gBTlnVkwgkdYzKz6CFQ2hns6tQRN8DASBgNVHRMBAf8ECDAGAQH<span style="color: #333333;">/</span>AgEAMA4GA1Ud
DwEB<span style="color: #333333;">/</span>wQEAwIBhjAnBgNVHSUEIDAeBggrBgEFBQcDAQYIKwYBBQUHAwIGCCsGAQUF
BwMJMDQGCCsGAQUFBwEBBCgwJjAkBggrBgEFBQcwAYYYaHR0cDovL29jc3AuZGln
aWNlcnQuY29tMDoGA1UdHwQzMDEwL6AtoCuGKWh0dHA6Ly9jcmwzLmRpZ2ljZXJ0
LmNvbS9PbW5pcm9vdDIwMjUuY3JsMD0GA1UdIAQ2MDQwMgYEVR0gADAqMCgGCCsG
AQUFBwIBFhxodHRwczovL3d3dy5kaWdpY2VydC5jb20vQ1BTMA0GCSqGSIb3DQEB
CwUAA4IBAQBsf<span style="color: #333333;">+</span>pqb89rW8E0rP<span style="color: #333333;">/</span>cDuB9ixMX4C9OWQ7EA7n0BSllR64ZmuhU9mTV
<span style="color: #0000dd; font-weight: bold;">2L0</span>G4HEiGXvOmt15i99wJ0ho2<span style="color: #333333;">/</span>dvMxm1ZeufkAfMuEc5fQ9RE5ENgNR2UCuFB2Bt
bVmaKUAWxscN4GpXS4AJv<span style="color: #333333;">+/</span>HS0VXs5Su19J0DA8Bg<span style="color: #333333;">+</span>lo8ekCl4dq2G1m1WsCvFBI
oLIjd4neCLlGoxT2jA43lj2JpQ<span style="color: #333333;">/</span>SMkLkLy9DXj<span style="color: #333333;">/</span>JHdsqJDR5ogcij4VIX8V<span style="color: #333333;">+</span>bVD0
NCw7kQa6Ulq9Zo0jDEq1at4zSeH4mV2PMM3LwIXBA2xo5sda1cnUWJo3Pq4uMgcL
e0t<span style="color: #333333;">+</span>fCut38NMkTl8F0arflspaqUVVUov
<span style="color: #333333;">-----</span>END CERTIFICATE<span style="color: #333333;">-----</span>
<span style="color: #333333;">---</span>
Server certificate
subject<span style="color: #333333;">=/</span>CN<span style="color: #333333;">=*</span>.cognitiveservices.azure.com
issuer<span style="color: #333333;">=/</span>C<span style="color: #333333;">=</span>US<span style="color: #333333;">/</span>ST<span style="color: #333333;">=</span>Washington<span style="color: #333333;">/</span>L<span style="color: #333333;">=</span>Redmond<span style="color: #333333;">/</span>O<span style="color: #333333;">=</span>Microsoft Corporation<span style="color: #333333;">/</span>OU<span style="color: #333333;">=</span>Microsoft IT<span style="color: #333333;">/</span>CN<span style="color: #333333;">=</span>Microsoft IT TLS CA <span style="color: #0000dd; font-weight: bold;">2</span>
<span style="color: #333333;">---</span>
No client certificate CA names sent
Server Temp Key<span style="color: #333333;">:</span> ECDH, P<span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">384</span>, <span style="color: #0000dd; font-weight: bold;">384</span> bits
<span style="color: #333333;">---</span>
SSL handshake has read <span style="color: #0000dd; font-weight: bold;">4513</span> bytes and written <span style="color: #0000dd; font-weight: bold;">358</span> bytes
<span style="color: #333333;">---</span>
New, TLSv1<span style="color: #333333;">/</span>SSLv3, Cipher is ECDHE<span style="color: #333333;">-</span>RSA<span style="color: #333333;">-</span>AES256<span style="color: #333333;">-</span>GCM<span style="color: #333333;">-</span>SHA384
Server public key is <span style="color: #0000dd; font-weight: bold;">2048</span> bit
Secure Renegotiation IS supported
<span style="color: #997700; font-weight: bold;">Compression:</span> NONE
<span style="color: #997700; font-weight: bold;">Expansion:</span> NONE
No ALPN negotiated
SSL<span style="color: #333333;">-</span>Session<span style="color: #333333;">:</span>
Protocol <span style="color: #333333;">:</span> TLSv1<span style="color: #6600ee; font-weight: bold;">.2</span>
Cipher <span style="color: #333333;">:</span> ECDHE<span style="color: #333333;">-</span>RSA<span style="color: #333333;">-</span>AES256<span style="color: #333333;">-</span>GCM<span style="color: #333333;">-</span>SHA384
Session<span style="color: #333333;">-</span>ID<span style="color: #333333;">:</span> <span style="color: #6600ee; font-weight: bold;">996FF</span>FB3854CAC1205B783A59B76BDFAE38D24425C77C1C50A8B80832D606261
Session<span style="color: #333333;">-</span>ID<span style="color: #333333;">-</span>ctx<span style="color: #333333;">:</span>
Master<span style="color: #333333;">-</span>Key<span style="color: #333333;">:</span> BCD00D7E1211EBD9A8755BC67584AEFEAE435E1F8842B9D13F90F6C2F8E4CE0AA646FE75377DACA2DDC40323C70B2910
TLS session ticket lifetime hint<span style="color: #333333;">:</span> <span style="color: #0000dd; font-weight: bold;">36000</span> (seconds)
TLS session ticket<span style="color: #333333;">:</span>
<span style="color: #4400ee; font-weight: bold;">0000</span> <span style="color: #333333;">-</span> <span style="color: #4400ee; font-weight: bold;">00</span> <span style="color: #4400ee; font-weight: bold;">00</span> <span style="color: #4400ee; font-weight: bold;">00</span> <span style="color: #4400ee; font-weight: bold;">00</span> f1 <span style="color: #0000dd; font-weight: bold;">09</span> a9 bd<span style="color: #333333;">-</span>e1 cc <span style="color: #0000dd; font-weight: bold;">12</span> <span style="color: #0000dd; font-weight: bold;">43</span> b9 <span style="color: #0000dd; font-weight: bold;">30</span> <span style="color: #0000dd; font-weight: bold;">10</span> <span style="color: #0000dd; font-weight: bold;">64</span> ...........C<span style="color: #6600ee; font-weight: bold;">.0</span>.d
<span style="color: #4400ee; font-weight: bold;">0010</span> <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">28</span> <span style="color: #0000dd; font-weight: bold;">4</span>e <span style="color: #6600ee; font-weight: bold;">9f</span> b9 d4 <span style="color: #0000dd; font-weight: bold;">14</span> fb <span style="color: #0000dd; font-weight: bold;">68</span><span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">92</span> <span style="color: #0000dd; font-weight: bold;">1</span>b ea <span style="color: #0000dd; font-weight: bold;">73</span> <span style="color: #0000dd; font-weight: bold;">13</span> <span style="color: #0000dd; font-weight: bold;">94</span> <span style="color: #0000dd; font-weight: bold;">94</span> d5 (N.....h...s....
<span style="color: #4400ee; font-weight: bold;">0020</span> <span style="color: #333333;">-</span> d5 <span style="color: #0000dd; font-weight: bold;">27</span> <span style="color: #4400ee; font-weight: bold;">00</span> <span style="color: #0000dd; font-weight: bold;">73</span> cc c6 <span style="color: #0000dd; font-weight: bold;">2</span>d d8<span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">76</span> e3 <span style="color: #0000dd; font-weight: bold;">36</span> bf <span style="color: #0000dd; font-weight: bold;">65</span> <span style="color: #0000dd; font-weight: bold;">5</span>b c9 e4 .<span style="background-color: #ffaaaa; color: red;">'</span>.s..<span style="color: #333333;">-</span>.v<span style="color: #6600ee; font-weight: bold;">.6</span>.e[..
<span style="color: #4400ee; font-weight: bold;">0030</span> <span style="color: #333333;">-</span> af <span style="color: #6600ee; font-weight: bold;">7f</span> <span style="color: #0000dd; font-weight: bold;">09</span> <span style="color: #0000dd; font-weight: bold;">39</span> <span style="color: #0000dd; font-weight: bold;">18</span> fc <span style="color: #0000dd; font-weight: bold;">7</span>d d4<span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">1</span>c <span style="color: #0000dd; font-weight: bold;">4</span>c c0 <span style="color: #0000dd; font-weight: bold;">8</span>c <span style="color: #0000dd; font-weight: bold;">11</span> e5 a4 c8 ..<span style="color: #6600ee; font-weight: bold;">.9</span>..}..L......
<span style="color: #4400ee; font-weight: bold;">0040</span> <span style="color: #333333;">-</span> d4 <span style="color: #0000dd; font-weight: bold;">24</span> <span style="color: #0000dd; font-weight: bold;">8</span>c <span style="color: #0000dd; font-weight: bold;">68</span> <span style="color: #0000dd; font-weight: bold;">4</span>d <span style="color: #0000dd; font-weight: bold;">74</span> <span style="color: #0000dd; font-weight: bold;">12</span> <span style="color: #0000dd; font-weight: bold;">12</span><span style="color: #333333;">-</span><span style="color: #6600ee; font-weight: bold;">1f</span> <span style="color: #0000dd; font-weight: bold;">86</span> c6 a3 <span style="color: #0000dd; font-weight: bold;">1</span>c d2 <span style="color: #0000dd; font-weight: bold;">27</span> <span style="color: #0000dd; font-weight: bold;">14</span> .<span style="background-color: #ffaaaa; color: red;">$</span>.hMt........<span style="background-color: #ffaaaa; color: red;">'</span>.
<span style="color: #4400ee; font-weight: bold;">0050</span> <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">4</span>d <span style="color: #0000dd; font-weight: bold;">1</span>d <span style="color: #0000dd; font-weight: bold;">3</span>b <span style="color: #4400ee; font-weight: bold;">03</span> ec e9 ac d2<span style="color: #333333;">-</span>f8 d3 d1 <span style="color: #0000dd; font-weight: bold;">53</span> <span style="color: #0000dd; font-weight: bold;">76</span> <span style="color: #0000dd; font-weight: bold;">60</span> <span style="color: #0000dd; font-weight: bold;">5</span>a <span style="color: #0000dd; font-weight: bold;">31</span> M.;........Sv<span style="background-color: #ffaaaa; color: red;">`</span>Z1
<span style="color: #4400ee; font-weight: bold;">0060</span> <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">91</span> <span style="color: #0000dd; font-weight: bold;">76</span> <span style="color: #0000dd; font-weight: bold;">92</span> <span style="color: #0000dd; font-weight: bold;">67</span> ce ee <span style="color: #0000dd; font-weight: bold;">5</span>e <span style="color: #0000dd; font-weight: bold;">68</span><span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">73</span> <span style="color: #0000dd; font-weight: bold;">9</span>c <span style="color: #0000dd; font-weight: bold;">4</span>c a7 <span style="color: #0000dd; font-weight: bold;">9</span>a <span style="color: #0000dd; font-weight: bold;">55</span> <span style="color: #0000dd; font-weight: bold;">93</span> a2 .v.g..<span style="color: #333333;">^</span>hs.L..U..
<span style="color: #4400ee; font-weight: bold;">0070</span> <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">17</span> <span style="color: #4400ee; font-weight: bold;">00</span> <span style="color: #4400ee; font-weight: bold;">05</span> <span style="color: #0000dd; font-weight: bold;">25</span> <span style="color: #0000dd; font-weight: bold;">1</span>a <span style="color: #0000dd; font-weight: bold;">25</span> e9 cb<span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">32</span> <span style="color: #0000dd; font-weight: bold;">97</span> <span style="color: #0000dd; font-weight: bold;">31</span> <span style="color: #0000dd; font-weight: bold;">23</span> fc <span style="color: #0000dd; font-weight: bold;">15</span> <span style="color: #0000dd; font-weight: bold;">5</span>d a5 ...<span style="color: #333333;">%</span>.<span style="color: #333333;">%</span>.<span style="color: #6600ee; font-weight: bold;">.2.1</span><span style="background-color: #ffaaaa; color: red;">#</span>..].
<span style="color: #4400ee; font-weight: bold;">00</span><span style="color: #0000dd; font-weight: bold;">80</span> <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">84</span> ae <span style="color: #0000dd; font-weight: bold;">5</span>b <span style="color: #0000dd; font-weight: bold;">90</span> <span style="color: #0000dd; font-weight: bold;">2</span>e <span style="color: #0000dd; font-weight: bold;">9</span>c e9 <span style="color: #6600ee; font-weight: bold;">0f</span><span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">63</span> <span style="color: #6600ee; font-weight: bold;">5f</span> <span style="color: #0000dd; font-weight: bold;">76</span> <span style="color: #0000dd; font-weight: bold;">2</span>e <span style="color: #0000dd; font-weight: bold;">61</span> <span style="color: #0000dd; font-weight: bold;">4</span>b <span style="color: #0000dd; font-weight: bold;">90</span> d9 ..[.....c_v.aK..
<span style="color: #4400ee; font-weight: bold;">00</span><span style="color: #0000dd; font-weight: bold;">90</span> <span style="color: #333333;">-</span> a6 ab ca ea df <span style="color: #0000dd; font-weight: bold;">36</span> <span style="color: #0000dd; font-weight: bold;">23</span> cc<span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">41</span> <span style="color: #0000dd; font-weight: bold;">85</span> <span style="color: #0000dd; font-weight: bold;">54</span> <span style="color: #0000dd; font-weight: bold;">13</span> <span style="color: #6600ee; font-weight: bold;">4f</span> cc <span style="color: #0000dd; font-weight: bold;">7</span>b d6 ....<span style="color: #6600ee; font-weight: bold;">.6</span><span style="background-color: #ffaaaa; color: red;">#</span>.A.T.O.{.
<span style="color: #4400ee; font-weight: bold;">00</span>a0 <span style="color: #333333;">-</span> a5 <span style="color: #0000dd; font-weight: bold;">73</span> <span style="color: #0000dd; font-weight: bold;">88</span> c5 <span style="color: #0000dd; font-weight: bold;">2</span>a <span style="color: #0000dd; font-weight: bold;">9</span>c e7 ad<span style="color: #333333;">-</span><span style="color: #4400ee; font-weight: bold;">01</span> b3 <span style="color: #0000dd; font-weight: bold;">0</span>b <span style="color: #0000dd; font-weight: bold;">47</span> <span style="color: #0000dd; font-weight: bold;">76</span> <span style="color: #4400ee; font-weight: bold;">02</span> df <span style="color: #0000dd; font-weight: bold;">3</span>a .s..<span style="color: #333333;">*</span>......Gv..<span style="color: #333333;">:</span>
<span style="color: #4400ee; font-weight: bold;">00</span>b0 <span style="color: #333333;">-</span> b4 <span style="color: #0000dd; font-weight: bold;">49</span> f0 <span style="color: #6600ee; font-weight: bold;">0f</span> a0 <span style="color: #6600ee; font-weight: bold;">4f</span> ba ac<span style="color: #333333;">-</span>a5 c5 be <span style="color: #0000dd; font-weight: bold;">35</span> <span style="color: #0000dd; font-weight: bold;">29</span> <span style="color: #0000dd; font-weight: bold;">53</span> <span style="color: #0000dd; font-weight: bold;">66</span> <span style="color: #0000dd; font-weight: bold;">44</span> .I...O....<span style="color: #6600ee; font-weight: bold;">.5</span>)SfD
<span style="color: #4400ee; font-weight: bold;">00</span>c0 <span style="color: #333333;">-</span> ec <span style="color: #0000dd; font-weight: bold;">8</span>d ad <span style="color: #0000dd; font-weight: bold;">1</span>a <span style="color: #0000dd; font-weight: bold;">1</span>c d4 e6 <span style="color: #0000dd; font-weight: bold;">55</span><span style="color: #333333;">-</span>e6 ae eb <span style="color: #0000dd; font-weight: bold;">9</span>e <span style="color: #0000dd; font-weight: bold;">3</span>e <span style="color: #6600ee; font-weight: bold;">9f</span> <span style="color: #6600ee; font-weight: bold;">9f</span> d5 .......U....<span style="color: #333333;">></span>...
<span style="color: #4400ee; font-weight: bold;">00</span>d0 <span style="color: #333333;">-</span> f0 <span style="color: #0000dd; font-weight: bold;">11</span> <span style="color: #0000dd; font-weight: bold;">0</span>d <span style="color: #0000dd; font-weight: bold;">68</span> de <span style="color: #0000dd; font-weight: bold;">66</span> <span style="color: #0000dd; font-weight: bold;">94</span> <span style="color: #6600ee; font-weight: bold;">7e-18</span> <span style="color: #0000dd; font-weight: bold;">82</span> c9 <span style="color: #4400ee; font-weight: bold;">03</span> a8 ee b7 b2 ...h.f.<span style="color: #333333;">~</span>........
<span style="color: #6600ee; font-weight: bold;">00e0</span> <span style="color: #333333;">-</span> c0 <span style="color: #0000dd; font-weight: bold;">08</span> aa a8 b4 <span style="color: #0000dd; font-weight: bold;">48</span> <span style="color: #0000dd; font-weight: bold;">61</span> cb<span style="color: #333333;">-</span><span style="color: #6600ee; font-weight: bold;">1f</span> a5 <span style="color: #6600ee; font-weight: bold;">1f</span> b1 <span style="color: #0000dd; font-weight: bold;">63</span> <span style="color: #0000dd; font-weight: bold;">93</span> de f1 .....Ha.....c...
<span style="color: #6600ee; font-weight: bold;">00f</span><span style="color: #0000dd; font-weight: bold;">0</span> <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">8</span>a f8 f4 <span style="color: #0000dd; font-weight: bold;">23</span> <span style="color: #0000dd; font-weight: bold;">6</span>b <span style="color: #4400ee; font-weight: bold;">02</span> <span style="color: #0000dd; font-weight: bold;">76</span> <span style="color: #6600ee; font-weight: bold;">7f</span><span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">7</span>b ad b1 <span style="color: #0000dd; font-weight: bold;">94</span> f7 <span style="color: #0000dd; font-weight: bold;">93</span> <span style="color: #0000dd; font-weight: bold;">80</span> f9 ...<span style="background-color: #ffaaaa; color: red;">#</span>k.v.{.......
<span style="color: #4400ee; font-weight: bold;">0100</span> <span style="color: #333333;">-</span> ea <span style="color: #0000dd; font-weight: bold;">26</span> <span style="color: #0000dd; font-weight: bold;">28</span> <span style="color: #0000dd; font-weight: bold;">82</span> .<span style="color: #333333;">&</span>(.
Start Time<span style="color: #333333;">:</span> <span style="color: #0000dd; font-weight: bold;">1561476387</span>
Timeout <span style="color: #333333;">:</span> <span style="color: #0000dd; font-weight: bold;">7200</span> (sec)
Verify <span style="color: #008800; font-weight: bold;">return</span> code<span style="color: #333333;">:</span> <span style="color: #0000dd; font-weight: bold;">0</span> (ok)
<span style="color: #333333;">---</span>
</pre>
</div>
<br />
注意第二段 標示 CyberTrust Root 或是Root CA 即為所求<br />
<pre style="line-height: 16.25px;"><span style="color: #333333;">-----</span>BEGIN CERTIFICATE<span style="color: #333333;">-----</span>
MIIFtDCCBJygAwIBAgIQDywQyVsGwJN<span style="color: #333333;">/</span>uNRJ<span style="color: #333333;">+</span>D6FaTANBgkqhkiG9w0BAQsFADBa
MQswCQYDVQQGEwJJRTESMBAGA1UEChMJQmFsdGltb3JlMRMwEQYDVQQLEwpDeWJl
clRydXN0MSIwIAYDVQQDExlCYWx0aW1vcmUgQ3liZXJUcnVzdCBSb290MB4XDTE2
MDUyMDEyNTE1N1oXDTI0MDUyMDEyNTE1N1owgYsxCzAJBgNVBAYTAlVTMRMwEQYD
VQQIEwpXYXNoaW5ndG9uMRAwDgYDVQQHEwdSZWRtb25kMR4wHAYDVQQKExVNaWNy
b3NvZnQgQ29ycG9yYXRpb24xFTATBgNVBAsTDE1pY3Jvc29mdCBJVDEeMBwGA1UE
AxMVTWljcm9zb2Z0IElUIFRMUyBDQSAyMIICIjANBgkqhkiG9w0BAQEFAAOCAg8A
MIICCgKCAgEAnqoVwRuhY1<span style="color: #333333;">/</span>mURjFFrsR3AtNm5EKukBJK9zWBgvFd1ksNEJFC06o
yRbwKPMflpW<span style="color: #333333;">/</span>HtOfzIeBliGk57MwZq18bgASr70sPUWuoD917HUgBfxBYoF8zA7Z
Ie5zAHODFboJL7Fg<span style="color: #333333;">/</span>apgbQs<span style="color: #333333;">/</span>GiZZNCi0QkQUWzw0nTUmVSNQ0mz6pCu95Dv1WMsL
GyPGfdN9zD3Q<span style="color: #333333;">/</span>QEDyJ695QgjRIxYA1DUE<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">54</span>ti2k6r0ycKFQYkyWwZ25HD1h2kYt
<span style="color: #0000dd; font-weight: bold;">3</span>ovW85vF6y7tjTqUEcLbgKUCB81<span style="color: #333333;">/</span><span style="color: #0000dd; font-weight: bold;">955</span>hdLLsbFd6f9o2PkU8xuOc3U<span style="color: #333333;">+</span>bUedvv6Sb
tvGjBEZeFyH8<span style="color: #333333;">/</span>CaQhzlsKMH0<span style="color: #333333;">+</span>OPOFv<span style="color: #333333;">/</span>bMqcLarPw1V1sOV1bl4W9vi2278niblzI
bEHt7nN888p4KNIwqCcXaGhbtS4tjn3NKI6v1d2XRyxIvCJDjgoZ09zF39Pyoe92
sSRikZh7xns4tQEQ8BCs4o5NBSx8UxEsgyzNSskWGEWqsIjt<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">7</span><span style="color: #333333;">+</span>A1skDDZv6k2o8
VCHNbTLFKS7d72wMI4ErpzVsBIicxaG2ezuMBBuqThxIiJ<span style="color: #333333;">+</span>G9zfoP9lxim<span style="color: #333333;">/</span><span style="color: #0000dd; font-weight: bold;">9</span>rvJA
xbh3nujA1VJfkOYTJIojEAYCxR3QjEoGdapJmBle97AfqEBnwoJsu2wav8h9v<span style="color: #333333;">+</span>po
DL4h6dRzRUxY1DHypcFlXGoHu<span style="color: #333333;">/</span>REQgFLq2IN30<span style="color: #333333;">/</span>AhQLN90Pj9TT2RQECAwEAAaOC
AUIwggE<span style="color: #333333;">+</span>MB0GA1UdDgQWBBSRnjtEbD1XnEJ3KjTXT9HMSpcs2jAfBgNVHSMEGDAW
gBTlnVkwgkdYzKz6CFQ2hns6tQRN8DASBgNVHRMBAf8ECDAGAQH<span style="color: #333333;">/</span>AgEAMA4GA1Ud
DwEB<span style="color: #333333;">/</span>wQEAwIBhjAnBgNVHSUEIDAeBggrBgEFBQcDAQYIKwYBBQUHAwIGCCsGAQUF
BwMJMDQGCCsGAQUFBwEBBCgwJjAkBggrBgEFBQcwAYYYaHR0cDovL29jc3AuZGln
aWNlcnQuY29tMDoGA1UdHwQzMDEwL6AtoCuGKWh0dHA6Ly9jcmwzLmRpZ2ljZXJ0
LmNvbS9PbW5pcm9vdDIwMjUuY3JsMD0GA1UdIAQ2MDQwMgYEVR0gADAqMCgGCCsG
AQUFBwIBFhxodHRwczovL3d3dy5kaWdpY2VydC5jb20vQ1BTMA0GCSqGSIb3DQEB
CwUAA4IBAQBsf<span style="color: #333333;">+</span>pqb89rW8E0rP<span style="color: #333333;">/</span>cDuB9ixMX4C9OWQ7EA7n0BSllR64ZmuhU9mTV
<span style="color: #0000dd; font-weight: bold;">2L0</span>G4HEiGXvOmt15i99wJ0ho2<span style="color: #333333;">/</span>dvMxm1ZeufkAfMuEc5fQ9RE5ENgNR2UCuFB2Bt
bVmaKUAWxscN4GpXS4AJv<span style="color: #333333;">+/</span>HS0VXs5Su19J0DA8Bg<span style="color: #333333;">+</span>lo8ekCl4dq2G1m1WsCvFBI
oLIjd4neCLlGoxT2jA43lj2JpQ<span style="color: #333333;">/</span>SMkLkLy9DXj<span style="color: #333333;">/</span>JHdsqJDR5ogcij4VIX8V<span style="color: #333333;">+</span>bVD0
NCw7kQa6Ulq9Zo0jDEq1at4zSeH4mV2PMM3LwIXBA2xo5sda1cnUWJo3Pq4uMgcL
e0t<span style="color: #333333;">+</span>fCut38NMkTl8F0arflspaqUVVUov
<span style="color: #333333;">-----</span>END CERTIFICATE<span style="color: #333333;">-----</span></pre>
<pre style="line-height: 16.25px;"><span style="color: #333333;">
</span></pre>
<pre style="line-height: 16.25px;"><span style="color: #333333;">
</span></pre>
<pre style="line-height: 16.25px;"><span style="color: #333333;">參考文章</span></pre>
<pre style="line-height: 16.25px;"><span style="color: #333333;">
</span></pre>
<pre style="line-height: 16.25px;"><span style="color: #333333;"><a href="http://www.iotsharing.com/2017/08/how-to-use-https-in-arduino-esp32.html">http://www.iotsharing.com/2017/08/how-to-use-https-in-arduino-esp32.html</a></span></pre>
金石微開http://www.blogger.com/profile/13160756791496033950noreply@blogger.com0tag:blogger.com,1999:blog-2933755125431570931.post-82355224913872592382019-04-24T00:45:00.000+08:002019-04-24T00:45:31.516+08:00[IoT]Line Things 初體驗Line Things是Line推出的IoT平台 ,簡單來說就是透過Line 去控制附近的藍芽裝置,<br />
<br />
介面則是透過Line去載入LIFF App中所設定的EndPoint URL,開發商只需依照Line的<br />
<br />
規範去實作硬體及韌體,無須自行再開發APP。<br />
<br />
1.首先要申請一個Line Bot ,然候掃描Bot QR Code加入好友!!!<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhI_XcUlpyclSAmrNILjch7tXpAKjeP44sneiZrmi6okoYHZ92u5Wrx5flJ3t_K4hwjvMTRdsCwXma-95zFI1ImNIa2k4ZS_AqDChYnct7QFJa91FcO8_8Psbg2IgqtPvatfFCHzQR691p3/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2019-04-23+%25E4%25B8%258B%25E5%258D%258811.19.11.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="1066" data-original-width="1316" height="518" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhI_XcUlpyclSAmrNILjch7tXpAKjeP44sneiZrmi6okoYHZ92u5Wrx5flJ3t_K4hwjvMTRdsCwXma-95zFI1ImNIa2k4ZS_AqDChYnct7QFJa91FcO8_8Psbg2IgqtPvatfFCHzQR691p3/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2019-04-23+%25E4%25B8%258B%25E5%258D%258811.19.11.png" width="640" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
2.Fork 這個Github到您的Github帳戶 (若有自己的網頁空間亦可以將<a class="js-navigation-open" href="https://github.com/line/line-things-starter/tree/master/liff-app" id="538c02431a3d387af1b2b094a01306ab-16fd37d9af5b588abbcdbadcdb5341fd7c107575" style="background-color: #f6f8fa; box-sizing: border-box; color: #0366d6; font-family: -apple-system, system-ui, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; font-size: 14px; text-decoration-line: none; white-space: nowrap;" title="liff-app">liff-app</a>下的內容複制到您的個人空間中)<br />
<br />
<a href="https://github.com/line/line-things-starter">https://github.com/line/line-things-starter</a><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgri8pfaojQwMZYj5T-lukZ3lEX6wEmhIrd526rgQPhpN0UdjwPMOHQq9UYHwSd0UEny4GAjaybu-RZnY14-aTrZrNqhgKw3G30RvdC4x3dvDEY_al3puv0FORWoPAJJp6pIrnHKx4mIKX9/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2019-04-23+%25E4%25B8%258B%25E5%258D%258811.23.34.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="798" data-original-width="1600" height="318" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgri8pfaojQwMZYj5T-lukZ3lEX6wEmhIrd526rgQPhpN0UdjwPMOHQq9UYHwSd0UEny4GAjaybu-RZnY14-aTrZrNqhgKw3G30RvdC4x3dvDEY_al3puv0FORWoPAJJp6pIrnHKx4mIKX9/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2019-04-23+%25E4%25B8%258B%25E5%258D%258811.23.34.png" width="640" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
3.到您帳號下Fork出來的專案中Settings頁面<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhq644iYkZgzb1xY6p_H9a34ikyjFyMAGBPUpExeSd_UFxIHGJIB6Kmw93Xudxu2KN0eqcMsNd0y9DwWATYuqpmdk_gVaTym14LgpbdwkYi36LO9KSlWq7avLvOS8u4sDI2t0gUEOga0zR7/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2019-04-23+%25E4%25B8%258B%25E5%258D%258811.25.38.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="1065" data-original-width="1600" height="424" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhq644iYkZgzb1xY6p_H9a34ikyjFyMAGBPUpExeSd_UFxIHGJIB6Kmw93Xudxu2KN0eqcMsNd0y9DwWATYuqpmdk_gVaTym14LgpbdwkYi36LO9KSlWq7avLvOS8u4sDI2t0gUEOga0zR7/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2019-04-23+%25E4%25B8%258B%25E5%258D%258811.25.38.png" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: left;">
將Source設為master branch,並且點擊Change theme後任選一個 ,就會出現您的網頁URL</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg47F8csK19AUfaP5LW5RRdwv8TA8H0z9NdigUA0pz6J-56BWDmES80WGuuJOw_9QYNx40A_oR1JCdkwjzfq0RUK-m12hzgd3YIZNPUqedntmYpJdkwbsnT217OxDiqOtvN6gkwvjts5v7F/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2019-04-23+%25E4%25B8%258B%25E5%258D%258811.26.03.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="847" data-original-width="1600" height="338" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg47F8csK19AUfaP5LW5RRdwv8TA8H0z9NdigUA0pz6J-56BWDmES80WGuuJOw_9QYNx40A_oR1JCdkwjzfq0RUK-m12hzgd3YIZNPUqedntmYpJdkwbsnT217OxDiqOtvN6gkwvjts5v7F/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2019-04-23+%25E4%25B8%258B%25E5%258D%258811.26.03.png" width="640" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
4.接下來回到Line Bot,申請一個LIFF App<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiMYuvO-yBO0pi4-brN6eirQ1iCD3LoW7yfua7RKEIP6MVbR-FNRkVOk9LpgvLFWbcFVt3EV0yE9O2Gou9ZntV-KXO_RtTsODZYDS6yk60cyPCccRhII8zy_KR1uQvzvPiasM8icZESgwDd/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2019-04-23+%25E4%25B8%258B%25E5%258D%258811.32.06.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiMYuvO-yBO0pi4-brN6eirQ1iCD3LoW7yfua7RKEIP6MVbR-FNRkVOk9LpgvLFWbcFVt3EV0yE9O2Gou9ZntV-KXO_RtTsODZYDS6yk60cyPCccRhII8zy_KR1uQvzvPiasM8icZESgwDd/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2019-04-23+%25E4%25B8%258B%25E5%258D%258811.32.06.png" imageanchor="1" style="clear: left; display: inline !important; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="436" data-original-width="1600" height="174" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiMYuvO-yBO0pi4-brN6eirQ1iCD3LoW7yfua7RKEIP6MVbR-FNRkVOk9LpgvLFWbcFVt3EV0yE9O2Gou9ZntV-KXO_RtTsODZYDS6yk60cyPCccRhII8zy_KR1uQvzvPiasM8icZESgwDd/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2019-04-23+%25E4%25B8%258B%25E5%258D%258811.32.06.png" width="640" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiMYuvO-yBO0pi4-brN6eirQ1iCD3LoW7yfua7RKEIP6MVbR-FNRkVOk9LpgvLFWbcFVt3EV0yE9O2Gou9ZntV-KXO_RtTsODZYDS6yk60cyPCccRhII8zy_KR1uQvzvPiasM8icZESgwDd/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2019-04-23+%25E4%25B8%258B%25E5%258D%258811.32.06.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiMYuvO-yBO0pi4-brN6eirQ1iCD3LoW7yfua7RKEIP6MVbR-FNRkVOk9LpgvLFWbcFVt3EV0yE9O2Gou9ZntV-KXO_RtTsODZYDS6yk60cyPCccRhII8zy_KR1uQvzvPiasM8icZESgwDd/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2019-04-23+%25E4%25B8%258B%25E5%258D%258811.32.06.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
把剛才的URL貼在Endpoint URL中,記得補上/liff_app , 記下LIFF URL 最後數字及英文,就是LIFF APP ID ,記得BLE Feature要開<br />
<br />
EX: <span style="background-color: white; color: #4a4a4a; font-family: Roboto, "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; white-space: nowrap;">https://flowercatswets.github.io/line-things-starter/liff-app/</span><br />
<span style="background-color: white; color: #4a4a4a; font-family: Roboto, "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; white-space: nowrap;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgM0eDDS3NS88-xaZSBFL9pEY4drq4jv03OE9rjOUcFYMhu1ORFNtswI1ZeIGw0j8KgkWmVEnCAhAyRXoK6snNQ2Aezw0w1VkAKT-YVWKmfOzVGjte-XWQlptrjhd4jxD5eluC4NMUn22F7/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2019-04-23+%25E4%25B8%258B%25E5%258D%258811.30.58.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="1276" data-original-width="1572" height="518" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgM0eDDS3NS88-xaZSBFL9pEY4drq4jv03OE9rjOUcFYMhu1ORFNtswI1ZeIGw0j8KgkWmVEnCAhAyRXoK6snNQ2Aezw0w1VkAKT-YVWKmfOzVGjte-XWQlptrjhd4jxD5eluC4NMUn22F7/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2019-04-23+%25E4%25B8%258B%25E5%258D%258811.30.58.png" width="640" /></a></div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
5.回到Channel Setting 記一下Token ,如果沒有出現按一下最右邊的Issue,選個24 HR</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdZ4WFpbMNHpM0QzKFNGK4qqhAft62vTbIcKKjZVDefoFXG6AQNO0KOVPsq_fdgvUf_KMTPoKD36jHsAe4NNW735O50y8DtG2p-Lr378h2SnCxc9TyBz_-Mp1p2c5kFqyPW1ldfALERTOV/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2019-04-23+%25E4%25B8%258B%25E5%258D%258811.36.40.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="422" data-original-width="1452" height="186" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdZ4WFpbMNHpM0QzKFNGK4qqhAft62vTbIcKKjZVDefoFXG6AQNO0KOVPsq_fdgvUf_KMTPoKD36jHsAe4NNW735O50y8DtG2p-Lr378h2SnCxc9TyBz_-Mp1p2c5kFqyPW1ldfALERTOV/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2019-04-23+%25E4%25B8%258B%25E5%258D%258811.36.40.png" width="640" /></a></div>
<div style="text-align: left;">
<br /></div>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgM0eDDS3NS88-xaZSBFL9pEY4drq4jv03OE9rjOUcFYMhu1ORFNtswI1ZeIGw0j8KgkWmVEnCAhAyRXoK6snNQ2Aezw0w1VkAKT-YVWKmfOzVGjte-XWQlptrjhd4jxD5eluC4NMUn22F7/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2019-04-23+%25E4%25B8%258B%25E5%258D%258811.30.58.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgM0eDDS3NS88-xaZSBFL9pEY4drq4jv03OE9rjOUcFYMhu1ORFNtswI1ZeIGw0j8KgkWmVEnCAhAyRXoK6snNQ2Aezw0w1VkAKT-YVWKmfOzVGjte-XWQlptrjhd4jxD5eluC4NMUn22F7/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2019-04-23+%25E4%25B8%258B%25E5%258D%258811.30.58.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgM0eDDS3NS88-xaZSBFL9pEY4drq4jv03OE9rjOUcFYMhu1ORFNtswI1ZeIGw0j8KgkWmVEnCAhAyRXoK6snNQ2Aezw0w1VkAKT-YVWKmfOzVGjte-XWQlptrjhd4jxD5eluC4NMUn22F7/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2019-04-23+%25E4%25B8%258B%25E5%258D%258811.30.58.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br /></a><br />
<span style="background-color: white; color: #4a4a4a; font-family: Roboto, "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; white-space: nowrap;"><br /></span>
<span style="background-color: white; color: #4a4a4a; font-family: Roboto, "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; white-space: nowrap;"><br /></span>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOSNnFCIWUSVb6mGc0bo-HUsXVBrKfflG9cWGdJnynQ4_u8SaI7DFPfL22B4KltJhqUNmFQ9_TdKrBx_te7rLwbprau3ccpBaCIbDoWfxpGhENl3dJ3LfFmsp-qQC6espocnlMbiSMDfev/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2019-04-23+%25E4%25B8%258B%25E5%258D%258811.36.53.png" imageanchor="1" style="clear: left; display: inline !important; margin-bottom: 1em; margin-right: 1em; text-align: center;"><img border="0" data-original-height="310" data-original-width="1600" height="122" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOSNnFCIWUSVb6mGc0bo-HUsXVBrKfflG9cWGdJnynQ4_u8SaI7DFPfL22B4KltJhqUNmFQ9_TdKrBx_te7rLwbprau3ccpBaCIbDoWfxpGhENl3dJ3LfFmsp-qQC6espocnlMbiSMDfev/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2019-04-23+%25E4%25B8%258B%25E5%258D%258811.36.53.png" width="640" /></a><br />
<br />
<br />
6.最重要的過程是註冊取得Service UUID ,在mac 或Linux可以透過指令<br />
<br />
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px 'Helvetica Neue'}
span.s1 {font: 12.0px '.PingFang TC'}
</style>
<br />
<div class="p1">
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"<span class="s1">,</span>"liffId": "LIFF URL最後面的數字及英文"}'</div>
<div class="p1">
<br /></div>
在Windows可以透過Restlet Client <div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiyG7fzWkGID8gZ8JTCOdqc48Un96Uacb9a0E9cmwJXLyArgMVX8y-fmvkXbvQfNZ9LzFIVPg_r0Bp4Gu3iQbDuRkkJuAB2MpqV5e2oEZzTmPaSqJi_s0D6oyfBeI3A1w512GRmi-NyFNJO/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2019-04-23+%25E4%25B8%258B%25E5%258D%258811.44.51.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="518" data-original-width="1600" height="206" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiyG7fzWkGID8gZ8JTCOdqc48Un96Uacb9a0E9cmwJXLyArgMVX8y-fmvkXbvQfNZ9LzFIVPg_r0Bp4Gu3iQbDuRkkJuAB2MpqV5e2oEZzTmPaSqJi_s0D6oyfBeI3A1w512GRmi-NyFNJO/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2019-04-23+%25E4%25B8%258B%25E5%258D%258811.44.51.png" width="640" /></a></div>
<div class="p1">
<br /></div>
<div class="p1">
<br /></div>
如果成功會回應如下內容,重要的只有圈起來的部份,就是我們要的UUID。<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEht1qGFUGbdCFLLa7NqKw8CjcRF3me8AcXfEXtZ5L0M2bCQglP6LZxY0_BP5TbCzEDDBR0fIOX2-yCZPliQYM6DYarkK4NgF4mTuYb5071kQQDX3PTnwEVVwYy2TagPYUeH7ZsDMHb0aziz/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2019-04-23+%25E4%25B8%258B%25E5%258D%258811.46.09.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="437" data-original-width="1234" height="226" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEht1qGFUGbdCFLLa7NqKw8CjcRF3me8AcXfEXtZ5L0M2bCQglP6LZxY0_BP5TbCzEDDBR0fIOX2-yCZPliQYM6DYarkK4NgF4mTuYb5071kQQDX3PTnwEVVwYy2TagPYUeH7ZsDMHb0aziz/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2019-04-23+%25E4%25B8%258B%25E5%258D%258811.46.09.png" width="640" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
7.點擊您Fork出來的專案下的liff-app中的liff.js<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiiJXvbkdfA8pCqqVBx7x8431a1PGmHHyUiqpRbmqP748BIx5vibkZ1eMkWhSHkv6DN55yX17CuCerf0zvolIR7BYvDeeIldGmWslfgUavctMUguFAOIMegbn456HZnyg_hTyH_I3z7Kn4-/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2019-04-23+%25E4%25B8%258B%25E5%258D%258811.50.04.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="818" data-original-width="1600" height="326" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiiJXvbkdfA8pCqqVBx7x8431a1PGmHHyUiqpRbmqP748BIx5vibkZ1eMkWhSHkv6DN55yX17CuCerf0zvolIR7BYvDeeIldGmWslfgUavctMUguFAOIMegbn456HZnyg_hTyH_I3z7Kn4-/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2019-04-23+%25E4%25B8%258B%25E5%258D%258811.50.04.png" width="640" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
點擊右方的筆圖示編輯它<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi04dKLiiuS_VPpV0TiDzBvkBbzggJ0qY3GTqZY7gh-JekkxfUbRjMltp3NjkKNKHaD0mrzbOoaHl7ROk7tE3azOkadn8TZ3XAqeXzdvJfK4CNFT7ct2dfVZAq1jVJ6mIG430ye4ro9hTjw/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2019-04-23+%25E4%25B8%258B%25E5%258D%258811.51.23.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="936" data-original-width="1600" height="374" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi04dKLiiuS_VPpV0TiDzBvkBbzggJ0qY3GTqZY7gh-JekkxfUbRjMltp3NjkKNKHaD0mrzbOoaHl7ROk7tE3azOkadn8TZ3XAqeXzdvJfK4CNFT7ct2dfVZAq1jVJ6mIG430ye4ro9hTjw/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2019-04-23+%25E4%25B8%258B%25E5%258D%258811.51.23.png" width="640" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
把USER_SERVICE_UUID改成剛才得到的UUID<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTNM6l9hbdRyPpaSrjSjV6Sn_EtAA04HvA7HcVa7fQ1OBsLyZXZpwcmFMNI-A9qIkJ5rXEB1tCk7ZVn5Epd-4QssoSPNnrHBkC-D_pmhfWlUfggW4guMlLjBk5NRtvhwjKlLpujZyVBn4I/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2019-04-23+%25E4%25B8%258B%25E5%258D%258811.52.07.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="790" data-original-width="1600" height="316" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTNM6l9hbdRyPpaSrjSjV6Sn_EtAA04HvA7HcVa7fQ1OBsLyZXZpwcmFMNI-A9qIkJ5rXEB1tCk7ZVn5Epd-4QssoSPNnrHBkC-D_pmhfWlUfggW4guMlLjBk5NRtvhwjKlLpujZyVBn4I/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2019-04-23+%25E4%25B8%258B%25E5%258D%258811.52.07.png" width="640" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTNM6l9hbdRyPpaSrjSjV6Sn_EtAA04HvA7HcVa7fQ1OBsLyZXZpwcmFMNI-A9qIkJ5rXEB1tCk7ZVn5Epd-4QssoSPNnrHBkC-D_pmhfWlUfggW4guMlLjBk5NRtvhwjKlLpujZyVBn4I/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2019-04-23+%25E4%25B8%258B%25E5%258D%258811.52.07.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br /></a></div>
<div class="separator" style="clear: both; text-align: left;">
接下來拉到最下方按Commit存檔</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAZsle0Afw7jcSN8f5pmXfJd5NXcnFdpzLbDxkmg9Io6DLgYu-rQXiZ5Xutw70SIkkwDNmmsI4Jqf5tZTpF_CbXQqoZXyZxgcCRfxgaAP4MZ-EOM137HdjdhdzortURv6WxA_Sw3z0OEDH/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2019-04-23+%25E4%25B8%258B%25E5%258D%258811.54.19.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="649" data-original-width="1600" height="258" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAZsle0Afw7jcSN8f5pmXfJd5NXcnFdpzLbDxkmg9Io6DLgYu-rQXiZ5Xutw70SIkkwDNmmsI4Jqf5tZTpF_CbXQqoZXyZxgcCRfxgaAP4MZ-EOM137HdjdhdzortURv6WxA_Sw3z0OEDH/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2019-04-23+%25E4%25B8%258B%25E5%258D%258811.54.19.png" width="640" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAZsle0Afw7jcSN8f5pmXfJd5NXcnFdpzLbDxkmg9Io6DLgYu-rQXiZ5Xutw70SIkkwDNmmsI4Jqf5tZTpF_CbXQqoZXyZxgcCRfxgaAP4MZ-EOM137HdjdhdzortURv6WxA_Sw3z0OEDH/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2019-04-23+%25E4%25B8%258B%25E5%258D%258811.54.19.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br /></a></div>
<div class="separator" style="clear: both; text-align: left;">
7.在此以ESP32示範,官方的範例中亦支援nrf52 / Micro:bit等開發版的範例程式。</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
開啟Arduino,點擊<span style="background-color: white; color: #24292e; font-family: -apple-system, system-ui, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; font-size: 16px; font-weight: 600;">Preferences,加入額外的開發版網址</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="background-color: rgba(27, 31, 35, 0.05); color: #24292e; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.6px;">https://dl.espressif.com/dl/package_esp32_index.json</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="background-color: rgba(27, 31, 35, 0.05); color: #24292e; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.6px;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjDt-f9_crJCMzs7ZIX5XO5zDpy49x6x6cGbIcJP3hw_OSAsTDn3QkFiqaUziLjC9mOYDcWGgZLdsFzLIepY3SKW7f1HsNsRA2y7QAPkhVgoRp5GrHPS383ct0-LGvBMw6t5gK9WJOlA3Kp/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2019-04-23+%25E4%25B8%258B%25E5%258D%258811.58.14.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="78" data-original-width="1410" height="34" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjDt-f9_crJCMzs7ZIX5XO5zDpy49x6x6cGbIcJP3hw_OSAsTDn3QkFiqaUziLjC9mOYDcWGgZLdsFzLIepY3SKW7f1HsNsRA2y7QAPkhVgoRp5GrHPS383ct0-LGvBMw6t5gK9WJOlA3Kp/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2019-04-23+%25E4%25B8%258B%25E5%258D%258811.58.14.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="background-color: rgba(27, 31, 35, 0.05); color: #24292e; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.6px;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="background-color: white; color: #24292e; font-family: -apple-system, system-ui, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; font-size: 16px; font-weight: 600;">接下來到版子管理員,搜尋ESP32並安裝</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzB3pnOAFp_8xUihr9ozhvgWx7vMMige1ug00AEn65JoLWp9BswNlq9N3nko-BW-QJsqyaYq8zbnu0MU_uvZIGLMt7egeBJE1um8HXdJ2UMVbZyJyENfC9HgbTVvdStaI5zw0mIvSvvqmq/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2019-04-23+%25E4%25B8%258B%25E5%258D%258811.59.35.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="873" data-original-width="1600" height="348" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzB3pnOAFp_8xUihr9ozhvgWx7vMMige1ug00AEn65JoLWp9BswNlq9N3nko-BW-QJsqyaYq8zbnu0MU_uvZIGLMt7egeBJE1um8HXdJ2UMVbZyJyENfC9HgbTVvdStaI5zw0mIvSvvqmq/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2019-04-23+%25E4%25B8%258B%25E5%258D%258811.59.35.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="color: #24292e; font-family: -apple-system, system-ui, Segoe UI, Helvetica, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol;"><span style="background-color: white;"><b>裝官方的Sample Code 貼到一個Arduino IDE中 ,並修改</b></span><b>USER_SERVICE_UUID</b></span></div>
<div class="separator" style="clear: both; text-align: left;">
<a href="https://github.com/line/line-things-starter/tree/master/esp32/arduino/sample">https://github.com/line/line-things-starter/tree/master/esp32/arduino/sample</a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiFuPU7qIjMXxNn-j3zcmDxd26cUNXDc-mJOd7HSxKp-96-m21GmJ7Qe2iW0Cq4m2Ms2htVM1mjq4KvltCGn_7B12N6Kc7ZUzNePeXs7BxBAyKQo31s4BNbMSEE0yVyB62p8fn30mqVp984/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2019-04-24+%25E4%25B8%258A%25E5%258D%258812.01.52.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="1166" data-original-width="988" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiFuPU7qIjMXxNn-j3zcmDxd26cUNXDc-mJOd7HSxKp-96-m21GmJ7Qe2iW0Cq4m2Ms2htVM1mjq4KvltCGn_7B12N6Kc7ZUzNePeXs7BxBAyKQo31s4BNbMSEE0yVyB62p8fn30mqVp984/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2019-04-24+%25E4%25B8%258A%25E5%258D%258812.01.52.png" width="542" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
我用的版子是這一塊 ESP32 Bit Kit , 版子上有LED及Button , 腳位和程式碼中相同。<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgKq1NGpyert4SGS4qE1Zls287x8_-W_cgnoQcZnCqcdhM2nfuA_-N6hxbOD1-o_P-FKwXBz-HLSC6Dml9VcrmeVErBbjWs8yRcL6v-PLjLQPvqkxbb80DXY0nUcrlsLmEtdabNxY_FWAX-/s1600/IMG_0383.HEIC" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="1200" data-original-width="1600" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgKq1NGpyert4SGS4qE1Zls287x8_-W_cgnoQcZnCqcdhM2nfuA_-N6hxbOD1-o_P-FKwXBz-HLSC6Dml9VcrmeVErBbjWs8yRcL6v-PLjLQPvqkxbb80DXY0nUcrlsLmEtdabNxY_FWAX-/s640/IMG_0383.HEIC" width="640" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
選擇開發版為ESP32 Dev Module ,注意一下您的序列埠設定可能與我不同。<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhH36Bkg_6RQDsHSVnS4WM7gleYdZbL-fzkdtSAMtiqojWSAHLk1HILr8UCWHtClHtRdqlc43etNcvWInlg3vRU4YmCXj-NkrJW3WhxkzbI-d3RUKNKom1TcBKupwZlVldZPOcTBCJiWpGu/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2019-04-24+%25E4%25B8%258A%25E5%258D%258812.06.57.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="1002" data-original-width="1600" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhH36Bkg_6RQDsHSVnS4WM7gleYdZbL-fzkdtSAMtiqojWSAHLk1HILr8UCWHtClHtRdqlc43etNcvWInlg3vRU4YmCXj-NkrJW3WhxkzbI-d3RUKNKom1TcBKupwZlVldZPOcTBCJiWpGu/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2019-04-24+%25E4%25B8%258A%25E5%258D%258812.06.57.png" width="640" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
沒問題的上請上傳程式碼到ESP32,大概要1~2分鐘。<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhcbSj2tRaEUkhFwGgBr8gVItsZR7U7CbBux-p88J-hnpoG1v2s-FH7cPz3OIC8qqytoWC_nPzX87dcE3ZM3VdcMRfeJwjwNPw-_sEz8M_DED8g4C6zhLjVnUFBuQI9Tg46sQl5tkYyxd-3/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2019-04-24+%25E4%25B8%258A%25E5%258D%258812.08.45.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="1216" data-original-width="980" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhcbSj2tRaEUkhFwGgBr8gVItsZR7U7CbBux-p88J-hnpoG1v2s-FH7cPz3OIC8qqytoWC_nPzX87dcE3ZM3VdcMRfeJwjwNPw-_sEz8M_DED8g4C6zhLjVnUFBuQI9Tg46sQl5tkYyxd-3/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2019-04-24+%25E4%25B8%258A%25E5%258D%258812.08.45.png" width="514" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
8.用手機掃描這個QR Code 開啟Line Things ,第一次開啟要同意資料存取。<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihlNbW8v_cVDl0Ta9TaiAk5aWNboD3vEC7xk4K121g3YPAX4sbUljFzXw6OhFYGuLWsAf_emQxkN3Old-LBEsKSD_lOnXtseaW9DgiCvfGkq6MPzQBnsjjli08hG3E4Vk2SZyGbdy15_UA/s1600/68747470733a2f2f646576656c6f706572732e6c696e652e62697a2f6d656469612f6c696e652d7468696e67732f71725f636f64652d33313166333530332e706e67.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="300" data-original-width="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihlNbW8v_cVDl0Ta9TaiAk5aWNboD3vEC7xk4K121g3YPAX4sbUljFzXw6OhFYGuLWsAf_emQxkN3Old-LBEsKSD_lOnXtseaW9DgiCvfGkq6MPzQBnsjjli08hG3E4Vk2SZyGbdy15_UA/s1600/68747470733a2f2f646576656c6f706572732e6c696e652e62697a2f6d656469612f6c696e652d7468696e67732f71725f636f64652d33313166333530332e706e67.png" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
接下來你就可以看到畫面上有你的LIFF APP名字<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsUZsBSEDrAQt71QhcN802dZI5082MEHZsiVN3lbPpGM0aUCrqCrqiLOmIQobImrOmFTFpiGDpB3iC98O61oCieH0ssmhquUE8XltF9pqmYxAaf9Vpx6gWFwSOk8yrUoHUdVOI_-_MIKa1/s1600/IMG_0386.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="900" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsUZsBSEDrAQt71QhcN802dZI5082MEHZsiVN3lbPpGM0aUCrqCrqiLOmIQobImrOmFTFpiGDpB3iC98O61oCieH0ssmhquUE8XltF9pqmYxAaf9Vpx6gWFwSOk8yrUoHUdVOI_-_MIKa1/s640/IMG_0386.PNG" width="360" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
允許配對藍芽(iphone)</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvxVY74byEhYM6L_eZ9-k8kaHWYI8kSjKJXQ8ZE7D-teoiAnxXXa28BZLwA-CgDinksxhUcfnYs4VB1WLzfEZbyldb16aQioM1R9pTnCsI7rbk5C_dkGW7qJmEjEZAEnXwyStn999Cwz7U/s1600/IMG_0387.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="900" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvxVY74byEhYM6L_eZ9-k8kaHWYI8kSjKJXQ8ZE7D-teoiAnxXXa28BZLwA-CgDinksxhUcfnYs4VB1WLzfEZbyldb16aQioM1R9pTnCsI7rbk5C_dkGW7qJmEjEZAEnXwyStn999Cwz7U/s640/IMG_0387.PNG" width="360" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvxVY74byEhYM6L_eZ9-k8kaHWYI8kSjKJXQ8ZE7D-teoiAnxXXa28BZLwA-CgDinksxhUcfnYs4VB1WLzfEZbyldb16aQioM1R9pTnCsI7rbk5C_dkGW7qJmEjEZAEnXwyStn999Cwz7U/s1600/IMG_0387.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br /></a></div>
<div class="separator" style="clear: both; text-align: left;">
連線裝置成功。</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjBdA2WqUQHGa16X6sUYBvewWi16S_VxYzx7yNXvxs1ex-e077_pzE5HeicZZqbYOQUB9bl_UeAYH9Urf4E23bbfTVx3bzlEBEmXlc9OAd2A2vOUbCjI_pGAcqZywcV0iaD0RhETmFzTyJw/s1600/IMG_0389.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="902" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjBdA2WqUQHGa16X6sUYBvewWi16S_VxYzx7yNXvxs1ex-e077_pzE5HeicZZqbYOQUB9bl_UeAYH9Urf4E23bbfTVx3bzlEBEmXlc9OAd2A2vOUbCjI_pGAcqZywcV0iaD0RhETmFzTyJw/s640/IMG_0389.jpg" width="360" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
至於為什麼頁面只有半面呢?這是剛才的選項中選擇了Compact,選擇FULL的話會是整頁。</div>
<div class="separator" style="clear: both; text-align: left;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgM0eDDS3NS88-xaZSBFL9pEY4drq4jv03OE9rjOUcFYMhu1ORFNtswI1ZeIGw0j8KgkWmVEnCAhAyRXoK6snNQ2Aezw0w1VkAKT-YVWKmfOzVGjte-XWQlptrjhd4jxD5eluC4NMUn22F7/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2019-04-23+%25E4%25B8%258B%25E5%258D%258811.30.58.png" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-right: 1em; text-align: center;"><img border="0" data-original-height="1276" data-original-width="1572" height="518" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgM0eDDS3NS88-xaZSBFL9pEY4drq4jv03OE9rjOUcFYMhu1ORFNtswI1ZeIGw0j8KgkWmVEnCAhAyRXoK6snNQ2Aezw0w1VkAKT-YVWKmfOzVGjte-XWQlptrjhd4jxD5eluC4NMUn22F7/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2019-04-23+%25E4%25B8%258B%25E5%258D%258811.30.58.png" width="640" /></a></div>
<br />
接下來點一下Switch LED ON , 畫面呈現如下,此時ESP32上的LED也亮起來了<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-UUtY0hek0UyrfiJndAIcIvKy1QIRmr8qjBnH-oJwfY-Jtz7_h5_TaipKqGEeL09igYo6tKVcq9VlRNh-skd7w9NAc90aHKqevEuEaLEyk7ifv9os7zwbmLYLBfnTTwdvy4xbPyYfhqWI/s1600/IMG_0390.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="900" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-UUtY0hek0UyrfiJndAIcIvKy1QIRmr8qjBnH-oJwfY-Jtz7_h5_TaipKqGEeL09igYo6tKVcq9VlRNh-skd7w9NAc90aHKqevEuEaLEyk7ifv9os7zwbmLYLBfnTTwdvy4xbPyYfhqWI/s640/IMG_0390.PNG" width="360" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-UUtY0hek0UyrfiJndAIcIvKy1QIRmr8qjBnH-oJwfY-Jtz7_h5_TaipKqGEeL09igYo6tKVcq9VlRNh-skd7w9NAc90aHKqevEuEaLEyk7ifv9os7zwbmLYLBfnTTwdvy4xbPyYfhqWI/s1600/IMG_0390.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKEhodaTz7g3yh8pOyWYR21TdfGr3YXIHcBdgEed7xBmB5h5XWiuEp6r7-lrAa3IMHKoAyazPzOJXslhCH57rd2yjW6gdvgcJPDkYS07PZZ5p8RzxOFixTZCCw2upykK2yXyxt_xL6OMni/s1600/IMG_0392.HEIC" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="1200" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKEhodaTz7g3yh8pOyWYR21TdfGr3YXIHcBdgEed7xBmB5h5XWiuEp6r7-lrAa3IMHKoAyazPzOJXslhCH57rd2yjW6gdvgcJPDkYS07PZZ5p8RzxOFixTZCCw2upykK2yXyxt_xL6OMni/s640/IMG_0392.HEIC" width="480" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKEhodaTz7g3yh8pOyWYR21TdfGr3YXIHcBdgEed7xBmB5h5XWiuEp6r7-lrAa3IMHKoAyazPzOJXslhCH57rd2yjW6gdvgcJPDkYS07PZZ5p8RzxOFixTZCCw2upykK2yXyxt_xL6OMni/s1600/IMG_0392.HEIC" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div style="text-align: left;">
按幾下右邊的按鈕(左邊的是重置,不要按到),你會發現Click Count累進了。</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTPLR3mJ9U5mWu4PZz0_uMZzVN9r06dAFPgKNWsxoe4yuKpzk5QLZbWWk7M3PS7lpcrESQlb5VMqSO6edNqaBQyFbwlBsy8gmne7udRLqFHpnNCdmKLTraaA36SQ6LaGnfjpqTtK809iPN/s1600/IMG_0391.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="900" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTPLR3mJ9U5mWu4PZz0_uMZzVN9r06dAFPgKNWsxoe4yuKpzk5QLZbWWk7M3PS7lpcrESQlb5VMqSO6edNqaBQyFbwlBsy8gmne7udRLqFHpnNCdmKLTraaA36SQ6LaGnfjpqTtK809iPN/s640/IMG_0391.PNG" width="360" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTPLR3mJ9U5mWu4PZz0_uMZzVN9r06dAFPgKNWsxoe4yuKpzk5QLZbWWk7M3PS7lpcrESQlb5VMqSO6edNqaBQyFbwlBsy8gmne7udRLqFHpnNCdmKLTraaA36SQ6LaGnfjpqTtK809iPN/s1600/IMG_0391.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div style="text-align: left;">
當你按下ESP32上的按鍵不放時,Button State也會變成Pressed</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6YWf5G-6wi_gMhT1NXhdlSJbXNZ1RlyBDVfLb9ZAmIzTwpPs6BcNuCvKsNNSh-vHTxyqtCSzY4x4cAnpYNK1e-bco4p9S6HZ_qVlZgdJ2VQ1qyNzNAdgOw1Ke7s1pzXRoPlv_Lcli-4zZ/s1600/IMG_38734C17A807-1.jpeg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="900" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6YWf5G-6wi_gMhT1NXhdlSJbXNZ1RlyBDVfLb9ZAmIzTwpPs6BcNuCvKsNNSh-vHTxyqtCSzY4x4cAnpYNK1e-bco4p9S6HZ_qVlZgdJ2VQ1qyNzNAdgOw1Ke7s1pzXRoPlv_Lcli-4zZ/s640/IMG_38734C17A807-1.jpeg" width="360" /></a></div>
<div style="text-align: left;">
<br /></div>
<br />
<div style="text-align: left;">
<br /></div>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKEhodaTz7g3yh8pOyWYR21TdfGr3YXIHcBdgEed7xBmB5h5XWiuEp6r7-lrAa3IMHKoAyazPzOJXslhCH57rd2yjW6gdvgcJPDkYS07PZZ5p8RzxOFixTZCCw2upykK2yXyxt_xL6OMni/s1600/IMG_0392.HEIC" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKEhodaTz7g3yh8pOyWYR21TdfGr3YXIHcBdgEed7xBmB5h5XWiuEp6r7-lrAa3IMHKoAyazPzOJXslhCH57rd2yjW6gdvgcJPDkYS07PZZ5p8RzxOFixTZCCw2upykK2yXyxt_xL6OMni/s1600/IMG_0392.HEIC" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br /></a><br /><br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-UUtY0hek0UyrfiJndAIcIvKy1QIRmr8qjBnH-oJwfY-Jtz7_h5_TaipKqGEeL09igYo6tKVcq9VlRNh-skd7w9NAc90aHKqevEuEaLEyk7ifv9os7zwbmLYLBfnTTwdvy4xbPyYfhqWI/s1600/IMG_0390.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br /></a><br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
以上是初次玩Line Things心得,如果我們把LIFF APP Size改成Tall及Full, 則如下<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgU-UaMF37kiqqz3jC0PD9dXfJmGqpaOmi00oVSstMtzWcLv0agUkO-ljked_b-0jxSH1HYLNM02hF9CbV54uv_RqyAbC_fUS3xIuc37c4-wB9Ewkq8cJ6K9W2Zu11uugP5kkiDuB0fkBKh/s1600/IMG_0395.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="900" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgU-UaMF37kiqqz3jC0PD9dXfJmGqpaOmi00oVSstMtzWcLv0agUkO-ljked_b-0jxSH1HYLNM02hF9CbV54uv_RqyAbC_fUS3xIuc37c4-wB9Ewkq8cJ6K9W2Zu11uugP5kkiDuB0fkBKh/s640/IMG_0395.PNG" width="360" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiwJK-6Nkn9QfxmLiS2Krvmf9m107qSRS8YCRPnsdRXJnxO0w4a3VIxoLukf0fucoKVuRo1uPcWWNBUlg1EX51rFnw9SIycvlER9oM2oOLVDfTWmR0zwvA2_08n0LUOywhuQOLFvzw8szX2/s1600/IMG_0394.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="900" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiwJK-6Nkn9QfxmLiS2Krvmf9m107qSRS8YCRPnsdRXJnxO0w4a3VIxoLukf0fucoKVuRo1uPcWWNBUlg1EX51rFnw9SIycvlER9oM2oOLVDfTWmR0zwvA2_08n0LUOywhuQOLFvzw8szX2/s640/IMG_0394.PNG" width="360" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiwJK-6Nkn9QfxmLiS2Krvmf9m107qSRS8YCRPnsdRXJnxO0w4a3VIxoLukf0fucoKVuRo1uPcWWNBUlg1EX51rFnw9SIycvlER9oM2oOLVDfTWmR0zwvA2_08n0LUOywhuQOLFvzw8szX2/s1600/IMG_0394.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div style="text-align: left;">
Line Things目前還比較麻煩,取得UUID必須靠注冊,每次註冊取得的UUID會不同。</div>
<div style="text-align: left;">
即使你使用同一組Token,這點要稍微注意一下。</div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
參考資料:</div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<a href="https://blog.dg-space.com/2019/01/line-things-iot.html">https://blog.dg-space.com/2019/01/line-things-iot.html</a></div>
<div style="text-align: left;">
<a href="https://github.com/line/line-things-starter">https://github.com/line/line-things-starter</a></div>
<br /><br />
<br />
<br />金石微開http://www.blogger.com/profile/13160756791496033950noreply@blogger.com0tag:blogger.com,1999:blog-2933755125431570931.post-73866841595366357822019-04-19T13:41:00.001+08:002019-04-19T13:41:21.693+08:00[Android] TextView 中顯示不同字體大小效果如下<br />
<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuwYKeVKY17VCkPSIJsS34Atjv3qI1U1vQoE5HLGEX4Q6K49qWgbFPlZK97sZGV-wl8LGYy6qWLl9unrPlKSa2mCm7QeO4te1BiNhPe6XTzgjuWwRrfjt_xBrjkcSyBQqIYkUrNdex0-n_/s1600/device-2018-02-26-231356.png" imageanchor="1"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuwYKeVKY17VCkPSIJsS34Atjv3qI1U1vQoE5HLGEX4Q6K49qWgbFPlZK97sZGV-wl8LGYy6qWLl9unrPlKSa2mCm7QeO4te1BiNhPe6XTzgjuWwRrfjt_xBrjkcSyBQqIYkUrNdex0-n_/s640/device-2018-02-26-231356.png" width="360" /></a><br />
這時就要透過<b>Spannable</b> 來做對應的處理<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;">TextView textView<span style="color: #333333;">=(</span>TextView<span style="color: #333333;">)</span>findViewById<span style="color: #333333;">(</span>R<span style="color: #333333;">.</span><span style="color: #0000cc;">id</span><span style="color: #333333;">.</span><span style="color: #0000cc;">txt</span><span style="color: #333333;">);</span>
String str<span style="color: #333333;">=</span><span style="background-color: #fff0f0;">"您今天已經寫了100行書法"</span><span style="color: #333333;">;</span>
<span style="color: #888888;">//找到數字1的位置</span>
<span style="color: #333399; font-weight: bold;">int</span> startIndex <span style="color: #333333;">=</span> str<span style="color: #333333;">.</span><span style="color: #0000cc;">indexOf</span><span style="color: #333333;">(</span><span style="color: #0044dd;">'1'</span><span style="color: #333333;">);</span>
<span style="color: #888888;">//數字只有3個所以是startIndex+2</span>
<span style="color: #333399; font-weight: bold;">int</span> endIndex <span style="color: #333333;">=</span> startIndex<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">;</span>
<span style="color: #888888;">//初始化Spannable</span>
Spannable textSpan <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> SpannableStringBuilder<span style="color: #333333;">(</span>str<span style="color: #333333;">);</span>
<span style="color: #888888;">//將數字1之前的字串,字體大小設為28 像素</span>
textSpan<span style="color: #333333;">.</span><span style="color: #0000cc;">setSpan</span><span style="color: #333333;">(</span><span style="color: #008800; font-weight: bold;">new</span> AbsoluteSizeSpan<span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">28</span><span style="color: #333333;">),</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> startIndex<span style="color: #333333;">,</span> Spannable<span style="color: #333333;">.</span><span style="color: #0000cc;">SPAN_INCLUSIVE_INCLUSIVE</span><span style="color: #333333;">);</span>
<span style="color: #888888;">//將數字100字體大小設為45 像素</span>
textSpan<span style="color: #333333;">.</span><span style="color: #0000cc;">setSpan</span><span style="color: #333333;">(</span><span style="color: #008800; font-weight: bold;">new</span> AbsoluteSizeSpan<span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">45</span><span style="color: #333333;">),</span> startIndex<span style="color: #333333;">,</span> endIndex<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">1</span> <span style="color: #333333;">,</span> Spannable<span style="color: #333333;">.</span><span style="color: #0000cc;">SPAN_INCLUSIVE_INCLUSIVE</span><span style="color: #333333;">);</span>
<span style="color: #888888;">//將100之後的內容字體大小設為28像素</span>
textSpan<span style="color: #333333;">.</span><span style="color: #0000cc;">setSpan</span><span style="color: #333333;">(</span><span style="color: #008800; font-weight: bold;">new</span> AbsoluteSizeSpan<span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">28</span><span style="color: #333333;">),</span> endIndex<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">1</span> <span style="color: #333333;">,</span> str<span style="color: #333333;">.</span><span style="color: #0000cc;">length</span><span style="color: #333333;">(),</span> Spannable<span style="color: #333333;">.</span><span style="color: #0000cc;">SPAN_INCLUSIVE_INCLUSIVE</span><span style="color: #333333;">);</span>
<span style="color: #888888;">//將Spannable設定給TextView</span>
textView<span style="color: #333333;">.</span><span style="color: #0000cc;">setText</span><span style="color: #333333;">(</span>textSpan<span style="color: #333333;">);</span>
</pre>
</div>
<br />
<div>
若要使用dip做為單位,則可以改成如下<br />
<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;">TextView textView<span style="color: #333333;">=(</span>TextView<span style="color: #333333;">)</span>findViewById<span style="color: #333333;">(</span>R<span style="color: #333333;">.</span><span style="color: #0000cc;">id</span><span style="color: #333333;">.</span><span style="color: #0000cc;">txt</span><span style="color: #333333;">);</span>
String str<span style="color: #333333;">=</span><span style="background-color: #fff0f0;">"您今天已經寫了100行書法"</span><span style="color: #333333;">;</span>
<span style="color: #888888;">//找到數字1的位置</span>
<span style="color: #333399; font-weight: bold;">int</span> startIndex <span style="color: #333333;">=</span> str<span style="color: #333333;">.</span><span style="color: #0000cc;">indexOf</span><span style="color: #333333;">(</span><span style="color: #0044dd;">'1'</span><span style="color: #333333;">);</span>
<span style="color: #888888;">//數字只有3個所以是startIndex+2</span>
<span style="color: #333399; font-weight: bold;">int</span> endIndex <span style="color: #333333;">=</span> startIndex<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">;</span>
<span style="color: #888888;">//初始化Spannable</span>
Spannable textSpan <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> SpannableStringBuilder<span style="color: #333333;">(</span>str<span style="color: #333333;">);</span>
<span style="color: #888888;">//將數字1之前的字串,字體大小設為28</span>
textSpan<span style="color: #333333;">.</span><span style="color: #0000cc;">setSpan</span><span style="color: #333333;">(</span><span style="color: #008800; font-weight: bold;">new</span> AbsoluteSizeSpan<span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">28</span><span style="color: #333333;">,</span><span style="color: #008800; font-weight: bold;">true</span><span style="color: #333333;">),</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> startIndex<span style="color: #333333;">,</span> Spannable<span style="color: #333333;">.</span><span style="color: #0000cc;">SPAN_INCLUSIVE_INCLUSIVE</span><span style="color: #333333;">);</span>
<span style="color: #888888;">//將數字100字體大小設為45</span>
textSpan<span style="color: #333333;">.</span><span style="color: #0000cc;">setSpan</span><span style="color: #333333;">(</span><span style="color: #008800; font-weight: bold;">new</span> AbsoluteSizeSpan<span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">45</span><span style="color: #333333;">,</span><span style="color: #008800; font-weight: bold;">true</span><span style="color: #333333;">),</span> startIndex<span style="color: #333333;">,</span> endIndex<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">1</span> <span style="color: #333333;">,</span> Spannable<span style="color: #333333;">.</span><span style="color: #0000cc;">SPAN_INCLUSIVE_INCLUSIVE</span><span style="color: #333333;">);</span>
<span style="color: #888888;">//將100之後的內容字體大小設為28</span>
textSpan<span style="color: #333333;">.</span><span style="color: #0000cc;">setSpan</span><span style="color: #333333;">(</span><span style="color: #008800; font-weight: bold;">new</span> AbsoluteSizeSpan<span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">28</span><span style="color: #333333;">,</span><span style="color: #008800; font-weight: bold;">true</span><span style="color: #333333;">),</span> endIndex<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">1</span> <span style="color: #333333;">,</span> str<span style="color: #333333;">.</span><span style="color: #0000cc;">length</span><span style="color: #333333;">(),</span> Spannable<span style="color: #333333;">.</span><span style="color: #0000cc;">SPAN_INCLUSIVE_INCLUSIVE</span><span style="color: #333333;">);</span>
<span style="color: #888888;">//將Spannable設定給TextView</span>
textView<span style="color: #333333;">.</span><span style="color: #0000cc;">setText</span><span style="color: #333333;">(</span>textSpan<span style="color: #333333;">);</span>
</pre>
</div>
<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJEri1LdUXUU3KALovf6dEOeHlhR69Tl0s6k64GvtDy288VixxQpn9dbkaDsaWQHO8ysujRrPC3YaAHpxt9FyTTGI9AnTskRx1eUEnchVXIZiDhcnTRdAQwLQ96tCkky1ws9YNuAbyqPkt/s1600/device-2018-02-26-231955.png" imageanchor="1"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJEri1LdUXUU3KALovf6dEOeHlhR69Tl0s6k64GvtDy288VixxQpn9dbkaDsaWQHO8ysujRrPC3YaAHpxt9FyTTGI9AnTskRx1eUEnchVXIZiDhcnTRdAQwLQ96tCkky1ws9YNuAbyqPkt/s640/device-2018-02-26-231955.png" width="360" /></a><br />
<br /></div>
<div>
以下有針對幾個範圍的設定值做出解釋,但試起來還是有點怪怪的,多包函。</div>
<br />
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE<br />
<div>
不包含StartIndex及EndIndex</div>
<div>
<span style="background-color: #f7f7f7; color: rgba(0 , 0 , 0 , 0.68); font-family: "roboto" , sans-serif; font-size: 14px;">Spans of type SPAN_EXCLUSIVE_EXCLUSIVE do not expand to include text inserted at either their starting or ending point.</span></div>
<div>
<br /></div>
<div>
Spanned.SPAN_EXCLUSIVE_INCLUSIVE</div>
<div>
不包含startIndex , 但包含endIndex</div>
<div>
<span style="background-color: #f7f7f7; color: rgba(0 , 0 , 0 , 0.68); font-family: "roboto" , sans-serif; font-size: 14px;">Non-0-length spans of type SPAN_EXCLUSIVE_INCLUSIVE expand to include text inserted at their ending point but not at their starting point.</span></div>
<div>
<br />
Spanned.SPAN_INCLUSIVE_EXCLUSIVE</div>
<div>
包含startIndex 但不包含endIndex</div>
<div>
<table class="responsive constants" id="constants" style="background-color: #f7f7f7; border-collapse: collapse; border-spacing: 0px; border: 0px; color: rgba(0, 0, 0, 0.68); font-family: Roboto, sans-serif; font-size: 14px; margin: 0.5em 1em 1em 0px; width: 939px;"><tbody>
<tr class="api apilevel-1" data-version-added="1"><td style="background-color: inherit; border: 1px solid rgb(221, 221, 221); padding: 4px 12px; vertical-align: top;" width="100%">Non-0-length spans of type SPAN_INCLUSIVE_EXCLUSIVE expand to include text inserted at their starting point but not at their ending point.</td></tr>
<tr class="api apilevel-1" data-version-added="1"></tr>
</tbody></table>
</div>
<div>
<br />
Spanned.SPAN_INCLUSIVE_INCLUSIVE</div>
<div>
包含startIndex及endIndex</div>
<div>
<span style="background-color: #f7f7f7; color: rgba(0 , 0 , 0 , 0.68); font-family: "roboto" , sans-serif; font-size: 14px;">Spans of type SPAN_INCLUSIVE_INCLUSIVE expand to include text inserted at either their starting or ending point.</span></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
金石微開http://www.blogger.com/profile/13160756791496033950noreply@blogger.com0tag:blogger.com,1999:blog-2933755125431570931.post-53387877666142733552018-12-17T00:07:00.004+08:002018-12-17T00:07:38.618+08:00[Android] 時間會倒流 ...Orz最近遇到QC單位跑來說在把手機時間往前調幾小時後,APP失效了,調整前是OK的。<br />
<br />
發生問題的程式碼大致上如下<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #333399; font-weight: bold;">long</span> lastTime<span style="color: #333333;">=</span><span style="color: #0000dd; font-weight: bold;">0</span> <span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">long</span> now<span style="color: #333333;">=</span><span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">myFun</span><span style="color: #333333;">()</span>
<span style="color: #333333;">{</span>
now<span style="color: #333333;">=</span>System<span style="color: #333333;">.</span><span style="color: #0000cc;">currentTimeMillis</span><span style="color: #333333;">();</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>now<span style="color: #333333;">-</span>lastTime<span style="color: #333333;">></span><span style="color: #0000dd; font-weight: bold;">500</span><span style="color: #333333;">)</span>
<span style="color: #333333;">{</span>
<span style="color: #888888;">//do something</span>
lastTime<span style="color: #333333;">=</span>now<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
</pre>
</div>
<br />
當QC單位的人操作過一次後last=now 之後,System<span style="color: #333333;">.</span><span style="color: #0000cc;">currentTimeMillis</span><span style="color: #333333;">() 會取出相對於1970/1/1 以來的亳秒,但此時將時間往前幾個小時之後,在這幾個小時內now將持續小於lastTime,因此不會有任何反應。</span><br />
<span style="color: #333333;"><br /></span>
<span style="color: #333333;">解決方式是使用絕對值來計算二者時間。</span><br />
<span style="color: #333333;"><br /></span>
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #333399; font-weight: bold;">long</span> lastTime<span style="color: #333333;">=</span><span style="color: #0000dd; font-weight: bold;">0</span> <span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">long</span> now<span style="color: #333333;">=</span><span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">myFun</span><span style="color: #333333;">()</span>
<span style="color: #333333;">{</span>
now<span style="color: #333333;">=</span>System<span style="color: #333333;">.</span><span style="color: #0000cc;">currentTimeMillis</span><span style="color: #333333;">();</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>Math<span style="color: #333333;">.</span><span style="color: #0000cc;">abs</span><span style="color: #333333;">(</span>now<span style="color: #333333;">-</span>lasttime<span style="color: #333333;">)></span><span style="color: #0000dd; font-weight: bold;">500</span><span style="color: #333333;">)</span>
<span style="color: #333333;">{</span>
<span style="color: #888888;">//do something</span>
last<span style="color: #333333;">=</span>now<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
</pre>
</div>
<span style="color: #333333;"><br /></span>
時間不會倒流....但手機可以。金石微開http://www.blogger.com/profile/13160756791496033950noreply@blogger.com0tag:blogger.com,1999:blog-2933755125431570931.post-66420997553795976532018-11-24T21:51:00.000+08:002018-11-24T21:51:14.328+08:00[OpenWRT] 用C語言寫UART轉RS485RS-485 (EIA-485 標準) 為 RS-422 的改良版本,從原本的 10 組裝置<br />
<div>
提高至 32 組裝置,僅並定義必要的電子特性,並沒有定義傳輸介面,</div>
<div>
所以你會看到有人用普通的單芯線直接連接,或是RJ45/DMX之類的接頭</div>
<div>
來做485的傳輸,亦可以混用不同介面在同一個RS-485網路中。</div>
<div>
<br /></div>
<div>
RS485與RS232最大的不同在於它是半雙工,也就是同一時間只能傳送或是接收,RS-485網路中只有同時間有1個以上裝置在發送資料就會出現干擾,所以還會透過Modbus之類的協定來搭配實際的應用。</div>
<div>
<br /></div>
<div>
RS-485是依靠A/B二端的電壓差做為判定1或是0 ,只要A/B之間壓差大於0.2V特,</div>
<div>
即判定訊號為1,否則為0 ,RS-485可以接受的電壓範圍比較大,在-7~+12V。</div>
<div>
<br /></div>
<div>
一般的MCU若需要加入RS-485傳輸,則可以透過UART轉RS485 Chip,例如MX232/SP3485等等,透過控制DE/RE腳來控制目前為發送或接收狀態。</div>
<div>
<br /></div>
<div>
程式碼,在AR9331中測試過,DE為PIN 7 ,RE為PIN 13</div>
<div>
<span style="background-color: white; color: #333333; font-family: "arial" , "helvetica" , sans-serif; font-size: 12px;"><br /></span>
<br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #557799;">#include <stdio.h></span>
<span style="color: #557799;">#include <stdlib.h></span>
<span style="color: #557799;">#include <unistd.h></span>
<span style="color: #557799;">#include <fcntl.h></span>
<span style="color: #557799;">#include <sys/types.h></span>
<span style="color: #557799;">#include <sys/stat.h></span>
<span style="color: #557799;">#include <sys/mman.h></span>
<span style="color: #557799;">#include <string.h></span>
<span style="color: #557799;">#include <time.h></span>
<span style="color: #557799;">#include <errno.h></span>
<span style="color: #557799;">#include <termios.h></span>
<span style="color: #557799;">#define GPIO_ADDR 0x18040000 </span><span style="color: #888888;">// base address</span>
<span style="color: #557799;">#define GPIO_BLOCK 48 </span><span style="color: #888888;">// memory block size</span>
<span style="color: #333399; font-weight: bold;">char</span> <span style="color: #333333;">*</span>portname <span style="color: #333333;">=</span> <span style="background-color: #fff0f0;">"/dev/ttyATH0"</span>;
<span style="color: #008800; font-weight: bold;">volatile</span> <span style="color: #333399; font-weight: bold;">unsigned</span> <span style="color: #333399; font-weight: bold;">long</span> <span style="color: #333333;">*</span>gpioAddress;
<span style="color: #333399; font-weight: bold;">int</span> <span style="color: #0066bb; font-weight: bold;">set_interface_attribs</span> (<span style="color: #333399; font-weight: bold;">int</span> fd, <span style="color: #333399; font-weight: bold;">int</span> speed, <span style="color: #333399; font-weight: bold;">int</span> parity)
{
<span style="color: #008800; font-weight: bold;">struct</span> termios tty;
memset (<span style="color: #333333;">&</span>tty, <span style="color: #0000dd; font-weight: bold;">0</span>, <span style="color: #008800; font-weight: bold;">sizeof</span> tty);
<span style="color: #008800; font-weight: bold;">if</span> (tcgetattr (fd, <span style="color: #333333;">&</span>tty) <span style="color: #333333;">!=</span> <span style="color: #0000dd; font-weight: bold;">0</span>)
{
printf(<span style="background-color: #fff0f0;">"error %d from tcgetattr"</span>, errno);
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">1</span>;
}
cfsetospeed (<span style="color: #333333;">&</span>tty, speed);
cfsetispeed (<span style="color: #333333;">&</span>tty, speed);
tty.c_cflag <span style="color: #333333;">=</span> (tty.c_cflag <span style="color: #333333;">&</span> <span style="color: #333333;">~</span>CSIZE) <span style="color: #333333;">|</span> CS8; <span style="color: #888888;">// 8-bit chars</span>
<span style="color: #888888;">// disable IGNBRK for mismatched speed tests; otherwise receive break</span>
<span style="color: #888888;">// as \000 chars</span>
tty.c_iflag <span style="color: #333333;">&=</span> <span style="color: #333333;">~</span>IGNBRK; <span style="color: #888888;">// disable break processing</span>
tty.c_lflag <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span>; <span style="color: #888888;">// no signaling chars, no echo,</span>
<span style="color: #888888;">// no canonical processing</span>
tty.c_oflag <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span>; <span style="color: #888888;">// no remapping, no delays</span>
tty.c_cc[VMIN] <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span>; <span style="color: #888888;">// read doesn't block</span>
tty.c_cc[VTIME] <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">5</span>; <span style="color: #888888;">// 0.5 seconds read timeout</span>
tty.c_iflag <span style="color: #333333;">&=</span> <span style="color: #333333;">~</span>(IXON <span style="color: #333333;">|</span> IXOFF <span style="color: #333333;">|</span> IXANY); <span style="color: #888888;">// shut off xon/xoff ctrl</span>
tty.c_cflag <span style="color: #333333;">|=</span> (CLOCAL <span style="color: #333333;">|</span> CREAD);<span style="color: #888888;">// ignore modem controls,</span>
<span style="color: #888888;">// enable reading</span>
tty.c_cflag <span style="color: #333333;">&=</span> <span style="color: #333333;">~</span>(PARENB <span style="color: #333333;">|</span> PARODD); <span style="color: #888888;">// shut off parity</span>
tty.c_cflag <span style="color: #333333;">|=</span> parity;
tty.c_cflag <span style="color: #333333;">&=</span> <span style="color: #333333;">~</span>CSTOPB;
tty.c_cflag <span style="color: #333333;">&=</span> <span style="color: #333333;">~</span>CRTSCTS;
<span style="color: #008800; font-weight: bold;">if</span> (tcsetattr (fd, TCSANOW, <span style="color: #333333;">&</span>tty) <span style="color: #333333;">!=</span> <span style="color: #0000dd; font-weight: bold;">0</span>)
{
printf (<span style="background-color: #fff0f0;">"error %d from tcsetattr"</span>, errno);
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">1</span>;
}
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #0000dd; font-weight: bold;">0</span>;
}
<span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">set_blocking</span> (<span style="color: #333399; font-weight: bold;">int</span> fd, <span style="color: #333399; font-weight: bold;">int</span> should_block)
{
<span style="color: #008800; font-weight: bold;">struct</span> termios tty;
memset (<span style="color: #333333;">&</span>tty, <span style="color: #0000dd; font-weight: bold;">0</span>, <span style="color: #008800; font-weight: bold;">sizeof</span> tty);
<span style="color: #008800; font-weight: bold;">if</span> (tcgetattr (fd, <span style="color: #333333;">&</span>tty) <span style="color: #333333;">!=</span> <span style="color: #0000dd; font-weight: bold;">0</span>)
{
printf (<span style="background-color: #fff0f0;">"error %d from tggetattr"</span>, errno);
<span style="color: #008800; font-weight: bold;">return</span>;
}
tty.c_cc[VMIN] <span style="color: #333333;">=</span> should_block <span style="color: #333333;">?</span> <span style="color: #0000dd; font-weight: bold;">1</span> <span style="color: #333333;">:</span> <span style="color: #0000dd; font-weight: bold;">0</span>;
tty.c_cc[VTIME] <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">5</span>; <span style="color: #888888;">// 0.5 seconds read timeout</span>
<span style="color: #008800; font-weight: bold;">if</span> (tcsetattr (fd, TCSANOW, <span style="color: #333333;">&</span>tty) <span style="color: #333333;">!=</span> <span style="color: #0000dd; font-weight: bold;">0</span>)
printf (<span style="background-color: #fff0f0;">"error %d setting term attributes"</span>, errno);
}
<span style="color: #333399; font-weight: bold;">int</span> <span style="color: #0066bb; font-weight: bold;">gpioRead</span>(<span style="color: #333399; font-weight: bold;">int</span> gpio)
{
<span style="color: #333399; font-weight: bold;">unsigned</span> <span style="color: #333399; font-weight: bold;">long</span> value <span style="color: #333333;">=</span> <span style="color: #333333;">*</span>(gpioAddress <span style="color: #333333;">+</span> <span style="color: #0000dd; font-weight: bold;">1</span>);
<span style="color: #888888;">//printf("value =%d\n",value); </span>
<span style="color: #888888;">//printf("(1<<gpio) =%d",(1 << gpio));</span>
<span style="color: #008800; font-weight: bold;">return</span> (value <span style="color: #333333;">&</span> (<span style="color: #0000dd; font-weight: bold;">1</span> <span style="color: #333333;"><<</span> gpio));
}
<span style="color: #888888;">// "1" (output) or "0" (input) </span>
<span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">gpioDirection</span>(<span style="color: #333399; font-weight: bold;">int</span> gpio, <span style="color: #333399; font-weight: bold;">int</span> direction)
{
<span style="color: #333399; font-weight: bold;">unsigned</span> <span style="color: #333399; font-weight: bold;">long</span> value <span style="color: #333333;">=</span> <span style="color: #333333;">*</span>(gpioAddress <span style="color: #333333;">+</span> <span style="color: #0000dd; font-weight: bold;">0</span>); <span style="color: #888888;">// obtain current settings</span>
<span style="color: #008800; font-weight: bold;">if</span> (direction <span style="color: #333333;">==</span> <span style="color: #0000dd; font-weight: bold;">1</span>)
{
value <span style="color: #333333;">|=</span> (<span style="color: #0000dd; font-weight: bold;">1</span> <span style="color: #333333;"><<</span> gpio); <span style="color: #888888;">// set bit to 1</span>
}
<span style="color: #008800; font-weight: bold;">else</span>
{
value <span style="color: #333333;">&=</span> <span style="color: #333333;">~</span>(<span style="color: #0000dd; font-weight: bold;">1</span> <span style="color: #333333;"><<</span> gpio); <span style="color: #888888;">// clear bit</span>
}
<span style="color: #333333;">*</span>(gpioAddress <span style="color: #333333;">+</span> <span style="color: #0000dd; font-weight: bold;">0</span>) <span style="color: #333333;">=</span> value;
}
<span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">gpioSet</span>(<span style="color: #333399; font-weight: bold;">int</span> gpio, <span style="color: #333399; font-weight: bold;">int</span> data)
{
<span style="color: #333399; font-weight: bold;">unsigned</span> <span style="color: #333399; font-weight: bold;">long</span> value <span style="color: #333333;">=</span> <span style="color: #333333;">*</span>(gpioAddress <span style="color: #333333;">+</span> <span style="color: #0000dd; font-weight: bold;">2</span>); <span style="color: #888888;">// obtain current settings</span>
<span style="color: #008800; font-weight: bold;">if</span> (data <span style="color: #333333;">==</span> <span style="color: #0000dd; font-weight: bold;">1</span>)
{
value <span style="color: #333333;">|=</span> (<span style="color: #0000dd; font-weight: bold;">1</span> <span style="color: #333333;"><<</span> gpio); <span style="color: #888888;">// set bit to 1</span>
}
<span style="color: #008800; font-weight: bold;">else</span>
{
value <span style="color: #333333;">&=</span> <span style="color: #333333;">~</span>(<span style="color: #0000dd; font-weight: bold;">1</span> <span style="color: #333333;"><<</span> gpio); <span style="color: #888888;">// clear bit</span>
}
<span style="color: #333333;">*</span>(gpioAddress <span style="color: #333333;">+</span> <span style="color: #0000dd; font-weight: bold;">2</span>) <span style="color: #333333;">=</span> value;
}
<span style="color: #888888;">/*void gpioSet(int gpio, int value)</span>
<span style="color: #888888;">{</span>
<span style="color: #888888;"> if (value == 0)</span>
<span style="color: #888888;"> {</span>
<span style="color: #888888;"> *(gpioAddress + 4) = (1 << gpio);</span>
<span style="color: #888888;"> }</span>
<span style="color: #888888;"> else</span>
<span style="color: #888888;"> {</span>
<span style="color: #888888;"> *(gpioAddress + 3) = (1 << gpio);</span>
<span style="color: #888888;"> }</span>
<span style="color: #888888;">}*/</span>
<span style="color: #333399; font-weight: bold;">int</span> <span style="color: #0066bb; font-weight: bold;">gpioSetup</span>()
{
<span style="color: #333399; font-weight: bold;">int</span> m_mfd;
<span style="color: #008800; font-weight: bold;">if</span> ((m_mfd <span style="color: #333333;">=</span> open(<span style="background-color: #fff0f0;">"/dev/mem"</span>, O_RDWR)) <span style="color: #333333;"><</span> <span style="color: #0000dd; font-weight: bold;">0</span>)
{
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">1</span>;
}
gpioAddress <span style="color: #333333;">=</span> (<span style="color: #333399; font-weight: bold;">unsigned</span> <span style="color: #333399; font-weight: bold;">long</span><span style="color: #333333;">*</span>)mmap(<span style="color: #007020;">NULL</span>, GPIO_BLOCK, PROT_READ<span style="color: #333333;">|</span>PROT_WRITE, MAP_SHARED, m_mfd, GPIO_ADDR);
close(m_mfd);
<span style="color: #008800; font-weight: bold;">if</span> (gpioAddress <span style="color: #333333;">==</span> MAP_FAILED)
{
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">2</span>;
}
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #0000dd; font-weight: bold;">0</span>;
}
<span style="color: #333399; font-weight: bold;">int</span> <span style="color: #0066bb; font-weight: bold;">main</span>(<span style="color: #333399; font-weight: bold;">int</span> argc, <span style="color: #333399; font-weight: bold;">char</span> <span style="color: #333333;">**</span>argv)
{
<span style="color: #333399; font-weight: bold;">int</span> rs485_de<span style="color: #333333;">=</span><span style="color: #0000dd; font-weight: bold;">7</span>;
<span style="color: #333399; font-weight: bold;">int</span> rs485_re<span style="color: #333333;">=</span><span style="color: #0000dd; font-weight: bold;">13</span>;
gpioSetup();
gpioDirection(rs485_de,<span style="color: #0000dd; font-weight: bold;">1</span>);<span style="color: #888888;">//set pin output</span>
gpioDirection(rs485_re,<span style="color: #0000dd; font-weight: bold;">1</span>);<span style="color: #888888;">//set pin output</span>
<span style="color: #333399; font-weight: bold;">int</span> fd <span style="color: #333333;">=</span> open (portname, O_RDWR <span style="color: #333333;">|</span> O_NOCTTY <span style="color: #333333;">|</span> O_SYNC);
<span style="color: #008800; font-weight: bold;">if</span> (fd <span style="color: #333333;"><</span> <span style="color: #0000dd; font-weight: bold;">0</span>)
{
printf (<span style="background-color: #fff0f0;">"error %d opening %s: %s"</span>, errno, portname, strerror (errno));
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">1</span>;
}
set_interface_attribs (fd, B115200, <span style="color: #0000dd; font-weight: bold;">0</span>); <span style="color: #888888;">// set speed to 115,200 bps, 8n1 (no parity)</span>
set_blocking (fd, <span style="color: #0000dd; font-weight: bold;">0</span>); <span style="color: #888888;">// set no blocking</span>
<span style="color: #888888;">//get Model Name</span>
<span style="color: #333399; font-weight: bold;">int</span> cmd_len<span style="color: #333333;">=</span><span style="color: #0000dd; font-weight: bold;">7</span>;
<span style="color: #333399; font-weight: bold;">char</span> w_buff[<span style="color: #0000dd; font-weight: bold;">8</span>];
w_buff[<span style="color: #0000dd; font-weight: bold;">0</span>]<span style="color: #333333;">=</span><span style="color: #005588; font-weight: bold;">0x01</span>;
w_buff[<span style="color: #0000dd; font-weight: bold;">1</span>]<span style="color: #333333;">=</span><span style="color: #005588; font-weight: bold;">0x02</span>;
w_buff[<span style="color: #0000dd; font-weight: bold;">2</span>]<span style="color: #333333;">=</span><span style="color: #005588; font-weight: bold;">0x03</span>;
w_buff[<span style="color: #0000dd; font-weight: bold;">3</span>]<span style="color: #333333;">=</span><span style="color: #005588; font-weight: bold;">0x04</span>;
w_buff[<span style="color: #0000dd; font-weight: bold;">4</span>]<span style="color: #333333;">=</span><span style="color: #005588; font-weight: bold;">0x05</span>;
w_buff[<span style="color: #0000dd; font-weight: bold;">5</span>]<span style="color: #333333;">=</span><span style="color: #005588; font-weight: bold;">0x06</span>;
w_buff[<span style="color: #0000dd; font-weight: bold;">6</span>]<span style="color: #333333;">=</span><span style="color: #005588; font-weight: bold;">0x07</span>;
w_buff[<span style="color: #0000dd; font-weight: bold;">7</span>]<span style="color: #333333;">=</span><span style="color: #0044dd;">'\0'</span>;
<span style="color: #008800; font-weight: bold;">for</span> (<span style="color: #333399; font-weight: bold;">int</span> t<span style="color: #333333;">=</span><span style="color: #0000dd; font-weight: bold;">0</span>;t<span style="color: #333333;"><</span><span style="color: #0000dd; font-weight: bold;">20</span>;t<span style="color: #333333;">++</span>)
{
gpioSet(rs485_de,<span style="color: #0000dd; font-weight: bold;">1</span>); <span style="color: #888888;">//Set RS485 to Send Mode</span>
gpioSet(rs485_re,<span style="color: #0000dd; font-weight: bold;">1</span>);
usleep (<span style="color: #0000dd; font-weight: bold;">100</span>);
write (fd, w_buff, cmd_len);
usleep (cmd_len<span style="color: #333333;">*</span><span style="color: #0000dd; font-weight: bold;">100</span>); <span style="color: #888888;">// sleep enough to transmit the command date</span>
gpioSet(rs485_de,<span style="color: #0000dd; font-weight: bold;">0</span>); <span style="color: #888888;">// Set RS485 to Receive Mode</span>
gpioSet(rs485_re,<span style="color: #0000dd; font-weight: bold;">0</span>);
usleep (<span style="color: #0000dd; font-weight: bold;">10</span> <span style="color: #333333;">*</span> <span style="color: #0000dd; font-weight: bold;">1000</span>); <span style="color: #888888;">//wait a little time before read data</span>
<span style="color: #333399; font-weight: bold;">char</span> buf [<span style="color: #0000dd; font-weight: bold;">100</span>];
<span style="color: #333399; font-weight: bold;">int</span> n <span style="color: #333333;">=</span> read (fd, buf, <span style="color: #008800; font-weight: bold;">sizeof</span> buf); <span style="color: #888888;">// read up to 100 characters if ready to read</span>
printf(<span style="background-color: #fff0f0;">"rec:%d bytes</span><span style="background-color: #fff0f0; color: #666666; font-weight: bold;">\n</span><span style="background-color: #fff0f0;">"</span>,n);
<span style="color: #008800; font-weight: bold;">for</span> (<span style="color: #333399; font-weight: bold;">int</span> i<span style="color: #333333;">=</span><span style="color: #0000dd; font-weight: bold;">0</span>;i<span style="color: #333333;"><</span>n;i<span style="color: #333333;">++</span>)
{
printf(<span style="background-color: #fff0f0;">"%d</span><span style="background-color: #fff0f0; color: #666666; font-weight: bold;">\t</span><span style="background-color: #fff0f0;">"</span>,buf[i]);
}
printf(<span style="background-color: #fff0f0;">"</span><span style="background-color: #fff0f0; color: #666666; font-weight: bold;">\n</span><span style="background-color: #fff0f0;">"</span>);
}
}
</pre>
</div>
</div>
<br />金石微開http://www.blogger.com/profile/13160756791496033950noreply@blogger.com0tag:blogger.com,1999:blog-2933755125431570931.post-60923910346706490242018-10-14T01:27:00.004+08:002018-10-14T01:27:47.787+08:00[OpenWRT] 透過Direct Acess存取AR9331 GPIO在OpenWRT上要控制GPIO有二種方式<br />
<br />
1.透過修改/sys/class/gpio/gpioxx/Value來變更,此種方法好處是可以在多種程式語言,<br />
<br />
單純透過讀寫檔案的方式就可以改變GPIO,亦不需要知道實際GPIO所對應的記憶體位置。<br />
<br />
缺點則是速度較慢。<br />
<br />
Ex:切換系統LED<br />
<br />
<pre class="code" style="background: rgba(255, 255, 255, 0.9); border-radius: 2px; border: 1px solid rgb(204, 204, 204); box-shadow: rgb(204, 204, 204) 0px 0px 0.5em inset; color: #333333; direction: ltr; font-family: Consolas, "Andale Mono WT", "Andale Mono", "Bitstream Vera Sans Mono", "Nimbus Mono L", Monaco, "Courier New", monospace; font-size: 14px; margin-bottom: 1.4em; overflow-wrap: normal; overflow: auto; padding: 0.7em 1em;">echo "27" > /sys/class/gpio/export</pre>
<span style="background-color: rgba(255 , 255 , 255 , 0.8); color: #333333; display: inline; float: none; font-family: "arial" , sans-serif; font-size: 14px; font-style: normal; font-weight: 400; letter-spacing: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"></span><br />
<pre class="code" style="-webkit-text-stroke-width: 0px; background: rgba(255, 255, 255, 0.9); border-radius: 2px; border: 1px solid rgb(204, 204, 204); box-shadow: rgb(204, 204, 204) 0px 0px 0.5em inset; color: #333333; direction: ltr; font-family: Consolas, "Andale Mono WT", "Andale Mono", "Bitstream Vera Sans Mono", "Nimbus Mono L", Monaco, "Courier New", monospace; font-size: 14px; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: 400; letter-spacing: normal; margin: 0px 0px 1.4em; orphans: 2; overflow-wrap: normal; overflow: auto; padding: 0.7em 1em; text-align: left; text-decoration-color: initial; text-decoration-style: initial; text-indent: 0px; text-transform: none; white-space: pre; widows: 2; word-spacing: 0px;">echo "out" > /sys/class/gpio/gpio27/direction</pre>
<pre class="code" style="background: rgba(255, 255, 255, 0.9); border-radius: 2px; border: 1px solid rgb(204, 204, 204); box-shadow: rgb(204, 204, 204) 0px 0px 0.5em inset; color: #333333; direction: ltr; font-family: Consolas, "Andale Mono WT", "Andale Mono", "Bitstream Vera Sans Mono", "Nimbus Mono L", Monaco, "Courier New", monospace; font-size: 14px; margin-bottom: 1.4em; overflow-wrap: normal; overflow: auto; padding: 0.7em 1em;">echo "1" > /sys/class/gpio/gpio27/value</pre>
or<br />
<pre class="code" style="background: rgba(255, 255, 255, 0.9); border-radius: 2px; border: 1px solid rgb(204, 204, 204); box-shadow: rgb(204, 204, 204) 0px 0px 0.5em inset; color: #333333; direction: ltr; font-family: Consolas, "Andale Mono WT", "Andale Mono", "Bitstream Vera Sans Mono", "Nimbus Mono L", Monaco, "Courier New", monospace; font-size: 14px; margin-bottom: 1.4em; overflow-wrap: normal; overflow: auto; padding: 0.7em 1em;">echo "0" > /sys/class/gpio/gpio27/value</pre>
2. Direct Access GPIO Register,這種方式需要知道GPIO所對應的暫存器位置 ,適合以C語言開發,並對切換GPIO腳位速度有需求的使用者,例如RS 485應用。<br />
<br />
<br />
以AR9331為例,參考它的<a href="https://www.openhacks.com/uploadsproductos/ar9331_datasheet.pdf">DataSheet</a> ,可以得知GPIO的位置為18040000。<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEin8XFN0anUPi7F7tPOzXq2pJgpAJW4no3gengqZ9Fw-t4fYn6YEK0yAtluDskhNEya7C-wN4b0tP2GUmZ1fnO7xA9bJ7-at2Tg9iN5d_lS40XBhGpqIh59qfbnbM0ay6PLmbOSkoTWXCMD/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-10-14+%25E4%25B8%258A%25E5%258D%258812.53.05.png" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="746" data-original-width="1214" height="392" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEin8XFN0anUPi7F7tPOzXq2pJgpAJW4no3gengqZ9Fw-t4fYn6YEK0yAtluDskhNEya7C-wN4b0tP2GUmZ1fnO7xA9bJ7-at2Tg9iN5d_lS40XBhGpqIh59qfbnbM0ay6PLmbOSkoTWXCMD/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-10-14+%25E4%25B8%258A%25E5%258D%258812.53.05.png" width="640" /></a><br />
<br />
讓GPIO 27 閃爍的範例程碼<br />
<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #557799;">#include <stdio.h></span>
<span style="color: #557799;">#include <stdlib.h></span>
<span style="color: #557799;">#include <unistd.h></span>
<span style="color: #557799;">#include <fcntl.h></span>
<span style="color: #557799;">#include <sys/types.h></span>
<span style="color: #557799;">#include <sys/stat.h></span>
<span style="color: #557799;">#include <sys/mman.h></span>
<span style="color: #557799;">#include <string.h></span>
<span style="color: #557799;">#include <time.h></span>
<span style="color: #557799;">#define GPIO_ADDR 0x18040000 </span><span style="color: #888888;">// base address</span>
<span style="color: #557799;">#define GPIO_BLOCK 48 </span><span style="color: #888888;">// memory block size</span>
<span style="color: #008800; font-weight: bold;">volatile</span> <span style="color: #333399; font-weight: bold;">unsigned</span> <span style="color: #333399; font-weight: bold;">long</span> <span style="color: #333333;">*</span>gpioAddress;
<span style="color: #888888;">//Read GPIO Status</span>
<span style="color: #888888;">//return 0 -->Low</span>
<span style="color: #888888;">//return >0 -->High</span>
<span style="color: #333399; font-weight: bold;">int</span> <span style="color: #0066bb; font-weight: bold;">gpioRead</span>(<span style="color: #333399; font-weight: bold;">int</span> gpio)
{
<span style="color: #333399; font-weight: bold;">unsigned</span> <span style="color: #333399; font-weight: bold;">long</span> value <span style="color: #333333;">=</span> <span style="color: #333333;">*</span>(gpioAddress <span style="color: #333333;">+</span> <span style="color: #0000dd; font-weight: bold;">1</span>);
<span style="color: #008800; font-weight: bold;">return</span> (value <span style="color: #333333;">&</span> (<span style="color: #0000dd; font-weight: bold;">1</span> <span style="color: #333333;"><<</span> gpio));
}
<span style="color: #888888;">// "1" (output) or "0" (input) </span>
<span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">gpioDirection</span>(<span style="color: #333399; font-weight: bold;">int</span> gpio, <span style="color: #333399; font-weight: bold;">int</span> direction)
{
<span style="color: #888888;">// obtain current GPIO settings</span>
<span style="color: #333399; font-weight: bold;">unsigned</span> <span style="color: #333399; font-weight: bold;">long</span> value <span style="color: #333333;">=</span> <span style="color: #333333;">*</span>(gpioAddress <span style="color: #333333;">+</span> <span style="color: #0000dd; font-weight: bold;">0</span>);
<span style="color: #008800; font-weight: bold;">if</span> (direction <span style="color: #333333;">==</span> <span style="color: #0000dd; font-weight: bold;">1</span>)
{
value <span style="color: #333333;">|=</span> (<span style="color: #0000dd; font-weight: bold;">1</span> <span style="color: #333333;"><<</span> gpio); <span style="color: #888888;">// set bit to 1 (output)</span>
}
<span style="color: #008800; font-weight: bold;">else</span>
{
value <span style="color: #333333;">&=</span> <span style="color: #333333;">~</span>(<span style="color: #0000dd; font-weight: bold;">1</span> <span style="color: #333333;"><<</span> gpio); <span style="color: #888888;">// clear bit (input)</span>
}
<span style="color: #333333;">*</span>(gpioAddress <span style="color: #333333;">+</span> <span style="color: #0000dd; font-weight: bold;">0</span>) <span style="color: #333333;">=</span> value;
}
<span style="color: #888888;">//Set GPIO</span>
<span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">gpioSet</span>(<span style="color: #333399; font-weight: bold;">int</span> gpio, <span style="color: #333399; font-weight: bold;">int</span> data)
{
<span style="color: #888888;">// obtain current GPIO settings</span>
<span style="color: #333399; font-weight: bold;">unsigned</span> <span style="color: #333399; font-weight: bold;">long</span> value <span style="color: #333333;">=</span> <span style="color: #333333;">*</span>(gpioAddress <span style="color: #333333;">+</span> <span style="color: #0000dd; font-weight: bold;">2</span>);
<span style="color: #008800; font-weight: bold;">if</span> (data <span style="color: #333333;">==</span> <span style="color: #0000dd; font-weight: bold;">1</span>)
{
value <span style="color: #333333;">|=</span> (<span style="color: #0000dd; font-weight: bold;">1</span> <span style="color: #333333;"><<</span> gpio); <span style="color: #888888;">// set bit to 1 (High)</span>
}
<span style="color: #008800; font-weight: bold;">else</span>
{
value <span style="color: #333333;">&=</span> <span style="color: #333333;">~</span>(<span style="color: #0000dd; font-weight: bold;">1</span> <span style="color: #333333;"><<</span> gpio); <span style="color: #888888;">// clear bit (Low)</span>
}
<span style="color: #333333;">*</span>(gpioAddress <span style="color: #333333;">+</span> <span style="color: #0000dd; font-weight: bold;">2</span>) <span style="color: #333333;">=</span> value;
}
<span style="color: #888888;">//Init GPIO Address, if /dev/mem not foud, you need to rebuild Image and add this module</span>
<span style="color: #333399; font-weight: bold;">int</span> <span style="color: #0066bb; font-weight: bold;">gpioSetup</span>()
{
<span style="color: #333399; font-weight: bold;">int</span> m_mfd;
<span style="color: #008800; font-weight: bold;">if</span> ((m_mfd <span style="color: #333333;">=</span> open(<span style="background-color: #fff0f0;">"/dev/mem"</span>, O_RDWR)) <span style="color: #333333;"><</span> <span style="color: #0000dd; font-weight: bold;">0</span>)
{
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">1</span>;
}
gpioAddress <span style="color: #333333;">=</span> (<span style="color: #333399; font-weight: bold;">unsigned</span> <span style="color: #333399; font-weight: bold;">long</span><span style="color: #333333;">*</span>)mmap(<span style="color: #007020;">NULL</span>, GPIO_BLOCK, PROT_READ<span style="color: #333333;">|</span>PROT_WRITE, MAP_SHARED, m_mfd, GPIO_ADDR);
close(m_mfd);
<span style="color: #008800; font-weight: bold;">if</span> (gpioAddress <span style="color: #333333;">==</span> MAP_FAILED)
{
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">2</span>;
}
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #0000dd; font-weight: bold;">0</span>;
}
<span style="color: #333399; font-weight: bold;">int</span> <span style="color: #0066bb; font-weight: bold;">main</span>(<span style="color: #333399; font-weight: bold;">int</span> argc, <span style="color: #333399; font-weight: bold;">char</span> <span style="color: #333333;">**</span>argv)
{
<span style="color: #333399; font-weight: bold;">int</span> pin<span style="color: #333333;">=</span><span style="color: #0000dd; font-weight: bold;">27</span>;
<span style="color: #333399; font-weight: bold;">int</span> ms<span style="color: #333333;">=</span><span style="color: #0000dd; font-weight: bold;">500</span>;
gpioSetup();
sscanf(argv[<span style="color: #0000dd; font-weight: bold;">1</span>], <span style="background-color: #fff0f0;">"%d"</span>, <span style="color: #333333;">&</span>pin);
gpioDirection(pin,<span style="color: #0000dd; font-weight: bold;">1</span>);<span style="color: #888888;">//set pin output </span>
<span style="color: #008800; font-weight: bold;">for</span> (<span style="color: #333399; font-weight: bold;">int</span> i<span style="color: #333333;">=</span><span style="color: #0000dd; font-weight: bold;">0</span>;i<span style="color: #333333;"><</span><span style="color: #0000dd; font-weight: bold;">100</span>;i<span style="color: #333333;">++</span>) <span style="color: #888888;">//blink system led</span>
{
gpioSet(pin,<span style="color: #0000dd; font-weight: bold;">1</span>); <span style="color: #888888;">//set syteme led high</span>
usleep(<span style="color: #0000dd; font-weight: bold;">1000</span><span style="color: #333333;">*</span>ms); <span style="color: #888888;">//sleep 500ms</span>
gpioSet(pin,<span style="color: #0000dd; font-weight: bold;">0</span>); <span style="color: #888888;">//set system led low</span>
usleep(<span style="color: #0000dd; font-weight: bold;">1000</span><span style="color: #333333;">*</span>ms); <span style="color: #888888;">//sleep 500ms</span>
}
}
</pre>
</div>
<br />
參考來源:<br />
<br />
Working with GPIOs (C/C++)<div>
<a href="https://www.unwireddevices.com/wiki/index.php/Working_with_GPIOs_(C/C%2B%2B)">https://www.unwireddevices.com/wiki/index.php/Working_with_GPIOs_(C/C%2B%2B)</a></div>
<div>
<br /></div>
<div>
AR9331 Datasheet</div>
<div>
<a href="https://www.openhacks.com/uploadsproductos/ar9331_datasheet.pdf">https://www.openhacks.com/uploadsproductos/ar9331_datasheet.pdf</a></div>
金石微開http://www.blogger.com/profile/13160756791496033950noreply@blogger.com0tag:blogger.com,1999:blog-2933755125431570931.post-75934253841396527702018-09-16T01:01:00.002+08:002018-09-16T01:01:31.667+08:00[Python] OSX esptool.py 燒錄MicroPython 到 Node MCU(CH340 USB to UART Chip)問題在燒錄MicroPython到Node MCU後,使用adafruit ampy出問題<br />
<br />
could not enter raw repl<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiyGMnlA0XgV9G-xizHV4x_9PNl2dLH7cKltrWCVmCsFothuJRUhV956Y5qF2T221Ym46DYtxZMrC7d3badrkblVCLxlEhT2eHeAiVKGOncwYWo7OEE42_vvdZsPC041-Dg4xtd045MjPIH/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-09-15+%25E4%25B8%258A%25E5%258D%258812.56.19.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="778" data-original-width="1600" height="310" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiyGMnlA0XgV9G-xizHV4x_9PNl2dLH7cKltrWCVmCsFothuJRUhV956Y5qF2T221Ym46DYtxZMrC7d3badrkblVCLxlEhT2eHeAiVKGOncwYWo7OEE42_vvdZsPC041-Dg4xtd045MjPIH/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-09-15+%25E4%25B8%258A%25E5%258D%258812.56.19.png" width="640" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
網路上說加-d 2可解<br />
<br />
ampy --port /dev/cu.wchusebserial1410 -d 2 ls<br />
<br />
結果是卡住,沒有回應...Orz,該不是會沒燒好吧....<br />
<br />
<br />
最後想到過去在工作中遇到CH3400 在linux上baud rate 250000 無法正確工作的情況,<br />
<br />
仔細看了一下,它燒錄baud rate用460800~降速到115200看看,皆大歡喜。<br />
<br />
<pre style="background-color: #f6f8fa; border-radius: 3px; box-sizing: border-box; color: #24292e; font-size: 13.6px; line-height: 1.45; margin-bottom: 16px; overflow: auto; padding: 16px; word-wrap: normal;"><span style="background-color: white; color: black; font-family: menlo; font-size: 11px; white-space: normal;">esptool.py --port /dev/cu.wchusbserial1410 --baud 115200 write_flash --flash_size=detect 0 ~/Downloads/esp8266-20180511-v1.9.4.bin</span></pre>
<span style="background-color: white; font-family: menlo; font-size: 11px;"><br /></span>
目前試了2款Mac book Pro , MBP 2015用460800可以燒錄,不會有錯誤訊息,但有機會不成功,我就是踩到這個坑。<div>
<br /></div>
<div>
MBP 2017則會直接無法燒錄,改成115200後正常</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgEJZ3wa5Zi8zsfuPe4GwS4RvZyuxh6KJ1Qa5_LEdQdcMf5LI7f3S0SGo3PfL1Q2SW1YY1g6mDR4gKSY7o8EPkLBhsuUdFyf62dQCGB0ECX0HJlivK8yo1W_G64ehiRpOnzi-unCdvvq9id/s1600/41796675_2159934637586777_2031187272337981440_n.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="1262" data-original-width="1150" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgEJZ3wa5Zi8zsfuPe4GwS4RvZyuxh6KJ1Qa5_LEdQdcMf5LI7f3S0SGo3PfL1Q2SW1YY1g6mDR4gKSY7o8EPkLBhsuUdFyf62dQCGB0ECX0HJlivK8yo1W_G64ehiRpOnzi-unCdvvq9id/s640/41796675_2159934637586777_2031187272337981440_n.png" width="583" /></a></div>
<div>
<br /></div>
<div>
<br /><br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
參考資料<br />
CH340 OSX flash error with speed greater 115200<a href="https://github.com/espressif/esptool/issues/145">https://github.com/espressif/esptool/issues/145</a></div>
金石微開http://www.blogger.com/profile/13160756791496033950noreply@blogger.com0tag:blogger.com,1999:blog-2933755125431570931.post-531163046304636102018-09-16T00:40:00.004+08:002018-09-16T01:02:09.809+08:00[ESP8266] 燒錄MicroPython到Node MCU (OS X)<span style="font-family: "arial" , "helvetica" , sans-serif , "dk"; font-size: 14px;">MicroPython 是一種精簡且高效率實作的 Python 3 程式語言,其中含有少量 Python 標準函式庫子集,針對在微控制器和受限環境中執行進行最佳化。</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk"; font-size: 14px;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;">執行MicroPython需要的硬體如下:</span></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;"><br /></span></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;">至少</span></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;"><br /></span></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;">256K Flash Rom</span></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;">16K RAM</span></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;">時脈80MHz</span></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;">------------------------------------------------------------------------------------</span></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;"><br /></span></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;"><br /></span></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;">要在ESP8266上運行MicroPython,需要</span></span><span style="font-family: "arial" , "helvetica" , sans-serif , "dk"; font-size: 14px;">至少1MB的Flash Rom 版本,</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk"; font-size: 14px;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk"; font-size: 14px;">(MicroPython Firmware大約佔去512K) ,而Node MCU選用的是ESP12E,</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk"; font-size: 14px;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk"; font-size: 14px;">有4MB Flash Rom,十分足夠。</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk"; font-size: 14px;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk"; font-size: 14px;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk"; font-size: 14px;">1.首先要下載MicroPython Firmware。</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk"; font-size: 14px;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;">http://micropython.org/download#esp8266</span></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;"><br /></span></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;">到此連結選擇最新的穩定版本,撰寫本文時最新版本為</span></span><a href="http://micropython.org/resources/firmware/esp8266-20180511-v1.9.4.bin" style="background-color: white; border: 0px; box-sizing: border-box; color: #d43738; font-family: sans-serif; font-size: 14px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin: 0px; padding: 0px; text-decoration-line: none; transition: all 0.2s ease 0s; vertical-align: baseline;">esp8266-20180511-v1.9.4.bin</a>這<br />
<span id="goog_1994705271"></span><span id="goog_1994705272"></span><br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnNbiSCT2hIEymSwbdojFkOpB2777LHuTA7UQfrc6Vya2tRh1PLCylsR0TSzPh-ACTbrLNKbYcF6Jw32RYFfaYSlL5r013LxvxqIhsgJ20hibHdVQR3JsnzcV2ihPRBLMJz7K_KPGavUQj/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-09-14+%25E4%25B8%258B%25E5%258D%258811.07.48.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="499" data-original-width="1504" height="211" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnNbiSCT2hIEymSwbdojFkOpB2777LHuTA7UQfrc6Vya2tRh1PLCylsR0TSzPh-ACTbrLNKbYcF6Jw32RYFfaYSlL5r013LxvxqIhsgJ20hibHdVQR3JsnzcV2ihPRBLMJz7K_KPGavUQj/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-09-14+%25E4%25B8%258B%25E5%258D%258811.07.48.png" width="640" /></a></div>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdqd_eClhYpZ-FbTU38D8nG5RoAbKy76AAPX-drwMxIq2e4cMetrudvJanr2sYjfJ9D1SDGStl3LuAgrtIQ0pYJPxm3t_1he-tMY7XO8zIkoj7YEIsAoo91N64Ptf_vaB2tfQXR_CM8Twn/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-09-14+%25E4%25B8%258B%25E5%258D%258810.58.05.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br /></a>
<br />
<div class="separator" style="clear: both; text-align: left;">
2.燒錄工具 (電腦需要有python環境以及pip工具), 建議用python3</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<pre style="background-color: #f6f8fa; border-radius: 3px; box-sizing: border-box; color: #24292e; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.6px; line-height: 1.45; margin-bottom: 16px; overflow: auto; padding: 16px; word-wrap: normal;">pip3 install esptool</pre>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgsozYHGgZkYPVIo4CsnIcZK3ya8btFxsyq0muhNLKzV4vozwxwECsElx6gdzeTB5g3_WzsnQy0uzIqddiKmX8ielTdVaH6sHh5PR8_psKrA1pI1FQhraRSRdoVtIvSJYogDljFHUfv1DLa/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-09-15+%25E4%25B8%258A%25E5%258D%258812.46.41.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="372" data-original-width="1600" height="148" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgsozYHGgZkYPVIo4CsnIcZK3ya8btFxsyq0muhNLKzV4vozwxwECsElx6gdzeTB5g3_WzsnQy0uzIqddiKmX8ielTdVaH6sHh5PR8_psKrA1pI1FQhraRSRdoVtIvSJYogDljFHUfv1DLa/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-09-15+%25E4%25B8%258A%25E5%258D%258812.46.41.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
3.檔案工具<span style="background-color: white; color: #24292e; font-family: , , "segoe ui" , "helvetica" , "arial" , sans-serif , "apple color emoji" , "segoe ui emoji" , "segoe ui symbol"; font-size: 16px;">Adafruit MicroPython Tool</span><span style="background-color: white; color: #24292e; font-family: , , "segoe ui" , "helvetica" , "arial" , sans-serif , "apple color emoji" , "segoe ui emoji" , "segoe ui symbol"; font-size: 16px;"> (AMPY)</span><br />
<div class="separator" style="clear: both; text-align: left;">
<span style="background-color: white; color: #24292e; font-family: , , "segoe ui" , "helvetica" , "arial" , sans-serif , "apple color emoji" , "segoe ui emoji" , "segoe ui symbol"; font-size: 16px;"><br /></span></div>
<pre style="background-color: #f6f8fa; border-radius: 3px; box-sizing: border-box; color: #24292e; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.6px; line-height: 1.45; margin-bottom: 16px; overflow: auto; padding: 16px; word-wrap: normal;"><code style="background: transparent; border-radius: 3px; border: 0px; box-sizing: border-box; display: inline; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.6px; line-height: inherit; margin: 0px; overflow: visible; padding: 0px; word-break: normal; word-wrap: normal;">pip3 install adafruit-ampy</code></pre>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhcs6B1TI5GSLCPt6v-QbkRGUUzVdPExO6pCsc-aKKx4R3A0QE_HR75LmkWdo1TjgzFby_72jvXdqOnOuZeDAOH9XykMhfv8MQxB3UCxG_VOIPe5eDDpGsC2Wm98WNtm9OXRAE2tEs2k2jp/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-09-15+%25E4%25B8%258A%25E5%258D%258812.48.25.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="503" data-original-width="1600" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhcs6B1TI5GSLCPt6v-QbkRGUUzVdPExO6pCsc-aKKx4R3A0QE_HR75LmkWdo1TjgzFby_72jvXdqOnOuZeDAOH9XykMhfv8MQxB3UCxG_VOIPe5eDDpGsC2Wm98WNtm9OXRAE2tEs2k2jp/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-09-15+%25E4%25B8%258A%25E5%258D%258812.48.25.png" width="640" /></a></div>
<br />
4.將Node MCU連接到電腦 ,確認是否可以看到Node MCU的Serial Port<br />
<br />
<pre style="background-color: #f6f8fa; border-radius: 3px; box-sizing: border-box; color: #24292e; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.6px; line-height: 1.45; margin-bottom: 16px; overflow: auto; padding: 16px; word-wrap: normal;">ls /dev/cu.*</pre>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2CNTLAvkgy51EfS3RDm0t2fHguwbncMR0LURtjRC-OwXveJ_0oVqU3l2lN8_N_KTmhx1-EVS7DhBmg_NP2iEk-DDLedg-jur33eozQMgmhNfJji6LzGbf9yuX6YMgC8KTM21Wh52yjozL/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-09-14+%25E4%25B8%258B%25E5%258D%258811.30.06.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="152" data-original-width="962" height="100" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2CNTLAvkgy51EfS3RDm0t2fHguwbncMR0LURtjRC-OwXveJ_0oVqU3l2lN8_N_KTmhx1-EVS7DhBmg_NP2iEk-DDLedg-jur33eozQMgmhNfJji6LzGbf9yuX6YMgC8KTM21Wh52yjozL/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-09-14+%25E4%25B8%258B%25E5%258D%258811.30.06.png" width="640" /></a></div>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk"; font-size: 14px;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk"; font-size: 14px;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;"><br /></span></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;"><br /></span></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;"><br /></span></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;"><br /></span></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;"><br /></span></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;"><br /></span></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;">若能夠看到/dev/cu.wchusbserial1410(或1420) 代表能夠捉到Node MCU的Serial Port (驅動成功安裝) , 如果沒有看到</span></span><br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;">需要確定您使用的Node MCU是使用那一個版本的USB to TTL晶片</span></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;"><br /></span></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;">若是CH340</span></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;">安裝以下驅動(安裝完畢後必須重開機,並且在隱私設定中允許)</span></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;"><br /></span></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;"><a href="http://www.wch.cn/download/CH341SER_MAC_ZIP.html">http://www.wch.cn/download/CH341SER_MAC_ZIP.html</a></span></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHwOCoFvNsWE5BgRJn2kAcPwr9rsv_Nw4hPB9kpC-YmLPeicPwb0aNlwi4PnRk4lG0okaV4ac6a2B-UCgEhcScUV3s-thCKtvpf9Gw0fmv5lkoP1IsAwhxDO3QsBSabcb0Mdm7itY9FCHb/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-09-14+%25E4%25B8%258B%25E5%258D%258811.32.33.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="553" data-original-width="1600" height="220" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHwOCoFvNsWE5BgRJn2kAcPwr9rsv_Nw4hPB9kpC-YmLPeicPwb0aNlwi4PnRk4lG0okaV4ac6a2B-UCgEhcScUV3s-thCKtvpf9Gw0fmv5lkoP1IsAwhxDO3QsBSabcb0Mdm7itY9FCHb/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-09-14+%25E4%25B8%258B%25E5%258D%258811.32.33.png" width="640" /></a></div>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;"><br /></span></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;"><br /></span></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;"><br /></span></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;"><br /></span></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;"><br /></span></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;"><br /></span></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;"><br /></span></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;"><br /></span></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;"><br /></span></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;"><br /></span></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;"><br /></span></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;"><br /></span></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;"><br /></span></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;"><br /></span></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;">若是CP2102 則安裝以下驅動,並允許隱私權中的設定,然候重開機</span></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-family: "arial" , "helvetica" , sans-serif , "dk"; font-size: 14px;">https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers</span></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYZ_cx2iLKz840lwRBdphbezUC_Vuw1Sfi-oYiKaY8jj8-l8DotWJmx2h8sC4eSmx3KASh0P4Q-5t6jyqyF75V-jiBl672KU52CNeO_fP76HmeCoiO6mwT0CU2vpJNRN0Mm-GoysdjPDNP/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-09-15+%25E4%25B8%258B%25E5%258D%258811.17.11.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="346" data-original-width="1600" height="137" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYZ_cx2iLKz840lwRBdphbezUC_Vuw1Sfi-oYiKaY8jj8-l8DotWJmx2h8sC4eSmx3KASh0P4Q-5t6jyqyF75V-jiBl672KU52CNeO_fP76HmeCoiO6mwT0CU2vpJNRN0Mm-GoysdjPDNP/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-09-15+%25E4%25B8%258B%25E5%258D%258811.17.11.png" width="640" /></a></div>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;"><br /></span></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;"><br /></span></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;">5.抺除Node MCU中原廠的Firmware (注意 port可能和我不同)</span></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;"><br /></span></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;"></span></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;">CH340</span></span><br />
<pre style="background-color: #f6f8fa; border-radius: 3px; box-sizing: border-box; color: #24292e; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.6px; line-height: 1.45; margin-bottom: 16px; overflow: auto; padding: 16px; word-wrap: normal;"><div class="p1">
<span class="s1">esptool.py --port /dev/cu.wchusbserial1410 erase_flash</span></div>
</pre>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLRvMrJoWuNOAxMHwlk9L5phluObUP4GsztRSF0UX1DBnIp60J1an4pQIO-ek2NNTA5nj7cHgnLCqmsHWHjKjTejQ1xCZqeWwH44gSLBT5NLHjIsz5QyCpoW737WcxZKbGCN5IbLPHiN_1/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-09-14+%25E4%25B8%258B%25E5%258D%258811.37.34.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="408" data-original-width="1252" height="208" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLRvMrJoWuNOAxMHwlk9L5phluObUP4GsztRSF0UX1DBnIp60J1an4pQIO-ek2NNTA5nj7cHgnLCqmsHWHjKjTejQ1xCZqeWwH44gSLBT5NLHjIsz5QyCpoW737WcxZKbGCN5IbLPHiN_1/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-09-14+%25E4%25B8%258B%25E5%258D%258811.37.34.png" width="640" /></a></div>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;"><br /></span></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;"><br /></span></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;"><br /></span></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;"><br /></span></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;"><br /></span></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;"><br /></span></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;"><br /></span></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;"><br /></span></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;"><br /></span></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;"><br /></span></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;"><br /></span></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;"><br /></span></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;"><br /></span></span>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;"><br />CP2102</span></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEia9E1Qd4pE7X1gzHkCaH6Ab_5KLLQSl99AtLT5l0M4pUvX8jKlrjECEcdYit06Qnc_HwCH7sNGEhEwiRO1XWJQHigmIubRBcBLwfveXa_9xj7-rY-CI-t1ML9IIeKN8axWSU9PSsm-Lq15/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-09-15+%25E4%25B8%258B%25E5%258D%258811.57.45.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="424" data-original-width="1244" height="218" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEia9E1Qd4pE7X1gzHkCaH6Ab_5KLLQSl99AtLT5l0M4pUvX8jKlrjECEcdYit06Qnc_HwCH7sNGEhEwiRO1XWJQHigmIubRBcBLwfveXa_9xj7-rY-CI-t1ML9IIeKN8axWSU9PSsm-Lq15/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-09-15+%25E4%25B8%258B%25E5%258D%258811.57.45.png" width="640" /></a></div>
<span style="font-family: "arial" , "helvetica" , sans-serif , "dk";"><span style="font-size: 14px;"><br /></span></span>
6.寫入MicroPython Firmware<br />
<br />
CP2102<br />
<pre style="background-color: #f6f8fa; border-radius: 3px; box-sizing: border-box; color: #24292e; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.6px; line-height: 1.45; margin-bottom: 16px; overflow: auto; padding: 16px; word-wrap: normal;"><span style="background-color: white; color: black; font-family: "menlo"; font-size: 11px; white-space: normal;">esptool.py --port /dev/cu.SLAB_USBtoUART --baud 460800 write_flash --flash_size=detect 0 ~/Downloads/esp8266-20180511-v1.9.4.bin</span></pre>
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff}
span.s1 {font-variant-ligatures: no-common-ligatures}
</style>
<br />
<div class="p1">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEitm2p_irry2buDQAIpT_VA7UHh7CsY9bK3mXHza_i8dwLb_BJJWRUIc9cxTRAVGqPsLQ6xB-I0RYT6VjgMRQN0iK5lZU0EdsFk0dP_i15GKMwkY17wjeaoL1_mOh4E56yTkaF7WiRMIUqT/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-09-16+%25E4%25B8%258A%25E5%258D%258812.02.17.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="1060" data-original-width="1260" height="538" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEitm2p_irry2buDQAIpT_VA7UHh7CsY9bK3mXHza_i8dwLb_BJJWRUIc9cxTRAVGqPsLQ6xB-I0RYT6VjgMRQN0iK5lZU0EdsFk0dP_i15GKMwkY17wjeaoL1_mOh4E56yTkaF7WiRMIUqT/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-09-16+%25E4%25B8%258A%25E5%258D%258812.02.17.png" width="640" /></a></div>
<br />
CH340<br />
<pre style="background-color: #f6f8fa; border-radius: 3px; box-sizing: border-box; color: #24292e; font-size: 13.6px; line-height: 1.45; margin-bottom: 16px; overflow: auto; padding: 16px; word-wrap: normal;"><span style="background-color: white; color: black; font-family: "menlo"; font-size: 11px; white-space: normal;">esptool.py --port /dev/cu.wchusbserial1410 --baud 115200 write_flash --flash_size=detect 0 ~/Downloads/esp8266-20180511-v1.9.4.bin</span></pre>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgEPtUXMV2LHAtPRrNMdNqccA9Nx5EqRXqGZh0cZluBdKmB7TSDrsarFnIYg0VLYoqSGc61tRGZKqkP_nbBhWKj8Q6JNXEIen0lNiYLO5Jqm8FrTY-1VAwhlkoSsqvqCZDz7KE7NRQZ_Gdt/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-09-15+%25E4%25B8%258B%25E5%258D%258811.47.34.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="616" data-original-width="1272" height="308" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgEPtUXMV2LHAtPRrNMdNqccA9Nx5EqRXqGZh0cZluBdKmB7TSDrsarFnIYg0VLYoqSGc61tRGZKqkP_nbBhWKj8Q6JNXEIen0lNiYLO5Jqm8FrTY-1VAwhlkoSsqvqCZDz7KE7NRQZ_Gdt/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-09-15+%25E4%25B8%258B%25E5%258D%258811.47.34.png" width="640" /></a></div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<br />
<br />
7.透過ampy 查詢一下Node MCU中有什麼東要(測試燒錄是否成功)<br />
<br />
CH340<br />
<div>
<br /></div>
<pre style="background-color: #f6f8fa; border-radius: 3px; box-sizing: border-box; color: #24292e; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.6px; line-height: 1.45; margin-bottom: 16px; overflow: auto; padding: 16px; word-wrap: normal;"><div class="p1">
<span class="s1">ampy --port /dev/cu.wchusbserial1410 ls</span></div>
</pre>
<div>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgdEKnFlGbAPj7NPM-3QH16Rd1sM6otTRvVpIdQMElMEwsuPJz8R0_YABL0qizm1EvemY_yggylx_dJkRRPHSnjdZhro9ShAWzVZrLFZa_HXpEQa9rn0n2EfSCBkHP4QkC43gYa4phZP5J/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-09-15+%25E4%25B8%258A%25E5%258D%258812.56.19.png" imageanchor="1" style="clear: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" data-original-height="778" data-original-width="1600" height="310" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgdEKnFlGbAPj7NPM-3QH16Rd1sM6otTRvVpIdQMElMEwsuPJz8R0_YABL0qizm1EvemY_yggylx_dJkRRPHSnjdZhro9ShAWzVZrLFZa_HXpEQa9rn0n2EfSCBkHP4QkC43gYa4phZP5J/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-09-15+%25E4%25B8%258A%25E5%258D%258812.56.19.png" width="640" /></a></div>
<div>
<br /></div>
<div>
出現錯誤 colud not entr raw repl</div>
<div>
<br />
俺試過加入Delay 2秒也沒用,最後發現跟本是沒有燒好(MBP 2015不會跳錯,但不一定燒錄成功,而MBP 2017則是無法燒錄),在CH340的USB To TTL晶片記得要在燒錄時把baud 改成 115200.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgbyxA5H3ZXc9Rl8aUtR-vSBgEPxlzHFjzHC3XVxhYiwO9pQCkReDiX3HXJ88myfAiaYwrlbHyaJHA-5DqyejZspciont0zzG5SEhX29-68yR7ZyfzM9pn9rjXi4BNr8ogFE9cmXB0SILzh/s1600/41796675_2159934637586777_2031187272337981440_n.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="1262" data-original-width="1150" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgbyxA5H3ZXc9Rl8aUtR-vSBgEPxlzHFjzHC3XVxhYiwO9pQCkReDiX3HXJ88myfAiaYwrlbHyaJHA-5DqyejZspciont0zzG5SEhX29-68yR7ZyfzM9pn9rjXi4BNr8ogFE9cmXB0SILzh/s640/41796675_2159934637586777_2031187272337981440_n.png" width="583" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
CP2102<br />
<pre style="background-color: #f6f8fa; border-radius: 3px; box-sizing: border-box; color: #24292e; font-size: 13.6px; line-height: 1.45; margin-bottom: 16px; overflow: auto; padding: 16px; word-wrap: normal;">ampy --port /dev/cu.SLAB_USBtoUART<span class="Apple-converted-space" style="background-color: white; color: black; font-family: "menlo"; font-size: 11px; white-space: normal;"> </span><span style="background-color: white; color: black; font-family: "menlo"; font-size: 11px; white-space: normal;">ls</span></pre>
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff}
span.s1 {font-variant-ligatures: no-common-ligatures}
</style>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgt-So2sYU8kxaAXmzoZ4FXmsRXWImUSX0BbA7pdgvU7Uz4Bx4MqB6ngHLKFdMqWCiJ-FCuLDXsfOLNnfyeuQnLgDm_AjAwwRiQuxLlSOh4lGZRR9V0Wg_IAvvQ-64Ajk-a1WEVdYBGw2Sq/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-09-16+%25E4%25B8%258A%25E5%258D%258812.06.27.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="68" data-original-width="1026" height="42" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgt-So2sYU8kxaAXmzoZ4FXmsRXWImUSX0BbA7pdgvU7Uz4Bx4MqB6ngHLKFdMqWCiJ-FCuLDXsfOLNnfyeuQnLgDm_AjAwwRiQuxLlSOh4lGZRR9V0Wg_IAvvQ-64Ajk-a1WEVdYBGw2Sq/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-09-16+%25E4%25B8%258A%25E5%258D%258812.06.27.png" width="640" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgt-So2sYU8kxaAXmzoZ4FXmsRXWImUSX0BbA7pdgvU7Uz4Bx4MqB6ngHLKFdMqWCiJ-FCuLDXsfOLNnfyeuQnLgDm_AjAwwRiQuxLlSOh4lGZRR9V0Wg_IAvvQ-64Ajk-a1WEVdYBGw2Sq/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-09-16+%25E4%25B8%258A%25E5%258D%258812.06.27.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgt-So2sYU8kxaAXmzoZ4FXmsRXWImUSX0BbA7pdgvU7Uz4Bx4MqB6ngHLKFdMqWCiJ-FCuLDXsfOLNnfyeuQnLgDm_AjAwwRiQuxLlSOh4lGZRR9V0Wg_IAvvQ-64Ajk-a1WEVdYBGw2Sq/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-09-16+%25E4%25B8%258A%25E5%258D%258812.06.27.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br /></a></div>
<div class="p1">
<br /></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
8.到此燒錄MicroPython已完成,接下來寫一個main.py<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">time</span>
<span style="color: #008800; font-weight: bold;">from</span> <span style="color: #0e84b5; font-weight: bold;">machine</span> <span style="color: #008800; font-weight: bold;">import</span> Pin
led <span style="color: #333333;">=</span> Pin(<span style="color: #0000dd; font-weight: bold;">2</span>, Pin<span style="color: #333333;">.</span>OUT)
led<span style="color: #333333;">.</span>value(<span style="color: #0000dd; font-weight: bold;">1</span>)
<span style="color: #008800; font-weight: bold;">while</span> <span style="color: #007020;">True</span>:
led<span style="color: #333333;">.</span>value(<span style="color: #0000dd; font-weight: bold;">0</span>)
time<span style="color: #333333;">.</span>sleep_ms(<span style="color: #0000dd; font-weight: bold;">500</span>)
led<span style="color: #333333;">.</span>value(<span style="color: #0000dd; font-weight: bold;">1</span>)
time<span style="color: #333333;">.</span>sleep_ms(<span style="color: #0000dd; font-weight: bold;">500</span>)
</pre>
</div>
<br />
9.將main.py丟到Node MCU<br />
<br />
CP2102<br />
<pre style="background-color: #f6f8fa; border-radius: 3px; box-sizing: border-box; color: #24292e; font-size: 13.6px; line-height: 1.45; margin-bottom: 16px; overflow: auto; padding: 16px; word-wrap: normal;">ampy --port /dev/cu.SLAB_USBtoUART<span class="Apple-converted-space" style="background-color: white; color: black; font-family: "menlo"; font-size: 11px; white-space: normal;"> </span><span style="background-color: white; color: black; font-family: "menlo"; font-size: 11px; white-space: normal;">ls</span></pre>
</div>
CH340<br />
<pre style="background-color: #f6f8fa; border-radius: 3px; box-sizing: border-box; color: #24292e; font-size: 13.6px; line-height: 1.45; margin-bottom: 16px; overflow: auto; padding: 16px; word-wrap: normal;">ampy --port /dev/cu.wchusbserial1410 put<span class="Apple-converted-space" style="background-color: white; color: black; font-family: "menlo"; font-size: 11px; white-space: normal;"> </span><span style="background-color: white; color: black; font-family: "menlo"; font-size: 11px; white-space: normal;">main.py</span></pre>
接下來按下RST鍵,藍色LED就會以0.5秒間隔閃爍。<br />
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAXaxSYfikgi-fR7NrIrKKuBUReh6pWpZzhDZ3BXUt6Lutw15syYoIK4uHfjKWMWBY_RhvnOxV62vJ1YejDFW0QMcv0M5GwEVdoQghANgdtbQZAFe3ngw-1i0qGyUMJDA_pUzaW-q75cb-/s1600/IMG_7913.JPG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="1200" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAXaxSYfikgi-fR7NrIrKKuBUReh6pWpZzhDZ3BXUt6Lutw15syYoIK4uHfjKWMWBY_RhvnOxV62vJ1YejDFW0QMcv0M5GwEVdoQghANgdtbQZAFe3ngw-1i0qGyUMJDA_pUzaW-q75cb-/s640/IMG_7913.JPG" width="480" /></a></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
參考資料:</div>
<div>
<br /></div>
<div>
Malo老師的GitHub</div>
<div>
<a href="https://github.com/maloyang/MicroPython-How-To/blob/master/MicroPython%20How%20to.ipynb">https://github.com/maloyang/MicroPython-How-To/blob/master/MicroPython%20How%20to.ipynb</a></div>
<div>
<br /></div>
CH340 OSX flash error with speed greater 115200<br />
<div>
<a href="https://github.com/espressif/esptool/issues/145">https://github.com/espressif/esptool/issues/145</a></div>
<div>
<br /></div>
<div>
<br /></div>
金石微開http://www.blogger.com/profile/13160756791496033950noreply@blogger.com0tag:blogger.com,1999:blog-2933755125431570931.post-14279611167793348372018-09-14T23:22:00.001+08:002018-09-14T23:22:09.464+08:00[Python] [SSL: TLSV1_ALERT_PROTOCOL_VERSION]
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff}
span.s1 {font-variant-ligatures: no-common-ligatures}
</style>
<br />
<div class="p1">
<span style="font-variant-ligatures: no-common-ligatures;">在OS X Python 2.7.14使用pip套件安裝出現以下錯誤</span></div>
<div class="p1">
<span class="s1"><br /></span></div>
<div class="p1">
<span class="s1">There was a problem confirming the ssl certificate: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:661) - skipping</span></div>
<br /><br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGzV_Jn8XteCZjO5aqic47I-JqSFRXRsCmUcvmehpJyxo8rQ4dqD9aNT7WCQpdzaLiQQuE_qvuGyqwt7GNFbp6tVtS7P9s2OQU73CRcn3yAr78_SMVR8KqxESjnl7NtNN7-b93hTuBejWa/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-09-14+%25E4%25B8%258B%25E5%258D%258811.16.27.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="330" data-original-width="1146" height="184" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGzV_Jn8XteCZjO5aqic47I-JqSFRXRsCmUcvmehpJyxo8rQ4dqD9aNT7WCQpdzaLiQQuE_qvuGyqwt7GNFbp6tVtS7P9s2OQU73CRcn3yAr78_SMVR8KqxESjnl7NtNN7-b93hTuBejWa/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-09-14+%25E4%25B8%258B%25E5%258D%258811.16.27.png" width="640" /></a><br />
<br />
<br />
<br />
<br />
<br />
在網路上找到一個解法<br />
<br />
<span style="background-color: rgba(27, 31, 35, 0.05); color: #24292e; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 11.9px;">curl https://bootstrap.pypa.io/get-pip.py | python</span><br />
<span style="background-color: rgba(27, 31, 35, 0.05); color: #24292e; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 11.9px;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWr-VTBe07V88yY-ELwVqehvc0uAh_4ZGWcvD8B5S8fd2DhMtatcUWH5iV8EmJSN60Wht8fYK_yHB6mXXO5vKU9UOrrX5M7LWmAH3qqTPkQYevz0rRNh1f35OLYehtgr1aEXmgPnafYar2/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-09-14+%25E4%25B8%258B%25E5%258D%258811.17.16.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="512" data-original-width="1458" height="224" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWr-VTBe07V88yY-ELwVqehvc0uAh_4ZGWcvD8B5S8fd2DhMtatcUWH5iV8EmJSN60Wht8fYK_yHB6mXXO5vKU9UOrrX5M7LWmAH3qqTPkQYevz0rRNh1f35OLYehtgr1aEXmgPnafYar2/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-09-14+%25E4%25B8%258B%25E5%258D%258811.17.16.png" width="640" /></a></div>
<span style="background-color: rgba(27, 31, 35, 0.05); color: #24292e; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 11.9px;"><br /></span>
<span style="background-color: rgba(27, 31, 35, 0.05); color: #24292e; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 11.9px;"><br /></span>
<span style="background-color: rgba(27, 31, 35, 0.05); color: #24292e; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 11.9px;"><br /></span>
<span style="background-color: rgba(27, 31, 35, 0.05); color: #24292e; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 11.9px;"><br /></span>
<span style="background-color: rgba(27, 31, 35, 0.05); color: #24292e; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 11.9px;"><br /></span>
<span style="background-color: rgba(27, 31, 35, 0.05); color: #24292e; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 11.9px;"><br /></span>
<span style="background-color: rgba(27, 31, 35, 0.05); color: #24292e; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 11.9px;"><br /></span>
<span style="background-color: rgba(27, 31, 35, 0.05); color: #24292e; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 11.9px;"><br /></span>
<span style="background-color: rgba(27, 31, 35, 0.05); color: #24292e; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 11.9px;"><br /></span>
<span style="background-color: rgba(27, 31, 35, 0.05); color: #24292e; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 11.9px;"><br /></span>
<span style="background-color: rgba(27, 31, 35, 0.05); color: #24292e; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 11.9px;"><br /></span>
<span style="background-color: rgba(27, 31, 35, 0.05); color: #24292e; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 11.9px;"><br /></span>
<span style="background-color: rgba(27, 31, 35, 0.05); color: #24292e; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 11.9px;"><br /></span>
<span style="background-color: rgba(27, 31, 35, 0.05); color: #24292e; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 11.9px;"><br /></span>
<span style="background-color: rgba(27, 31, 35, 0.05); color: #24292e; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 11.9px;"><br /></span>
<span style="background-color: rgba(27, 31, 35, 0.05); color: #24292e; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 11.9px;"><br /></span>
<span style="background-color: rgba(27, 31, 35, 0.05); color: #24292e; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 11.9px;"><br /></span>
<span style="background-color: rgba(27, 31, 35, 0.05); color: #24292e; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 11.9px;"><br /></span>
<span style="background-color: rgba(27, 31, 35, 0.05); color: #24292e; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 11.9px;">之後pip就正常了</span><br />
<span style="background-color: rgba(27, 31, 35, 0.05); color: #24292e; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 11.9px;"><br /></span>
<span style="background-color: rgba(27, 31, 35, 0.05); color: #24292e; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 11.9px;"><br /></span>
參考網頁:<br />
<br />
Problem Confirming the SSL Certificate - OSX<a href="https://github.com/pypa/pip/issues/5236">https://github.com/pypa/pip/issues/5236</a>金石微開http://www.blogger.com/profile/13160756791496033950noreply@blogger.com0tag:blogger.com,1999:blog-2933755125431570931.post-33894300656071143352018-09-14T22:39:00.000+08:002018-09-14T22:39:46.149+08:00[Arduino]外部中斷過去我們在偵測button有沒有按下時,我們會在loop() 中不斷的去檢查button狀態,<br />
<br />
但這樣其實效能不佳,我們可以透過中斷,來處理Button按下的問題。<br />
<br />
但記住一件事,傳統的button會有彈跳現像,這個我們之後再談。<br />
<br />
<br />金石微開http://www.blogger.com/profile/13160756791496033950noreply@blogger.com0tag:blogger.com,1999:blog-2933755125431570931.post-55014422518055474042018-05-06T00:59:00.004+08:002018-05-06T00:59:40.679+08:00[EPS8266」Node MCU 使用LCD 1602(5V版本),電壓問題解法之前遇到一個鳥問題,想要使用Node MCU來手驅動LCD 1602時LCD並不正常,<br />
<br />
僅有LCD背光亮起,但無法正常顯示內容,查詢後可能是電壓的問題(NODE MCU<br />
<br />
,找到一個不需要另外拉線可以使用5V供電的方法。<br />
<br />
<br />
手上的nodeMCU 為 v3 LoLin (不同版本的NodeMCU腳位可能略有不同)<br />
<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimabvaecoDX_n9sbrZ8j-MiKpwvd3wXgDh6s3OWSihB24xiR5VA-asGnxQ7VKkrujotZGGGr2p0arak7Nlb2olec8ODQw1trFy8PrY378_lnd-SYm6wFyscI0DVEP-grUvSwKrS-uSm0FS/s1600/nodemcu-lua-wifi-v3-esp8266-wifi.jpg" imageanchor="1"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimabvaecoDX_n9sbrZ8j-MiKpwvd3wXgDh6s3OWSihB24xiR5VA-asGnxQ7VKkrujotZGGGr2p0arak7Nlb2olec8ODQw1trFy8PrY378_lnd-SYm6wFyscI0DVEP-grUvSwKrS-uSm0FS/s640/nodemcu-lua-wifi-v3-esp8266-wifi.jpg" width="640" /></a><br />
找了很多資料都需要額外電路,最後發現,其實<b>左邊第三隻腳VV</b>,<br />
<br />
就是輸出USB供給的電壓(5V),實際量起來大約4.98V,足夠囉。<br />
<br />
<img alt="ãnodemcu lolinãçåçæå°çµæ" src="https://shopofthings.ch/wp-content/uploads/2017/11/nodemcuv3_pinout.png" /><br />
<br />
<br />
<br />金石微開http://www.blogger.com/profile/13160756791496033950noreply@blogger.com0tag:blogger.com,1999:blog-2933755125431570931.post-63360482701409723412018-02-26T22:24:00.002+08:002018-02-26T22:24:36.979+08:00[Android] TextView 的 freezesText今天在處理當螢幕旋轉問題時,意外看到freezesText這個設定。<br />
<br />
先來看一下Android的文件上怎麼說明的<br />
<br />
<span style="background-color: white; color: rgba(0 , 0 , 0 , 0.87); font-family: "roboto" , sans-serif; font-size: 24px;">android:freezesText</span><br />
<div style="background-color: white; color: rgba(0, 0, 0, 0.68); font-family: Roboto, sans-serif; font-size: 14px; margin-bottom: 12px;">
If set, the text view will include its current complete text inside of its frozen icicle in addition to meta-data such as the current cursor position. By default this is disabled; it can be useful when the contents of a text view is not stored in a persistent place such as a content provider. For <code style="-webkit-font-smoothing: subpixel-antialiased; color: #006600; font-family: Consolas, "Liberation Mono", Menlo, Monaco, Courier, monospace; font-size: 13px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: 18px;"><a href="https://developer.android.com/reference/android/widget/EditText.html" style="color: #039be5; text-decoration-line: none;">EditText</a></code> it is always enabled, regardless of the value of the attribute.</div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.68); font-family: Roboto, sans-serif; font-size: 14px; margin-bottom: 12px;">
May be a boolean value, such as "<code style="-webkit-font-smoothing: subpixel-antialiased; color: #006600; font-family: Consolas, "Liberation Mono", Menlo, Monaco, Courier, monospace; font-size: 13px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: 18px;">true</code>" or "<code style="-webkit-font-smoothing: subpixel-antialiased; color: #006600; font-family: Consolas, "Liberation Mono", Menlo, Monaco, Courier, monospace; font-size: 13px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: 18px;">false</code>".</div>
<br />
預設這個設定是關閉的,當你開啟時,它會完整保留TextView上的內容,遊標位置除外。<br />
<br />
在EditText中,這個設定總是開啟的。<br />
<br />
預設情況下,當我們用在執行過程中,透過程式去設定TextView內容後,當螢幕進行旋轉後,<br />
<br />
TextView的內容會消失.<br />
<br />
<br />
以下是範例程式碼,當按下Add Button後,會把TextView的內容+1
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"> <span style="color: #555555; font-weight: bold;">@Override</span>
<span style="color: #008800; font-weight: bold;">protected</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">onCreate</span><span style="color: #333333;">(</span>Bundle savedInstanceState<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">super</span><span style="color: #333333;">.</span><span style="color: #0000cc;">onCreate</span><span style="color: #333333;">(</span>savedInstanceState<span style="color: #333333;">);</span>
setContentView<span style="color: #333333;">(</span>R<span style="color: #333333;">.</span><span style="color: #0000cc;">layout</span><span style="color: #333333;">.</span><span style="color: #0000cc;">activity_main</span><span style="color: #333333;">);</span>
<span style="color: #008800; font-weight: bold;">final</span> TextView textView<span style="color: #333333;">=(</span>TextView<span style="color: #333333;">)</span>findViewById<span style="color: #333333;">(</span>R<span style="color: #333333;">.</span><span style="color: #0000cc;">id</span><span style="color: #333333;">.</span><span style="color: #0000cc;">txt</span><span style="color: #333333;">);</span>
Button button<span style="color: #333333;">=(</span>Button<span style="color: #333333;">)</span>findViewById<span style="color: #333333;">(</span>R<span style="color: #333333;">.</span><span style="color: #0000cc;">id</span><span style="color: #333333;">.</span><span style="color: #0000cc;">add</span><span style="color: #333333;">);</span>
button<span style="color: #333333;">.</span><span style="color: #0000cc;">setOnClickListener</span><span style="color: #333333;">(</span><span style="color: #008800; font-weight: bold;">new</span> View<span style="color: #333333;">.</span><span style="color: #0000cc;">OnClickListener</span><span style="color: #333333;">()</span> <span style="color: #333333;">{</span>
<span style="color: #555555; font-weight: bold;">@Override</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">onClick</span><span style="color: #333333;">(</span>View v<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span> num<span style="color: #333333;">=</span><span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(!</span>textView<span style="color: #333333;">.</span><span style="color: #0000cc;">getText</span><span style="color: #333333;">().</span><span style="color: #0000cc;">toString</span><span style="color: #333333;">().</span><span style="color: #0000cc;">equals</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">""</span><span style="color: #333333;">))</span>
<span style="color: #333333;">{</span>
num<span style="color: #333333;">=</span>Integer<span style="color: #333333;">.</span><span style="color: #0000cc;">parseInt</span><span style="color: #333333;">(</span>textView<span style="color: #333333;">.</span><span style="color: #0000cc;">getText</span><span style="color: #333333;">().</span><span style="color: #0000cc;">toString</span><span style="color: #333333;">());</span>
<span style="color: #333333;">}</span>
num<span style="color: #333333;">++;</span>
textView<span style="color: #333333;">.</span><span style="color: #0000cc;">setText</span><span style="color: #333333;">(</span>String<span style="color: #333333;">.</span><span style="color: #0000cc;">valueOf</span><span style="color: #333333;">(</span>num<span style="color: #333333;">));</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">});</span>
<span style="color: #333333;">}</span>
</pre>
</div>
<br />
例如我按了六下Button,目前TextView的內容是6<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidvl0UENkIFnz-pxrlnU3pb-cNr_meOLp3XNZGhRuLFOBGmou1XmIqRS57cNEaoIdsBC1pVoCsSdSw55Ho2W_Yg7Kkdy4o08YwGSzbkEBTl8vPszmc-x-osiKWhrcQvrZVjVaNkbTxIrV_/s1600/device-2018-02-26-221622.png" imageanchor="1"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidvl0UENkIFnz-pxrlnU3pb-cNr_meOLp3XNZGhRuLFOBGmou1XmIqRS57cNEaoIdsBC1pVoCsSdSw55Ho2W_Yg7Kkdy4o08YwGSzbkEBTl8vPszmc-x-osiKWhrcQvrZVjVaNkbTxIrV_/s640/device-2018-02-26-221622.png" width="360" /></a><br />
<br />
當我進行螢幕旋轉後,TextView的內容不見囉<br />
<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjPxJAICpzxH882bHALO8SEr7zzRoeh24-kn2-9jFM67YI-pbtRthZsMPQCSNFhjv6RkoohmSnLylKQMByzVVMMn-lbAZSnukjWeqtgn_y1fxHNHK2WsWZYzsOUeU9yzuSwSHahi6dU-TJc/s1600/device-2018-02-26-221916.png" imageanchor="1"><img border="0" height="225" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjPxJAICpzxH882bHALO8SEr7zzRoeh24-kn2-9jFM67YI-pbtRthZsMPQCSNFhjv6RkoohmSnLylKQMByzVVMMn-lbAZSnukjWeqtgn_y1fxHNHK2WsWZYzsOUeU9yzuSwSHahi6dU-TJc/s400/device-2018-02-26-221916.png" width="400" /></a><br />
<br />
如果我將freezesText設為True<br />
<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #557799;"><?xml version="1.0" encoding="utf-8"?></span>
<span style="color: #007700;"><RelativeLayout</span> <span style="color: #0000cc;">xmlns:android=</span><span style="background-color: #fff0f0;">"http://schemas.android.com/apk/res/android"</span>
<span style="color: #0000cc;">xmlns:tools=</span><span style="background-color: #fff0f0;">"http://schemas.android.com/tools"</span>
<span style="color: #0000cc;">android:layout_width=</span><span style="background-color: #fff0f0;">"match_parent"</span>
<span style="color: #0000cc;">android:layout_height=</span><span style="background-color: #fff0f0;">"match_parent"</span>
<span style="color: #0000cc;">android:paddingBottom=</span><span style="background-color: #fff0f0;">"@dimen/activity_vertical_margin"</span>
<span style="color: #0000cc;">android:paddingLeft=</span><span style="background-color: #fff0f0;">"@dimen/activity_horizontal_margin"</span>
<span style="color: #0000cc;">android:paddingRight=</span><span style="background-color: #fff0f0;">"@dimen/activity_horizontal_margin"</span>
<span style="color: #0000cc;">android:paddingTop=</span><span style="background-color: #fff0f0;">"@dimen/activity_vertical_margin"</span>
<span style="color: #0000cc;">tools:context=</span><span style="background-color: #fff0f0;">"com.example.boywhychen.context_menu.MainActivity"</span><span style="color: #007700;">></span>
<span style="color: #007700;"><TextView</span>
<span style="color: #0000cc;">android:layout_width=</span><span style="background-color: #fff0f0;">"wrap_content"</span>
<span style="color: #0000cc;">android:layout_height=</span><span style="background-color: #fff0f0;">"wrap_content"</span>
<span style="color: #0000cc;">android:id=</span><span style="background-color: #fff0f0;">"@+id/txt"</span>
<span style="color: #0000cc;">android:freezesText=</span><span style="background-color: #fff0f0;">"true"</span>
<span style="color: #007700;">/></span>
<span style="color: #007700;"><Button</span>
<span style="color: #0000cc;">android:layout_width=</span><span style="background-color: #fff0f0;">"wrap_content"</span>
<span style="color: #0000cc;">android:layout_height=</span><span style="background-color: #fff0f0;">"wrap_content"</span>
<span style="color: #0000cc;">android:id=</span><span style="background-color: #fff0f0;">"@+id/add"</span>
<span style="color: #0000cc;">android:text=</span><span style="background-color: #fff0f0;">"Add"</span>
<span style="color: #0000cc;">android:layout_below=</span><span style="background-color: #fff0f0;">"@+id/txt"</span>
<span style="color: #007700;">/></span>
<span style="color: #007700;"></RelativeLayout></span>
</pre>
</div>
<br />
執行結果如下<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0PJlIInz-XU5HVeFK0pU-8tAAV_3_LIbdTrT6iH6yaCz07oXFQaTRGmNDJAJUPuwUtg-64RQ9kl6CDLeI4EnVNu1bC4DBElk5tnwrirdVLyxQiSuRbQyVsaZXs0JBxelC7RDEUWUf7Jjg/s1600/device-2018-02-26-222239.png" imageanchor="1"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0PJlIInz-XU5HVeFK0pU-8tAAV_3_LIbdTrT6iH6yaCz07oXFQaTRGmNDJAJUPuwUtg-64RQ9kl6CDLeI4EnVNu1bC4DBElk5tnwrirdVLyxQiSuRbQyVsaZXs0JBxelC7RDEUWUf7Jjg/s640/device-2018-02-26-222239.png" width="360" /></a><br />
<br />
它會保留TextView的內容。<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjaTjAfMjH7pWOAQfVIL9s7n6g5MRbuwoCw834POiXQkbM8BVvA5MXawjhPM9I-fQM55JmenSFzg4ZJIeW0i3kF9lPMLzi7O3ncAD2QKxZf4mpPY13nHUc1nxt3KEKYQGtmCgC7lj_sUPlR/s1600/device-2018-02-26-222410.png" imageanchor="1"><img border="0" height="225" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjaTjAfMjH7pWOAQfVIL9s7n6g5MRbuwoCw834POiXQkbM8BVvA5MXawjhPM9I-fQM55JmenSFzg4ZJIeW0i3kF9lPMLzi7O3ncAD2QKxZf4mpPY13nHUc1nxt3KEKYQGtmCgC7lj_sUPlR/s400/device-2018-02-26-222410.png" width="400" /></a><br />
參考資料:<br />
<br />
<a href="https://developer.android.com/reference/android/widget/TextView.html">https://developer.android.com/reference/android/widget/TextView.html</a><br />
<br />金石微開http://www.blogger.com/profile/13160756791496033950noreply@blogger.com0tag:blogger.com,1999:blog-2933755125431570931.post-23106241863190230082018-02-25T16:01:00.001+08:002018-02-25T16:01:15.572+08:00[Android] String Format 中的 $一般來說如果我們要透過String.Format 作字串格式化顯示 , 例如我們要顯示<br />
<br />
1 + 10 = 11<br />
<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipEj4jUO_3gXxUwttld7XGBU1PIFfBIjHjDI9komh36pXbN87ebW_K2zzdfkJIc21W96iorgvQYqPoZaOA6-d57jrwGttpbu0dHjGrkqRJrZnspylz9wLEHxXNoa2UF1Cfj-NaFJOVLnrD/s1600/device-2018-02-25-155741.png" imageanchor="1"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipEj4jUO_3gXxUwttld7XGBU1PIFfBIjHjDI9komh36pXbN87ebW_K2zzdfkJIc21W96iorgvQYqPoZaOA6-d57jrwGttpbu0dHjGrkqRJrZnspylz9wLEHxXNoa2UF1Cfj-NaFJOVLnrD/s640/device-2018-02-25-155741.png" width="360" /></a><br />
<br />
<br />
我們會這樣用
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;">String formatStr<span style="color: #333333;">=</span><span style="background-color: #fff0f0;">"%d + %d = %d"</span><span style="color: #333333;">;</span>
TextView textView<span style="color: #333333;">=(</span>TextView<span style="color: #333333;">)</span>findViewById<span style="color: #333333;">(</span>R<span style="color: #333333;">.</span><span style="color: #0000cc;">id</span><span style="color: #333333;">.</span><span style="color: #0000cc;">txt</span><span style="color: #333333;">);</span>
String text<span style="color: #333333;">=</span>String<span style="color: #333333;">.</span><span style="color: #0000cc;">format</span><span style="color: #333333;">(</span>formatStr<span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">10</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">11</span><span style="color: #333333;">);</span> textView<span style="color: #333333;">.</span><span style="color: #0000cc;">setText</span><span style="color: #333333;">(</span>text<span style="color: #333333;">);</span>
</pre>
</div>
<br />
但也可以透過$指定索引順序,效果相同<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;">String formatStr<span style="color: #333333;">=</span><span style="background-color: #fff0f0;">"%1$d + %3$d = %2$d"</span><span style="color: #333333;">;</span>
TextView textView<span style="color: #333333;">=(</span>TextView<span style="color: #333333;">)</span>findViewById<span style="color: #333333;">(</span>R<span style="color: #333333;">.</span><span style="color: #0000cc;">id</span><span style="color: #333333;">.</span><span style="color: #0000cc;">txt</span><span style="color: #333333;">);</span>
String text<span style="color: #333333;">=</span>String<span style="color: #333333;">.</span><span style="color: #0000cc;">format</span><span style="color: #333333;">(</span>formatStr<span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">11</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">10</span><span style="color: #333333;">);</span>
textView<span style="color: #333333;">.</span><span style="color: #0000cc;">setText</span><span style="color: #333333;">(</span>text<span style="color: #333333;">);</span>
</pre>
</div>
<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpjfzq5uYHbrYJQyv2aC1HkIO64j4FayvOczhHEkLimKpyGJNBrBXtnnqL7mre5D4BbG5XvtB0ZsX8Dg-cXOlMHs_tZSMjvteGKUMCi5XNVnbu26ugkarECE9dNL36UfOcwLWpQWkjC3Gk/s1600/device-2018-02-25-160044.png" imageanchor="1"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpjfzq5uYHbrYJQyv2aC1HkIO64j4FayvOczhHEkLimKpyGJNBrBXtnnqL7mre5D4BbG5XvtB0ZsX8Dg-cXOlMHs_tZSMjvteGKUMCi5XNVnbu26ugkarECE9dNL36UfOcwLWpQWkjC3Gk/s640/device-2018-02-25-160044.png" width="360" /></a>金石微開http://www.blogger.com/profile/13160756791496033950noreply@blogger.com0tag:blogger.com,1999:blog-2933755125431570931.post-63354648995541256452018-02-24T22:21:00.000+08:002018-02-24T22:21:44.100+08:00[Android] FusedLocationProviderClientFusedLocationProviderClient<div>
<br /></div>
<div>
<span style="background-color: white; color: rgba(0, 0, 0, 0.67); font-family: Roboto, sans-serif; font-size: 16px;">The 11.0.0 release of the Google Play services SDK includes a new way to access</span><a href="https://developers.google.com/android/reference/com/google/android/gms/location/LocationServices" style="background-color: white; color: #039be5; font-family: Roboto, sans-serif; font-size: 16px; text-decoration-line: none;">LocationServices</a><span style="background-color: white; color: rgba(0, 0, 0, 0.67); font-family: Roboto, sans-serif; font-size: 16px;">. The new APIs do not require your app to manually manage a connection to Google Play services through a </span><code style="-webkit-font-smoothing: subpixel-antialiased; background-color: white; color: #006600; font-family: Consolas, "Liberation Mono", Menlo, Monaco, Courier, monospace; font-size: 13px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: 18px;">GoogleApiClient</code><span style="background-color: white; color: rgba(0, 0, 0, 0.67); font-family: Roboto, sans-serif; font-size: 16px;">. This reduces boilerplate and common pitfalls in your app.</span></div>
<div>
<span style="background-color: white; color: rgba(0, 0, 0, 0.67); font-family: Roboto, sans-serif; font-size: 16px;"><br /></span></div>
<div>
<span style="background-color: white; color: rgba(0, 0, 0, 0.67); font-family: Roboto, sans-serif; font-size: 16px;"><br /></span></div>
<div>
<ul style="background-color: white; color: rgba(0, 0, 0, 0.67); font-family: Roboto, sans-serif; font-size: 16px; line-height: 1.4; margin: 16px 0px; padding: 0px 0px 0px 24px;">
<li style="margin: 0.5em 0px 0.25em; padding: 0px;">The API calls automatically wait for the service connection to be established, which removes the need to wait for <code style="-webkit-font-smoothing: subpixel-antialiased; color: #006600; font-family: Consolas, "Liberation Mono", Menlo, Monaco, Courier, monospace; font-size: 13px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: 18px;">onConnected</code> before making requests.</li>
<li style="margin: 0.5em 0px 0.25em; padding: 0px;">It uses the <a href="https://firebase.googleblog.com/2016/09/become-a-firebase-taskmaster-part-1.html" style="color: #039be5; text-decoration-line: none;">Task</a> API which makes it easier to compose asynchronous operations.</li>
<li style="margin: 0.5em 0px 0.25em; padding: 0px;">The code is self-contained and could easily be moved into a shared utility class or similar.</li>
<li style="margin: 0.5em 0px 0.25em; padding: 0px;">You don't need to understand the underlying connection process to start coding.</li>
</ul>
<div>
<br /></div>
</div>
<div>
它是新的存取位置的API,整合在Google Play Service中,不再因為API不同而在過去使用LocationManager上有所差異。</div>
金石微開http://www.blogger.com/profile/13160756791496033950noreply@blogger.com0tag:blogger.com,1999:blog-2933755125431570931.post-53769001365220998632018-02-20T23:38:00.000+08:002018-02-20T23:39:05.783+08:00[iOS]使用Google Map使用GOOGLE的API,萬法不離宗,就是要申請API KEY,<br />
<br />
所以到Google Cloud Platform 新增專案<br />
<a href="https://console.developers.google.com/">https://console.developers.google.com</a><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSezCdc57kPx24koFlyh_ry0__EMhkswGAZKp0a56ff-70sSQxUhhNtgBGQuIJ304Id4o611zeYPrfUf5F1VHwePKUUv_RsZz056HFd_oB0WrfE79v4ASi957wYZfJ4-ye613iqZ3qKX3r/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-19+%25E4%25B8%258B%25E5%258D%25886.01.15.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="230" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSezCdc57kPx24koFlyh_ry0__EMhkswGAZKp0a56ff-70sSQxUhhNtgBGQuIJ304Id4o611zeYPrfUf5F1VHwePKUUv_RsZz056HFd_oB0WrfE79v4ASi957wYZfJ4-ye613iqZ3qKX3r/s400/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-19+%25E4%25B8%258B%25E5%258D%25886.01.15.png" width="400" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
建立完成後畫面如下,接下來點選啟用API和服務<br />
<br />
<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjH0TYTIjcz81J8gG4Z6uHmS_NLe7JmqhkPFVOfPEikCq0HL1joCMag3Ivzjzzo1bYOIg-SykESphr0yrX15a_yanb36XEwlCclE2rz9Rsv-ELR-Nv_2ctFRZ018FQERYYsVSs4A7DMtoI9/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-19+%25E4%25B8%258B%25E5%258D%25886.04.26.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="308" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjH0TYTIjcz81J8gG4Z6uHmS_NLe7JmqhkPFVOfPEikCq0HL1joCMag3Ivzjzzo1bYOIg-SykESphr0yrX15a_yanb36XEwlCclE2rz9Rsv-ELR-Nv_2ctFRZ018FQERYYsVSs4A7DMtoI9/s400/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-19+%25E4%25B8%258B%25E5%258D%25886.04.26.png" width="400" /></a><br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
點選Google Map for iOS<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj24FnZFzRk9XJBFNjGF1akR-Wk3epEqyRD9JTZLL1DZOWQvstnvuTOTs5U3i6zl9JtYFhWNwyd0c3uR7KVkNq2m_wNybes3q-OQEzf1d86F7BrbYkHfYNy0oRF9NF5nXD14SrnvBgJdt5J/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-19+%25E4%25B8%258B%25E5%258D%25886.06.39.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="378" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj24FnZFzRk9XJBFNjGF1akR-Wk3epEqyRD9JTZLL1DZOWQvstnvuTOTs5U3i6zl9JtYFhWNwyd0c3uR7KVkNq2m_wNybes3q-OQEzf1d86F7BrbYkHfYNy0oRF9NF5nXD14SrnvBgJdt5J/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-19+%25E4%25B8%258B%25E5%258D%25886.06.39.png" width="640" /></a><br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
啟用<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEivwWWXPipWjN26f26cZdeWmpkqooVuVLlhVr5RNU1rk1UsczHvGvfJP4zyLuEvjbKe1VY0Ed2ipdhEV1EtsfnHupODVpFmeMrpuwO38dZsgFKh2O8mFwpJRJFpeP7-2xFxIEA5kspIPgmY/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-19+%25E4%25B8%258B%25E5%258D%25886.06.49.png" imageanchor="1"><img border="0" height="468" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEivwWWXPipWjN26f26cZdeWmpkqooVuVLlhVr5RNU1rk1UsczHvGvfJP4zyLuEvjbKe1VY0Ed2ipdhEV1EtsfnHupODVpFmeMrpuwO38dZsgFKh2O8mFwpJRJFpeP7-2xFxIEA5kspIPgmY/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-19+%25E4%25B8%258B%25E5%258D%25886.06.49.png" width="640" /></a><br />
<br />
建立憑證<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhuJVWNeONU7ADwPyRIr2Rq_L0D4H7i0WX263r-yG-c60jmzd5bvhRp_qGThDqbOd9-Axc-PT4q9otq3NPPRogq4TY-845iMoU6iVwKEOV2m76kvaN6SilMAHebVGcV3WigAC2ko2REd5h/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-19+%25E4%25B8%258B%25E5%258D%25886.11.20.png" imageanchor="1"><img border="0" height="338" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhuJVWNeONU7ADwPyRIr2Rq_L0D4H7i0WX263r-yG-c60jmzd5bvhRp_qGThDqbOd9-Axc-PT4q9otq3NPPRogq4TY-845iMoU6iVwKEOV2m76kvaN6SilMAHebVGcV3WigAC2ko2REd5h/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-19+%25E4%25B8%258B%25E5%258D%25886.11.20.png" width="640" /></a><br />
點選"我需要那些憑證?"<br />
<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7OJ3ZFVTvXC88TDkSpEs69XzrUR30Ma4VC-ViHtJXztf3Vxf6BElD2q0Lnt0_IXE4dcqrSWc1hiI7sMFWaJ9G7ZauHNatgLUBcm1BZno3YoR8qJCD70kcJEpSSFw5dNSKtTQTsIsAH97F/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-19+%25E4%25B8%258B%25E5%258D%25886.11.33.png" imageanchor="1"><img border="0" height="630" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7OJ3ZFVTvXC88TDkSpEs69XzrUR30Ma4VC-ViHtJXztf3Vxf6BElD2q0Lnt0_IXE4dcqrSWc1hiI7sMFWaJ9G7ZauHNatgLUBcm1BZno3YoR8qJCD70kcJEpSSFw5dNSKtTQTsIsAH97F/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-19+%25E4%25B8%258B%25E5%258D%25886.11.33.png" width="640" /></a><br />
<br />
點選"為金鑰新增限制"保護你的KEY不被預期之外的程序呼叫<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvBvjAU8jqcWmzatcldYuSprI2okV_nSAeT5XJc1B8VD4HyhUca4QA1TXjPCxxGiIqM6liDdMgHH-9xE1juEIur9u2xFee6-v6T9hBkPa-h_K59k_ukdei5zBnYZQUm515426vuTvA0WgG/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-19+%25E4%25B8%258B%25E5%258D%25886.11.40.png" imageanchor="1"><img border="0" height="534" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvBvjAU8jqcWmzatcldYuSprI2okV_nSAeT5XJc1B8VD4HyhUca4QA1TXjPCxxGiIqM6liDdMgHH-9xE1juEIur9u2xFee6-v6T9hBkPa-h_K59k_ukdei5zBnYZQUm515426vuTvA0WgG/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-19+%25E4%25B8%258B%25E5%258D%25886.11.40.png" width="640" /></a><br />
如果你有要限定某一款iOS APP 才能呼叫,記得在com.example.MyAPP填入<br />
<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhjqM3EChQN4FwEsMCeJ-_tVi5GzcXHWz8Ir_KOor3jWa93q-7dqFqre6tIfc9azifd7RN2Fpp72gb7ATEgFt1hUMWZ4FKLoNXI-4alVDw5aAecARSpTq2voDfcRoWngpHLhp5MgX-dbmJ/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-19+%25E4%25B8%258B%25E5%258D%25886.11.58.png" imageanchor="1"><img border="0" height="592" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhjqM3EChQN4FwEsMCeJ-_tVi5GzcXHWz8Ir_KOor3jWa93q-7dqFqre6tIfc9azifd7RN2Fpp72gb7ATEgFt1hUMWZ4FKLoNXI-4alVDw5aAecARSpTq2voDfcRoWngpHLhp5MgX-dbmJ/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-19+%25E4%25B8%258B%25E5%258D%25886.11.58.png" width="640" /></a> 金鑰這樣就申請好囉<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxTjQuXxUinpJhaSjjBQlXecXeuznAEYDolrnfgeOF9lZJgIJv7rieHVOLQY7o2TFOC1rznmygfEWbb2Zv9jpMvQdfkpJy3j2afSMmf-41J1OdYxctSfbksBsVnQkEI4PfQL87_tCR8k9Z/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-19+%25E4%25B8%258B%25E5%258D%25886.18.33.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="264" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxTjQuXxUinpJhaSjjBQlXecXeuznAEYDolrnfgeOF9lZJgIJv7rieHVOLQY7o2TFOC1rznmygfEWbb2Zv9jpMvQdfkpJy3j2afSMmf-41J1OdYxctSfbksBsVnQkEI4PfQL87_tCR8k9Z/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-19+%25E4%25B8%258B%25E5%258D%25886.18.33.png" width="640" /></a></div>
接下來記住你的金鑰,進入軟體部份了,如果您沒安裝過<a href="https://cocoapods.org/" style="background-color: white; box-sizing: inherit; color: #039be5; font-family: Roboto, sans-serif; font-size: 14px; outline: 0px; text-decoration-line: none;">CocoaPods</a> 需要先安裝,否則<br />
<br />
請跳過安裝這一步,記得要是Xcode 8 or 9 ,請在終端機打上以下內容<br />
<br />
<pre class="highlight" style="background-color: whitesmoke; border-radius: 4px; border: 1px solid rgb(204, 204, 204); box-sizing: border-box; font-family: Monaco, Menlo, Consolas, "courier new", monospace; font-size: 13px; line-height: 1.42857; margin-bottom: 10px; padding: 9.5px; white-space: pre-wrap; word-break: break-all; word-wrap: break-word;">sudo gem install cocoapods</pre>
<br />
等待安裝完成。<br />
<br />
接下來我們要開啟一個Xcode專案<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJRkRHg4l5wdaZ0qJcrdcwYiwbLcUgsYOW2EuCcai6jN58A6K8sTK43wBvTC6z4DI85v9O_eyplx4o7sxU87ubtJeqmP49Vir7UOeNU0jWGpULqoKLyMCgWZvRVmwCO54HOz_QsQz2gC8d/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-20+%25E4%25B8%258B%25E5%258D%25889.19.28.png" imageanchor="1"><img border="0" height="452" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJRkRHg4l5wdaZ0qJcrdcwYiwbLcUgsYOW2EuCcai6jN58A6K8sTK43wBvTC6z4DI85v9O_eyplx4o7sxU87ubtJeqmP49Vir7UOeNU0jWGpULqoKLyMCgWZvRVmwCO54HOz_QsQz2gC8d/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-20+%25E4%25B8%258B%25E5%258D%25889.19.28.png" width="640" /></a><br />
<br />
當專案建立完畢後,關閉專案及Xcode,回到終端機,進入專案根目錄下<br />
<br />
<pre class="highlight" style="background-color: whitesmoke; border-radius: 4px; border: 1px solid rgb(204, 204, 204); box-sizing: border-box; font-family: monaco, menlo, consolas, "courier new", monospace; font-size: 13px; line-height: 1.42857; margin-bottom: 10px; padding: 9.5px; white-space: pre-wrap; word-break: break-all; word-wrap: break-word;">cd MapDemo/</pre>
<br />
接下來要安裝GOOGLE MAP SDK,首先初始化一下cocoa pods 需要的設定檔<br />
<pre class="highlight" style="background-color: whitesmoke; border-radius: 4px; border: 1px solid rgb(204, 204, 204); box-sizing: border-box; font-family: monaco, menlo, consolas, "courier new", monospace; font-size: 13px; line-height: 1.42857; margin-bottom: 10px; padding: 9.5px; white-space: pre-wrap; word-break: break-all; word-wrap: break-word;">pod init</pre>
<br />
接下來編輯設定檔
<br />
<pre class="highlight" style="background-color: whitesmoke; border-radius: 4px; border: 1px solid rgb(204, 204, 204); box-sizing: border-box; font-family: monaco, menlo, consolas, "courier new", monospace; font-size: 13px; line-height: 1.42857; margin-bottom: 10px; padding: 9.5px; white-space: pre-wrap; word-break: break-all; word-wrap: break-word;">vi Podfile
</pre>
<br />
設定檔一開始長這樣
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"># Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
target 'MapDemo' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Pods for MapDemo
target 'MapDemoTests' do
inherit! :search_paths
# Pods for testing
end
target 'MapDemoUITests' do
inherit! :search_paths
# Pods for testing
end
end
~
</pre>
</div>
<br />
加入GOOGLE MAP SDK,主要有三行<br />
<pre style="line-height: 16.25px;">source <span style="background-color: #fff0f0;">'https://github.com/CocoaPods/Specs.git'</span></pre>
及<br />
<pre style="line-height: 16.25px;">pod <span style="background-color: #fff0f0;">'GoogleMaps'</span>
pod <span style="background-color: #fff0f0;">'GooglePlaces'</span> </pre>
<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"># Uncomment the next line <span style="color: #008800; font-weight: bold;">to</span> <span style="color: #007020;">define</span> <span style="color: #008800; font-weight: bold;">a</span> global platform <span style="color: #008800; font-weight: bold;">for</span> your project
# platform :ios, <span style="background-color: #fff0f0;">'9.0'</span>
source <span style="background-color: #fff0f0;">'https://github.com/CocoaPods/Specs.git'</span>
target <span style="background-color: #fff0f0;">'MapDemo'</span> <span style="color: #008800; font-weight: bold;">do</span>
# Comment the next line <span style="color: #008800; font-weight: bold;">if</span> you<span style="background-color: #fff0f0;">'re not using Swift and don'</span><span style="color: #008800; font-weight: bold;">t</span> want <span style="color: #008800; font-weight: bold;">to</span> use dynamic frameworks
use_frameworks!
pod <span style="background-color: #fff0f0;">'GoogleMaps'</span>
pod <span style="background-color: #fff0f0;">'GooglePlaces'</span>
# Pods <span style="color: #008800; font-weight: bold;">for</span> MapDemo
target <span style="background-color: #fff0f0;">'MapDemoTests'</span> <span style="color: #008800; font-weight: bold;">do</span>
inherit! :search_paths
# Pods <span style="color: #008800; font-weight: bold;">for</span> testing
<span style="color: #008800; font-weight: bold;">end</span>
target <span style="background-color: #fff0f0;">'MapDemoUITests'</span> <span style="color: #008800; font-weight: bold;">do</span>
inherit! :search_paths
# Pods <span style="color: #008800; font-weight: bold;">for</span> testing
<span style="color: #008800; font-weight: bold;">end</span>
<span style="color: #008800; font-weight: bold;">end</span>
# Uncomment the next line <span style="color: #008800; font-weight: bold;">to</span> <span style="color: #007020;">define</span> <span style="color: #008800; font-weight: bold;">a</span> global platform <span style="color: #008800; font-weight: bold;">for</span> your project
# platform :ios, <span style="background-color: #fff0f0;">'9.0'</span>
target <span style="background-color: #fff0f0;">'MapDemo'</span> <span style="color: #008800; font-weight: bold;">do</span>
# Comment the next line <span style="color: #008800; font-weight: bold;">if</span> you<span style="background-color: #fff0f0;">'re not using Swift and don'</span><span style="color: #008800; font-weight: bold;">t</span> want <span style="color: #008800; font-weight: bold;">to</span> use dynamic frameworks
use_frameworks!
# Pods <span style="color: #008800; font-weight: bold;">for</span> MapDemo
target <span style="background-color: #fff0f0;">'MapDemoTests'</span> <span style="color: #008800; font-weight: bold;">do</span>
inherit! :search_paths
# Pods <span style="color: #008800; font-weight: bold;">for</span> testing
<span style="color: #008800; font-weight: bold;">end</span>
target <span style="background-color: #fff0f0;">'MapDemoUITests'</span> <span style="color: #008800; font-weight: bold;">do</span>
inherit! :search_paths
# Pods <span style="color: #008800; font-weight: bold;">for</span> testing
<span style="color: #008800; font-weight: bold;">end</span>
<span style="color: #008800; font-weight: bold;">end</span>
~
</pre>
</div>
<br />
接下來存檔,然候開始安裝SDK囉,視網路情況,可能需要一點時間喔。<br />
<pre class="highlight" style="background-color: whitesmoke; border-radius: 4px; border: 1px solid rgb(204, 204, 204); box-sizing: border-box; font-family: monaco, menlo, consolas, "courier new", monospace; font-size: 13px; line-height: 1.42857; margin-bottom: 10px; padding: 9.5px; white-space: pre-wrap; word-break: break-all; word-wrap: break-word;">pod install</pre>
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #34bd26}
p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px}
p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #afad24}
span.s1 {font-variant-ligatures: no-common-ligatures}
</style>
安裝過程如下<br />
<br />
<div class="p1">
<span class="s1">Analyzing dependencies</span></div>
<div class="p1">
<span class="s1">Downloading dependencies</span></div>
<div class="p2">
<span class="s1">Installing GoogleMaps (2.5.0)</span></div>
<div class="p2">
<span class="s1">Installing GooglePlaces (2.5.0)</span></div>
<div class="p1">
<span class="s1">Generating Pods project</span></div>
<div class="p1">
<span class="s1">Integrating client project</span></div>
<div class="p3">
<span class="s1"></span><br /></div>
<div class="p2">
<span class="s1">[!] Please close any current Xcode sessions and use `MapDemo.xcworkspace` for this project from now on.</span></div>
<div class="p1">
<span class="s1">Sending stats</span></div>
<div class="p2">
<span class="s1">Pod installation complete! There are 2 dependencies from the Podfile and 2 total pods installed.</span></div>
<div class="p3">
<span class="s1"></span><br /></div>
<div class="p4">
<span class="s1">[!] Automatically assigning platform ios with version 10.2 on target MapDemo because no platform was specified. Please specify a platform for this target in your Podfile. See `https://guides.cocoapods.org/syntax/podfile.html#platform`.</span></div>
<div class="p1">
<br /></div>
<br />
<br />
接下來用指令啟動xocde<br />
<pre class="highlight" style="background-color: whitesmoke; border-radius: 4px; border: 1px solid rgb(204, 204, 204); box-sizing: border-box; font-family: monaco, menlo, consolas, "courier new", monospace; font-size: 13px; line-height: 1.42857; margin-bottom: 10px; padding: 9.5px; white-space: pre-wrap; word-break: break-all; word-wrap: break-word;">open MapDemo.xcworkspace</pre>
<br />
安裝成功的話你會發現專案多了一個Pods<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhILXVe_JnavpG_hJrj84O9AJJaoRv5RrRQL0WexOFIujt5xhemNDqJr61NocFSNojo-jez_8EKEwoc4_SmLqSrN4gB0v5CJ8HrexRfCaEqEladrtBbayLKIhc8FiCbi3N2iW7gkvZ6ugEW/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-20+%25E4%25B8%258B%25E5%258D%25889.40.13.png" imageanchor="1"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhILXVe_JnavpG_hJrj84O9AJJaoRv5RrRQL0WexOFIujt5xhemNDqJr61NocFSNojo-jez_8EKEwoc4_SmLqSrN4gB0v5CJ8HrexRfCaEqEladrtBbayLKIhc8FiCbi3N2iW7gkvZ6ugEW/s400/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-20+%25E4%25B8%258B%25E5%258D%25889.40.13.png" /></a><br />
<br />
在AppDelegate.swift 加入<span class="s1" style="font-family: "menlo"; font-size: 11px;">import</span><span class="s2" style="font-family: "menlo"; font-size: 11px;"> GoogleMaps</span><br />
<span class="s2" style="font-family: "menlo"; font-size: 11px;"><br /></span>
<span class="s2" style="font-family: "menlo"; font-size: 11px;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkjVMuWFn_iYaH9X16npM9-EJ20eaJgRTog5J5QaANRBh2Qowfd8JqMQvDjOhvZbaVivsGa4oDPbkakcQe1v0_UJaJ2xXPSRhB45_jycdi9B-yKd1V6TMivsvXYP50MkdqOApMnZnV2WqB/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-20+%25E4%25B8%258B%25E5%258D%25889.44.23.png" imageanchor="1"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkjVMuWFn_iYaH9X16npM9-EJ20eaJgRTog5J5QaANRBh2Qowfd8JqMQvDjOhvZbaVivsGa4oDPbkakcQe1v0_UJaJ2xXPSRhB45_jycdi9B-yKd1V6TMivsvXYP50MkdqOApMnZnV2WqB/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-20+%25E4%25B8%258B%25E5%258D%25889.44.23.png" /></a></span><br />
<br />
接下來在application(_:didFinishLaunchingWithOptions:) 方法中填入你的API KEY(金鑰)<br />
<br />
<pre class="prettyprint notranslate" style="background: rgb(247, 247, 247); box-sizing: inherit; color: #37474f; font-family: "Roboto Mono", monospace; font-size: 14px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: 20px; margin-bottom: 16px; margin-top: 16px; overflow-x: auto; padding: 8px; position: relative;"><span class="typ" style="box-sizing: inherit; color: #9c27b0;">GMSServices</span><span class="pun" style="box-sizing: inherit;">.</span><span class="pln" style="box-sizing: inherit;">provideAPIKey</span><span class="pun" style="box-sizing: inherit;">(</span><span class="str" style="box-sizing: inherit; color: #0d904f;">"</span><var aria-label="點擊即可插入您的憑證" class="apiparam replaceable-credential" data-tooltip-align="b,c" data-tooltip="點擊即可插入您的憑證" style="-webkit-font-smoothing: auto; border: 1px dashed rgb(233, 30, 99); box-sizing: inherit; color: #ec407a; cursor: pointer; font-weight: 700; padding: 2px;"><span class="str" style="-webkit-font-smoothing: auto; box-sizing: inherit;">YOUR_API_KEY</span></var><span class="str" style="box-sizing: inherit; color: #0d904f;">"</span><span class="pun" style="box-sizing: inherit;">)</span></pre>
<span style="background-color: #f7f7f7; color: #37474f; font-family: "roboto mono" , monospace; font-size: 12.6px;"><br /></span>
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo}
span.s1 {font-variant-ligatures: no-common-ligatures; color: #bb2ca2}
span.s2 {font-variant-ligatures: no-common-ligatures}
</style>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-11ShqtB56E61RST7EYAMgUu-vktzSaecWCtV0h7eQThNh2xSqsGsKbB-iC3CdTQo0pXlniMCD2lWGjxTc68KbUlJmvVHriivd7mBulDxE3jWYxagciAJ4w2MFP4kkmA7y8jfrgEIhq6g/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-20+%25E4%25B8%258B%25E5%258D%25889.47.49.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-11ShqtB56E61RST7EYAMgUu-vktzSaecWCtV0h7eQThNh2xSqsGsKbB-iC3CdTQo0pXlniMCD2lWGjxTc68KbUlJmvVHriivd7mBulDxE3jWYxagciAJ4w2MFP4kkmA7y8jfrgEIhq6g/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-20+%25E4%25B8%258B%25E5%258D%25889.47.49.png" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-11ShqtB56E61RST7EYAMgUu-vktzSaecWCtV0h7eQThNh2xSqsGsKbB-iC3CdTQo0pXlniMCD2lWGjxTc68KbUlJmvVHriivd7mBulDxE3jWYxagciAJ4w2MFP4kkmA7y8jfrgEIhq6g/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-20+%25E4%25B8%258B%25E5%258D%25889.47.49.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><br /></a><br />
<br />
<br />
<br />
<br />
<br />
<br />
接下來把Main.storyboard的View的Class改成GMSMapView<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgijPVN-BIps-jRb3HIOFEw0jmmhDvD3TuyCJ0Mo4ieEX29M7AM0MowNocw3NneXsyXUhNlEve6rgnrEwV5tchIrmQKjT93wFHfcyO8t8O24BPPwHw1QrM3I9lgIHq6KrYa4W6CqoALXsWu/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-20+%25E4%25B8%258B%25E5%258D%258810.17.13.png" imageanchor="1"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgijPVN-BIps-jRb3HIOFEw0jmmhDvD3TuyCJ0Mo4ieEX29M7AM0MowNocw3NneXsyXUhNlEve6rgnrEwV5tchIrmQKjT93wFHfcyO8t8O24BPPwHw1QrM3I9lgIHq6KrYa4W6CqoALXsWu/s400/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-20+%25E4%25B8%258B%25E5%258D%258810.17.13.png" /></a><br />
<br />
接著在ViewController.swift中加入<span class="s1" style="font-family: "menlo"; font-size: 11px;">import</span><span class="s2" style="font-family: "menlo"; font-size: 11px;"> GoogleMaps </span>以及以下程式碼<br />
<br />
<div class="p1">
<span class="s1"><span class="Apple-converted-space"> </span></span><span class="s2">override</span><span class="s1"> </span><span class="s2">func</span><span class="s1"> loadView() {</span></div>
<div class="p2">
<span class="s3"><span class="Apple-converted-space"> </span></span><span class="s1">// Create a GMSCameraPosition that tells the map to display the</span></div>
<div class="p2">
<span class="s3"><span class="Apple-converted-space"> </span></span><span class="s1">// coordinate -33.86,151.20 at zoom level 6.</span></div>
<div class="p1">
<span class="s1"><span class="Apple-converted-space"> </span></span><span class="s2">let</span><span class="s1"> camera = </span><span class="s4">GMSCameraPosition</span><span class="s1">.</span><span class="s5">camera</span><span class="s1">(withLatitude: </span><span class="s6">-33.86</span><span class="s1">, longitude: </span><span class="s6">151.20</span><span class="s1">, zoom: </span><span class="s6">6.0</span><span class="s1">)</span></div>
<div class="p1">
<span class="s1"><span class="Apple-converted-space"> </span></span><span class="s2">let</span><span class="s1"> mapView = </span><span class="s4">GMSMapView</span><span class="s1">.</span><span class="s5">map</span><span class="s1">(withFrame: </span><span class="s7">CGRect</span><span class="s1">.</span><span class="s7">zero</span><span class="s1">, camera: camera)</span></div>
<div class="p1">
<span class="s1"><span class="Apple-converted-space"> </span>mapView.</span><span class="s4">isMyLocationEnabled</span><span class="s1"> = </span><span class="s2">true</span></div>
<div class="p1">
<span class="s1"><span class="Apple-converted-space"> </span></span><span class="s7">view</span><span class="s1"> = mapView</span></div>
<div class="p3">
<span class="s1"><span class="Apple-converted-space"> </span></span></div>
<div class="p2">
<span class="s3"><span class="Apple-converted-space"> </span></span><span class="s1">// Creates a marker in the center of the map.</span></div>
<div class="p1">
<span class="s1"><span class="Apple-converted-space"> </span></span><span class="s2">let</span><span class="s1"> marker = </span><span class="s4">GMSMarker</span><span class="s1">()</span></div>
<div class="p1">
<span class="s1"><span class="Apple-converted-space"> </span>marker.</span><span class="s4">position</span><span class="s1"> = </span><span class="s7">CLLocationCoordinate2D</span><span class="s1">(latitude: </span><span class="s6">-33.86</span><span class="s1">, longitude: </span><span class="s6">151.20</span><span class="s1">)</span></div>
<div class="p1">
<span class="s1"><span class="Apple-converted-space"> </span>marker.</span><span class="s4">title</span><span class="s1"> = </span><span class="s8">"Sydney"</span></div>
<div class="p1">
<span class="s1"><span class="Apple-converted-space"> </span>marker.</span><span class="s4">snippet</span><span class="s1"> = </span><span class="s8">"Australia"</span></div>
<div class="p1">
<span class="s1"><span class="Apple-converted-space"> </span>marker.</span><span class="s4">map</span><span class="s1"> = mapView</span></div>
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008400}
p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px}
span.s1 {font-variant-ligatures: no-common-ligatures}
span.s2 {font-variant-ligatures: no-common-ligatures; color: #bb2ca2}
span.s3 {font-variant-ligatures: no-common-ligatures; color: #000000}
span.s4 {font-variant-ligatures: no-common-ligatures; color: #4f8187}
span.s5 {font-variant-ligatures: no-common-ligatures; color: #31595d}
span.s6 {font-variant-ligatures: no-common-ligatures; color: #272ad8}
span.s7 {font-variant-ligatures: no-common-ligatures; color: #703daa}
span.s8 {font-variant-ligatures: no-common-ligatures; color: #d12f1b}
</style>
<br />
<div class="p1">
<span class="s1"><span class="Apple-converted-space"> </span>}</span></div>
<div class="p1">
<span class="s1"><br /></span></div>
<div class="p1">
<span class="s1"><br /></span></div>
完整ViewController.swift如下
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo}
span.s1 {font-variant-ligatures: no-common-ligatures}
</style>
<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfH50Kl9SdkVU1CK3X5NxzwhDCY5joVNtfCiWWwvxAZCKCsucfTCaK1YoSPjS_jTG09iaEQ4Q8bHqJ8eg8CbULzCOmCfNiZmLbChp7fnjpty0MaK71DqGVmw0trRbipW_KgyvSYqY8SCw2/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-20+%25E4%25B8%258B%25E5%258D%258810.20.54.png" imageanchor="1"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfH50Kl9SdkVU1CK3X5NxzwhDCY5joVNtfCiWWwvxAZCKCsucfTCaK1YoSPjS_jTG09iaEQ4Q8bHqJ8eg8CbULzCOmCfNiZmLbChp7fnjpty0MaK71DqGVmw0trRbipW_KgyvSYqY8SCw2/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-20+%25E4%25B8%258B%25E5%258D%258810.20.54.png" /></a><br />
<br />
接著在Info.plist中加入<span style="color: #212121; font-family: "roboto" , sans-serif; font-size: 16px;">Google Maps SDK for iOS 使用的 URL 配置</span><br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3zuuA8YJuQRtZb0KUM0E2Km57MYcMZFOM8RyojkrhE5TmgtYFW0ShDAty7lpRhAdYg2fE3JJ8Vv4rDyQF6EYYy202i0FK5VIAp1JR1bg28lAFTk4jG9iUoFYjaj2tN1Y9ciClPeRBJY7F/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-20+%25E4%25B8%258B%25E5%258D%25889.53.28.png" imageanchor="1"><img border="0" height="510" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3zuuA8YJuQRtZb0KUM0E2Km57MYcMZFOM8RyojkrhE5TmgtYFW0ShDAty7lpRhAdYg2fE3JJ8Vv4rDyQF6EYYy202i0FK5VIAp1JR1bg28lAFTk4jG9iUoFYjaj2tN1Y9ciClPeRBJY7F/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-20+%25E4%25B8%258B%25E5%258D%25889.53.28.png" width="640" /></a><br />
<br />
或是用UI介面編輯<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjnmg5NRowgeI4sCP5V_ANF7nsfLKRPFsRfK1i50uJRzooAbHlnCBoMRJsXk_PhE7wJnak7tew9neIKn3ch46rjfb5_hVlegk3PcidTAYdN8OYh8_PAaa2mGxcvMzTWb2CO14nWopbPj6Qa/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-20+%25E4%25B8%258B%25E5%258D%258811.06.49.png" imageanchor="1"><img border="0" height="201" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjnmg5NRowgeI4sCP5V_ANF7nsfLKRPFsRfK1i50uJRzooAbHlnCBoMRJsXk_PhE7wJnak7tew9neIKn3ch46rjfb5_hVlegk3PcidTAYdN8OYh8_PAaa2mGxcvMzTWb2CO14nWopbPj6Qa/s320/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-20+%25E4%25B8%258B%25E5%258D%258811.06.49.png" width="320" /></a><br />
<br />
接下來就可以開啟模擬器執行看看地圖會不會出來囉,地點會在雪梨<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhO4fA5uuFwZFHzxDM72sJldWrJVFw2sE-Om8yHr8dMy5iww5W6qkxrwfeX0G_ATf5af9B3MWMu_-0axDBmis_Txx9eiv0S8DE4jqC50nehTeYptDby2wTIAOlOSa34CbYB2RK-LVhGG1Ax/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-20+%25E4%25B8%258B%25E5%258D%258810.22.10.png" imageanchor="1"><img border="0" height="499" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhO4fA5uuFwZFHzxDM72sJldWrJVFw2sE-Om8yHr8dMy5iww5W6qkxrwfeX0G_ATf5af9B3MWMu_-0axDBmis_Txx9eiv0S8DE4jqC50nehTeYptDby2wTIAOlOSa34CbYB2RK-LVhGG1Ax/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-20+%25E4%25B8%258B%25E5%258D%258810.22.10.png" width="640" /></a><br />
<br />
接下來我們試著顯示自己位置看看,此時我們會需要再加入一個NSLocationAlwaysUsageDescription 到Info.plis 提示用戶需要位置權限的字串<br />
<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicENPyUREhw10QMaduZHy3DVeVndQzov7gMDhopevfX9j_tVAuhOnaOfv0YvrATNkSZF-xzhvMNzdkQG9Z9TQ7X4IFYRbpxC6Zmkieq_ZOxnD5F_ol-rjtu02ftCNEr9abaPrtLkubnsUF/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-20+%25E4%25B8%258B%25E5%258D%258811.14.14.png" imageanchor="1"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicENPyUREhw10QMaduZHy3DVeVndQzov7gMDhopevfX9j_tVAuhOnaOfv0YvrATNkSZF-xzhvMNzdkQG9Z9TQ7X4IFYRbpxC6Zmkieq_ZOxnD5F_ol-rjtu02ftCNEr9abaPrtLkubnsUF/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-20+%25E4%25B8%258B%25E5%258D%258811.14.14.png" /></a><br />
<br />
接下來我們改一下程式碼如下<br />
<pre class="devsite-code-button-clone" style="background: rgb(247, 247, 247); box-sizing: inherit; color: #37474f; font-family: "Roboto Mono", monospace; font-size: 14px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; left: -99999px; line-height: 20px; margin-bottom: 16px; margin-top: 16px; overflow-x: auto; padding: 8px; position: absolute;"><div class="devsite-code-button-wrapper" style="box-sizing: inherit; margin: -8px 0px 0px; padding: 0px; position: absolute; right: 0px;">
<div aria-label="按這個按鈕即可複製" class="devsite-code-button gc-analytics-event material-icons devsite-click-to-copy-button" data-category="Site-Wide Custom Events" data-label="Click To Copy" data-title="按這個按鈕即可複製" data-tooltip-align="b,c" data-tooltip="按這個按鈕即可複製" style="-webkit-font-smoothing: antialiased; background: rgba(0, 0, 0, 0.26); box-sizing: inherit; color: white; cursor: pointer; direction: ltr; display: inline-block; font-family: "Material Icons"; font-feature-settings: 'liga' 1; font-size: 18px; line-height: 1; margin: 0px; padding: 3px; transition: background 0.2s; white-space: nowrap; word-wrap: normal;" track-name="clickToCopy" track-type="exampleCode">
</div>
</div>
<span class="kwd" style="box-sizing: inherit; color: #3b78e7;">import</span><span class="pln" style="box-sizing: inherit;"> </span><span class="typ" style="box-sizing: inherit; color: #9c27b0;">UIKit</span><span class="pln" style="box-sizing: inherit;">
</span><span class="kwd" style="box-sizing: inherit; color: #3b78e7;">import</span><span class="pln" style="box-sizing: inherit;"> </span><span class="typ" style="box-sizing: inherit; color: #9c27b0;">GoogleMaps</span><span class="pln" style="box-sizing: inherit;">
</span><span class="kwd" style="box-sizing: inherit; color: #3b78e7;">class</span><span class="pln" style="box-sizing: inherit;"> </span><span class="typ" style="box-sizing: inherit; color: #9c27b0;">YourViewController</span><span class="pun" style="box-sizing: inherit;">:</span><span class="pln" style="box-sizing: inherit;"> </span><span class="typ" style="box-sizing: inherit; color: #9c27b0;">UIViewController</span><span class="pln" style="box-sizing: inherit;"> </span><span class="pun" style="box-sizing: inherit;">{</span><span class="pln" style="box-sizing: inherit;">
</span><span class="com" style="box-sizing: inherit; color: #d81b60;">// You don't need to modify the default init(nibName:bundle:) method.</span><span class="pln" style="box-sizing: inherit;">
</span><span class="kwd" style="box-sizing: inherit; color: #3b78e7;">override</span><span class="pln" style="box-sizing: inherit;"> func loadView</span><span class="pun" style="box-sizing: inherit;">()</span><span class="pln" style="box-sizing: inherit;"> </span><span class="pun" style="box-sizing: inherit;">{</span><span class="pln" style="box-sizing: inherit;">
</span><span class="com" style="box-sizing: inherit; color: #d81b60;">// Create a GMSCameraPosition that tells the map to display the</span><span class="pln" style="box-sizing: inherit;">
</span><span class="com" style="box-sizing: inherit; color: #d81b60;">// coordinate -33.86,151.20 at zoom level 6.</span><span class="pln" style="box-sizing: inherit;">
let camera </span><span class="pun" style="box-sizing: inherit;">=</span><span class="pln" style="box-sizing: inherit;"> </span><span class="typ" style="box-sizing: inherit; color: #9c27b0;">GMSCameraPosition</span><span class="pun" style="box-sizing: inherit;">.</span><span class="pln" style="box-sizing: inherit;">camera</span><span class="pun" style="box-sizing: inherit;">(</span><span class="pln" style="box-sizing: inherit;">withLatitude</span><span class="pun" style="box-sizing: inherit;">:</span><span class="pln" style="box-sizing: inherit;"> </span><span class="pun" style="box-sizing: inherit;">-</span><span class="lit" style="box-sizing: inherit; color: #c53929;">33.86</span><span class="pun" style="box-sizing: inherit;">,</span><span class="pln" style="box-sizing: inherit;"> longitude</span><span class="pun" style="box-sizing: inherit;">:</span><span class="pln" style="box-sizing: inherit;"> </span><span class="lit" style="box-sizing: inherit; color: #c53929;">151.20</span><span class="pun" style="box-sizing: inherit;">,</span><span class="pln" style="box-sizing: inherit;"> zoom</span><span class="pun" style="box-sizing: inherit;">:</span><span class="pln" style="box-sizing: inherit;"> </span><span class="lit" style="box-sizing: inherit; color: #c53929;">6.0</span><span class="pun" style="box-sizing: inherit;">)</span><span class="pln" style="box-sizing: inherit;">
let mapView </span><span class="pun" style="box-sizing: inherit;">=</span><span class="pln" style="box-sizing: inherit;"> </span><span class="typ" style="box-sizing: inherit; color: #9c27b0;">GMSMapView</span><span class="pun" style="box-sizing: inherit;">.</span><span class="pln" style="box-sizing: inherit;">map</span><span class="pun" style="box-sizing: inherit;">(</span><span class="pln" style="box-sizing: inherit;">withFrame</span><span class="pun" style="box-sizing: inherit;">:</span><span class="pln" style="box-sizing: inherit;"> </span><span class="typ" style="box-sizing: inherit; color: #9c27b0;">CGRect</span><span class="pun" style="box-sizing: inherit;">.</span><span class="pln" style="box-sizing: inherit;">zero</span><span class="pun" style="box-sizing: inherit;">,</span><span class="pln" style="box-sizing: inherit;"> camera</span><span class="pun" style="box-sizing: inherit;">:</span><span class="pln" style="box-sizing: inherit;"> camera</span><span class="pun" style="box-sizing: inherit;">)</span><span class="pln" style="box-sizing: inherit;">
mapView</span><span class="pun" style="box-sizing: inherit;">.</span><span class="pln" style="box-sizing: inherit;">isMyLocationEnabled </span><span class="pun" style="box-sizing: inherit;">=</span><span class="pln" style="box-sizing: inherit;"> </span><span class="kwd" style="box-sizing: inherit; color: #3b78e7;">true</span><span class="pln" style="box-sizing: inherit;">
view </span><span class="pun" style="box-sizing: inherit;">=</span><span class="pln" style="box-sizing: inherit;"> mapView
</span><span class="com" style="box-sizing: inherit; color: #d81b60;">// Creates a marker in the center of the map.</span><span class="pln" style="box-sizing: inherit;">
let marker </span><span class="pun" style="box-sizing: inherit;">=</span><span class="pln" style="box-sizing: inherit;"> </span><span class="typ" style="box-sizing: inherit; color: #9c27b0;">GMSMarker</span><span class="pun" style="box-sizing: inherit;">()</span><span class="pln" style="box-sizing: inherit;">
marker</span><span class="pun" style="box-sizing: inherit;">.</span><span class="pln" style="box-sizing: inherit;">position </span><span class="pun" style="box-sizing: inherit;">=</span><span class="pln" style="box-sizing: inherit;"> </span><span class="typ" style="box-sizing: inherit; color: #9c27b0;">CLLocationCoordinate2D</span><span class="pun" style="box-sizing: inherit;">(</span><span class="pln" style="box-sizing: inherit;">latitude</span><span class="pun" style="box-sizing: inherit;">:</span><span class="pln" style="box-sizing: inherit;"> </span><span class="pun" style="box-sizing: inherit;">-</span><span class="lit" style="box-sizing: inherit; color: #c53929;">33.86</span><span class="pun" style="box-sizing: inherit;">,</span><span class="pln" style="box-sizing: inherit;"> longitude</span><span class="pun" style="box-sizing: inherit;">:</span><span class="pln" style="box-sizing: inherit;"> </span><span class="lit" style="box-sizing: inherit; color: #c53929;">151.20</span><span class="pun" style="box-sizing: inherit;">)</span><span class="pln" style="box-sizing: inherit;">
marker</span><span class="pun" style="box-sizing: inherit;">.</span><span class="pln" style="box-sizing: inherit;">title </span><span class="pun" style="box-sizing: inherit;">=</span><span class="pln" style="box-sizing: inherit;"> </span><span class="str" style="box-sizing: inherit; color: #0d904f;">"Sydney"</span><span class="pln" style="box-sizing: inherit;">
marker</span><span class="pun" style="box-sizing: inherit;">.</span><span class="pln" style="box-sizing: inherit;">snippet </span><span class="pun" style="box-sizing: inherit;">=</span><span class="pln" style="box-sizing: inherit;"> </span><span class="str" style="box-sizing: inherit; color: #0d904f;">"Australia"</span><span class="pln" style="box-sizing: inherit;">
marker</span><span class="pun" style="box-sizing: inherit;">.</span><span class="pln" style="box-sizing: inherit;">map </span><span class="pun" style="box-sizing: inherit;">=</span><span class="pln" style="box-sizing: inherit;"> mapView
</span><span class="pun" style="box-sizing: inherit;">}</span><span class="pln" style="box-sizing: inherit;">
</span><span class="pun" style="box-sizing: inherit;">}</span></pre>
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #888888;">//</span>
<span style="color: #888888;">// ViewController.swift</span>
<span style="color: #888888;">// MapDemo</span>
<span style="color: #888888;">//</span>
<span style="color: #888888;">// Created by boywhy chen on 2018/2/20.</span>
<span style="color: #888888;">// Copyright © 2018年 qq. All rights reserved.</span>
<span style="color: #888888;">//</span>
<span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">UIKit</span>
<span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">GoogleMaps</span>
<span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">ViewController</span><span style="color: #333333;">:</span> UIViewController<span style="color: #333333;">,</span>CLLocationManagerDelegate <span style="color: #333333;">{</span>
var locationManager <span style="color: #333333;">=</span> CLLocationManager<span style="color: #333333;">()</span>
var <span style="color: #997700; font-weight: bold;">currentLocation:</span> CLLocation<span style="color: #333333;">?</span>
var <span style="color: #997700; font-weight: bold;">mapView:</span> GMSMapView<span style="color: #333333;">!</span>
var <span style="color: #997700; font-weight: bold;">zoomLevel:</span> Float <span style="color: #333333;">=</span> <span style="color: #6600ee; font-weight: bold;">15.0</span>
override func <span style="color: #0066bb; font-weight: bold;">viewDidLoad</span><span style="color: #333333;">()</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">super</span><span style="color: #333333;">.</span><span style="color: #0000cc;">viewDidLoad</span><span style="color: #333333;">()</span>
<span style="color: #888888;">// Do any additional setup after loading the view, typically from a nib.</span>
<span style="color: #333333;">}</span>
override func <span style="color: #0066bb; font-weight: bold;">didReceiveMemoryWarning</span><span style="color: #333333;">()</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">super</span><span style="color: #333333;">.</span><span style="color: #0000cc;">didReceiveMemoryWarning</span><span style="color: #333333;">()</span>
<span style="color: #888888;">// Dispose of any resources that can be recreated.</span>
<span style="color: #333333;">}</span>
override func <span style="color: #0066bb; font-weight: bold;">loadView</span><span style="color: #333333;">()</span> <span style="color: #333333;">{</span>
locationManager <span style="color: #333333;">=</span> CLLocationManager<span style="color: #333333;">()</span>
locationManager<span style="color: #333333;">.</span><span style="color: #0000cc;">desiredAccuracy</span> <span style="color: #333333;">=</span> kCLLocationAccuracyBest
locationManager<span style="color: #333333;">.</span><span style="color: #0000cc;">requestAlwaysAuthorization</span><span style="color: #333333;">()</span>
locationManager<span style="color: #333333;">.</span><span style="color: #0000cc;">distanceFilter</span> <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">50</span>
locationManager<span style="color: #333333;">.</span><span style="color: #0000cc;">startUpdatingLocation</span><span style="color: #333333;">()</span>
locationManager<span style="color: #333333;">.</span><span style="color: #0000cc;">delegate</span> <span style="color: #333333;">=</span> self
<span style="color: #888888;">//init MapView</span>
let camera <span style="color: #333333;">=</span> GMSCameraPosition<span style="color: #333333;">.</span><span style="color: #0000cc;">camera</span><span style="color: #333333;">(</span><span style="color: #997700; font-weight: bold;">withLatitude:</span> <span style="color: #333333;">-</span><span style="color: #6600ee; font-weight: bold;">33.86</span><span style="color: #333333;">,</span> <span style="color: #997700; font-weight: bold;">longitude:</span> <span style="color: #6600ee; font-weight: bold;">151.20</span><span style="color: #333333;">,</span> <span style="color: #997700; font-weight: bold;">zoom:</span> <span style="color: #6600ee; font-weight: bold;">6.0</span><span style="color: #333333;">)</span>
mapView <span style="color: #333333;">=</span> GMSMapView<span style="color: #333333;">.</span><span style="color: #0000cc;">map</span><span style="color: #333333;">(</span><span style="color: #997700; font-weight: bold;">withFrame:</span> CGRect<span style="color: #333333;">.</span><span style="color: #0000cc;">zero</span><span style="color: #333333;">,</span> <span style="color: #997700; font-weight: bold;">camera:</span> camera<span style="color: #333333;">)</span>
mapView<span style="color: #333333;">.</span><span style="color: #0000cc;">isMyLocationEnabled</span> <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">true</span>
view <span style="color: #333333;">=</span> mapView
<span style="color: #333333;">}</span>
<span style="color: #888888;">// Handle incoming location events.</span>
func <span style="color: #0066bb; font-weight: bold;">locationManager</span><span style="color: #333333;">(</span>_ <span style="color: #997700; font-weight: bold;">manager:</span> CLLocationManager<span style="color: #333333;">,</span> didUpdateLocations <span style="color: #997700; font-weight: bold;">locations:</span> <span style="color: #333333;">[</span>CLLocation<span style="color: #333333;">])</span> <span style="color: #333333;">{</span>
let <span style="color: #997700; font-weight: bold;">location:</span> CLLocation <span style="color: #333333;">=</span> locations<span style="color: #333333;">.</span><span style="color: #0000cc;">last</span><span style="color: #333333;">!</span>
print<span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"Location: \(location)"</span><span style="color: #333333;">)</span>
let camera <span style="color: #333333;">=</span> GMSCameraPosition<span style="color: #333333;">.</span><span style="color: #0000cc;">camera</span><span style="color: #333333;">(</span><span style="color: #997700; font-weight: bold;">withLatitude:</span> location<span style="color: #333333;">.</span><span style="color: #0000cc;">coordinate</span><span style="color: #333333;">.</span><span style="color: #0000cc;">latitude</span><span style="color: #333333;">,</span>
<span style="color: #997700; font-weight: bold;">longitude:</span> location<span style="color: #333333;">.</span><span style="color: #0000cc;">coordinate</span><span style="color: #333333;">.</span><span style="color: #0000cc;">longitude</span><span style="color: #333333;">,</span>
<span style="color: #997700; font-weight: bold;">zoom:</span> zoomLevel<span style="color: #333333;">)</span>
<span style="color: #008800; font-weight: bold;">if</span> mapView<span style="color: #333333;">.</span><span style="color: #0000cc;">isHidden</span> <span style="color: #333333;">{</span>
mapView<span style="color: #333333;">.</span><span style="color: #0000cc;">isHidden</span> <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">false</span>
mapView<span style="color: #333333;">.</span><span style="color: #0000cc;">camera</span> <span style="color: #333333;">=</span> camera
<span style="color: #333333;">}</span> <span style="color: #008800; font-weight: bold;">else</span> <span style="color: #333333;">{</span>
mapView<span style="color: #333333;">.</span><span style="color: #0000cc;">animate</span><span style="color: #333333;">(</span><span style="color: #997700; font-weight: bold;">to:</span> camera<span style="color: #333333;">)</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #888888;">// Handle authorization for the location manager.</span>
func <span style="color: #0066bb; font-weight: bold;">locationManager</span><span style="color: #333333;">(</span>_ <span style="color: #997700; font-weight: bold;">manager:</span> CLLocationManager<span style="color: #333333;">,</span> didChangeAuthorization <span style="color: #997700; font-weight: bold;">status:</span> CLAuthorizationStatus<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">switch</span> status <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">case</span> <span style="color: #333333;">.</span><span style="color: #0000cc;">restricted</span><span style="color: #333333;">:</span>
print<span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"Location access was restricted."</span><span style="color: #333333;">)</span>
<span style="color: #008800; font-weight: bold;">case</span> <span style="color: #333333;">.</span><span style="color: #0000cc;">denied</span><span style="color: #333333;">:</span>
print<span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"User denied access to location."</span><span style="color: #333333;">)</span>
<span style="color: #888888;">// Display the map using the default location.</span>
mapView<span style="color: #333333;">.</span><span style="color: #0000cc;">isHidden</span> <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">false</span>
<span style="color: #008800; font-weight: bold;">case</span> <span style="color: #333333;">.</span><span style="color: #0000cc;">notDetermined</span><span style="color: #333333;">:</span>
print<span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"Location status not determined."</span><span style="color: #333333;">)</span>
<span style="color: #008800; font-weight: bold;">case</span> <span style="color: #333333;">.</span><span style="color: #0000cc;">authorizedAlways</span><span style="color: #333333;">:</span> fallthrough
<span style="color: #008800; font-weight: bold;">case</span> <span style="color: #333333;">.</span><span style="color: #0000cc;">authorizedWhenInUse</span><span style="color: #333333;">:</span>
print<span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"Location status is OK."</span><span style="color: #333333;">)</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #888888;">// Handle location manager errors.</span>
func <span style="color: #0066bb; font-weight: bold;">locationManager</span><span style="color: #333333;">(</span>_ <span style="color: #997700; font-weight: bold;">manager:</span> CLLocationManager<span style="color: #333333;">,</span> didFailWithError <span style="color: #997700; font-weight: bold;">error:</span> Error<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
locationManager<span style="color: #333333;">.</span><span style="color: #0000cc;">stopUpdatingLocation</span><span style="color: #333333;">()</span>
print<span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"Error: \(error)"</span><span style="color: #333333;">)</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
</pre>
</div>
<br />
主要是增加定位功能,接下來執行會要求權限,按下Allow<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDQ9Wj-gs1wnD9asKsXY8WWGvNmI4drymgHIshmP0L1yGjMrgaN_QcvqGHx0haQtltxVsShBryJOmFpWcdJ7E2chIGD2qg7_GzuYBqSoPf6BgBxG3yD3nY9u8ZVyvcnzmsaBQcusL91AuE/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-20+%25E4%25B8%258B%25E5%258D%258811.11.43.png" imageanchor="1"><img border="0" height="382" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDQ9Wj-gs1wnD9asKsXY8WWGvNmI4drymgHIshmP0L1yGjMrgaN_QcvqGHx0haQtltxVsShBryJOmFpWcdJ7E2chIGD2qg7_GzuYBqSoPf6BgBxG3yD3nY9u8ZVyvcnzmsaBQcusL91AuE/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-20+%25E4%25B8%258B%25E5%258D%258811.11.43.png" width="640" /></a><br />
<br />
如果是用模擬器的話,可以選置以下幾種方式模擬位置<br />
<br />
APPLE ,定位在APPLE總部<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEivDsSgVPvFvBcs1rFHZO-AU6z4KiucSMxu5ADT8mJraCQoDC4UKZoU_pXk3n5Qvp1b8TlRouUoVxV20pfkhmpp_UbnMOQoBuvuwxlyjuM0wmTbzEYNomno4PYgZYiuOTtOwx4bZYOjkh87/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-20+%25E4%25B8%258B%25E5%258D%258811.29.02.png" imageanchor="1"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEivDsSgVPvFvBcs1rFHZO-AU6z4KiucSMxu5ADT8mJraCQoDC4UKZoU_pXk3n5Qvp1b8TlRouUoVxV20pfkhmpp_UbnMOQoBuvuwxlyjuM0wmTbzEYNomno4PYgZYiuOTtOwx4bZYOjkh87/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-20+%25E4%25B8%258B%25E5%258D%258811.29.02.png" /></a><br />
<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUm03DjPcTjN9Ngj02tFTrPHap-kCLCkUSyZuvLrXeb3Msd0MZeNPGdPcvXPl0MRVk4-Sc2QjIdvtGAyTcH1uEjTGuBUoxlrkSECIc73N6XWyTbaAXBGQMkP44wnr7hCDtHDGxIkV6dIgv/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-20+%25E4%25B8%258B%25E5%258D%258811.31.17.png" imageanchor="1"><img border="0" height="502" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUm03DjPcTjN9Ngj02tFTrPHap-kCLCkUSyZuvLrXeb3Msd0MZeNPGdPcvXPl0MRVk4-Sc2QjIdvtGAyTcH1uEjTGuBUoxlrkSECIc73N6XWyTbaAXBGQMkP44wnr7hCDtHDGxIkV6dIgv/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-20+%25E4%25B8%258B%25E5%258D%258811.31.17.png" width="640" /></a><br />
<br />
Custom Location 則是自己輸入經緯度<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvkPBlgirLpwJstdZyXtxNJl3bSl-WucSr5lCis-RfHXtksf8vRHPUFS4HQKi9AfVANdQ1NdFfCoX7b_ZvhJppSLs87xf-d6oWbDn5B4yJgtKfGKApyfsR1bZC_NaCQHFqkAx7Z7PHBuQq/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-20+%25E4%25B8%258B%25E5%258D%258811.32.10.png" imageanchor="1"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvkPBlgirLpwJstdZyXtxNJl3bSl-WucSr5lCis-RfHXtksf8vRHPUFS4HQKi9AfVANdQ1NdFfCoX7b_ZvhJppSLs87xf-d6oWbDn5B4yJgtKfGKApyfsR1bZC_NaCQHFqkAx7Z7PHBuQq/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-20+%25E4%25B8%258B%25E5%258D%258811.32.10.png" /></a><br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnmczHQ21NbKo26HA24o9oNubtRQgBr0ZbtMYKddukhJCLGY8pt_bKrPl5L4pblu5q0sbEmXCygiq1ZkYf3ljrAQpCSxPdqRlnE3XhewwwCkg2aEX8yGJFKjjMYWaPlO65IQYOHK-gTWOn/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-20+%25E4%25B8%258B%25E5%258D%258811.32.48.png" imageanchor="1"><img border="0" height="499" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnmczHQ21NbKo26HA24o9oNubtRQgBr0ZbtMYKddukhJCLGY8pt_bKrPl5L4pblu5q0sbEmXCygiq1ZkYf3ljrAQpCSxPdqRlnE3XhewwwCkg2aEX8yGJFKjjMYWaPlO65IQYOHK-gTWOn/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-20+%25E4%25B8%258B%25E5%258D%258811.32.48.png" width="640" /></a><br />
<br />
City Bike Ride ,City Run<br />
<br />
其實是類似功能,只是移動速度不太一樣以及移動路徑不太相同<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhICbor9M0UHbPp0AW_RYAcyjHpu6la9AzrjJtBMO64ZSzdWMw_X2x1PJOzOyKvt-ZopIVNo-HuhgPsgPmSxcr14OWVcozBXBK1n_rfZ8b9ovwnhCi-1fxLfoo4EEJPnsN6OFktbs3d2fuX/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-20+%25E4%25B8%258B%25E5%258D%258811.33.49.png" imageanchor="1"><img border="0" height="488" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhICbor9M0UHbPp0AW_RYAcyjHpu6la9AzrjJtBMO64ZSzdWMw_X2x1PJOzOyKvt-ZopIVNo-HuhgPsgPmSxcr14OWVcozBXBK1n_rfZ8b9ovwnhCi-1fxLfoo4EEJPnsN6OFktbs3d2fuX/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-20+%25E4%25B8%258B%25E5%258D%258811.33.49.png" width="640" /></a><br />
<br />
Freeway Driver 則是模擬在高速公路開車<br />
<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1pd70DKB3NQi6an6MtU2TxBNuzuRc8AQLNKibDVxSekcBUQ-fEO76yesvvibWTuXloF1so9TP0PMCkcFZ9ml8DXSFY2TboaattaJ6A-O1dVCFRwhs-HRAjInN-xQogH0weo2tmngyvWXE/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-20+%25E4%25B8%258B%25E5%258D%258811.36.41.png" imageanchor="1"><img border="0" height="500" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1pd70DKB3NQi6an6MtU2TxBNuzuRc8AQLNKibDVxSekcBUQ-fEO76yesvvibWTuXloF1so9TP0PMCkcFZ9ml8DXSFY2TboaattaJ6A-O1dVCFRwhs-HRAjInN-xQogH0weo2tmngyvWXE/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-20+%25E4%25B8%258B%25E5%258D%258811.36.41.png" width="640" /></a><br />
<br />
<br />
參考文件<br />
<br />
<a href="https://developers.google.com/maps/documentation/ios-sdk/map?hl=zh-tw">https://developers.google.com/maps/documentation/ios-sdk/map?hl=zh-tw</a><br />
<br />
<a href="https://developers.google.com/maps/documentation/ios-sdk/current-places-tutorial?hl=zh-tw">https://developers.google.com/maps/documentation/ios-sdk/current-places-tutorial?hl=zh-tw</a><br />
<br />
<a href="https://stackoverflow.com/questions/24062509/location-services-not-working-in-ios-8">https://stackoverflow.com/questions/24062509/location-services-not-working-in-ios-8</a>金石微開http://www.blogger.com/profile/13160756791496033950noreply@blogger.com0tag:blogger.com,1999:blog-2933755125431570931.post-10908061713842963732018-02-17T11:16:00.001+08:002018-02-17T11:16:16.040+08:00[Android] Context Menu最近看到一個蠻特別的東西--Context Menu--,沒想到可以這樣用,<br />
幫Button加入"<b>長按</b>"選單<br />
<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrOmaKQUAKvMGpuDSIKo-vzMRudHWVG2mhyBrhjgPrb8P_S9GegpHS3NZfJCLBzkBx7wqL81QzdTKHDRM5MHFYIpSVS7SRsSLuZYVhkSU9mjBcm2_e5uzsBuJU2MxlSQPVURXi9zs6R7Om/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-17+%25E4%25B8%258A%25E5%258D%258810.59.43.png" imageanchor="1"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrOmaKQUAKvMGpuDSIKo-vzMRudHWVG2mhyBrhjgPrb8P_S9GegpHS3NZfJCLBzkBx7wqL81QzdTKHDRM5MHFYIpSVS7SRsSLuZYVhkSU9mjBcm2_e5uzsBuJU2MxlSQPVURXi9zs6R7Om/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-17+%25E4%25B8%258A%25E5%258D%258810.59.43.png" /></a><br />
<br />
<br />
首先這是MainActivity的layout,XML的部份,只有一個Button<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #557799;"><?xml version="1.0" encoding="utf-8"?></span>
<span style="color: #007700;"><RelativeLayout</span> <span style="color: #0000cc;">xmlns:android=</span><span style="background-color: #fff0f0;">"http://schemas.android.com/apk/res/android"</span>
<span style="color: #0000cc;">xmlns:tools=</span><span style="background-color: #fff0f0;">"http://schemas.android.com/tools"</span>
<span style="color: #0000cc;">android:layout_width=</span><span style="background-color: #fff0f0;">"match_parent"</span>
<span style="color: #0000cc;">android:layout_height=</span><span style="background-color: #fff0f0;">"match_parent"</span>
<span style="color: #0000cc;">android:paddingBottom=</span><span style="background-color: #fff0f0;">"@dimen/activity_vertical_margin"</span>
<span style="color: #0000cc;">android:paddingLeft=</span><span style="background-color: #fff0f0;">"@dimen/activity_horizontal_margin"</span>
<span style="color: #0000cc;">android:paddingRight=</span><span style="background-color: #fff0f0;">"@dimen/activity_horizontal_margin"</span>
<span style="color: #0000cc;">android:paddingTop=</span><span style="background-color: #fff0f0;">"@dimen/activity_vertical_margin"</span>
<span style="color: #0000cc;">tools:context=</span><span style="background-color: #fff0f0;">"com.example.boywhychen.context_menu.MainActivity"</span><span style="color: #007700;">></span>
<span style="color: #007700;"><Button</span>
<span style="color: #0000cc;">android:layout_width=</span><span style="background-color: #fff0f0;">"wrap_content"</span>
<span style="color: #0000cc;">android:layout_height=</span><span style="background-color: #fff0f0;">"wrap_content"</span>
<span style="color: #0000cc;">android:id=</span><span style="background-color: #fff0f0;">"@+id/menu_btn"</span>
<span style="color: #0000cc;">android:text=</span><span style="background-color: #fff0f0;">"Context Menu"</span> <span style="color: #007700;">/></span>
<span style="color: #007700;"></RelativeLayout></span>
</pre>
</div>
<br />
接下來我們需要在menu資料來下建立一個my_menu.xml<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjP4A4UcxQQ9JQg0zP8hgAlUJN547_dei0LeESEYNLnv-z0NoHA6C5a21tRc2RoQj9MfNohbct_iET6FrhLqAkRhtydN5DHewxOGXwLI82zMkwfOTT3SvAGc_qHcYnhnG2sKsX3vI_cXMzr/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-17+%25E4%25B8%258A%25E5%258D%258811.03.13.png" imageanchor="1"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjP4A4UcxQQ9JQg0zP8hgAlUJN547_dei0LeESEYNLnv-z0NoHA6C5a21tRc2RoQj9MfNohbct_iET6FrhLqAkRhtydN5DHewxOGXwLI82zMkwfOTT3SvAGc_qHcYnhnG2sKsX3vI_cXMzr/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-17+%25E4%25B8%258A%25E5%258D%258811.03.13.png" /></a><br />
<br />
內容就是列出Menu中要顯示的Item內容以及順序<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #557799;"><?xml version="1.0" encoding="utf-8"?></span>
<span style="color: #007700;"><menu</span> <span style="color: #0000cc;">xmlns:android=</span><span style="background-color: #fff0f0;">"http://schemas.android.com/apk/res/android"</span>
<span style="color: #0000cc;">xmlns:app=</span><span style="background-color: #fff0f0;">"http://schemas.android.com/apk/res-auto"</span><span style="color: #007700;">></span>
<span style="color: #007700;"><item</span> <span style="color: #0000cc;">android:id=</span><span style="background-color: #fff0f0;">"@+id/color_blue"</span>
<span style="color: #0000cc;">android:title=</span><span style="background-color: #fff0f0;">"Blue"</span>
<span style="color: #0000cc;">android:orderInCategory=</span><span style="background-color: #fff0f0;">"1"</span>
<span style="color: #0000cc;">app:showAsAction=</span><span style="background-color: #fff0f0;">"ifRoom"</span><span style="color: #007700;">/></span>
<span style="color: #007700;"><item</span> <span style="color: #0000cc;">android:id=</span><span style="background-color: #fff0f0;">"@+id/color_red"</span>
<span style="color: #0000cc;">android:title=</span><span style="background-color: #fff0f0;">"Red"</span>
<span style="color: #0000cc;">android:orderInCategory=</span><span style="background-color: #fff0f0;">"2"</span>
<span style="color: #0000cc;">app:showAsAction=</span><span style="background-color: #fff0f0;">"ifRoom"</span><span style="color: #007700;">/></span>
<span style="color: #007700;"><item</span> <span style="color: #0000cc;">android:id=</span><span style="background-color: #fff0f0;">"@+id/color_green"</span>
<span style="color: #0000cc;">android:title=</span><span style="background-color: #fff0f0;">"Green"</span>
<span style="color: #0000cc;">android:orderInCategory=</span><span style="background-color: #fff0f0;">"3"</span>
<span style="color: #0000cc;">app:showAsAction=</span><span style="background-color: #fff0f0;">"ifRoom"</span><span style="color: #007700;">/></span>
<span style="color: #007700;"></menu></span>
</pre>
</div>
<br />
接下來是主程式<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #008800; font-weight: bold;">package</span> com<span style="color: #333333;">.</span><span style="color: #0000cc;">example</span><span style="color: #333333;">.</span><span style="color: #0000cc;">boywhychen</span><span style="color: #333333;">.</span><span style="color: #0000cc;">context_menu</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">android.support.v7.app.AppCompatActivity</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">android.os.Bundle</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">android.view.ContextMenu</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">android.view.MenuItem</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">android.view.View</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">android.widget.Button</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">android.widget.Toast</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">MainActivity</span> <span style="color: #008800; font-weight: bold;">extends</span> AppCompatActivity <span style="color: #333333;">{</span>
<span style="color: #555555; font-weight: bold;">@Override</span>
<span style="color: #008800; font-weight: bold;">protected</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">onCreate</span><span style="color: #333333;">(</span>Bundle savedInstanceState<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">super</span><span style="color: #333333;">.</span><span style="color: #0000cc;">onCreate</span><span style="color: #333333;">(</span>savedInstanceState<span style="color: #333333;">);</span>
setContentView<span style="color: #333333;">(</span>R<span style="color: #333333;">.</span><span style="color: #0000cc;">layout</span><span style="color: #333333;">.</span><span style="color: #0000cc;">activity_main</span><span style="color: #333333;">);</span>
<span style="color: #888888;">//初始化Button</span>
Button menu_btn<span style="color: #333333;">=(</span>Button<span style="color: #333333;">)</span>findViewById<span style="color: #333333;">(</span>R<span style="color: #333333;">.</span><span style="color: #0000cc;">id</span><span style="color: #333333;">.</span><span style="color: #0000cc;">menu_btn</span><span style="color: #333333;">);</span>
<span style="color: #888888;">//幫Button註冊ContextMenu</span>
registerForContextMenu<span style="color: #333333;">(</span>menu_btn<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #555555; font-weight: bold;">@Override</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">onCreateContextMenu</span><span style="color: #333333;">(</span>ContextMenu menu<span style="color: #333333;">,</span> View v<span style="color: #333333;">,</span> ContextMenu<span style="color: #333333;">.</span><span style="color: #0000cc;">ContextMenuInfo</span> menuInfo<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">super</span><span style="color: #333333;">.</span><span style="color: #0000cc;">onCreateContextMenu</span><span style="color: #333333;">(</span>menu<span style="color: #333333;">,</span> v<span style="color: #333333;">,</span> menuInfo<span style="color: #333333;">);</span>
<span style="color: #888888;">//要使用的Context Menu XML檔案</span>
getMenuInflater<span style="color: #333333;">().</span><span style="color: #0000cc;">inflate</span><span style="color: #333333;">(</span>R<span style="color: #333333;">.</span><span style="color: #0000cc;">menu</span><span style="color: #333333;">.</span><span style="color: #0000cc;">my_menu</span><span style="color: #333333;">,</span>menu<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #555555; font-weight: bold;">@Override</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">boolean</span> <span style="color: #0066bb; font-weight: bold;">onContextItemSelected</span><span style="color: #333333;">(</span>MenuItem item<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #888888;">//按下Context Menu Item要做的事</span>
<span style="color: #008800; font-weight: bold;">switch</span> <span style="color: #333333;">((</span>item<span style="color: #333333;">.</span><span style="color: #0000cc;">getItemId</span><span style="color: #333333;">()))</span>
<span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">case</span> R<span style="color: #333333;">.</span><span style="color: #0000cc;">id</span><span style="color: #333333;">.</span><span style="color: #0000cc;">color_blue</span><span style="color: #333333;">:</span>
Toast<span style="color: #333333;">.</span><span style="color: #0000cc;">makeText</span><span style="color: #333333;">(</span>MainActivity<span style="color: #333333;">.</span><span style="color: #0000cc;">this</span><span style="color: #333333;">,</span><span style="background-color: #fff0f0;">"Blue"</span><span style="color: #333333;">,</span>Toast<span style="color: #333333;">.</span><span style="color: #0000cc;">LENGTH_SHORT</span><span style="color: #333333;">).</span><span style="color: #0000cc;">show</span><span style="color: #333333;">();</span>
<span style="color: #008800; font-weight: bold;">break</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">case</span> R<span style="color: #333333;">.</span><span style="color: #0000cc;">id</span><span style="color: #333333;">.</span><span style="color: #0000cc;">color_green</span><span style="color: #333333;">:</span>
Toast<span style="color: #333333;">.</span><span style="color: #0000cc;">makeText</span><span style="color: #333333;">(</span>MainActivity<span style="color: #333333;">.</span><span style="color: #0000cc;">this</span><span style="color: #333333;">,</span><span style="background-color: #fff0f0;">"Green"</span><span style="color: #333333;">,</span>Toast<span style="color: #333333;">.</span><span style="color: #0000cc;">LENGTH_SHORT</span><span style="color: #333333;">).</span><span style="color: #0000cc;">show</span><span style="color: #333333;">();</span>
<span style="color: #008800; font-weight: bold;">break</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">case</span> R<span style="color: #333333;">.</span><span style="color: #0000cc;">id</span><span style="color: #333333;">.</span><span style="color: #0000cc;">color_red</span><span style="color: #333333;">:</span>
Toast<span style="color: #333333;">.</span><span style="color: #0000cc;">makeText</span><span style="color: #333333;">(</span>MainActivity<span style="color: #333333;">.</span><span style="color: #0000cc;">this</span><span style="color: #333333;">,</span><span style="background-color: #fff0f0;">"Red"</span><span style="color: #333333;">,</span>Toast<span style="color: #333333;">.</span><span style="color: #0000cc;">LENGTH_SHORT</span><span style="color: #333333;">).</span><span style="color: #0000cc;">show</span><span style="color: #333333;">();</span>
<span style="color: #008800; font-weight: bold;">break</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #008800; font-weight: bold;">super</span><span style="color: #333333;">.</span><span style="color: #0000cc;">onContextItemSelected</span><span style="color: #333333;">(</span>item<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
</pre>
</div>
<br />
執行效果(記住是長按才會跳出選單~我一開始都用click都沒反應~搞了半天)<br />
<br />
點下Red後,Toast會顯示你按下的是Red<br />
<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgEzbbFloaZ3e2k3KTTFLmrVj9lv_S3XfE8bPmPzm_cNc_R7qi3gtDVuoaAfENpiFE4B53orweIMVXU1C-N7IZ3EyzgRAN6xvuFOOrGUJsK0S7AL4p-OIeU902-M-p76NcbhOb1bCGbrlFK/s1600/device-2018-02-17-111343.png" imageanchor="1"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgEzbbFloaZ3e2k3KTTFLmrVj9lv_S3XfE8bPmPzm_cNc_R7qi3gtDVuoaAfENpiFE4B53orweIMVXU1C-N7IZ3EyzgRAN6xvuFOOrGUJsK0S7AL4p-OIeU902-M-p76NcbhOb1bCGbrlFK/s320/device-2018-02-17-111343.png" width="180" /></a><br />
<br />
<br />
參考來源:<br />
<br />
The Complete Android Material Design Course: Become a Pro<br />
https://www.udemy.com/android-material-design-course-tutorial/learn/v4/overview<br />
上課心得筆記一下金石微開http://www.blogger.com/profile/13160756791496033950noreply@blogger.com0tag:blogger.com,1999:blog-2933755125431570931.post-16817545886112874022018-02-03T23:23:00.002+08:002018-02-03T23:28:39.089+08:00「HTML5][Java] Server-Sent Events Server-Sent Events<br />
<div>
<br /></div>
<div>
W3Schools上的說明:</div>
<div>
<br /></div>
<div>
<div style="background-color: white; box-sizing: inherit; font-family: Verdana, sans-serif; font-size: 15px;">
server-sent event is when a web page automatically gets updates from a server.</div>
<div style="background-color: white; box-sizing: inherit; font-family: Verdana, sans-serif; font-size: 15px;">
This was also possible before, but the web page would have to ask if any updates were available. With server-sent events, the updates come automatically.</div>
<div style="background-color: white; box-sizing: inherit; font-family: Verdana, sans-serif; font-size: 15px;">
Examples: Facebook/Twitter updates, stock price updates, news feeds, sport results, etc.</div>
<div style="background-color: white; box-sizing: inherit; font-family: Verdana, sans-serif; font-size: 15px;">
<br /></div>
<div style="background-color: white; box-sizing: inherit; font-family: Verdana, sans-serif; font-size: 15px;">
<br /></div>
簡單來說SSE的特點為"One Way Messaging" ,也就是Client端被動接收Server端訊息。</div>
<div>
<br /></div>
<div>
過去HTTP 都是一個單一回合結束,如果要取得新的資料,必須重新發送一次</div>
<div>
<br /></div>
<div>
HTTP Request,而SSE則是可以持續接收Server資訊,無須主動發送Request ,</div>
<div>
<br /></div>
<div>
但Client端無法透過SSE與Server端進行溝通,這是與webSocket不同的地方。</div>
<div>
<br /></div>
<div>
以下有一個範例,利用Java Servlet 透過SSE的方式與Client端JavaScript溝通.<br />
<br />
當下按Start Button後,JavaScript會開始接收由Server端傳送過來的SSE資料,並更新<br />
<br />
在網頁上。<br />
<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiw3qNP90bhw6QTdgEah8AUz4H78Mh2TAm0k-LJsFdPnTWaabIyCV4D_JO75URdv488EYNCiNO3ZNM6vCW71TD9ctJ859XPaPVty9CG49q2uWypQbD0Bi_Btt2HddeeOlLBAqVLr1fY4qCa/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-03+%25E4%25B8%258B%25E5%258D%258811.17.11.png" imageanchor="1"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiw3qNP90bhw6QTdgEah8AUz4H78Mh2TAm0k-LJsFdPnTWaabIyCV4D_JO75URdv488EYNCiNO3ZNM6vCW71TD9ctJ859XPaPVty9CG49q2uWypQbD0Bi_Btt2HddeeOlLBAqVLr1fY4qCa/s400/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-02-03+%25E4%25B8%258B%25E5%258D%258811.17.11.png" /></a></div>
Client端程式碼
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #557799;"><!DOCTYPE HTML></span>
<span style="color: #007700;"><html></span>
<span style="color: #007700;"><head></span>
<span style="color: #007700;"><title></span>Server-Sent Events Servlet example<span style="color: #007700;"></title></span>
<span style="color: #007700;"><script></span>
<span style="color: #008800; font-weight: bold;">function</span> start() {
<span style="color: #008800; font-weight: bold;">var</span> eventSource <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> EventSource(<span style="background-color: #fff0f0;">"Server"</span>);
eventSource.onmessage <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">function</span> (event) {
<span style="color: #007020;">document</span>.getElementById(<span style="background-color: #fff0f0;">'myDiv'</span>).innerHTML <span style="color: #333333;">=</span> event.data;
}
}
;
<span style="color: #007700;"></script></span>
<span style="color: #007700;"><style></span>
<span style="color: #007700;">body</span> {
<span style="color: #008800; font-weight: bold;">font-family</span><span style="color: #333333;">:</span> <span style="color: #008800; font-weight: bold;">sans-serif</span>;
}
<span style="color: #007700;"></style></span>
<span style="color: #007700;"></head></span>
<span style="color: #007700;"><body></span>
Time: <span style="color: #007700;"><span</span> <span style="color: #0000cc;">id=</span><span style="background-color: #fff0f0;">"myDiv"</span><span style="color: #007700;">></span></span>
<span style="color: #007700;"><br><br></span>
<span style="color: #007700;"><button</span> <span style="color: #0000cc;">onclick=</span><span style="background-color: #fff0f0;">"start()"</span><span style="color: #007700;">></span>Start<span style="color: #007700;"></button></span>
<span style="color: #007700;"></body></span>
<span style="color: #007700;"></html></span>
</pre>
</div>
<br />
<br />
Server端Servlet程式碼
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #888888;">/*</span>
<span style="color: #888888;"> * To change this license header, choose License Headers in Project Properties.</span>
<span style="color: #888888;"> * To change this template file, choose Tools | Templates</span>
<span style="color: #888888;"> * and open the template in the editor.</span>
<span style="color: #888888;"> */</span>
<span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">java.io.IOException</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">java.io.PrintWriter</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">java.text.SimpleDateFormat</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">java.util.Calendar</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">javax.servlet.ServletException</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">javax.servlet.annotation.WebServlet</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">javax.servlet.http.HttpServlet</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">javax.servlet.http.HttpServletRequest</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">javax.servlet.http.HttpServletResponse</span><span style="color: #333333;">;</span>
<span style="color: #888888;">/**</span>
<span style="color: #888888;"> *</span>
<span style="color: #888888;"> * @author boywhychen</span>
<span style="color: #888888;"> */</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">Server</span> <span style="color: #008800; font-weight: bold;">extends</span> HttpServlet <span style="color: #333333;">{</span>
<span style="color: #888888;">/**</span>
<span style="color: #888888;"> * Processes requests for both HTTP <code>GET</code> and <code>POST</code></span>
<span style="color: #888888;"> * methods.</span>
<span style="color: #888888;"> *</span>
<span style="color: #888888;"> * @param request servlet request</span>
<span style="color: #888888;"> * @param response servlet response</span>
<span style="color: #888888;"> * @throws ServletException if a servlet-specific error occurs</span>
<span style="color: #888888;"> * @throws IOException if an I/O error occurs</span>
<span style="color: #888888;"> */</span>
<span style="color: #008800; font-weight: bold;">protected</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">processRequest</span><span style="color: #333333;">(</span>HttpServletRequest request<span style="color: #333333;">,</span> HttpServletResponse response<span style="color: #333333;">)</span>
<span style="color: #008800; font-weight: bold;">throws</span> ServletException<span style="color: #333333;">,</span> IOException <span style="color: #333333;">{</span>
response<span style="color: #333333;">.</span><span style="color: #0000cc;">setContentType</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"text/event-stream"</span><span style="color: #333333;">);</span>
response<span style="color: #333333;">.</span><span style="color: #0000cc;">setCharacterEncoding</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"UTF-8"</span><span style="color: #333333;">);</span>
PrintWriter writer <span style="color: #333333;">=</span> response<span style="color: #333333;">.</span><span style="color: #0000cc;">getWriter</span><span style="color: #333333;">();</span>
<span style="color: #008800; font-weight: bold;">for</span> <span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> i <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span> i <span style="color: #333333;"><</span> <span style="color: #0000dd; font-weight: bold;">20</span><span style="color: #333333;">;</span> i<span style="color: #333333;">++)</span> <span style="color: #333333;">{</span>
writer<span style="color: #333333;">.</span><span style="color: #0000cc;">write</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"data: "</span> <span style="color: #333333;">+</span> getTime<span style="color: #333333;">()</span> <span style="color: #333333;">+</span> <span style="background-color: #fff0f0;">"\n\n"</span><span style="color: #333333;">);</span>
writer<span style="color: #333333;">.</span><span style="color: #0000cc;">flush</span><span style="color: #333333;">();</span>
<span style="color: #008800; font-weight: bold;">try</span> <span style="color: #333333;">{</span>
Thread<span style="color: #333333;">.</span><span style="color: #0000cc;">sleep</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">1000</span><span style="color: #333333;">);</span>
<span style="color: #333333;">}</span> <span style="color: #008800; font-weight: bold;">catch</span> <span style="color: #333333;">(</span>InterruptedException e<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
e<span style="color: #333333;">.</span><span style="color: #0000cc;">printStackTrace</span><span style="color: #333333;">();</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
writer<span style="color: #333333;">.</span><span style="color: #0000cc;">close</span><span style="color: #333333;">();</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">private</span> String <span style="color: #0066bb; font-weight: bold;">getTime</span><span style="color: #333333;">()</span> <span style="color: #333333;">{</span>
Calendar cal <span style="color: #333333;">=</span> Calendar<span style="color: #333333;">.</span><span style="color: #0000cc;">getInstance</span><span style="color: #333333;">();</span>
SimpleDateFormat sdf <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> SimpleDateFormat<span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"HH:mm:ss"</span><span style="color: #333333;">);</span>
<span style="color: #008800; font-weight: bold;">return</span> sdf<span style="color: #333333;">.</span><span style="color: #0000cc;">format</span><span style="color: #333333;">(</span>cal<span style="color: #333333;">.</span><span style="color: #0000cc;">getTime</span><span style="color: #333333;">());</span>
<span style="color: #333333;">}</span>
<span style="color: #888888;">// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code."></span>
<span style="color: #888888;">/**</span>
<span style="color: #888888;"> * Handles the HTTP <code>GET</code> method.</span>
<span style="color: #888888;"> *</span>
<span style="color: #888888;"> * @param request servlet request</span>
<span style="color: #888888;"> * @param response servlet response</span>
<span style="color: #888888;"> * @throws ServletException if a servlet-specific error occurs</span>
<span style="color: #888888;"> * @throws IOException if an I/O error occurs</span>
<span style="color: #888888;"> */</span>
<span style="color: #555555; font-weight: bold;">@Override</span>
<span style="color: #008800; font-weight: bold;">protected</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">doGet</span><span style="color: #333333;">(</span>HttpServletRequest request<span style="color: #333333;">,</span> HttpServletResponse response<span style="color: #333333;">)</span>
<span style="color: #008800; font-weight: bold;">throws</span> ServletException<span style="color: #333333;">,</span> IOException <span style="color: #333333;">{</span>
processRequest<span style="color: #333333;">(</span>request<span style="color: #333333;">,</span> response<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #888888;">/**</span>
<span style="color: #888888;"> * Handles the HTTP <code>POST</code> method.</span>
<span style="color: #888888;"> *</span>
<span style="color: #888888;"> * @param request servlet request</span>
<span style="color: #888888;"> * @param response servlet response</span>
<span style="color: #888888;"> * @throws ServletException if a servlet-specific error occurs</span>
<span style="color: #888888;"> * @throws IOException if an I/O error occurs</span>
<span style="color: #888888;"> */</span>
<span style="color: #555555; font-weight: bold;">@Override</span>
<span style="color: #008800; font-weight: bold;">protected</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">doPost</span><span style="color: #333333;">(</span>HttpServletRequest request<span style="color: #333333;">,</span> HttpServletResponse response<span style="color: #333333;">)</span>
<span style="color: #008800; font-weight: bold;">throws</span> ServletException<span style="color: #333333;">,</span> IOException <span style="color: #333333;">{</span>
processRequest<span style="color: #333333;">(</span>request<span style="color: #333333;">,</span> response<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #888888;">/**</span>
<span style="color: #888888;"> * Returns a short description of the servlet.</span>
<span style="color: #888888;"> *</span>
<span style="color: #888888;"> * @return a String containing servlet description</span>
<span style="color: #888888;"> */</span>
<span style="color: #555555; font-weight: bold;">@Override</span>
<span style="color: #008800; font-weight: bold;">public</span> String <span style="color: #0066bb; font-weight: bold;">getServletInfo</span><span style="color: #333333;">()</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="background-color: #fff0f0;">"Short description"</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span><span style="color: #888888;">// </editor-fold></span>
<span style="color: #333333;">}</span>
</pre>
</div>
<br />
<br />
參考資料來源:
<br />
<br />
<a href="https://gist.github.com/viralpatel/7007662">https://gist.github.com/viralpatel/7007662</a>金石微開http://www.blogger.com/profile/13160756791496033950noreply@blogger.com0