성태의 닷넷 이야기
홈 주인
모아 놓은 자료
프로그래밍
질문/답변
사용자 관리
사용자
메뉴
아티클
외부 아티클
유용한 코드
온라인 기능
MathJax 입력기
최근 덧글
[정성태] systemd for Developers I ; https:/...
[정성태] 엄밀히 object 타입의 인스턴스가 다른 타입으로 형변환 가능...
[정성태] 아래의 글에서 나오는 "Windows Application Pa...
[정성태] The history of calling conventions,...
[정성태] Secure and Deploy .NET Windows Form...
[정성태] Get Started with Milvus Vector DB i...
[정성태] cyberark/PipeViewer - A tool that...
[정성태] WinForms in a 64-Bit world – our st...
[정성태] 예제에서 SELECT_SQL도 내부적으로는 SqlCommand/...
[victor] SELECT_LINQ SELECT_SQL 같은 쿼리인...
글쓰기
제목
이름
암호
전자우편
HTML
홈페이지
유형
제니퍼 .NET
닷넷
COM 개체 관련
스크립트
VC++
VS.NET IDE
Windows
Team Foundation Server
디버깅 기술
오류 유형
개발 환경 구성
웹
기타
Linux
Java
DDK
Math
Phone
Graphics
사물인터넷
부모글 보이기/감추기
내용
<div style='display: inline'> <h1 style='font-family: Malgun Gothic, Consolas; font-size: 20pt; color: #006699; text-align: center; font-weight: bold'>New NodeMcu v3(ESP8266)의 https 통신</h1> <p> 지난 글에서 ESP8266의 http 통신을 알아봤는데요,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > New NodeMcu v3(ESP8266)의 http 통신 ; <a target='tab' href='http://www.sysnet.pe.kr/2/0/11762'>http://www.sysnet.pe.kr/2/0/11762</a> </pre> <br /> 근래에는 http 통신보다는, 보안 상의 이유로 https 통신이 더 현실적으로 사용할만합니다. 그렇다면, ESP8266도 https 통신을 지원할까요? 검색해 보니 다음의 글이 나옵니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Is there any support for HTTPS (SSL) in esp8266? ; <a target='tab' href='https://github.com/esp8266/Arduino/issues/2733'>https://github.com/esp8266/Arduino/issues/2733</a> </pre> <br /> 내용을 보면, 불안정하다는 의견이 중간에 나오다가 마지막 즈음에 문제가 되었던 axTLS보다 더 나은 "BearSSL" 라이브러리로 바꿨다고 합니다. 실제로 Arduino Library Manager로부터 설치하는 "ESP8266WiFi"의 소스 코드를 보면,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Arduino / libraries / ESP8266WiFi / src / ; <a target='tab' href='https://github.com/esp8266/Arduino/tree/master/libraries/ESP8266WiFi/src'>https://github.com/esp8266/Arduino/tree/master/libraries/ESP8266WiFi/src</a> </pre> <br /> BearSSLHelpers.h 등의 파일이 있는 걸로 봤을 때 현재 적용된 것이 맞는 것 같습니다. 그렇다면 기존 작성했던 http 통신 소스 코드를 어떻게 바꿔야 할까요? 이게 좀 ^^ 반가운데요, 기존 http 통신 코드에서 바꿔야 할 부분은 오직 포트 번호와 사용하는 클래스 이름만 변경하는 정도입니다.<br /> <br /> 다음의 코드를 통해 지난번 http 소스 코드와 비교해 바뀐 부분을 (굵은 글씨체로 바꿨으니) 한눈에 확인할 수 있습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > #include <ESP8266WiFi.h> #include <ESP8266WiFiAP.h> #include <ESP8266WiFiGeneric.h> #include <ESP8266WiFiMulti.h> #include <ESP8266WiFiScan.h> #include <ESP8266WiFiSTA.h> #include <ESP8266WiFiType.h> #include <WiFiClient.h> #include <WiFiClientSecure.h> #include <WiFiServer.h> #include <WiFiServerSecure.h> #include <WiFiUdp.h> const char *ssid = "...무선 ssdi..."; const char *password = "...무선 password..."; int _buildLedPin = 2; void setup() { Serial.begin(115200); delay(10); Serial.printf("%d: Connecting to %d\n", millis(), ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(1000); Serial.print("."); } Serial.printf("\n%d: WiFi connected: %s\n", millis(), WiFi.localIP().toString().c_str()); pinMode(_buildLedPin, OUTPUT); } void loop() { <span style='color: blue; font-weight: bold'>WiFiClientSecure</span> client; String host = "www.naver.com"; bool connected = client.connect(host, <span style='color: blue; font-weight: bold'>443</span>); Serial.printf("%d: Connected - %d\n", millis(), connected); do { if (connected == false) { break; } client.print(String("GET /") + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "Connection: close\r\n" + "\r\n"); int readBytes = 0; while (client.connected() == 1) { if (client.available()) { // 아래의 코드 영역만 원하는 용도에 맞게 재구성 String line = client.readStringUntil('\n'); readBytes += line.length(); } } Serial.printf("%d: # of recv bytes: %d\n", millis(), readBytes); Blink(2000); } while (false); client.stop(); } void Blink(int ledOnTime) { digitalWrite(_buildLedPin, LOW); delay(ledOnTime); digitalWrite(_buildLedPin, HIGH); } </pre> <br /> 한 가지 주의할 점은, 어쨌든 암호화 통신은 많은 계산량을 요구하기 때문에 이전보다 발열이 좀 더 생겼는지 잘 확인하셔야 합니다. (저도 이렇게 작은 기기들은 업무적으로 사용해 본 적은 없어서 확실하게 언급할 수가 없군요. ^^)<br /> </p><br /> <br /><hr /><span style='color: Maroon'>[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]</span> </div>
첨부파일
스팸 방지용 인증 번호
1142
(왼쪽의 숫자를 입력해야 합니다.)