{"id":6520,"date":"2019-12-08T10:57:36","date_gmt":"2019-12-08T02:57:36","guid":{"rendered":"https:\/\/blog.hoyo.idv.tw\/?p=6520"},"modified":"2023-04-14T09:16:06","modified_gmt":"2023-04-14T01:16:06","slug":"esp8266-%e6%87%89%e7%94%a8%e4%b8%80%ef%bc%9a%e6%99%ba%e8%83%bd%e6%8f%92%e5%ba%a7-7-ssl-%e9%80%9a%e8%a8%8a%e5%8a%a0%e5%af%86","status":"publish","type":"post","link":"https:\/\/blog.hoyo.idv.tw\/?p=6520","title":{"rendered":"ESP8266 \u61c9\u7528\u4e00\uff1a\u667a\u80fd\u63d2\u5ea7 .7 SSL \u901a\u8a0a\u52a0\u5bc6"},"content":{"rendered":"<h2>\u5b98\u65b9\u7bc4\u4f8b<\/h2>\n<ul>\n<li><a id=\"721fd3a11bead83a1761645b2ef560c6-aa74b40b9c8f813620f8008c109695b995118261\" class=\"js-navigation-open\" title=\"client-secure-examples.rst\" href=\"https:\/\/github.com\/esp8266\/Arduino\/blob\/master\/doc\/esp8266wifi\/client-secure-examples.rst\" target=\"_blank\" rel=\"noopener\">client-secure-examples.rst<\/a> (\u7db2\u5740\u5982\u679c\u63db\u4e86\u8acb\u81ea\u884c\u5230 GitHub Repositories \u5c0b\u627e)<\/li>\n<\/ul>\n<p>\u5728\u5beb\u9019\u7bc7\u7684\u6642\u5019 (2019\/12) \u53ef\u4ee5\u67e5\u5230\u6307\u7d0b\u6191\u8b49\u5df2\u7d93\u548c\u7bc4\u4f8b\u7db2\u7ad9 api.github.com \u4e0d\u540c\uff0c\u5982\u679c\u6c92\u6709 OTA \u6a5f\u5236\u66f4\u65b0 SSL \u6307\u7d0b\u6191\u8b49\u5c31\u662f\u4e00\u500b\u5927\u554f\u984c\uff0c\u6240\u4ee5 Hoyo \u4f7f\u7528\u81ea\u5df1\u767c\u6191\u8b49\u7684\u65b9\u5f0f\u89e3\u6c7a\uff0c\u56e0\u70ba ESP8266 \u4e26\u4e0d\u6703\u50cf\u700f\u89bd\u5668\u4e00\u6a23\u5be9\u6838\u767c\u884c\u55ae\u4f4d\u3002<\/p>\n<p>--<\/p>\n<h2>\u81ea\u5df1\u767c\u6191\u8b49<\/h2>\n<ul>\n<li><a href=\"https:\/\/blog.hoyo.idv.tw\/?p=3719\" target=\"_blank\" rel=\"noopener\">CentOS 6 \u5b89\u88dd Apache SSL (\u81ea\u5df1\u767c\u6191\u8b49\u7d66\u81ea\u5df1)<\/a><\/li>\n<\/ul>\n<p>\u6839\u64da\u81ea\u5df1\u7684\u7db2\u7ad9\u767c\u884c\u4e00\u500b\u8d85\u4e45\u7684\u6191\u8b49\u7d66 ESP8266 \u4f7f\u7528\uff0cHoyo \u9019\u88e1\u793a\u7bc4\u7684\u662f\u4e00\u500b\u6975\u7aef\u7684\u4f8b\u5b50<\/p>\n<p><a href=\"https:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2019\/12\/esp8266SSL.png\" data-rel=\"lightbox-image-0\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" class=\"alignnone size-medium wp-image-6551\" src=\"https:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2019\/12\/esp8266SSL-300x241.png\" alt=\"\" width=\"300\" height=\"241\" srcset=\"https:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2019\/12\/esp8266SSL-300x241.png 300w, https:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2019\/12\/esp8266SSL-373x300.png 373w, https:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2019\/12\/esp8266SSL.png 432w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>\u5982\u6b64\u5373\u53ef\u4f7f\u7528<\/p>\n<pre class=\"lang:default decode:true \">#include &lt;ESP8266WiFi.h&gt;\r\n#include &lt;WiFiClientSecure.h&gt;\r\n\r\nconst char* ssid = \"ssid name\";\r\nconst char* password = \"ssid password\";\r\n\r\n\/\/ Socket Server\r\nconst char* host = \"esp8266.hoyo.idv.tw\";\r\nconst int port = 3003;\r\n\r\n\/\/ Use web browser to view and copy SHA1 fingerprint of the certificate\r\nconst char fingerprint[] PROGMEM = \"24 42 DB E8 31 4E 1E C4 EB 4D 78 B4 EB 74 D0 D1 F0 2D 96 44\";\r\n\r\n\/\/ Use WiFiClientSecure class to create TLS connection\r\nWiFiClientSecure client;\r\n\r\nvoid(* resetFunc) (void) = 0;\r\n\r\nvoid setup() {\r\n  Serial.begin(115200);\r\n  \r\n  WiFi.mode(WIFI_STA);\r\n  WiFi.begin(ssid, password);\r\n  while (WiFi.status() != WL_CONNECTED) {\r\n    delay(500);\r\n    Serial.println(\".\");\r\n  }\r\n  delay(500);\r\n\r\n  Serial.printf(\"Using fingerprint '%s'\\n\", fingerprint);\r\n  client.setFingerprint(fingerprint);\r\n}\r\n\r\n\/\/\r\nvoid loop() {\r\n\r\n  \/\/\r\n  if (!client.connected()) {\r\n    client.connect(host, port);\r\n    Serial.println(\"connected\");\r\n  }\r\n}<\/pre>\n<p>--<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p class=\"pvc_stats all \" data-element-id=\"6520\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> &nbsp;2,766&nbsp;total views<\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u5b98\u65b9\u7bc4\u4f8b client-sec...<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p class=\"pvc_stats all \" data-element-id=\"6520\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> &nbsp;2,766&nbsp;total views<\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[273,306,272],"tags":[275,331],"_links":{"self":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/6520"}],"collection":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6520"}],"version-history":[{"count":5,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/6520\/revisions"}],"predecessor-version":[{"id":6553,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/6520\/revisions\/6553"}],"wp:attachment":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6520"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6520"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6520"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}