Node-RED 우노빅보드 스마트팜/우노빅보드와 Node-RED 연동
ESP8266 연결 & 이더넷 동작 테스트
ZEROWIN.ART
2020. 5. 27. 13:38
728x90
우노빅보드 디지털핀 2번, 3번과 ESP8266 RX, TX를 연결합니다.
소프트웨어 시리얼을 이용하여 ESP8266을 사용합니다.
#include <SoftwareSerial.h>
#define DEBUG true
#define RXPIN 3
#define TXPIN 2
SoftwareSerial esp8266Serial(RXPIN,TXPIN); //Pin 5 & 3 of Arduino as RX and TX. Connect TX and RX of ESP8266 respectively.
String esp8266Data(String command, const int timeout, boolean debug)
{
String response = "";
esp8266Serial.print(command);
long int time = millis();
while ( (time + timeout) > millis())
{
while (esp8266Serial.available())
{
char c = esp8266Serial.read();
response += c;
}
}
if (debug)
{
Serial.print(response);
}
return response;
}
bool bConnected = false;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("ESP8266 TEST");
// set the data rate for the SoftwareSerial port
esp8266Serial.begin(9600);
esp8266Data("AT+RST\r\n", 5000, DEBUG); // Reset the ESP8266
esp8266Data("AT+CWMODE=1\r\n", 5000, DEBUG); //Set station mode Operation
esp8266Data("AT+CWJAP=\"RION_WIFI\",\"zzzzzzzz\"\r\n", 5000, DEBUG);//Enter your WiFi network's SSID and Password.
esp8266Data("AT+CIFSR\r\n", 5000, DEBUG);//You will get the IP Address of the ESP8266 from this command.
esp8266Data("AT+CIPMUX=0\r\n", 5000, DEBUG);
}
void loop() {
// put your main code here, to run repeatedly:
}
시리얼모니터를 이용하여 정상적으로 공유기에서 IP를 가져오는 것을 확인 할 수 있습니다.
우노빅보드 핑테스트를 합니다. 정상동작하는 것을 확인 할 수있습니다.