Moon Blog

IoT 융합보안 교육과정 본문

기타

IoT 융합보안 교육과정

문블룸 2022. 7. 19. 12:23

NodeMCU 핀

- GPIO : 범용 목적 핀으로 다용도 입출력 포트를 의미함

 

NodeMCU 환경 설정

- 드라이버 다운로드 : https://goo.gl/49nZPz 

 

CP210x USB to UART Bridge VCP Drivers - Silicon Labs

The CP210x USB to UART Bridge Virtual COM Port (VCP) drivers are required for device operation as a Virtual COM Port to facilitate host communication with CP210x products. These devices can also interface to a host using the direct access driver.

www.silabs.com

- 라이브러리 설치

File -> Preferences -> Addtitional Board Manager URLs : http://arduino.esp8266.com/stable/package_esp8266com_index.json 

 

NodeMCU 스케치 코드

void setup() {
 pinMode(D0, OUTPUT); // Tool -> Board -> ESP8266 Board -> NodeMCU 1.0 설정해서 D0 사용
}

void loop() {
  digitalWrite(D0,HIGH);
  delay(1000);
  digitalsWrite(D0,LOW);
  delay(1000);
}

포트 연결 : Tool -> Port -> COM숫자 

 

외부 라이브러리 연결

Ex) DHT(온습도 센서)

https://github.com/markruys/arduino-DHT

 

GitHub - markruys/arduino-DHT: Efficient DHT library for Arduino

Efficient DHT library for Arduino. Contribute to markruys/arduino-DHT development by creating an account on GitHub.

github.com

ZIP 파일 다운로드 -> 아두이노 스케치 -> 라이브러리 포함하기 -> .ZIP 라이브러리 추가

 

- 아두이노와 라즈베리파이의 서버/클라이언트 통신

아두이노 IDE 메뉴에서 예제 코드 여는 방법 : File -> Examples -> ESP8266WebServer -> HelloServer

#define STASSID에는 와이파이 아이디를 #define STAPSK에는 와이파이 비밀번호 입력

 

void ledOn() {
	digitalWrite(led, HIGH);
    server.send(200, "text/plain", "on\r\n");
}

void ledOff() {
  digitalWrite(led, LOW);
  server.send(200, "text/plain", "off\r\n");
}

server.on("/on", ledOn);
server.on("/off", ledOff);

- 라즈베리파이에서 파이썬 코드로 led 컨트롤

import requests
r = requests.get('http://192.xxx.xxx.xxx/on').text
print(r)
import requests
r = requests.get('http://192.xxx.xxx.xxx/off').text
print(r)